· 7 years ago · Oct 28, 2018, 05:24 PM
1local player = game.Players.LocalPlayer
2local rEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent") -- IT'S COOLER WITH CAPS!!!
3local rFunc = game.ReplicatedStorage:WaitForChild("RemoteFunction") -- THE COOLEST!!!
4local ui = script.Parent
5local sidebar = ui:WaitForChild("SideBar")
6local introui = ui:WaitForChild("Intro")
7introui.Visible = true
8local asset = "http://www.roblox.com/asset/?id="
9local playerData
10
11local modules = require(game.ReplicatedStorage.ModuleHandler)
12modules.poll()
13local monsters = modules.require("monsters")
14local skills = modules.require("skills")
15local monstermeta = modules.require("monstermetadata")
16local statscales = modules.require("scaledstats")
17local rankranking = modules.require("rankranking")
18local ridemonster = modules.require("ridemonster")
19local settings = modules.require("gamesettings")
20
21-- Legacy Modules
22local movelist = modules.require("movelist")
23local musiclist = modules.require("musiclist")
24local sfxlist = modules.require("sfxlist")
25
26-- Kit Modules
27local ukit = modules.require("utilitykit")
28local dict = modules.require("dictionarykit")
29local tekkit = modules.require("tweenkit")
30local screenkit = modules.require("screenspace")
31local pk = modules.require("particlekit")
32local animkit = modules.require("animkit")
33local cas = modules.require("inputkit")
34
35-- important values
36local controls = cas.Controls
37local font = settings.Font
38
39function GenerateMonster(name, level) -- name As String
40 local monster = monsters[name]
41 if not monster then print("Monster ".. name .." does not exist!") return end
42 local character = {}
43 for i,v in pairs(monster) do
44 character[i] = v
45 end
46 for i,v in pairs(monstermeta) do
47 character[i] = v
48 end
49 character.Name = name
50 character.Level = level
51 character.Infusion = math.floor(level/20)*(10-rankranking[character.Rank])
52 character.Potency = math.min(1,0.4 + math.random()/10 + math.log10(1+ character.Infusion/20))
53 for i,v in pairs(statscales) do
54 local Potency = character.Potency + character.SynthesisPotency[v]
55 character[v] = math.floor(character[v] * Potency/100 * character.Level)
56 end
57 for i,v in pairs(character) do
58 print(i,v)
59 end
60 return character
61end
62
63
64local bgui = ui.Battle
65local vflash = ui.VisualFlash
66function visualFlash()
67 vflash.Visible = true
68 local blur = Instance.new("BlurEffect",game.Lighting)
69 for i=1,24 do
70 vflash.BackgroundTransparency = i/24
71 blur.Size = 25-i
72 wait()
73 end
74 blur:Destroy()
75 vflash.Visible = false
76end
77local mouse = player:GetMouse()
78local tf = ui.ToolTipFrame
79local imgf = ui.ToolTipImage
80function UpdateToolTipLocation()
81 local lowerHalf = mouse.Y>mouse.ViewSizeY/2
82 if lowerHalf then -- moves it above the mouse
83 tf.Position = UDim2.new(0,mouse.X + 1,0, mouse.Y - tf.Size.Y.Offset,0)
84 else -- otherwise, rests under the mouse
85 tf.Position = UDim2.new(0,mouse.X + 1,0, mouse.Y + 25,0)
86 end
87end
88mouse.Move:Connect(UpdateToolTipLocation)
89function ToolTip(text,title)
90 tf.Information.Text = text
91 tf.Visible = true
92 if title then
93 tf.Title.Text = title
94 tf.Title.Visible = true
95 tf.Information.Size = UDim2.new(1,0,0.8,0)
96 tf.Information.Position = UDim2.new(0,0,0.2,0)
97 else
98 tf.Title.Visible = false
99 tf.Information.Size = UDim2.new(1,0,1,0)
100 tf.Information.Position = UDim2.new(0,0,0,0)
101 end
102end
103function CloseTip()
104 tf.Visible = false
105end
106
107function AttachHint(button,text,title)
108 title = title or button.Text
109 button.MouseEnter:Connect(function()
110 ToolTip(text,title)
111 end)
112 button.MouseLeave:Connect(function()
113 CloseTip()
114 end)
115 button.AncestryChanged:Connect(function()
116 CloseTip()
117 end)
118end
119
120
121local actionCancel = false
122--
123local mouseState = ""
124function ChangeMouseState(state)
125 mouseState = state
126-- imgf.Visible = true
127-- if string.sub(state,1,6) == "Target" then
128-- imgf.Image = "rbxassetid://869729490"
129-- elseif string.sub(state,1,6) == "Attack" then
130-- imgf.Image = "rbxassetid://869721783"
131-- elseif state == "ItemTarget" then
132-- imgf.Image = "rbxassetid://869721682"
133-- else
134-- imgf.Visible = false
135-- end
136end
137
138local hint = ui.Hint
139function CloseHint()
140 hint.Visible = false
141end
142function DisplayHint(text,length)
143 hint.Visible = true
144 hint.Text = text
145 if length then
146 spawn(function()
147 wait(length)
148 CloseHint()
149 end)
150 end
151end
152
153local actions = bgui.Actions
154function LoadOptions(buttons)
155 actions:ClearAllChildren()
156 local btn = {}
157 local height = 50
158 bgui.Actions.CanvasSize = UDim2.new(0,0,0,height * #buttons)
159 for i,name in pairs(buttons) do
160 local foo = Instance.new("TextButton",bgui.Actions)
161 foo.Size = UDim2.new(1,0,0,height)
162 foo.Position = UDim2.new(0,0,0,(i-1)*height)
163 foo.Text = name
164 foo.Name = name
165 foo.BorderSizePixel = 0
166 foo.BackgroundTransparency = 0.5
167 foo.BackgroundColor3 = Color3.new(0,0,0)
168 foo.TextColor3 = Color3.new(1,1,1)
169 foo.TextXAlignment = Enum.TextXAlignment.Left
170 foo.TextYAlignment = Enum.TextYAlignment.Bottom
171 foo.TextScaled = true
172 foo.Font = font
173 btn[name] = foo
174 end
175 return btn
176end
177
178--[[
179 Camera Modes:
180
181 Birds Eye: FIELD + 10Y CFRAME = POS,POS-1Y
182 FACINGMONSTER: FIELD.MONSTER.LOOKVECTOR CFRAME = POS - LOOKVECTOR
183--]]
184local currentmode = ""
185local camerakey = 0
186local camera = workspace.CurrentCamera
187function ShiftCamera(mode,target)
188 camera.CameraType = Enum.CameraType.Scriptable
189 currentmode = mode
190 camerakey = camerakey + 1
191 local unique = camerakey
192 if mode == "RandomIdle" then -- decision making camera modes
193 local modes = {"CircleSky","CircleGround"}
194 mode = modes[math.random(#modes)]
195 end
196 spawn(function()
197 if mode == "CircleSky" then --birdseye circling
198 local angle = 0
199 local position = target.Position + Vector3.new(0,50,0)
200 while unique == camerakey do
201 camera.CoordinateFrame = CFrame.new(position,position-Vector3.new(0,1,0)) * CFrame.Angles(0,0,math.rad(angle))
202 angle = angle + 2
203 wait()
204 end
205 elseif mode == "CircleGround" then
206 local angle = 0
207 local position = target.Position + Vector3.new(0,7,0)
208 local face = target.CFrame.lookVector
209 while unique == camerakey do
210 camera.CoordinateFrame = CFrame.new(position,position + face) * CFrame.Angles(0,math.rad(angle),0)
211 angle = angle + 0.75
212 wait()
213 end
214 elseif mode == "StandardSky" then
215 local position = target.Position + Vector3.new(0,50,0)
216 while unique == camerakey do
217 camera.CoordinateFrame = CFrame.new(position,position-Vector3.new(0,1,0))
218 wait()
219 end
220 elseif mode == "ToDirectFace" then
221 local face = target.CFrame.lookVector
222 local range = 5 + target.Size.Z*1.25
223 local start = camera.CoordinateFrame
224 local cframe = CFrame.new(target.Position + face*(range+1),target.Position + face*range)
225 for i=1,10 do
226 camera.CoordinateFrame = start:lerp(cframe,i/10)
227 wait()
228 end
229 elseif mode == "ToFace" then
230 local face = target.CFrame.lookVector
231 local origin = target.Position + Vector3.new(0,7,0)
232 local cframe = CFrame.new(origin,origin + face)
233 local start = camera.CoordinateFrame
234 for i=1,10 do
235 camera.CoordinateFrame = start:lerp(cframe,i/10)
236 wait()
237 end
238 elseif mode == "ToBack" then
239 local face = -target.CFrame.lookVector
240 local origin = target.Position + Vector3.new(0,7,0)
241 local cframe = CFrame.new(origin,origin + face)
242 local start = camera.CoordinateFrame
243 for i=1,10 do
244 camera.CoordinateFrame = start:lerp(cframe,i/10)
245 wait()
246 end
247 elseif mode == "Face" then
248 local face = target.CFrame.lookVector
249 local range = 5 + target.Size.Z*1.25
250 while unique == camerakey do
251 camera.CoordinateFrame = CFrame.new(target.Position + face*(range+1),target.Position + face*range)
252 wait()
253 end
254 elseif mode == "Reset" then
255 camera.CameraType = Enum.CameraType.Custom
256 camera.CameraSubject = character.Humanoid
257 end
258 end)
259end
260
261function StartTurn(init)
262 actions:ClearAllChildren()
263 ChangeMouseState("inactive")
264 DisplayHint("Starting turn!")
265 ShiftCamera("StandardSky",init.Field.PrimaryPart)
266 actionCancel = true
267 local scouting
268 local fleeing
269 if #init.Instructions>0 then
270 local cmd = init.Instructions[1][1]
271 if cmd == "Scout" then
272 scouting = init.Instructions[1][2][1]
273 elseif cmd == "Flee" then
274 fleeing = true
275 end
276 end
277
278 local function battleCleanup()
279 bgui.Visible = false
280 bgui.Scout.Visible = false
281 spawn(visualFlash)
282 ShiftCamera("Reset")
283 cas:ClearAllChildren()
284 CloseHint()
285 ui.PartyChange.Visible = true
286 sidebar.Visible = true
287 init.Active = false
288 init.Field = {}
289 spawn(function()
290 ChangeSong(musiclist["Sandy Theme"],{TimePosition = 0, Steps = 60})
291 end)
292 playerData = rFunc:InvokeServer("CompletedBattle",init)
293 end
294
295 local field = workspace.Battles[init.Battle.Key]
296 local superindex = {}
297 -- SuperIndex holds the physicalmonster from key and what team the mon is on.
298 local speedlist = {}
299 for key,monster in pairs(init.Player.Party) do
300 table.insert(speedlist,monster.Speed.."X"..monster.Key)
301 end
302 for key,monster in pairs(init.Enemy.Party) do
303 table.insert(speedlist,monster.Speed.."X"..monster.Key)
304 end
305 speedlist = dict.Inverse(dict.BubbleSort(speedlist))
306 local initlist = {}
307 for _,val in pairs(speedlist) do
308 for key,monster in pairs(init.Player.Party) do
309 if string.find(val,monster.Key) then
310 monster.Enemy = false
311 if not (scouting or fleeing) then -- Ignore player moves if they attempt to scout.
312 table.insert(initlist,monster)
313 end
314 superindex[monster.Key] = {
315 Physical = field.Player[monster.Key],
316 Monster = monster, -- pseudo-paradox
317 Key = monster.Key, -- paradoxical
318 Team = "Player",
319 }
320 --print(monster.Name,monster.Speed)
321 end
322 end
323 for key,monster in pairs(init.Enemy.Party) do
324 if string.find(val,monster.Key) then
325 monster.Enemy = true
326 table.insert(initlist,monster)
327 superindex[monster.Key] = {
328 Physical = field.Enemy[monster.Key],
329 Monster = monster, -- pseudo-paradox
330 Key = monster.Key, -- paradoxical
331 Team = "Enemy",
332 }
333 --print(monster.Name,monster.Speed)
334 end
335 end
336 end
337 wait(1)
338 local function inflictDamage(attacker,move,defender,_index)
339 -- bgui[team][monsterkey][_type].Bar
340 -- _index = superindex[monsterkey]
341 local atk = attacker.Damage*move.Damage
342 local def = defender.Defense
343 -- classic formula
344 -- dmg = atk/2-def/4 +/- atk/2-def/4 /16
345 --local root = math.max(0,atk*0.1*math.log10(10 + atk - def/2) + atk*(atk/def)/3)
346-- local min = root*0.6
347-- local max = root*0.8+1
348-- local dmg = math.floor(math.random(min,max))
349 local root = ((atk-def/2.25) + (atk-def)*(math.random(2)==1 and 1 or -1)/16)/2
350 local dmg = math.floor(math.max(0, root + math.random(0,1)))
351
352 pk.Damage(dmg,_index.Physical.RootPart)
353 defender.PresentHealth = math.max(0,defender.PresentHealth-dmg)
354
355 if bgui:findFirstChild(_index.Team) then
356 local main = bgui[_index.Team][_index.Key]
357 local label = main.Bars.Health
358 local bar = label.Bar
359 label.Text = defender.PresentHealth
360 bar:TweenSize(UDim2.new(defender.PresentHealth/defender.Health,-10,1,-10))
361 end
362
363 if defender.PresentHealth == 0 then
364 local team = init[_index.Team].Party
365 for index,dta in pairs(team) do
366 local saved = false
367 if dta.Key == _index.Key then -- finds its key, removes itself from table
368 local monster = table.remove(team,index)
369 if not saved then
370 saved = true
371 table.insert(init[_index.Team].Dead, monster) -- moves the moster to the "Dead" team
372 end
373 end
374 end
375 local emitter = pk.Emit("Destroyed",_index.Physical.RootPart)
376 spawn(function()
377 for i=1,40 do
378 emitter.Transparency = NumberSequence.new(i/40)
379 wait()
380 end
381 _index.Physical:Destroy()
382 end)
383
384 do --local function playAnim(physicalmonster,name,hold)
385 local physicalmonster = _index.Physical
386 local name = "Death"
387 local animations = physicalmonster.Animations
388 local main = animations:FindFirstChild(name) or animations:FindFirstChild("Attack")
389 local anim = animkit.Play(physicalmonster.AnimationController,main,{})
390 if anim then
391 wait(anim.Length)
392 return anim
393 else
394 print(name,"not found")
395 end
396 end
397
398 --main.Icon.MouseButton1Click:Disconnect() -- replace this with the [if atk is zing then allow cmd] stuff
399 end
400 end
401 local function tweenSize(obj,x)
402 obj:TweenSize(UDim2.new(x,0,1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.7, true)
403 end
404 -- do moves!
405 if fleeing then
406 DisplayHint("Attempting to escape!")
407 ShiftCamera("Face",character.Head)
408 wait(1.5)
409 ShiftCamera("CircleGround",field.PrimaryPart)
410 if math.random(2)==1 then
411 DisplayHint("Escaped!")
412 wait(4)
413 battleCleanup()
414 return
415 else
416 DisplayHint("The enemies blocked the path!")
417 wait(4)
418 end
419 elseif scouting then -- if the first value is to scout
420 DisplayHint("Scouting!")
421 local chance = 0
422 local scouted = false
423
424 local _index = superindex[scouting]
425 local emodel = _index.Physical
426 local monster = _index.Monster
427 local def = monster.Defense
428 local hp = monster.Health
429 local siz = monster.BaseSize
430 local lvl = monster.Level
431
432 local label = bgui.Scout.Label
433 local bar = bgui.Scout.Frame.Bar
434 bar.Size = UDim2.new(0,0,1,0)
435 label.Text = chance.."%"
436 bgui.Scout.Visible = true
437 game.Lighting.TimeOfDay = 0
438 game.Lighting.FogColor = Color3.new(0,0,0)
439 local bloom = Instance.new("BloomEffect",game.Lighting)
440 spawn(function()
441 for i=1,30 do
442 game.Lighting.FogEnd = ukit.lerp(1000,50,i/30)
443 wait()
444 end
445 end)
446 for _,data in pairs(init.Player.Party) do
447 local part = superindex[data.Key].Physical.RootPart
448 pk.Emit("Cast",part,1)
449 ShiftCamera("Face",part)
450 wait(0.5)
451 end
452
453 ShiftCamera("Face",character.Head)
454 wait(1)
455 local function playAnim(physicalmonster,name,hold)
456 local animations = physicalmonster.Animations
457 local main = animations:FindFirstChild(name) or animations:FindFirstChild("Attack")
458 local anim = animkit.Play(physicalmonster.AnimationController,main,{})
459 if anim then
460 if hold then
461 print("Waiting: ",anim.Length)
462 wait(anim.Length)
463 end
464 return anim
465 else
466 print(name,"not found")
467 end
468 end
469
470 for _,data in pairs(init.Player.Party) do
471 local physicalmonster = superindex[data.Key].Physical
472 DisplayHint(data.Nickname .." is attempting to scout!")
473 ShiftCamera("Face",physicalmonster.RootPart)
474 local anm = playAnim(physicalmonster,"Attack")
475 pk.Emit("Cast",physicalmonster.RootPart,1)
476 wait(0.5)
477
478 ShiftCamera("Face",emodel.RootPart)
479 playAnim(emodel,"Hurt")
480 pk.Emit("Hurt",emodel.RootPart,1)
481 -- DEAL DAMAGE
482 local atk = data.Damage
483 local root = atk/((monster.BaseSize-data.BaseSize)*2 + math.max(0,7 - rankranking[monster.Rank]) + math.max(0,2*math.log10(def-atk*0.85)))
484 local root = math.max(math.abs(root),0)*2
485 local newchance = math.min(100, chance+root)
486 tweenSize(bar,newchance/100)
487 for i=1,15 do
488 label.Text = (math.floor(ukit.lerp(chance*10,newchance*10,i/15))/10).."%"
489 wait()
490 end
491 chance = newchance
492 if chance >= 100 then
493 break
494 end
495 wait(1)
496 end
497 DisplayHint(_index.Monster.Nickname .." is deciding...")
498 ShiftCamera("Face",emodel.RootPart)
499 wait(3 - chance/100)
500 local roll = math.random(100)
501 bloom:Destroy()
502 game.Lighting.FogEnd = 100000
503 game.Lighting.TimeOfDay = 12
504 if roll<=chance then
505 DisplayHint(_index.Monster.Nickname .." has been scouted!")
506 ShiftCamera("CircleGround",field.PrimaryPart)
507 ChangeSong(musiclist["Battle Victory"],{TimePosition = 0, Steps = 60})
508 wait(4)
509 init.Player.Scouted = _index.Monster
510 battleCleanup()
511 return
512 else
513 DisplayHint("Scouting was a failure...")
514 bgui.Scout.Visible = false
515 ShiftCamera("CircleGround",field.PrimaryPart)
516 wait(4)
517 end
518 end
519
520 print("Entered the fight-zone")
521 tekkit:TweenPosition(bgui.Operations,UDim2.new(0.25, 0, 1, 0))
522 tekkit:TweenPosition(bgui.Player,UDim2.new(0,0,0.3,0))
523 print(#initlist)
524 for _,data in pairs(initlist) do
525 local command = init.Instructions[data.Key]
526 if type(command)=="table" then
527 local move = movelist[command[1]]
528 local targets = command[2]
529 local alivetargets = {}
530 for _,key in pairs(targets) do
531 if not superindex[key].Physical:findFirstChild("RootPart") then
532 else
533 table.insert(alivetargets,key)
534 end
535 end
536 if #alivetargets==0 then
537 command = false
538 else
539 command[2] = alivetargets
540 end
541 end
542
543 local partymissing = false
544 if not command then
545 local tab = data.Enemy and init.Player.Party or init.Enemy.Party
546 if #tab>0 then
547 local chosen = tab[math.random(#tab)]
548 if type(chosen)=="string" then
549 command = {"Attack",{chosen}}
550 else
551 command = {"Attack",{chosen.Key}}
552 end
553 else
554 partymissing = true
555 end
556 end
557 if partymissing then
558 print("Skipped Move: Enemy party was dead.")
559 elseif data.PresentHealth == 0 then
560 print("Skipped Move: Monster was dead.")
561 else
562 print(command,command[1])
563 local move = movelist[command[1]]
564 local targets = command[2]
565 local physicalmonster = superindex[data.Key].Physical
566 local function playAnim(name,hold,overide)
567 local physicalmonster = overide or physicalmonster
568 local anim = physicalmonster.Animations:findFirstChild(name) or physicalmonster.Animations:findFirstChild("Attack")
569 if anim then
570 local anm = physicalmonster.AnimationController:LoadAnimation(anim)
571 anm:Play()
572 if hold then
573 print("Waiting: ",anm.Length)
574 wait(anm.Length)
575 end
576 return anm
577 else
578 print(name,"not found")
579 end
580 end
581
582 if command[1] == "Attack" then
583 DisplayHint(data.Nickname .." attacks!")
584 ShiftCamera("Face",physicalmonster.RootPart)
585 local anm = playAnim("Attack")
586 pk.Emit("Cast",physicalmonster.RootPart,1)
587 wait(0.5)
588
589 for _,emon in pairs(targets) do
590 print(emon)
591 local _index = superindex[emon]
592 local physical = _index.Physical
593 ShiftCamera("Face",physical.RootPart)
594 playAnim("Hurt",false,physical)
595 pk.Emit("Hurt",physical.RootPart,1)
596 inflictDamage(data,move,_index.Monster,_index)
597 wait(1.5)
598 end
599 elseif command[1] == "Defend" then
600 DisplayHint(data.Nickname .." defends!")
601 ShiftCamera("Face",superindex[data.Key].Physical.RootPart)
602 wait(1)
603 elseif move.DamageType == "Wisdom" then
604 DisplayHint(data.Nickname .." casts "..command[1].."!")
605 ShiftCamera("Face",superindex[data.Key].Physical.RootPart)
606 playAnim("Cast",true)
607 for _,emon in pairs(targets) do
608 local _index = superindex[emon]
609 local physical = _index.Physical
610 ShiftCamera("Face",physical.RootPart)
611 playAnim("Hurt",false,physical)
612 pk.Emit("Hurt",physical.RootPart,1)
613 inflictDamage(data,move,_index.Monster,_index)
614 wait(1.5)
615 end
616 elseif move.DamageType == "Attack" then
617 DisplayHint(data.Nickname .." attacks with "..command[1].."!")
618 ShiftCamera("Face",superindex[data.Key].Physical.RootPart)
619 playAnim("Attack",true)
620 for _,emon in pairs(targets) do
621 local _index = superindex[emon]
622 local physical = _index.Physical
623 ShiftCamera("Face",physical.RootPart)
624 playAnim("Hurt",false,physical)
625 pk.Emit("Hurt",physical.RootPart,1)
626 inflictDamage(data,move,_index.Monster,_index)
627 wait(1.5)
628 end
629 end
630
631 -- move to enemy
632 -- deal damage
633 -- check if monster dead -> destroy monster/update gui
634 -- check if party dead -> award exp/terminate battle
635 wait(1)
636 end
637 end
638 local playeralive = false
639 local enemyalive = false
640 print("Player Party:")
641 for i,v in pairs(init.Player.Party) do
642 playeralive = true
643 print(i,v)
644 end
645 print("Enemy Party:")
646 for i,v in pairs(init.Enemy.Party) do
647 enemyalive = true
648 print(i,v)
649 end
650 if (not playeralive) and (not enemyalive) then
651 DisplayHint("Both teams were defeated...")
652 ShiftCamera("CircleGround",field.PrimaryPart)
653 ChangeSong(musiclist["Battle Loss"],{TimePosition = 0, Steps = 60})
654 wait(3)
655 battleCleanup()
656 return
657 elseif not playeralive then
658 DisplayHint("Your party was defeated...")
659 ShiftCamera("CircleGround",field.PrimaryPart)
660 ChangeSong(musiclist["Battle Loss"],{TimePosition = 0, Steps = 60})
661 wait(3)
662 battleCleanup()
663 return
664 elseif not enemyalive then
665 DisplayHint("Enemy team was defeated!")
666 ShiftCamera("CircleGround",field.PrimaryPart)
667 ChangeSong(musiclist["Battle Victory"],{TimePosition = 0, Steps = 60})
668 wait(2)
669 DisplayHint("Awarding EXP...")
670 local expGain = 0
671 for _,data in pairs(init.Enemy.Dead) do
672 local amount = math.abs((1+data.Level)^(data.BaseSize/4 + data.ExpScalar + data.Potency))
673 expGain = expGain + amount
674 print(amount)
675 end
676 expGain = math.floor(expGain * settings.ExpMult)
677 print("total",expGain)
678 ui.BlackScreen.Visible = true
679
680 local results = ui.MonsterResults
681 results.Label.Text = "VICTORY EXP: +"..expGain
682 results.Visible = true
683 local container = results.Container
684 container:ClearAllChildren()
685
686 bgui.Visible = false
687 spawn(visualFlash)
688 -- dead monsters don't gain exp btw :p
689
690 local monsters = {}
691 local i = 0
692 for _,data in pairs(init.Player.Party) do
693 local frame = Instance.new("Frame",container)
694 frame.Size = UDim2.new(1,0,data.BaseSize/4,0)
695 frame.Position = UDim2.new(0,0,i/4,0)
696 frame.ZIndex = container.ZIndex
697 frame.Name = data.Key
698 frame.BackgroundTransparency = 1
699 i = i + data.BaseSize
700
701 local icon = Instance.new("TextButton",frame)
702 icon.Size = UDim2.new(0.1,0,0.8,0)
703 icon.Position = UDim2.new(0.05,0,0.1,0)
704 icon.BackgroundColor = game.ReplicatedStorage.Monster[data.Name].Heart.BrickColor
705 icon.BorderSizePixel = 5
706 icon.BorderColor3 = Color3.new(1,1,1)
707 icon.Name = "Icon"
708 icon.Font = font
709 icon.Text = data.Nickname
710 icon.TextScaled = true
711 icon.TextColor3 = Color3.new(1,1,1)
712 icon.ZIndex = frame.ZIndex
713
714 local level = Instance.new("TextLabel",frame)
715 level.BackgroundTransparency = 1
716 level.Position = UDim2.new(0.15,10,0.1,0)
717 level.Size = UDim2.new(0.7,0,0.4,0)
718 level.TextScaled = true
719 level.TextXAlignment = Enum.TextXAlignment.Left
720 level.TextYAlignment = Enum.TextYAlignment.Bottom
721 level.TextColor3 = Color3.new(1,1,1)
722 level.Text = "LEVEL: (not loaded)"
723 level.Name = "Level"
724 level.ZIndex = frame.ZIndex
725
726 data.MaxExp = ukit.MaxExp(data.Level,data.ExpGrowth)
727 data.ExpGain = expGain
728
729 local exp = Instance.new("TextLabel",frame)
730 exp.BackgroundTransparency = 1
731 exp.Position = UDim2.new(0.15,10,0.5,0)
732 exp.Size = UDim2.new(0.7,0,0.4,0)
733 exp.TextScaled = true
734 exp.TextColor3 = Color3.new(1,1,1)
735 exp.TextStrokeTransparency = 0
736 exp.Text = "["..math.floor(data.Exp).."/"..math.floor(data.MaxExp).."]"
737 exp.Name = "Experience"
738 exp.ZIndex = frame.ZIndex + 2
739
740 local bar = Instance.new("Frame",exp)
741 bar.Size = UDim2.new(ukit.ExpRatio(data),0,1,0)
742 bar.BorderSizePixel = 3
743 bar.BackgroundColor3 = Color3.new(1,1,0.5)
744 bar.ZIndex = exp.ZIndex - 1
745 bar.Name = "Bar"
746
747 local undershadow = bar:Clone()
748 undershadow.Parent = exp
749 undershadow.ZIndex = exp.ZIndex - 2
750 undershadow.Name = "Bottom"
751 undershadow.BorderSizePixel = 5
752 undershadow.Size = UDim2.new(1,0,1,0)
753 undershadow.BackgroundColor3 = Color3.new(0.75,0.75,0.5)
754
755 end
756
757 local activity = false
758 local continue = false
759 local function exit()
760 continue = true
761 end
762 cas:BindAction("ExitMatch", exit, controls.Activate)
763 results.Button.MouseButton1Click:Connect(exit)
764 repeat
765 activity = false
766 for _,data in pairs(init.Player.Party) do
767 local frame = container[data.Key]
768 local level = frame.Level
769 local exp = frame.Experience
770 local expbar = exp.Bar
771 expbar.Size = UDim2.new(data.Exp/data.MaxExp,0,1,0)
772 local _xp = data.Exp
773 local _mxp = data.MaxExp
774 data.MaxExp = ukit.MaxExp(data.Level,data.ExpGrowth)
775 local missingexp = (data.MaxExp - data.Exp)
776 if ukit.ReachedLevelCap(data) then
777 data.Exp = math.min(data.MaxExp,data.Exp+data.ExpGain)
778 level.Text = "LEVEL: ".. data.Level
779 elseif data.ExpGain > 0 then
780 local overpowered = data.ExpGain>=missingexp
781 print("OVERPOWERED",overpowered)
782 if overpowered then
783 data.ExpGain = data.ExpGain - missingexp
784 data.Exp = 0
785 data.Level = data.Level + 1
786 tweenSize(expbar,1)
787 spawn(function()
788 for i=1,20 do
789 exp.Text = "["..math.floor(ukit.lerp(_xp,_mxp,i/20)).."/"..math.floor(_mxp).."]"
790 wait()
791 end
792 end)
793 else
794 print("Junior Change!")
795 data.Exp = data.Exp + data.ExpGain
796 data.ExpGain = 0
797 tweenSize(expbar,data.Exp/data.MaxExp)
798 spawn(function()
799 for i=1,20 do
800 exp.Text = "["..math.floor(ukit.lerp(_xp, data.Exp, i/20)).."/"..math.floor(data.MaxExp).."]"
801 wait()
802 end
803 end)
804 end
805 level.Text = "LEVEL: ".. data.Level
806 activity = true
807 else
808 tweenSize(expbar,data.Exp/data.MaxExp)
809 exp.Text = "["..math.floor(data.Exp).."/"..math.floor(data.MaxExp).."]"
810 end
811 end
812 for i=1,22 do
813 if continue then break end
814 wait()
815 end
816 until not activity
817 repeat
818 wait()
819 until continue
820 results:TweenPosition(UDim2.new(0.1,0,-1,-50))
821 wait(1.1)
822 ui.BlackScreen.Visible = false
823 results.Visible = false
824 results.Position = UDim2.new(0.1,0,0.2,0)
825 battleCleanup()
826 return
827 end
828 wait(1)
829 ShiftCamera("RandomIdle",init.Field.PrimaryPart)
830 actionCancel = false
831 init.Instructions = {}
832 CloseHint()
833end
834
835function VisualiseParty(container,init,enemy)
836 local team = enemy and init.Enemy.Party or init.Player.Party
837 local btn = {}
838 container:ClearAllChildren()
839 local len = 0
840 for name,data in pairs(team) do
841 len = len + data.BaseSize
842 end
843 local i = 0
844 for name,data in pairs(team) do
845 local frame = Instance.new("Frame",container)
846 frame.BackgroundTransparency = 1
847 frame.Size = UDim2.new(1,0,data.BaseSize/4,0)
848 frame.Position = UDim2.new(0,0,i/len,0)
849 frame.Name = data.Key
850 i = i + data.BaseSize
851
852 local icon = Instance.new("TextButton",frame)
853 icon.Size = UDim2.new(0.3,0,0.8,0)
854 icon.Position = UDim2.new(0.1,-5,0.1,0)
855 icon.BackgroundColor = game.ReplicatedStorage.Monster[data.Name].Heart.BrickColor
856 icon.BorderSizePixel = 5
857 icon.BorderColor3 = Color3.new(1,1,1)
858 icon.Name = "Icon"
859 icon.Font = font
860 icon.Text = data.Nickname
861 icon.TextScaled = true
862 icon.TextColor3 = Color3.new(1,1,1)
863
864 local bars = Instance.new("Frame",frame)
865 bars.Size = UDim2.new(0.5,0, 0.8 * (1.25-data.BaseSize/4),0)
866 bars.Position = UDim2.new(0.5,0,0.9-bars.Size.Y.Scale,0)
867 bars.BackgroundTransparency = 0.9
868 bars.Name = "Bars"
869
870 local contents = {{"Health",Color3.new(0.25,170/255,0.25)},{"Mana",Color3.new(.25,.25,170/255)}}
871 local refstats = {}
872 for i,tab in pairs(contents) do
873 local _type = tab[1]
874 local clr = tab[2]
875 local constraint = Instance.new("TextLabel",bars)
876 constraint.BackgroundTransparency = 1
877 constraint.Size = UDim2.new(1,0,1/#contents,0)
878 constraint.Position = UDim2.new(0,0,(i-1)/#contents,0)
879 if not data["Present".._type] then
880 data["Present".._type] = data[_type]
881 end
882 local present = data["Present".._type]
883
884 constraint.Name = _type
885 constraint.ZIndex = 2
886 constraint.Font = font
887 constraint.Text = present
888 constraint.TextScaled = true
889 constraint.TextColor3 = Color3.new(1,1,1)
890
891 local bar = Instance.new("Frame",constraint)
892 bar.Position = UDim2.new(0,5,0,5)
893 bar.BorderSizePixel = 5
894 bar.BackgroundColor3 = clr
895 bar.BorderColor3 = Color3.new(clr.r/1.5,clr.g/1.5,clr.b/1.5)
896 bar.Size = UDim2.new(present/data[_type],-10,1,-10)
897 bar.Name = "Bar"
898
899 refstats[_type] = constraint
900 end
901 refstats.Icon = icon
902 refstats.Key = data.Key
903 table.insert(btn, refstats)
904 end
905
906 return btn
907end
908
909rEvent.OnClientEvent:Connect(function(condition,...)
910 if condition == "BeginBattle" then
911 local init = ...
912 actionCancel = false
913 spawn(visualFlash)
914 ui.PartyChange.Visible = false
915 sidebar.Visible = false
916
917 -- get battlefield
918 init.Field = workspace.Battles[init.Battle.Key]
919 init.Active = true
920 ShiftCamera("RandomIdle",init.Field.PrimaryPart)
921 local cone = game.ReplicatedStorage.Models.TargetCone:Clone()
922 cone.Parent = init.Field
923
924 -- visualise party
925 local pbuttons = VisualiseParty(bgui.Player,init,false)
926 bgui.Player.Position = UDim2.new(-0.2,0,0.3,0)
927
928 local function giveMeta(t)
929 for _,data in pairs(t) do
930 for _,_type in pairs({"Health","Mana"}) do
931 if not data["Present".._type] then
932 data["Present".._type] = data[_type]
933 end
934 end
935 end
936 end
937 giveMeta(init.Player.Party)
938 giveMeta(init.Enemy.Party)
939
940 -- load buttons
941 bgui.Visible = true
942 local buttons = {"Attack","Instructions","Items","Scout","Flee"} -- "Tactics"
943 local operations = bgui.Operations
944 local moveinfo = bgui.MoveInfo
945 local s_button = operations.Selected
946 local selected = 1
947 s_button.Text = buttons[selected]
948 local function terminate_default()
949 print("nothing to destroy :c")
950 end
951 local terminate = terminate_default
952
953 local function createSelections(monsters)
954 local points = {}
955 local keys = {}
956 local inverse = false
957 local default = function()
958 print("Missing function fired...")
959 end
960 do print("getScreenPoints(monsters)") -- field.Player:GetChildren(), etc.
961 -- note player mouse.ViewSizeX
962 local len = #monsters
963 local fieldpos = init.Field.PrimaryPart.Position
964 for i,model in pairs(monsters) do
965 local pos = model.RootPart.Position
966 local mag = (fieldpos.Z-pos.Z)
967 -- it's 25 facing enemy and works fine
968 -- it's -25 facing player and works wonky
969
970 local siz = model.RootPart.Size * Vector3.new(1,0,0)
971 local key = model.Name
972 local data = {}
973 data.Min = i/len - 1/len --screenkit.WorldToScreen(pos - siz/2).X
974 data.Max = i/len --screenkit.WorldToScreen(pos + siz/2).X
975 data.Model = model
976 data.Key = key
977 data.OnFire = default
978 if mag<0 then
979 inverse = true
980 local min = data.Min
981 local max = data.Max
982 data.Min = 1-max
983 data.Max = 1-min
984 end
985 table.insert(keys,key)
986 points[key] = data
987 end
988 end
989 local selected
990 terminate()
991 local down = mouse.Button1Down:Connect(function()
992 if selected then
993 tekkit:Tween(cone,{CFrame = cone.CFrame + Vector3.new(0,50,0)})
994 points[selected].OnFire()
995 end
996 end)
997 local move = mouse.Move:Connect(function()
998 local y = mouse.Y/mouse.ViewSizeY
999 local x = mouse.X/mouse.ViewSizeX
1000 if y<0.3 or y>0.8 then
1001 selected = false
1002 return
1003 end
1004 for _,p in pairs(points) do
1005 if p.Min < x and x < p.Max then
1006 selected = p.Key
1007 local root = p.Model.RootPart
1008 local pos = root.Position + Vector3.new(0, root.Size.Y/2 + cone.Size.Y, 0)
1009 tekkit:Tween(cone,{CFrame = CFrame.new(pos)})
1010 end
1011 end
1012 end)
1013
1014 terminate = function()
1015 move:Disconnect()
1016 down:Disconnect()
1017 terminate = terminate_default
1018 end
1019 local n = 0
1020 local l = #keys
1021 local list = dict.List(points)
1022 local function activate()
1023 if selected then
1024 tekkit:Tween(cone,{CFrame = cone.CFrame + Vector3.new(0,50,0)})
1025 points[selected].OnFire()
1026 end
1027 end
1028 local function left()
1029 n = inverse and n%l + 1 or (n - 2)%l + 1
1030 local p = points[keys[n]]
1031 selected = p.Key
1032 local root = p.Model.RootPart
1033 local pos = root.Position + Vector3.new(0, root.Size.Y/2 + cone.Size.Y, 0)
1034 tekkit:Tween(cone,{CFrame = CFrame.new(pos)})
1035 end
1036 local function right()
1037 n = inverse and (n - 2)%l + 1 or n%l + 1
1038 print(keys[n])
1039 local p = points[keys[n]]
1040 selected = p.Key
1041 local root = p.Model.RootPart
1042 local pos = root.Position + Vector3.new(0, root.Size.Y/2 + cone.Size.Y, 0)
1043 tekkit:Tween(cone,{CFrame = CFrame.new(pos)})
1044 end
1045 cas:BindAction("ActionActivate", activate, controls.Activate)
1046 cas:BindAction("ArrowLeft", left, controls.Left)
1047 cas:BindAction("ArrowRight", right, controls.Right)
1048 return points
1049 end
1050
1051 local active = false
1052 local debounce = false
1053 local function DoButton()
1054 local chosen = buttons[selected]
1055 print("do cast", chosen)
1056 bgui.Actions.Visible = false
1057 if actionCancel then ChangeMouseState("inactive") return end
1058 if active then return end
1059 active = true
1060 cas:ClearAllChildren()
1061 if chosen == "Attack" then
1062 ChangeMouseState("BeginBattle")
1063 StartTurn(init)
1064 ExitButton()
1065 return
1066 end
1067
1068 if chosen == "Flee" then
1069 init.Instructions = {{"Flee",{}}} -- wipes all other actions
1070 StartTurn(init)
1071 ExitButton()
1072 return
1073 end
1074
1075 tekkit:TweenPosition(operations,UDim2.new(0.25, 0, 1, 0))
1076 cas:BindAction("ActionLeave", ExitButton, controls.Leave)
1077
1078 if chosen == "Instructions" then
1079 local points = createSelections(init.Field.Player:GetChildren())
1080 for _,p in pairs(points) do
1081 p.OnFire = function()
1082 print("fired!")
1083 local data
1084 for i,monster in pairs(init.Player.Party) do
1085 if monster.Key == p.Key then
1086 data = monster
1087 end
1088 end
1089 if data and data.PresentHealth > 0 then
1090 terminate()
1091 ShiftCamera("ToDirectFace",p.Model.RootPart)
1092 moveinfo.Visible = true
1093 local function Exit()
1094 moveinfo.Visible = false
1095 CloseHint()
1096 ExitButton()
1097 end
1098 local moves = {"Attack","Defend"}
1099 local n = 0
1100 local l = #moves
1101 local function activate()
1102 local move = moves[n]
1103 local stats = movelist[move]
1104 if stats.Range == "Single" then
1105 DisplayHint("Pick a target for ".. move .."!")
1106 local team = stats.Team
1107 if team == "Player" then
1108 ShiftCamera("ToBack",init.Field.PrimaryPart)
1109 else
1110 ShiftCamera("ToFace",init.Field.PrimaryPart)
1111 end
1112 local points = createSelections(init.Field[team]:GetChildren())
1113 for _,mdl in pairs(points) do
1114 mdl.OnFire = function()
1115 table.insert(init.Instructions, {move,{mdl.Key}})
1116 Exit()
1117 end
1118 end
1119 elseif stats.Range == "Self" then
1120 table.insert(init.Instructions, {move,{data.Key}})
1121 Exit()
1122 else -- shouldn't have annythang heeer
1123 local targets = {}
1124 table.insert(init.Instructions, {move,targets})
1125 Exit()
1126 end
1127 end
1128 local function right()
1129 n = n%l + 1
1130 local move = moves[n]
1131 local stats = movelist[move]
1132 moveinfo.MoveName.Text = move
1133 if not stats.ManaCost then
1134 moveinfo.ManaCost.Text = "MP 0"
1135 else
1136 moveinfo.ManaCost.Text = "MP ".. stats.ManaCost
1137 end
1138 moveinfo.Description.Text = stats.Description
1139 end
1140 local function left()
1141 n = (n - 2)%l + 1
1142 local move = moves[n]
1143 local stats = movelist[move]
1144 moveinfo.MoveName.Text = move
1145 if not stats.ManaCost then
1146 moveinfo.ManaCost.Text = "MP 0"
1147 else
1148 moveinfo.ManaCost.Text = "MP ".. stats.ManaCost
1149 end
1150 moveinfo.Description.Text = stats.Description
1151 end
1152 right()
1153 moveinfo.Activate.MouseButton1Click:Connect(activate)
1154 moveinfo.Left.MouseButton1Click:Connect(left)
1155 moveinfo.Right.MouseButton1Click:Connect(right)
1156 cas:BindAction("ActionActivate", activate, controls.Activate)
1157 cas:BindAction("ArrowLeft", left, controls.Left)
1158 cas:BindAction("ArrowRight", right, controls.Right)
1159 return
1160 else
1161 ChangeMouseState("DeadScootAttempt")
1162 end
1163 end
1164 end
1165
1166 end
1167
1168 if chosen == "Items" then
1169 ChangeMouseState("ItemTarget")
1170 end
1171
1172 if chosen == "Scout" then
1173 ChangeMouseState("AttackScout")
1174 local points = createSelections(init.Field.Enemy:GetChildren())
1175 for _,p in pairs(points) do
1176 p.OnFire = function()
1177 local data
1178 for i,monster in pairs(init.Enemy.Party) do
1179 if monster.Key == p.Key then
1180 data = monster
1181 end
1182 end
1183 if data and data.PresentHealth > 0 then
1184 terminate()
1185 init.Instructions = {{"Scout",{data.Key}}} -- wipes all other actions
1186 StartTurn(init)
1187 ExitButton()
1188 return
1189 else
1190 ChangeMouseState("DeadScootAttempt")
1191 end
1192 end
1193 end
1194 end
1195
1196 if chosen == "Tactics" then
1197 ChangeMouseState("TargetTactics")
1198 end
1199 end
1200
1201 local function mouseReset()
1202 terminate()
1203 tekkit:TweenPosition(bgui.Player,UDim2.new(-0.2,0,0.3,0))
1204 tekkit:TweenPosition(operations,UDim2.new(0.25, 0,0.85, 0))
1205 if not init.Active then
1206 return
1207 end
1208 camloc()
1209 cas:BindAction("ActionActivate", DoButton, controls.Activate)
1210 cas:BindAction("ActionLeave", ExitButton, controls.Leave)
1211 cas:BindAction("ArrowLeft", bckwrd, controls.Left)
1212 cas:BindAction("ArrowRight", fwrd, controls.Right)
1213 end
1214
1215 function ExitButton()
1216 print("t-ttodo...")
1217 mouseReset()
1218 active = false
1219 bgui.Actions.Visible = false
1220 end
1221
1222 function camloc()
1223 --{"Attack","Instructions","Items","Scout","Tactics","Flee"}
1224 local chosen = buttons[selected]
1225 if actionCancel then ChangeMouseState("inactive") return end
1226 if chosen == "Attack" then
1227 ShiftCamera("ToBack",init.Field.PrimaryPart)
1228 elseif chosen == "Instructions" then
1229 ShiftCamera("ToBack",init.Field.PrimaryPart)
1230 elseif chosen == "Items" then
1231 ShiftCamera("ToFace",character.Head)
1232 elseif chosen == "Scout" then
1233 ShiftCamera("ToFace",init.Field.PrimaryPart)
1234 elseif chosen == "Tactics" then
1235 ShiftCamera("ToBack",init.Field.PrimaryPart)
1236 elseif chosen == "Flee" then
1237 ShiftCamera("ToDirectFace",character.Head)
1238 end
1239 end
1240
1241 function fwrd()
1242 print("fwrd cast")
1243 if debounce then return end
1244 debounce = true
1245 ExitButton()
1246 selected = selected + 1
1247 if selected >#buttons then
1248 selected = 1
1249 end
1250 s_button.Text = buttons[selected]
1251 camloc()
1252 wait(0.1)
1253 debounce = false
1254 end
1255 function bckwrd()
1256 print("backwrd cast")
1257 if debounce then return end
1258 debounce = true
1259 ExitButton()
1260 selected = selected - 1
1261 if selected < 1 then
1262 selected = #buttons
1263 end
1264 s_button.Text = buttons[selected]
1265 camloc()
1266 wait(0.1)
1267 debounce = false
1268 end
1269
1270 s_button.MouseButton1Click:Connect(DoButton)
1271
1272 mouseReset()
1273
1274 operations.Left.MouseButton1Click:Connect(bckwrd)
1275 operations.Right.MouseButton1Click:Connect(fwrd)
1276
1277 cas:BindAction("ActionActivate", DoButton, controls.Activate)
1278 cas:BindAction("ActionLeave", ExitButton, controls.Leave)
1279 cas:BindAction("ArrowLeft", bckwrd, controls.Left)
1280 cas:BindAction("ArrowRight", fwrd, controls.Right)
1281 ChangeSong(musiclist["Monster Battle"],{TimePosition = 0, Steps = 60})
1282 elseif condition == "BeginBattle" then
1283 local init = ...
1284 actionCancel = false
1285 spawn(visualFlash)
1286 ui.PartyChange.Visible = false
1287 sidebar.Visible = false
1288
1289 -- get battlefield
1290 init.Field = workspace.Battles[init.Battle.Key]
1291 ShiftCamera("RandomIdle",init.Field.PrimaryPart)
1292
1293 -- if mobile then bgui.Size = UDim2.new(0.3,0,0.65,0)
1294
1295 -- load buttons
1296 bgui.Visible = true
1297 local buttons = {"Attack","Instructions","Items","Scout","Tactics","Flee"}
1298 local btn = {}
1299 bgui.Operations:ClearAllChildren()
1300 for i,name in pairs(buttons) do
1301 local foo = Instance.new("TextButton",bgui.Operations)
1302 foo.Size = UDim2.new(1,0,1/#buttons,0)
1303 foo.Position = UDim2.new(0,0,(i-1)/#buttons,0)
1304 foo.Text = name
1305 foo.Name = name
1306 foo.BorderSizePixel = 0
1307 foo.BackgroundTransparency = 0.5
1308 foo.BackgroundColor3 = Color3.new(0,0,0)
1309 foo.TextColor3 = Color3.new(1,1,1)
1310 foo.TextXAlignment = Enum.TextXAlignment.Left
1311 foo.TextYAlignment = Enum.TextYAlignment.Bottom
1312 foo.TextScaled = true
1313 foo.Font = font
1314 btn[name] = foo
1315 end
1316
1317 -- load teams
1318 local pbuttons = VisualiseParty(bgui.Player,init,false)
1319 local ebuttons = VisualiseParty(bgui.Enemy,init, true)
1320
1321 btn.Attack.MouseButton1Click:Connect(function()
1322 if actionCancel then ChangeMouseState("inactive") return end
1323 ChangeMouseState("BeginBattle")
1324 StartTurn(init)
1325 end)
1326
1327 btn.Instructions.MouseButton1Click:Connect(function()
1328 if actionCancel then ChangeMouseState("inactive") return end
1329 ChangeMouseState("TargetInstruction")
1330 LoadOptions({"(Select a monster)"})
1331 end)
1332
1333 btn.Tactics.MouseButton1Click:Connect(function()
1334 if actionCancel then ChangeMouseState("inactive") return end
1335 ChangeMouseState("TargetTactics")
1336 LoadOptions({"(Select a monster)"})
1337 end)
1338
1339 btn.Scout.MouseButton1Click:Connect(function()
1340 if actionCancel then ChangeMouseState("inactive") return end
1341 ChangeMouseState("AttackScout")
1342 LoadOptions({"(Select an enemy monster)"})
1343 end)
1344
1345 btn.Items.MouseButton1Click:Connect(function()
1346 if actionCancel then ChangeMouseState("inactive") return end
1347 ChangeMouseState("ItemTarget")
1348 end)
1349
1350 btn.Flee.MouseButton1Click:Connect(function()
1351 if actionCancel then ChangeMouseState("inactive") return end
1352 init.Instructions = {{"Flee",{}}} -- wipes all other actions
1353 StartTurn(init)
1354 end)
1355
1356 ChangeSong(musiclist["Monster Battle"],{TimePosition = 0, Steps = 60})
1357 end
1358end)
1359
1360rFunc.OnClientInvoke = function(condition,...)
1361
1362 return
1363end
1364
1365
1366local previoussongid
1367function ChangeSong(to,args)
1368 if not type(to) == "string" then to = tostring(to) end
1369 local steps = args and args.Steps or 30 -- steps (frames it takes to tween the music)
1370 local newsong = Instance.new("Sound",player)
1371 newsong.Looped = true
1372 newsong.SoundId = asset..to
1373 newsong.TimePosition = (not args or not args.TimePosition) and _G["Music"].TimePosition or args.TimePosition
1374 newsong.Volume = 0
1375 newsong:Play()
1376 previoussongid = _G["SongId"]
1377 _G["SongId"] = to
1378 for i=1,steps do
1379 wait()
1380 newsong.Volume = newsong.Volume + (1/(steps*2))
1381 _G["Music"].Volume = _G["Music"].Volume - (1/(steps*1.333333))
1382 end
1383 _G["Music"]:Destroy()
1384 _G["Music"] = newsong
1385end
1386
1387local Gamepasses = ui:WaitForChild("Gamepasses")
1388local gamepassopen = false
1389function GamePassMove(override)
1390 gamepassopen = override or not gamepassopen
1391 if gamepassopen then
1392 Gamepasses:TweenPosition(UDim2.new(0.2,0,0.05,0))
1393 else
1394 Gamepasses:TweenPosition(UDim2.new(0.2,0,-0.2,-35))
1395 end
1396end
1397
1398function SideBar(title,args)
1399 sidebar:ClearAllChildren()
1400 local header = Instance.new("TextLabel",sidebar)
1401 header.Size = UDim2.new(1.2,0,0.1,0)
1402 header.Position = UDim2.new(0,0,-0.02,0)
1403 header.Text = title
1404 header.BorderSizePixel = 0
1405 header.BackgroundColor3 = Color3.new(0,0,200/255)
1406 header.BackgroundTransparency = 0.5
1407 header.TextXAlignment = Enum.TextXAlignment.Left
1408 header.TextTransparency = 0.1
1409 header.TextColor3 = Color3.new(1,1,1)
1410 header.Font = font
1411 header.TextScaled = true
1412 local buttons = {}
1413 for i=1,#args do
1414 local element = args[i]
1415 local body = Instance.new("TextButton",sidebar)
1416 body.Position = UDim2.new(0,0,0.1*i,0)
1417 body.Size = UDim2.new(1,0,0.07,0)
1418 body.Text = element
1419 body.BorderSizePixel = 0
1420 body.BackgroundColor3 = Color3.new(0,0,0)
1421 body.BackgroundTransparency = 0.5
1422 body.TextXAlignment = Enum.TextXAlignment.Left
1423 body.TextTransparency = 0.1
1424 body.TextColor3 = Color3.new(1,1,1)
1425 body.Font = font
1426 body.TextScaled = true
1427 body.MouseEnter:connect(function() body:TweenSize(UDim2.new(1.2,0,0.07,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.3,true) end)
1428 body.MouseLeave:connect(function() wait(1/15) body:TweenSize(UDim2.new(1,0,0.07,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.5,true) end)
1429 buttons[element] = body
1430
1431 if element == "Gamepasses" then
1432 body.MouseButton1Click:Connect(function()
1433 GamePassMove()
1434 end)
1435 end
1436 end
1437 return buttons
1438end
1439function synthesis()
1440 ChangeSong(musiclist["Scoutpost"],{TimePosition = 0, Steps = 60})
1441end
1442function intro()
1443 local loadbarX,loadbarY = 0.68,0.08
1444 local loadinglabel = introui:WaitForChild("Loading")
1445 local loadingbar = introui:WaitForChild("LoadBar")
1446 local totalrequests = 0
1447 for _,id in pairs(musiclist) do
1448 totalrequests = totalrequests + 1
1449 game:GetService("ContentProvider"):Preload(asset..id)
1450 end
1451 local prepreloadtick = tick()
1452 while (game:GetService("ContentProvider").RequestQueueSize > 0) do
1453 local requests = game:GetService("ContentProvider").RequestQueueSize
1454 wait()
1455 if requests ~= game:GetService("ContentProvider").RequestQueueSize then
1456 local barX = loadbarX*(game:GetService("ContentProvider").RequestQueueSize/totalrequests)
1457 barX = barX>1 and 0 or barX
1458 loadingbar:TweenSize(UDim2.new(barX,0,loadbarY,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,1,true)
1459 end
1460 if tick() - prepreloadtick > 5 then
1461 break
1462 end
1463 end
1464 loadinglabel.Text = "Loaded!"
1465
1466 -- Initial Camera setup, we want to make sure its not acting dum
1467 local camera = workspace.CurrentCamera
1468 local cameralocations = game.ReplicatedStorage.CameraLocations:GetChildren()
1469 local timer = 0
1470 camera.CameraType = Enum.CameraType.Scriptable
1471
1472 --- one time event
1473 local location = cameralocations[math.random(#cameralocations)]
1474 camera.CFrame = location.Position.CFrame
1475 camera.Focus = location.Focus.CFrame
1476
1477 loadingbar:TweenSize(UDim2.new(loadbarX,0,loadbarY,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.5,true)
1478 introui:TweenPosition(UDim2.new(0,0,1,0))
1479 local button = SideBar("Main Menu",{"Play","Options","Gamepasses"})
1480 local play
1481 button.Play.MouseButton1Click:Connect(function()
1482 play = true
1483 end)
1484 ChangeSong(musiclist["Title Screen"])
1485
1486 -- moving around workspace
1487 repeat
1488 timer = timer+1
1489 if timer%90==1 then
1490 local location = cameralocations[math.random(#cameralocations)]
1491 camera:Interpolate(location.Position.CFrame,location.Focus.CFrame,1)
1492 end
1493 wait()
1494 until play
1495
1496 sidebar:ClearAllChildren()
1497 wait(1)
1498
1499 -- refocusing to character
1500 repeat wait() until player.Character
1501 character = player.Character
1502 --character:MoveTo(workspace.StartLocation.Position)
1503 camera:Interpolate(character.Head.CFrame - camera.CFrame.lookVector*10,camera.Focus:inverse(),2)
1504 wait(2)
1505 camera.CameraSubject = character.Humanoid
1506 camera.CameraType = Enum.CameraType.Custom
1507end
1508_G["Music"] = _G["Music"] or Instance.new("Sound",player)
1509intro()
1510ChangeSong(musiclist["Sandy Theme"],{TimePosition = 0, Steps = 60})
1511playerData = rFunc:InvokeServer("GetData")
1512function monFK(key) -- MONSTER FROM KEY ( KEY as INTEGER )
1513 for i,v in pairs(playerData.Monsters) do
1514 if v.Key == key then
1515 return v
1516 end
1517 end
1518 print("key not found")
1519 print("key:",key)
1520 return false
1521end
1522
1523function RenderMain()
1524 local button = SideBar("Main Menu",{"Party","Options","Gamepasses","Synthesis","Ride"})
1525
1526 local partydebounce = false
1527 local partychanged = false
1528 local partyopen = false
1529 local partyui = ui.PartyChange
1530 local btngui = partyui.Buttons
1531 local container = partyui.Monsters
1532 local playerparty = partyui.PlayerParty
1533 btngui:ClearAllChildren()
1534 partyui.Visible = true
1535 partyui.Position = UDim2.new(0.6,0,(partyopen and 0.5 or 1),0)
1536 button.Party.MouseButton1Click:Connect(function()
1537 if partydebounce then return end
1538 partydebounce = true
1539 partyopen = not partyopen
1540 partyui:TweenPosition(UDim2.new(0.6,0,(partyopen and 0.5 or 1),0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.5, true)
1541 wait(0.5)
1542 if not partyopen then
1543 btngui:ClearAllChildren()
1544 container:ClearAllChildren()
1545 playerparty:ClearAllChildren()
1546 partyui.Loading.Visible = true
1547 end
1548 partydebounce = false
1549 wait(0.75)
1550 if partyopen then
1551 local cells = {}
1552 local buttons = {"Replace","Info"}
1553 local switch = false
1554 local id = 0
1555 local function loadButtons(data,inParty)
1556 btngui:ClearAllChildren()
1557 switch = false
1558 local btn = {}
1559 for i,txt in pairs(buttons) do
1560 local button = Instance.new("TextButton",btngui)
1561 button.Size = UDim2.new(1/5,0,0.8,0)
1562 button.Position = UDim2.new(0.05 + 0.225*(i-1),0,0.1,0)
1563 button.Style = Enum.ButtonStyle.RobloxRoundDefaultButton
1564 button.TextColor3 = Color3.new(1,1,1)
1565 button.TextScaled = true
1566 button.Font = font
1567 button.Text = txt
1568 button.Name = txt
1569 btn[txt] = button
1570 end
1571
1572 btn.Replace.MouseButton1Click:Connect(function()
1573 switch = false
1574 id = id + 1
1575 local cid = id
1576 ChangeMouseState("SwitchTo")
1577 while id == cid do
1578 btn.Replace.Style = Enum.ButtonStyle.RobloxRoundButton
1579 game:GetService("RunService").Heartbeat:wait()
1580 if switch and not inParty then
1581 cid = false
1582 partychanged = true
1583 local sum = data.BaseSize+switch
1584 local excess = data.BaseSize-1
1585 if sum > 4 then
1586 switch = 4 - excess
1587 end
1588 local new = {data.Key,switch,data.BaseSize}
1589 for i = switch,switch+excess do
1590 cells[i] = new
1591 end
1592 -- ok now create playerData.Party
1593 local party = {}
1594 local limit = 4
1595 local count = 0
1596 for _,tab in pairs(cells) do
1597 local exists = false
1598 for _,key in pairs(party) do
1599 if tab[1]==key then
1600 exists = true
1601 end
1602 end
1603 if not exists and tab[1]~=0 then
1604 if count+tab[3] > limit then
1605 break
1606 end
1607 count = count + tab[3]
1608 table.insert(party,tab[1])
1609 end
1610 end
1611 playerData.Party = party
1612 updateInfo()
1613 elseif switch and inParty then
1614 cid = false
1615 partychanged = true
1616 local length = inParty[3]
1617 local n = 0
1618 local t = {}
1619 for i=inParty[2],inParty[2]+(length-1) do
1620 table.insert(t,cells[switch + n])
1621 cells[switch + n] = inParty
1622 n = n + 1
1623 cells[i] = t[n]
1624 end
1625 -- ok now create playerData.Party
1626 local party = {}
1627 local limit = 4
1628 local count = 0
1629 for _,tab in pairs(cells) do
1630 local exists = false
1631 for _,key in pairs(party) do
1632 if tab[1]==key then
1633 exists = true
1634 end
1635 end
1636 if not exists and tab[1]~=0 then
1637 if count+tab[3] > limit then
1638 break
1639 end
1640 count = count + tab[3]
1641 table.insert(party,tab[1])
1642 end
1643 end
1644 playerData.Party = party
1645 updateInfo()
1646 end
1647 end
1648 btn.Replace.Style = Enum.ButtonStyle.RobloxRoundDefaultButton
1649 end)
1650 end
1651 function updateInfo()
1652 cells = {}
1653 btngui:ClearAllChildren()
1654 container:ClearAllChildren()
1655 playerparty:ClearAllChildren()
1656 partyui.Loading.Visible = true
1657 local len = #playerData.Monsters-#playerData.Party
1658 container.CanvasSize = UDim2.new(0,200*len,0,0)
1659 local i = 0
1660 for _,data in pairs(playerData.Monsters) do
1661 local inParty = false
1662 for _,key in pairs(playerData.Party) do
1663 if data.Key==key then
1664 inParty = true
1665 end
1666 end
1667 if not inParty then
1668 local icon = Instance.new("TextButton",container)
1669 icon.Size = UDim2.new(0,150,0.8,-10)
1670 icon.Position = UDim2.new(0,25 + 175*i,0.1,5)
1671 icon.BackgroundColor = game.ReplicatedStorage.Monster[data.Name].Heart.BrickColor
1672 icon.BorderSizePixel = 5
1673 icon.BorderColor3 = Color3.new(1,1,1)
1674 icon.Name = "Icon"
1675 icon.Font = font
1676 icon.Text = data.Nickname .." (lv."..data.Level..")"
1677 icon.TextScaled = true
1678 icon.TextColor3 = Color3.new(1,1,1)
1679 icon.MouseButton1Click:Connect(function()
1680 loadButtons(data)
1681 if mouseState == "SwitchTo" then
1682 ChangeMouseState("missed")
1683 end
1684 end)
1685 i = i + 1
1686 end
1687 end
1688 --for _,tab in pairs(cells) do
1689 local n = 1
1690 local party = {}
1691 for _,key in pairs(playerData.Party) do
1692 local new = true
1693 for _,oldkey in pairs(party) do
1694 if oldkey == key then
1695 new = false
1696 end
1697 end
1698 if new then
1699 local data = monFK(key)
1700 table.insert(party,data.Key)
1701 local tab = {key,n,data.BaseSize}
1702 for i=1,data.BaseSize do
1703 table.insert(cells,tab)
1704 end
1705 n = n + data.BaseSize
1706
1707 local icon = Instance.new("TextButton",playerparty)
1708 icon.Size = UDim2.new(tab[3]/5,0,0.9,-10)
1709 icon.Position = UDim2.new(0.025+0.25*(tab[2]-1),0,0.05,5)
1710 icon.BackgroundColor = game.ReplicatedStorage.Monster[data.Name].Heart.BrickColor
1711 icon.BorderSizePixel = 5
1712 icon.BorderColor3 = Color3.new(1,1,1)
1713 icon.Name = "Icon"
1714 icon.Font = font
1715 icon.Text = data.Nickname .." (lv."..data.Level..")"
1716 icon.TextScaled = true
1717 icon.TextColor3 = Color3.new(1,1,1)
1718 icon.MouseButton1Click:Connect(function()
1719 loadButtons(data,tab)
1720 if mouseState == "SwitchTo" then
1721 switch = tab[2]
1722 end
1723 end)
1724 end
1725 end
1726 for i=1,4-#cells do
1727 local tab = {0,n,1}
1728 table.insert(cells,tab)
1729 n = n + 1
1730 local icon = Instance.new("TextButton",playerparty)
1731 icon.Size = UDim2.new(tab[3]/5,0,0.9,-10)
1732 icon.Position = UDim2.new(0.025+0.25*(tab[2]-1),0,0.05,5)
1733 icon.BackgroundColor3 = Color3.new(0.5,0.5,0.5)
1734 icon.BorderSizePixel = 5
1735 icon.BorderColor3 = Color3.new(1,1,1)
1736 icon.Name = "Icon"
1737 icon.Font = font
1738 icon.Text = "Empty Slot"
1739 icon.TextScaled = true
1740 icon.TextColor3 = Color3.new(1,1,1)
1741 icon.MouseButton1Click:Connect(function()
1742 if mouseState == "SwitchTo" then
1743 switch = tab[2]
1744 end
1745 end)
1746 end
1747 partyui.Loading.Visible = false
1748 end
1749 updateInfo()
1750 elseif partychanged then
1751 rEvent:FireServer("UpdateParty",playerData.Party)
1752 end
1753 end)
1754
1755 button.Synthesis.MouseButton1Click:Connect(function()
1756 synthesis()
1757 end)
1758
1759 local riding
1760 local ridefreeze
1761 button.Ride.MouseButton1Click:Connect(function()
1762 if ridefreeze then return end
1763 if riding then
1764 riding = false
1765 ridefreeze = true
1766 rFunc:InvokeServer("UnRideMonster")
1767 wait(2)
1768 ridefreeze = false
1769 return
1770 end
1771 ridefreeze = true
1772 local monster = monFK(playerData.Party[1])
1773 local model = rFunc:InvokeServer("RideMonster",monster.Name)
1774-- model:Destroy()
1775 ridefreeze = false
1776-- local model = game.ReplicatedStorage.Monster:FindFirstChild(monster.Name):Clone()
1777-- model.Parent = Instance.new("Folder",character)
1778-- for i,part in pairs(model:GetChildren()) do
1779-- if part:IsA("BasePart") then
1780-- if part.Name == "RootPart" then
1781-- part.Transparency = 1
1782-- part.Anchored = true
1783-- model.PrimaryPart = part
1784-- else
1785-- part.Anchored = false
1786-- end
1787-- part.CanCollide = false
1788-- end
1789-- end
1790
1791 riding = true
1792 local ending_anims = {}
1793 local function AddAnim(anim)
1794 table.insert(ending_anims,anim)
1795 end
1796 AddAnim(animkit.PlayerAnim(character.Humanoid,"RideCore"))
1797 print("MISC PLAYER ANIMATIONS")
1798 local rideanim = monster.RideAnim
1799 if rideanim then
1800 AddAnim(animkit.PlayerAnim(character.Humanoid,rideanim))
1801 end
1802
1803 local height = ridemonster.CalculateGap(model.Heart,model.Saddle)
1804 local baseHip = character.Humanoid.HipHeight
1805 character.Humanoid.HipHeight = baseHip + height
1806 character.Humanoid.JumpPower = 50 + model.RootPart.Size.Y * 2
1807
1808
1809 do print("Loading MONSTER ANIMATIONS")
1810 local controller = model.AnimationController
1811 local anims = model.Animations
1812
1813 print("Loading idle:")
1814 animkit.Play(controller,anims:FindFirstChild("Idle"))
1815
1816 print("Loading run:")
1817 local run = animkit.Play(controller,anims:FindFirstChild("Run"),{Substitute = anims:FindFirstChild("Walk"), DontPlay = true})
1818 character.Humanoid.Running:connect(function(speed)
1819 if not run then return end
1820 if speed > 0 and not run.IsPlaying then
1821 run:Play()
1822 elseif speed < 0.1 then
1823 run:Stop()
1824 end
1825 end)
1826
1827 print("Loading jump:")
1828 local jump = animkit.Play(controller,anims:FindFirstChild("Jump"),{Substitute = anims:FindFirstChild("Run"), DontPlay = true})
1829 character.Humanoid.Jumping:connect(function(active)
1830 if not jump then return end
1831 if active and not jump.IsPlaying then
1832 jump:Play()
1833 else
1834 jump:Stop()
1835 end
1836 end)
1837 end
1838
1839 while riding do
1840 local height = ridemonster.CalculateGap(model.Heart,model.Saddle)
1841 character.Humanoid.HipHeight = baseHip + height
1842
1843 model.RootPart.CFrame = character.HumanoidRootPart.CFrame - Vector3.new(0,2.5 + height-model.RootPart.Size.Y/2,0)
1844 game:GetService("RunService").RenderStepped:wait()
1845 end
1846 character.Humanoid.JumpPower = 50
1847 character.Humanoid.WalkSpeed = 16
1848 character.Humanoid.HipHeight = baseHip
1849 model:Destroy()
1850 for _,anim in pairs(ending_anims) do
1851 anim:Stop()
1852 end
1853 end)
1854end
1855RenderMain()