Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local FightModule = {}
- -- SERVICES
- local RunService = game:GetService("RunService")
- local ReplicatedStorage = game:GetService("ReplicatedStorage").ReplicatedStoragePackage
- local ServerScriptService = game:GetService("ServerScriptService").ServerScriptServicePackage
- local TweenService = game:GetService("TweenService")
- local SoundService = game:GetService("SoundService")
- local PlayerService = game:GetService("Players")
- local ServerStorage = game:GetService("ServerStorage").ServerStoragePackage
- -- MODULES
- local Types = require(ReplicatedStorage.Modules.Types)
- local FighterDetails = require(ServerScriptService.Parent.FighterDetails)
- local PlayerStats = require(ServerScriptService.Modules.PlayerStats)
- local AbilityModule = require(script.AbilityModule)
- local Utilities = require(ServerScriptService.Modules.Utilities)
- local CustomEnum = require(ReplicatedStorage.Modules.CustomEnum)
- local FighterMethods = require(ServerScriptService.Modules.FighterMethods)
- local attackGuiUpdater = ReplicatedStorage.Remotes.AttackGuiUpdater
- local getTurnInfo = ServerStorage.Bindables.GetTurnInfo
- local highlightRemote = ReplicatedStorage.Remotes.HighlightRemote
- local fightPart: Part = workspace.FightPart -- part where the center of the fight is
- local turn: number = 1
- local playedTurns: number = 1
- local players: {number} = {} -- includes singleplayer NPCs
- local globalFighters: {Types.Fighter} = {}
- local attackTweenInfo = TweenInfo.new(1)
- getTurnInfo.OnInvoke = function()
- return players, playedTurns
- end
- local function GetPlayerFighters(fightersTable: {Types.Fighter}, userId: number)
- local fighters = {}
- for i,v in fightersTable do
- if v.userId == userId then
- table.insert(fighters, v)
- end
- end
- return fighters
- end
- local function IsFighterInTable(tableOfInstances: {Instance}, fighterName: string)
- for i,v in tableOfInstances do
- if v.Name == fighterName then
- return true
- end
- end
- return false
- end
- -- Checks if a fighter is within the fighters folder
- local function CheckFighterValidity(fighter: Types.Fighter)
- local normalFightersFolders = ReplicatedStorage.Fighters:GetChildren()
- for i,v in normalFightersFolders do
- if not IsFighterInTable(v:GetChildren(), FighterDetails[fighter.id].Information.Name) then
- continue
- end
- return true
- end
- if RunService:IsStudio() then
- local devFighters = ReplicatedStorage.Fighters.Dev:GetChildren()
- if not IsFighterInTable(devFighters, FighterDetails[fighter.id].Information.Name) then
- return false
- end
- return true
- end
- return false
- end
- local function PlaceFighter(fighter: Types.Fighter, newPosition: CFrame, userId: number)
- fighter.model.Parent = workspace
- fighter.model:PivotTo(workspace.FightPart.CFrame * newPosition)
- local detector = ServerStorage.Misc.AssignFighterDetector:Clone()
- detector.UserId.Value = userId
- detector.Parent = fighter.model
- end
- -- fighter must be in global fighters array. FilterId is optional,
- -- but prevents duplicate fighter for enemy being flagged instead
- local function GetFighterFromModel(fighterModel: Types.Character, filterId: number) : Types.Fighter
- if not filterId then
- for i,v: Types.Fighter in globalFighters do
- if v.model == fighterModel then
- return v
- end
- end
- else
- for i,v: Types.Fighter in globalFighters do
- local detector = fighterModel.AssignFighterDetector
- local userId = detector.UserId.Value
- if v.model == fighterModel and v.model.AssignFighterDetector.UserId.Value == userId then
- return v
- end
- end
- end
- return nil
- end
- local function ResetFighterAtTurnStart(fighter: Types.Fighter)
- if fighter.model.Humanoid.Health <= 0 then
- for i,v in fighter.model.Humanoid.Animator:GetPlayingAnimationTracks() do
- v:Stop()
- end
- Utilities.LoadAnimationOfFighter(fighter.model, FighterDetails[fighter.id].Animations, "Dead"):Play()
- end
- if fighter.abilityExpiry then
- if fighter.abilityExpiry > 0 then
- fighter.abilityExpiry -= 1
- else
- fighter.abilityExpiry = 0
- AbilityModule.StopAbility(fighter.ability, fighter)
- end
- end
- if fighter.isBlocking then
- fighter.isBlocking = false
- for i,v in fighter.model.Humanoid.Animator:GetPlayingAnimationTracks() do
- if v.Name == "Block" then
- v:Stop()
- end
- end
- Utilities.LoadAnimationOfFighter(fighter.model, FighterDetails[fighter.id].Animations, "Idle"):Play()
- end
- end
- local function NextTurn()
- turn += 1
- for i,v: Types.Fighter in globalFighters do
- if v.model.Humanoid.Health > 0 then
- -- prevent dead people from coming back to life every turn
- FighterMethods.GiveHealth(v, 5) -- regen every turn
- if v.model.Humanoid.Health > FighterDetails[v.id].Information.MaxHealth then
- FighterMethods.SetHealth(v, FighterDetails[v.id].Information.MaxHealth)
- end
- end
- end
- if #players > playedTurns then
- playedTurns += 1 -- current turn is players[2] if the previous turn was players[1]
- elseif #players == playedTurns then
- playedTurns = 1 -- reset turns back
- end
- attackGuiUpdater:FireAllClients(players, playedTurns, turn)
- if players[playedTurns] == 0 then
- FightModule.EnemyAITurn()
- else
- for i,fighter: Types.Fighter in globalFighters do
- if fighter.userId == players[playedTurns] then
- ResetFighterAtTurnStart(fighter)
- end
- end
- end
- end
- -- handles checks to see if fighter is alive too
- local function GetRandomFighter(aiFighters: {Types.Fighter}): Types.Fighter?
- local randomNum = math.random(1, #aiFighters)
- local opponentFighter = aiFighters[randomNum]
- if opponentFighter.model.Humanoid.Health <= 0 then
- table.remove(aiFighters, randomNum)
- if #aiFighters == 0 then
- return nil -- all fighters are dead
- end
- return GetRandomFighter(aiFighters)
- end
- return opponentFighter
- end
- local function PlaceFighterGroup(fighterGroup: {Types.Fighter}, leftSide: boolean, userId: number)
- local amount = #fighterGroup
- local multiplier = 1
- if leftSide then
- multiplier = -1
- end
- if amount == 2 then
- PlaceFighter(fighterGroup[1], CFrame.new(10 * multiplier, 2.5, -10), userId)
- PlaceFighter(fighterGroup[2], CFrame.new(10 * multiplier, 2.5, -18), userId)
- elseif amount == 3 then
- PlaceFighter(fighterGroup[1], CFrame.new(7 * multiplier, 2.5, -14), userId)
- PlaceFighter(fighterGroup[2], CFrame.new(10 * multiplier, 2.5, -18), userId)
- PlaceFighter(fighterGroup[3], CFrame.new(10 * multiplier, 2.5, -10), userId)
- elseif amount == 4 then
- PlaceFighter(fighterGroup[1], CFrame.new(10 * multiplier, 2.5, -10), userId)
- PlaceFighter(fighterGroup[2], CFrame.new(10 * multiplier, 2.5, -18), userId)
- PlaceFighter(fighterGroup[3], CFrame.new(16 * multiplier, 2.5, -10), userId)
- PlaceFighter(fighterGroup[4], CFrame.new(16 * multiplier, 2.5, -18), userId)
- end
- end
- function FightModule.SkipTurn()
- NextTurn()
- end
- function FightModule.AssignFighter(player: Player, userId: number, fighterModel: Types.Character)
- if userId == player.UserId then
- -- switch player fighter
- PlayerStats[player.UserId].fighter = GetFighterFromModel(fighterModel, userId)
- for i,v: Types.Fighter in globalFighters do
- if v.userId == player.UserId then
- highlightRemote:FireClient(player, v.model, nil, false)
- highlightRemote:FireClient(player, v.model, nil, false, true)
- end
- end
- highlightRemote:FireClient(player, fighterModel, Color3.new(0, 0.4, 1), true, true)
- else
- -- switch opponent fighter
- PlayerStats[player.UserId].opponent = GetFighterFromModel(fighterModel, userId)
- for i,v: Types.Fighter in globalFighters do
- if v.userId ~= player.UserId then
- highlightRemote:FireClient(player, v.model, nil, false)
- highlightRemote:FireClient(player, v.model, nil, false, true)
- end
- end
- highlightRemote:FireClient(player, fighterModel, Color3.new(1, 0, 0.0156863), true, true)
- end
- end
- function FightModule.StartPartyFight(player1: Player, player2: Player, fighters: {Types.Fighter})
- if #fighters <= 2 then return end -- literally just a normal 1v1
- -- make sure fighters are valid
- local valid = true
- for i,v in fighters do
- if not CheckFighterValidity(v) then valid = false end
- end
- if not valid then return end
- if player2 == nil then
- -- SINGLEPLAYER
- local p1char: Types.Character = player1.Character
- p1char.HumanoidRootPart.Anchored = true
- table.insert(players, 1, player1.UserId)
- table.insert(players, 2, 0)
- for i,v in fighters do
- table.insert(globalFighters, i, v)
- end
- task.delay(1, function()
- highlightRemote:FireClient(player1, fighters[1].model, Color3.new(0, 0.4, 1), true, true)
- for i,v in fighters do
- if v.userId ~= player1.UserId then
- highlightRemote:FireClient(player1, v.model, Color3.new(1, 0, 0.0156863), true, true)
- break
- end
- end
- -- choose first opponent found as main opponent
- end)
- player1.PlayerGui.StarterGuiPackage.AttackGui.Enabled = true
- for i,v in fighters do
- v.model.Humanoid.MaxHealth = FighterDetails[v.id].Information.MaxHealth
- v.model.Humanoid.Health = FighterDetails[v.id].Information.MaxHealth
- end
- for i,v in fighters do
- local gui = ReplicatedStorage.Prefabs.CharacterGui:Clone()
- gui.Holder.BarBackground.BarForeground.CharacterName.Text = FighterDetails[v.id].Information.Name
- gui.Parent = v.model.Head
- end
- local playerFighters = {}
- local opponentFighters = {}
- for i,v in fighters do
- if v.userId == player1.UserId then
- table.insert(playerFighters, v)
- else
- table.insert(opponentFighters, v)
- end
- end
- PlaceFighterGroup(playerFighters, true, player1.UserId)
- PlaceFighterGroup(opponentFighters, false, 0)
- for i,v in fighters do
- if v.userId == player1.UserId then
- v.model.PrimaryPart.CFrame *= CFrame.Angles(0, 80, 0)
- else
- v.model.PrimaryPart.CFrame *= CFrame.Angles(0, -80, 0)
- end
- end
- for i,v in fighters do
- Utilities.CreateAnimator(v.model)
- end
- for i,v in fighters do
- Utilities.LoadAnimationOfFighter(v.model, FighterDetails[v.id].Animations, "Idle"):Play()
- end
- attackGuiUpdater:FireAllClients(players, playedTurns, turn)
- else
- -- Multiplayer
- local p1char: Types.Character = player1.Character
- p1char.HumanoidRootPart.Anchored = true
- local p2char: Types.Character = player2.Character
- p2char.HumanoidRootPart.Anchored = true
- table.insert(players, 1, player1.UserId)
- table.insert(players, 2, player2.UserId)
- for i,v in fighters do
- table.insert(globalFighters, i, v)
- end
- task.delay(1, function()
- for i = 1, 2 do
- -- should probably make this a function
- if i == 1 then
- highlightRemote:FireClient(player1, GetPlayerFighters(globalFighters, players[i])[1].model, Color3.new(0, 0.4, 1), true, true)
- for i,v in fighters do
- if v.userId ~= player1.UserId then
- highlightRemote:FireClient(player1, v.model, Color3.new(1, 0, 0.0156863), true, true)
- break
- end
- end
- else
- highlightRemote:FireClient(player2, GetPlayerFighters(globalFighters, players[i])[1].model, Color3.new(0, 0.4, 1), true, true)
- for i,v in fighters do
- if v.userId ~= player2.UserId then
- highlightRemote:FireClient(player2, v.model, Color3.new(1, 0, 0.0156863), true, true)
- break
- end
- end
- end
- end
- -- chooses first opponent found as main opponent, and first fighter as main fighter.
- -- well not really that's already done it just highlights them
- end)
- player1.PlayerGui.StarterGuiPackage.AttackGui.Enabled = true
- player2.PlayerGui.StarterGuiPackage.AttackGui.Enabled = true
- for i,v in fighters do
- v.model.Humanoid.MaxHealth = FighterDetails[v.id].Information.MaxHealth
- v.model.Humanoid.Health = FighterDetails[v.id].Information.MaxHealth
- end
- for i,v in fighters do
- local gui = ReplicatedStorage.Prefabs.CharacterGui:Clone()
- gui.Holder.BarBackground.BarForeground.CharacterName.Text = FighterDetails[v.id].Information.Name
- gui.Parent = v.model.Head
- end
- local playerFighters = {}
- local opponentFighters = {}
- for i,v in fighters do
- if v.userId == player1.UserId then
- table.insert(playerFighters, v)
- else
- table.insert(opponentFighters, v)
- end
- end
- PlaceFighterGroup(playerFighters, true, player1.UserId)
- PlaceFighterGroup(opponentFighters, false, player2.UserId)
- for i,v in fighters do
- if v.userId == player1.UserId then
- v.model.PrimaryPart.CFrame *= CFrame.Angles(0, 80, 0)
- else
- v.model.PrimaryPart.CFrame *= CFrame.Angles(0, -80, 0)
- end
- end
- for i,v in fighters do
- Utilities.CreateAnimator(v.model)
- end
- for i,v in fighters do
- Utilities.LoadAnimationOfFighter(v.model, FighterDetails[v.id].Animations, "Idle"):Play()
- end
- attackGuiUpdater:FireAllClients(players, playedTurns, turn)
- end
- end
- function FightModule.StartOneOnOne(player1: Player, player2: Player, fighters: {Types.Fighter})
- if #fighters ~= 2 then return end -- only player 1 and player 2's fighters allowed
- -- make sure fighters are valid
- if not CheckFighterValidity(fighters[1]) then return end
- if not CheckFighterValidity(fighters[2]) then return end
- if player2 == nil then
- -- SINGLEPLAYER
- local p1char: Types.Character = player1.Character
- p1char.HumanoidRootPart.Anchored = true
- table.insert(players, 1, player1.UserId)
- table.insert(players, 2, 0)
- table.insert(globalFighters, 1, fighters[1])
- table.insert(globalFighters, 2, fighters[2])
- task.delay(1, function()
- highlightRemote:FireClient(player1, fighters[1].model, Color3.new(0, 0.4, 1), true, true)
- highlightRemote:FireClient(player1, fighters[2].model, Color3.new(1, 0, 0.0156863), true, true)
- end)
- player1.PlayerGui.StarterGuiPackage.AttackGui.Enabled = true
- for i = 1, 2 do
- fighters[i].model.Humanoid.MaxHealth = FighterDetails[fighters[i].id].Information.MaxHealth
- fighters[i].model.Humanoid.Health = FighterDetails[fighters[i].id].Information.MaxHealth
- end
- for i = 1, 2 do
- local gui = ReplicatedStorage.Prefabs.CharacterGui:Clone()
- gui.Holder.BarBackground.BarForeground.CharacterName.Text = FighterDetails[fighters[i].id].Information.Name
- gui.Parent = fighters[i].model.Head
- end
- PlaceFighter(fighters[1], CFrame.new(-10, 2.5, -10), player1.UserId) -- left
- PlaceFighter(fighters[2], CFrame.new(10, 2.5, -10), 0) -- right
- fighters[1].model.PrimaryPart.CFrame = CFrame.lookAt(fighters[1].model.PrimaryPart.Position, fighters[2].model.PrimaryPart.Position)
- fighters[2].model.PrimaryPart.CFrame = CFrame.lookAt(fighters[2].model.PrimaryPart.Position, fighters[1].model.PrimaryPart.Position)
- for i = 1, 2 do
- Utilities.CreateAnimator(fighters[i].model)
- end
- Utilities.LoadAnimationOfFighter(fighters[1].model, FighterDetails[fighters[1].id].Animations, "Idle"):Play()
- Utilities.LoadAnimationOfFighter(fighters[2].model, FighterDetails[fighters[2].id].Animations, "Idle"):Play()
- attackGuiUpdater:FireAllClients(players, playedTurns, turn)
- else
- -- 2 PLAYERS
- local p1char: Types.Character = player1.Character
- p1char.HumanoidRootPart.Anchored = true
- local p2char: Types.Character = player2.Character
- p2char.HumanoidRootPart.Anchored = true
- table.insert(players, 1, player1.UserId)
- table.insert(players, 2, player2.UserId)
- table.insert(globalFighters, 1, fighters[1])
- table.insert(globalFighters, 2, fighters[2])
- task.delay(2, function()
- highlightRemote:FireClient(player1, fighters[1].model, Color3.new(0, 0.4, 1), true, true)
- highlightRemote:FireClient(player1, fighters[2].model, Color3.new(1, 0, 0.0156863), true, true)
- highlightRemote:FireClient(player2, fighters[2].model, Color3.new(0, 0.4, 1), true, true)
- highlightRemote:FireClient(player2, fighters[1].model, Color3.new(1, 0, 0.0156863), true, true)
- end)
- player1.PlayerGui.StarterGuiPackage.AttackGui.Enabled = true
- player2.PlayerGui.StarterGuiPackage.AttackGui.Enabled = true
- for i = 1, 2 do
- fighters[i].model.Humanoid.MaxHealth = FighterDetails[fighters[i].id].Information.MaxHealth
- fighters[i].model.Humanoid.Health = FighterDetails[fighters[i].id].Information.MaxHealth
- end
- for i = 1, 2 do
- local gui = ReplicatedStorage.Prefabs.CharacterGui:Clone()
- gui.Holder.BarBackground.BarForeground.CharacterName.Text = FighterDetails[fighters[i].id].Information.Name
- gui.Parent = fighters[i].model.Head
- end
- PlaceFighter(fighters[1], CFrame.new(-10, 2.5, -10), player1.UserId) -- left
- PlaceFighter(fighters[2], CFrame.new(10, 2.5, -10), player2.UserId) -- right
- fighters[1].model.PrimaryPart.CFrame = CFrame.lookAt(fighters[1].model.PrimaryPart.Position, fighters[2].model.PrimaryPart.Position)
- fighters[2].model.PrimaryPart.CFrame = CFrame.lookAt(fighters[2].model.PrimaryPart.Position, fighters[1].model.PrimaryPart.Position)
- for i = 1, 2 do
- Utilities.CreateAnimator(fighters[i].model)
- end
- Utilities.LoadAnimationOfFighter(fighters[1].model, FighterDetails[fighters[1].id].Animations, "Idle"):Play()
- Utilities.LoadAnimationOfFighter(fighters[2].model, FighterDetails[fighters[2].id].Animations, "Idle"):Play()
- attackGuiUpdater:FireAllClients(players, playedTurns, turn)
- end
- end
- local function Attack(attacker: Types.Fighter, victim: Types.Fighter)
- if attacker.ability and
- (AbilityModule.IsAbilityType(attacker.ability, CustomEnum.AbilityType.Attack) or
- AbilityModule.IsAbilityType(attacker.ability, CustomEnum.AbilityType.Cutscene)) then
- for i,v in victim.model.Humanoid.Animator:GetPlayingAnimationTracks() do
- if v.Name ~= "Block" then continue end
- v:Stop()
- local newAnim = Utilities.LoadAnimationOfFighter(victim.model, FighterDetails[victim.id].Animations, "Idle")
- newAnim:Play()
- end
- AbilityModule.ActivateAbility(attacker.ability, attacker, victim)
- return
- end
- local damage = 30
- local oldCFrame = attacker.model.PrimaryPart.CFrame
- if attacker.damageBoost and attacker.damageBoost > 0 then
- damage *= attacker.damageBoost
- end
- local offset = Vector3.new(-4, 0, 0)
- local endPosition = {
- Position = victim.model.PrimaryPart.Position + victim.model.PrimaryPart.CFrame.LookVector * 4
- }
- -- preloading animations to avoid delay
- local damageAnimation = Utilities.LoadAnimationOfFighter(victim.model, FighterDetails[victim.id].Animations, "Damage")
- local moveAnimation = Utilities.LoadAnimationOfFighter(attacker.model, FighterDetails[attacker.id].Animations, "Move")
- local attackAnimation = Utilities.LoadAnimationOfFighter(attacker.model, FighterDetails[attacker.id].Animations, "Attack")
- moveAnimation:Play()
- local tween = TweenService:Create(attacker.model.PrimaryPart, attackTweenInfo, endPosition)
- tween:Play()
- tween.Completed:Wait()
- moveAnimation:Stop()
- Utilities.CreateAnimator(attacker.model)
- Utilities.CreateAnimator(victim.model)
- attackAnimation:Play()
- repeat
- task.wait()
- until attackAnimation.Length > 0
- local connection = attackAnimation:GetMarkerReachedSignal("Hit"):Connect(function()
- if not victim.isBlocking then
- local sound = SoundService.HitSFX.Hit2:Clone()
- sound.Parent = victim.model
- sound:Destroy()
- local vfx = ReplicatedStorage.VFX.Hit.HitVFX:Clone()
- vfx.Parent = victim.model
- vfx.smack.Anchored = true
- vfx.smack.CFrame = victim.model.HumanoidRootPart.CFrame
- game.Debris:AddItem(vfx, 0.4)
- damageAnimation:Play()
- else
- if victim.model.Humanoid.Health > damage * 0.5 then
- local sound = SoundService.HitSFX.Block:Clone()
- sound.Parent = victim.model
- sound:Destroy()
- else
- local sound = SoundService.HitSFX.Hit2:Clone()
- sound.Parent = victim.model
- sound:Destroy()
- end
- end
- end)
- task.wait(attackAnimation.Length)
- connection:Disconnect()
- FighterMethods.TakeDamage(victim, damage, 0.5, attackGuiUpdater)
- task.wait(0.5)
- moveAnimation:Play()
- local endPosition = {CFrame = oldCFrame}
- local endTween = TweenService:Create(attacker.model.PrimaryPart, attackTweenInfo, endPosition)
- endTween:Play()
- endTween.Completed:Wait()
- moveAnimation:Stop()
- end
- function FightModule.Attack(player: Player, fighter: Types.Fighter)
- if players[playedTurns] ~= player.UserId then return end -- not the player's turn
- if fighter.isAttacking then return end -- player is doing attack
- if fighter.isBlocking then return end -- player is blocking
- fighter.isAttacking = true
- Attack(fighter, PlayerStats[player.UserId].opponent)
- NextTurn()
- fighter.isAttacking = false
- end
- function FightModule.Ability(player: Player, fighter: Types.Fighter, ability: number)
- if players[playedTurns] ~= player.UserId then return end -- not the player's turn
- if fighter.isAttacking then return end -- player is doing attack
- if fighter.isBlocking then return end -- player is blocking
- local result
- if fighter.transformed then
- result = AbilityModule.UseAbility(FighterDetails[fighter.id].AbilitiesTransformed[ability], fighter)
- else
- result = AbilityModule.UseAbility(FighterDetails[fighter.id].Abilities[ability], fighter)
- end
- if result ~= false and player.UserId ~= 0 then
- NextTurn()
- end
- end
- local function Defend(fighter: Types.Fighter)
- local anim: AnimationTrack = Utilities.LoadAnimationOfFighter(fighter.model, FighterDetails[fighter.id].Animations, "Block")
- for i,v: AnimationTrack in fighter.model.Humanoid.Animator:GetPlayingAnimationTracks() do
- if v.Name == "Idle" then
- v:Stop()
- end
- end
- anim:Play()
- fighter.isBlocking = true
- end
- function FightModule.Defend(player: Player, fighter: Types.Fighter)
- if players[playedTurns] ~= player.UserId then return end -- not the player's turn
- if fighter.isAttacking then return end -- player is doing attack
- if fighter.isBlocking then return end -- player is blocking
- Defend(fighter)
- NextTurn()
- end
- function FightModule.EnemyAITurn()
- if #globalFighters == 2 then
- -- 1v1
- local playerFighter: Types.Fighter = globalFighters[1] -- player
- local opponentFighter: Types.Fighter = globalFighters[2] -- ai
- ResetFighterAtTurnStart(opponentFighter)
- if opponentFighter.model.Humanoid.Health <= 0 then
- NextTurn()
- return
- end
- task.wait(2) -- give the illusion of AI thinking
- local aiAction
- if opponentFighter.ability then
- aiAction = math.random(1, 2)
- else
- aiAction = math.random(1, 5)
- end
- if opponentFighter.ability then
- if
- AbilityModule.
- IsAbilityType(opponentFighter.ability, CustomEnum.AbilityType.Attack)
- or
- AbilityModule.
- IsAbilityType(opponentFighter.ability, CustomEnum.AbilityType.Cutscene)
- then
- aiAction = 1
- end
- end
- if aiAction == 1 then
- -- attack
- Attack(opponentFighter, playerFighter)
- elseif aiAction == 2 then
- Defend(opponentFighter)
- elseif aiAction > 2 then
- FightModule.Ability({UserId = 0}, opponentFighter, aiAction - 2)
- end
- NextTurn()
- elseif #globalFighters > 2 then
- -- party
- local playerFighters: {Types.Fighter} = GetPlayerFighters(globalFighters, players[1]) -- player
- local opponentFighters: {Types.Fighter} = GetPlayerFighters(globalFighters, 0) -- ai
- local opponentFighter = GetRandomFighter(opponentFighters)
- local playerFighter = GetRandomFighter(playerFighters)
- for i,v in opponentFighters do
- ResetFighterAtTurnStart(v)
- end
- if opponentFighter == nil or playerFighter == nil then
- NextTurn()
- return
- end
- task.wait(2) -- give the illusion of AI thinking
- local aiAction
- if opponentFighter.ability then
- aiAction = math.random(1, 2)
- else
- aiAction = math.random(1, 5)
- end
- if opponentFighter.ability then
- if
- AbilityModule.
- IsAbilityType(opponentFighter.ability, CustomEnum.AbilityType.Attack)
- or
- AbilityModule.
- IsAbilityType(opponentFighter.ability, CustomEnum.AbilityType.Cutscene)
- then
- aiAction = 1
- end
- end
- if aiAction == 1 then
- -- attack
- Attack(opponentFighter, playerFighter)
- elseif aiAction == 2 then
- Defend(opponentFighter)
- elseif aiAction > 2 then
- FightModule.Ability({UserId = 0}, opponentFighter, aiAction - 2)
- end
- NextTurn()
- end
- end
- return FightModule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement