Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local CombatManager = {}
- local PacketSender = require(game.ServerScriptService.Net.Packets.PacketSender)
- local WorldPlayers = require(game.ServerScriptService.World.WorldData)
- CombatManager.__index = CombatManager
- local MAGIC_FAST_CAST_MODE = 1
- local MAGIC_CAST_MODE = 2
- local RANGE_COMBAT_MODE = 3
- function CombatManager.new(Client)
- local combat = {}
- combat.Client = Client
- combat.combatMode = MAGIC_CAST_MODE
- combat.waitingToUseMainSkillClass = nil
- combat.lastHitReached = false
- combat.hasEquippedSpell = false
- combat.lastAttack = nil
- combat.lastHitComboTimer = nil
- combat.comboStage = 1
- combat.currentAttackAnim = nil
- setmetatable(combat, CombatManager)
- return combat
- end
- function CombatManager:UnEquipSkillSpell(MainClassData, Client)
- local Character = Client.Character;
- if(MainClassData.def.EquipPartNames ~= nil) then
- for _, v in ipairs(MainClassData.def.EquipPartNames) do
- local part = Character:FindFirstChild(v)
- --print("Char name :", Client, " value: ", v, "unequip skill at part found : ", part)
- if(part ~= nil and part:FindFirstChild("0"..MainClassData.spellId) ~= nil) then
- part:FindFirstChild("0"..MainClassData.spellId):Destroy()
- part:FindFirstChild("weld"):Destroy()
- end
- end
- end
- end
- function CombatManager:EquipSkillSpell(MainClassData, Client)
- local Character = Client.Character;
- if(MainClassData.def.EquipPartNames ~= nil) then
- for _, v in ipairs(MainClassData.def.EquipPartNames) do
- local part = Character:FindFirstChild(v)
- --print("Char name :", Client, " value: ", v, "part found : ", part)
- if(part ~= nil) then
- local WeldForPart = Instance.new("Weld")
- local skill = MainClassData.model:Clone()
- skill.root.CFrame = part.CFrame
- skill.Parent = part
- WeldForPart.Name = "weld"
- WeldForPart.Parent = part
- WeldForPart.Part0 = part
- WeldForPart.Part1 = skill.root
- end
- end
- end
- end
- function CombatManager:ActivateCombatMode(hotkeyslot, MainClassData, Client)
- if(MainClassData.cast_type == 1) then
- print("its a spell class to activate")
- self.waitingToUseMainSkillClass = MainClassData
- self.waitingToUseSkillAtHotKeySlot = hotkeyslot
- if(MainClassData.def.hasEquipCast ~= nil and MainClassData.def.hasEquipCast == true) then
- if(WorldPlayers.OnlinePlayers[Client] ~= nil) then
- if( WorldPlayers.OnlinePlayers[Client].combatManager.hasEquippedSpell == true and self.lastEquip ~= nil) then
- self:UnEquipSkillSpell(self.lastEquip, Client)
- --self.lastEquip = nil
- WorldPlayers.OnlinePlayers[Client].combatManager.hasEquippedSpell = false;
- end
- if(self.lastEquip == nil or self.lastEquip.spellId ~= MainClassData.spellId) then
- WorldPlayers.OnlinePlayers[Client].combatManager.combatMode = MAGIC_FAST_CAST_MODE
- self:EquipSkillSpell(MainClassData, Client)
- self.lastEquip = MainClassData
- WorldPlayers.OnlinePlayers[Client].combatManager.hasEquippedSpell = true
- else
- self.lastEquip = nil
- WorldPlayers.OnlinePlayers[Client].combatManager.hasEquippedSpell = false
- WorldPlayers.OnlinePlayers[Client].combatManager.combatMode = -1
- end
- end
- PacketSender:SendTargetIconToSpawn(Client, self.combatMode, true)
- else
- if(self.lastEquip ~= nil and self.lastEquip.spellId ~= MainClassData.spellId) then
- self:UnEquipSkillSpell(self.lastEquip, Client)
- self.lastEquip = nil
- WorldPlayers.OnlinePlayers[Client].combatManager.hasEquippedSpell = false;
- end
- WorldPlayers.OnlinePlayers[Client].combatManager.combatMode = MAGIC_CAST_MODE
- PacketSender:SendTargetIconToSpawn(Client, self.combatMode, false)
- end
- end
- end
- function CombatManager:StartHit(Client, Target, isVectorPos)
- -- print("Starting player combat:", Client)
- -- print(Client, " has target of : ", Target, " and is it vector click?", isVectorPos)
- local isVectorPosClick = (not (isVectorPos == false or isVectorPos == nil))
- if(isVectorPosClick == true) then
- self.waitingToUseMainSkillClass:Activate(Client, Target, nil)
- else
- if(self.waitingToUseMainSkillClass ~= nil) then
- local NpcClass = Target.NpcClassData
- --print("Target")
- for i,v in pairs(Target) do
- --print(i)
- end
- local NpcTargetArea = Target.npcModel:WaitForChild(NpcClass.RootName):WaitForChild(NpcClass.AttackPartName)
- --[[local starttime = tick()
- local cooldown = self.waitingToUseMainSkillClass.def.coolDown
- PacketSender:SendHotkeySlotCoolDown(Client, self.waitingToUseSkillAtHotKeySlot, cooldown)
- local slotToDisable = self.waitingToUseSkillAtHotKeySlot
- local waitforcooldown
- waitforcooldown = game:GetService('RunService').Stepped:Connect(function(delta)
- if(tick() - starttime > cooldown) then
- waitforcooldown:Disconnect()
- print("cool down completed disable cooldown. on hotkey slot: ", slotToDisable)
- PacketSender:SendHotkeySlotCoolDown(Client, slotToDisable, 0, true)
- end
- game:GetService('RunService').Stepped:Wait()
- end)--]]
- self.waitingToUseMainSkillClass:Activate(Client, NpcTargetArea, NpcClass)
- else
- --print("cant attack right now.")
- end
- end
- end
- function CombatManager:ApplyHit(Client, NpcToHit, DidHit, HitData)
- local value = {}
- local damageDealt = 0
- local finaldelevery = nil
- if(HitData ~= nil) then
- local bonusmanager = WorldPlayers.OnlinePlayers[Client].bonusmanager;
- damageDealt = bonusmanager:GetBaseDamage(HitData.attackType);
- local npcbonusmanager = NpcToHit.bonusmanager
- local npcattacklevel = npcbonusmanager.attacklevel
- local npcdeflevel = npcbonusmanager.deflevel
- if (npcattacklevel > npcdeflevel) then
- finaldelevery = math.floor(damageDealt* (1 + (npcattacklevel - npcdeflevel) / 100))
- elseif (npcattacklevel < npcdeflevel) then
- finaldelevery = math.floor(damageDealt / ( 1 + ( 1.2 * (npcdeflevel - npcattacklevel)/100)))
- end
- finaldelevery = math.floor(damageDealt* (1 + (npcattacklevel - npcdeflevel) / 100))
- -- print(damageDealt, ", final :", finaldelevery)
- local hitwith = HitData.hitWith
- if(hitwith ~= nil) then
- -- print("hit with spell id: ", hitwith.spellId, " damage of :", finaldelevery)
- end
- end
- if(finaldelevery ~= nil) then
- value.damage = finaldelevery
- else
- value.damage = damageDealt
- end
- if(DidHit == false) then
- value.damage = 0
- end
- self.lastHitReached = DidHit
- value.client = Client
- table.insert(NpcToHit.pendingHits, value)
- end
- function CombatManager:GetCastAnimationIdForComboStage(SkillClass)
- local allow = false
- if(self.lastHitComboTimer == nil) then
- self.lastHitComboTimer = tick()
- allow = true
- end
- --print(tick() - self.lastHitComboTimer)
- if(SkillClass.def.EquipPartNames ~= nil) then
- --print("annim at combo stage :", self.comboStage)
- return SkillClass.def.animationsAtPart[self.comboStage]
- else
- self.lastHitComboTimer = tick()
- return SkillClass.def.defaultCastAnim
- end
- end
- function CombatManager:GetSkillLaunchPosition(Client, SkillClass)
- local PartToLaunchFrom = Client.Character:FindFirstChild(SkillClass.def.PartPositionAtComboState(self.comboStage))
- --print("PArt to Launch from: ", PartToLaunchFrom)
- local Child = PartToLaunchFrom:FindFirstChild("0"..SkillClass.spellId)
- if(Child ~= nil) then
- return PartToLaunchFrom:FindFirstChild("0"..SkillClass.spellId).root.CFrame
- end
- return nil
- end
- function CombatManager:CanAttack(SkillClass, resetTimer)
- local allow = false
- if(SkillClass.hasActiveCoolDown~= nil and SkillClass.hasActiveCoolDown == true) then
- return false
- end
- if (self.lastAttack == nil) then
- if(self.lastHitComboTimer == nil and self.lastAttack == nil) then
- allow = true
- self.lastAttack = tick()
- self.lastHitComboTimer = self.lastAttack
- if(SkillClass.def.EquipPartNames ~= nil) then
- self.comboStage = 1
- end
- end
- return true
- end
- if(self.lastSpellCast == nil) then
- return true;
- end
- if(SkillClass.spellId ~= self.lastSpellCast.spellId) then
- return true
- end
- if(self.lastHitComboTimer == nil) then
- return true;
- end
- if(self.lastSpellCast ~= nil) then
- if(self.lastSpellCast.isBeingLaunched == true) then
- print("cant attack yet....")
- return false;
- end
- if(self.lastSpellCast.spellId == SkillClass.spellId) then
- print("casting same spell check for combo patterns and cooldown recast...")
- if(self.lastHitComboTimer ~= nil) then
- if(tick() - self.lastHitComboTimer > 0.5) then
- print(self.comboStage, " COMBOOOO STAGE")
- if(self.comboStage >= #SkillClass.def.EquipPartNames) then
- self.comboStage = 0
- end
- return true
- else
- return false
- end
- else
- return true;
- end
- else
- self.comboStage = 1
- print("casting new spell reset combos.")
- return true;
- end
- end
- --[[Old Version of combo increment]
- print("last casted cance:", self.lastCastCanceled, ", allow = ", allow, " lastSpellcast = ", self.lastSpellCast, " last spell Id: ", self.lastSpellCast.spellId, " Casting id: ", SkillClass.spellId," is this same spell as previous?: ", self.lastSpellCast.spellId ~= SkillClass.spellId)
- if(self.lastCastCanceled ~= nil and self.lastCastCanceled == true or allow == true or self.lastSpellCast ~= nil and self.lastSpellCast.spellId ~= SkillClass.spellId) then
- self.lastSpellCast = SkillClass
- if(self.lastHitComboTimer ~= nil) then
- if(tick() - self.lastHitComboTimer > 0.5) then
- if(SkillClass.def.EquipPartNames ~= nil) then
- if(self.comboStage >= #SkillClass.def.EquipPartNames) then
- self.comboStage = 0
- end
- self.comboStage = self.comboStage + 1
- if(resetTimer == true or resetTimer == nil) then
- self.lastHitComboTimer = tick()
- end
- else
- end
- end
- end
- if(resetTimer == true or resetTimer == nil) then
- self.lastAttack = tick()
- end
- return true;
- end
- --]]
- print("cant attack...")
- return false
- end
- function CombatManager:HandleLaunchAttack(SkillClass)
- if(SkillClass.def.EquipPartNames ~= nil) then
- self.comboStage = self.comboStage + 1
- print("increased...", self.comboStage)
- end
- if(SkillClass.def.EquipPartNames ~= nil and self.comboStage > #SkillClass.def.EquipPartNames) then
- self.comboStage = 1;
- end
- self.lastHitComboTimer = tick()
- self.lastSpellCast = SkillClass
- self.lastAttack = tick()
- end
- return CombatManager
Add Comment
Please, Sign In to add comment