akitheone

Untitled

Jan 20th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.28 KB | None | 0 0
  1. local CombatManager = {}
  2. local PacketSender = require(game.ServerScriptService.Net.Packets.PacketSender)
  3. local WorldPlayers = require(game.ServerScriptService.World.WorldData)
  4.  
  5. CombatManager.__index = CombatManager
  6.  
  7. local MAGIC_FAST_CAST_MODE = 1
  8. local MAGIC_CAST_MODE = 2
  9. local RANGE_COMBAT_MODE = 3
  10.  
  11. function CombatManager.new(Client)
  12.     local combat = {}
  13.     combat.Client = Client
  14.     combat.combatMode = MAGIC_CAST_MODE
  15.     combat.waitingToUseMainSkillClass = nil
  16.     combat.lastHitReached = false
  17.     combat.hasEquippedSpell = false
  18.     combat.lastAttack = nil
  19.     combat.lastHitComboTimer = nil
  20.     combat.comboStage = 1
  21.     combat.currentAttackAnim = nil
  22.     setmetatable(combat, CombatManager)
  23.     return combat
  24. end
  25.  
  26. function CombatManager:UnEquipSkillSpell(MainClassData, Client)
  27.     local Character = Client.Character;
  28.     if(MainClassData.def.EquipPartNames ~= nil) then
  29.         for _, v in ipairs(MainClassData.def.EquipPartNames) do
  30.            
  31.             local part = Character:FindFirstChild(v)
  32.             --print("Char name :", Client, " value: ", v, "unequip skill at part found : ", part)
  33.             if(part ~= nil and part:FindFirstChild("0"..MainClassData.spellId) ~= nil) then
  34.                 part:FindFirstChild("0"..MainClassData.spellId):Destroy()
  35.                 part:FindFirstChild("weld"):Destroy()
  36.             end
  37.         end
  38.     end
  39. end
  40.  
  41. function CombatManager:EquipSkillSpell(MainClassData, Client)
  42.     local Character = Client.Character;
  43.     if(MainClassData.def.EquipPartNames ~= nil) then
  44.         for _, v in ipairs(MainClassData.def.EquipPartNames) do
  45.            
  46.             local part = Character:FindFirstChild(v)
  47.             --print("Char name :", Client, " value: ", v, "part found : ", part)
  48.             if(part ~= nil) then
  49.                 local WeldForPart = Instance.new("Weld")
  50.                 local skill = MainClassData.model:Clone()
  51.                 skill.root.CFrame = part.CFrame
  52.                 skill.Parent = part
  53.                 WeldForPart.Name = "weld"
  54.                 WeldForPart.Parent = part
  55.                 WeldForPart.Part0 = part
  56.                 WeldForPart.Part1 = skill.root
  57.             end
  58.         end
  59.     end
  60. end
  61.  
  62. function CombatManager:ActivateCombatMode(hotkeyslot, MainClassData, Client)
  63.     if(MainClassData.cast_type == 1) then
  64.         print("its a spell class to activate")
  65.         self.waitingToUseMainSkillClass = MainClassData
  66.         self.waitingToUseSkillAtHotKeySlot = hotkeyslot
  67.        
  68.         if(MainClassData.def.hasEquipCast ~= nil and MainClassData.def.hasEquipCast == true) then
  69.             if(WorldPlayers.OnlinePlayers[Client] ~= nil) then
  70.                 if( WorldPlayers.OnlinePlayers[Client].combatManager.hasEquippedSpell == true and self.lastEquip ~= nil) then
  71.                     self:UnEquipSkillSpell(self.lastEquip, Client)
  72.                     --self.lastEquip = nil
  73.                     WorldPlayers.OnlinePlayers[Client].combatManager.hasEquippedSpell = false;
  74.                 end
  75.                 if(self.lastEquip == nil or self.lastEquip.spellId ~= MainClassData.spellId) then
  76.                     WorldPlayers.OnlinePlayers[Client].combatManager.combatMode = MAGIC_FAST_CAST_MODE
  77.                     self:EquipSkillSpell(MainClassData, Client)
  78.                     self.lastEquip = MainClassData
  79.                     WorldPlayers.OnlinePlayers[Client].combatManager.hasEquippedSpell = true
  80.                 else
  81.                     self.lastEquip = nil
  82.                     WorldPlayers.OnlinePlayers[Client].combatManager.hasEquippedSpell = false
  83.                     WorldPlayers.OnlinePlayers[Client].combatManager.combatMode = -1
  84.                 end
  85.             end
  86.             PacketSender:SendTargetIconToSpawn(Client, self.combatMode, true)
  87.         else
  88.            
  89.            
  90.             if(self.lastEquip ~= nil and self.lastEquip.spellId ~= MainClassData.spellId) then
  91.                 self:UnEquipSkillSpell(self.lastEquip, Client)
  92.                 self.lastEquip = nil
  93.                 WorldPlayers.OnlinePlayers[Client].combatManager.hasEquippedSpell = false;
  94.             end
  95.             WorldPlayers.OnlinePlayers[Client].combatManager.combatMode = MAGIC_CAST_MODE
  96.             PacketSender:SendTargetIconToSpawn(Client, self.combatMode, false)
  97.         end
  98.     end
  99. end
  100.  
  101. function CombatManager:StartHit(Client, Target, isVectorPos)
  102. --  print("Starting player combat:", Client)
  103. --  print(Client, " has target of : ", Target, " and is it vector click?", isVectorPos)
  104.     local isVectorPosClick = (not (isVectorPos == false or isVectorPos == nil))
  105.     if(isVectorPosClick == true) then
  106.            
  107.         self.waitingToUseMainSkillClass:Activate(Client, Target, nil)
  108.     else
  109.         if(self.waitingToUseMainSkillClass ~= nil) then
  110.             local NpcClass = Target.NpcClassData
  111.             --print("Target")
  112.             for i,v in pairs(Target) do
  113.                 --print(i)
  114.                
  115.             end
  116.             local NpcTargetArea = Target.npcModel:WaitForChild(NpcClass.RootName):WaitForChild(NpcClass.AttackPartName)
  117.             --[[local starttime = tick()
  118.             local cooldown = self.waitingToUseMainSkillClass.def.coolDown
  119.             PacketSender:SendHotkeySlotCoolDown(Client, self.waitingToUseSkillAtHotKeySlot, cooldown)
  120.             local slotToDisable = self.waitingToUseSkillAtHotKeySlot
  121.             local waitforcooldown
  122.             waitforcooldown = game:GetService('RunService').Stepped:Connect(function(delta)
  123.                 if(tick() - starttime > cooldown) then
  124.                     waitforcooldown:Disconnect()
  125.                     print("cool down completed disable cooldown. on hotkey slot: ", slotToDisable)
  126.                     PacketSender:SendHotkeySlotCoolDown(Client, slotToDisable, 0, true)
  127.                 end
  128.                 game:GetService('RunService').Stepped:Wait()
  129.             end)--]]
  130.             self.waitingToUseMainSkillClass:Activate(Client, NpcTargetArea, NpcClass)
  131.        
  132.         else
  133.             --print("cant attack right now.")
  134.         end
  135.     end
  136. end
  137.  
  138. function CombatManager:ApplyHit(Client, NpcToHit, DidHit, HitData)
  139.     local value = {}
  140.     local damageDealt = 0
  141.     local finaldelevery = nil
  142.     if(HitData ~= nil) then
  143.         local bonusmanager = WorldPlayers.OnlinePlayers[Client].bonusmanager;
  144.         damageDealt = bonusmanager:GetBaseDamage(HitData.attackType);
  145.         local npcbonusmanager = NpcToHit.bonusmanager
  146.         local npcattacklevel = npcbonusmanager.attacklevel
  147.         local npcdeflevel = npcbonusmanager.deflevel
  148.        
  149.        
  150.         if (npcattacklevel > npcdeflevel) then
  151.             finaldelevery = math.floor(damageDealt* (1 + (npcattacklevel - npcdeflevel) / 100))
  152.         elseif (npcattacklevel < npcdeflevel) then
  153.             finaldelevery = math.floor(damageDealt / ( 1 + ( 1.2 * (npcdeflevel - npcattacklevel)/100)))
  154.         end
  155.        
  156.        
  157.         finaldelevery = math.floor(damageDealt* (1 + (npcattacklevel - npcdeflevel) / 100))
  158. --      print(damageDealt, ", final :", finaldelevery)
  159.         local hitwith = HitData.hitWith
  160.         if(hitwith ~= nil) then
  161. --          print("hit with spell id: ", hitwith.spellId, " damage of :", finaldelevery)
  162.         end
  163.     end
  164.     if(finaldelevery ~= nil) then
  165.         value.damage = finaldelevery
  166.     else
  167.         value.damage = damageDealt
  168.     end
  169.     if(DidHit == false) then
  170.         value.damage = 0
  171.     end
  172.    
  173.     self.lastHitReached = DidHit
  174.     value.client = Client
  175.    
  176.     table.insert(NpcToHit.pendingHits, value)
  177. end
  178.  
  179. function CombatManager:GetCastAnimationIdForComboStage(SkillClass)
  180.     local allow = false
  181.     if(self.lastHitComboTimer == nil) then
  182.         self.lastHitComboTimer = tick()
  183.         allow = true
  184.     end
  185.     --print(tick() - self.lastHitComboTimer)
  186.     if(SkillClass.def.EquipPartNames ~= nil) then
  187.             --print("annim at combo stage :", self.comboStage)
  188.             return SkillClass.def.animationsAtPart[self.comboStage]
  189.     else
  190.         self.lastHitComboTimer = tick()
  191.         return SkillClass.def.defaultCastAnim
  192.     end
  193. end
  194.  
  195. function CombatManager:GetSkillLaunchPosition(Client, SkillClass)
  196.     local PartToLaunchFrom = Client.Character:FindFirstChild(SkillClass.def.PartPositionAtComboState(self.comboStage))
  197.     --print("PArt to Launch from: ", PartToLaunchFrom)
  198.     local Child = PartToLaunchFrom:FindFirstChild("0"..SkillClass.spellId)
  199.     if(Child ~= nil) then
  200.         return PartToLaunchFrom:FindFirstChild("0"..SkillClass.spellId).root.CFrame
  201.     end
  202.     return nil
  203. end
  204.  
  205. function CombatManager:CanAttack(SkillClass, resetTimer)
  206.     local allow = false
  207.     if(SkillClass.hasActiveCoolDown~= nil and SkillClass.hasActiveCoolDown == true) then
  208.         return false
  209.     end
  210.     if (self.lastAttack == nil) then
  211.             if(self.lastHitComboTimer == nil and self.lastAttack == nil) then
  212.                 allow = true   
  213.                 self.lastAttack = tick()
  214.                 self.lastHitComboTimer = self.lastAttack
  215.                 if(SkillClass.def.EquipPartNames ~= nil) then
  216.                     self.comboStage = 1
  217.                 end
  218.             end
  219.             return true
  220.     end
  221.    
  222.     if(self.lastSpellCast == nil) then
  223.         return true;
  224.     end
  225.    
  226.     if(SkillClass.spellId ~= self.lastSpellCast.spellId) then
  227.        
  228.         return true
  229.     end
  230.    
  231.     if(self.lastHitComboTimer == nil) then
  232.  
  233.         return true;
  234.     end
  235.  
  236.    
  237.     if(self.lastSpellCast ~= nil) then
  238.         if(self.lastSpellCast.isBeingLaunched == true) then
  239.             print("cant attack yet....")
  240.             return false;
  241.         end
  242.         if(self.lastSpellCast.spellId == SkillClass.spellId) then
  243.             print("casting same spell check for combo patterns and cooldown recast...")
  244.             if(self.lastHitComboTimer ~= nil) then
  245.                 if(tick() - self.lastHitComboTimer  > 0.5) then
  246.                     print(self.comboStage, " COMBOOOO STAGE")
  247.                     if(self.comboStage >= #SkillClass.def.EquipPartNames) then
  248.                         self.comboStage = 0
  249.                     end
  250.                     return true
  251.                 else
  252.                     return false
  253.                 end
  254.             else
  255.                 return true;
  256.             end
  257.         else
  258.            
  259.             self.comboStage = 1
  260.             print("casting new spell reset combos.")
  261.             return true;
  262.         end
  263.     end
  264.     --[[Old Version of combo increment]
  265.     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)
  266.     if(self.lastCastCanceled ~= nil and self.lastCastCanceled == true or allow == true or self.lastSpellCast ~= nil and self.lastSpellCast.spellId ~= SkillClass.spellId) then
  267.         self.lastSpellCast = SkillClass
  268.         if(self.lastHitComboTimer ~= nil) then
  269.             if(tick() - self.lastHitComboTimer  > 0.5) then
  270.                 if(SkillClass.def.EquipPartNames ~= nil) then
  271.                     if(self.comboStage >= #SkillClass.def.EquipPartNames) then
  272.                         self.comboStage = 0
  273.                     end
  274.                     self.comboStage = self.comboStage + 1
  275.    
  276.                     if(resetTimer == true or resetTimer == nil) then
  277.                         self.lastHitComboTimer = tick()
  278.                     end
  279.                 else
  280.                 end
  281.             end
  282.         end
  283.         if(resetTimer == true or resetTimer == nil) then
  284.             self.lastAttack = tick()
  285.         end
  286.         return true;
  287.     end
  288.     --]]
  289.    
  290.    
  291.     print("cant attack...")
  292.     return false
  293. end
  294.  
  295. function CombatManager:HandleLaunchAttack(SkillClass)
  296.     if(SkillClass.def.EquipPartNames ~= nil) then
  297.         self.comboStage = self.comboStage + 1
  298.         print("increased...", self.comboStage)
  299.     end
  300.     if(SkillClass.def.EquipPartNames ~= nil and self.comboStage > #SkillClass.def.EquipPartNames) then
  301.         self.comboStage = 1;
  302.     end
  303.     self.lastHitComboTimer = tick()
  304.     self.lastSpellCast = SkillClass
  305.     self.lastAttack = tick()
  306. end
  307. return CombatManager
Add Comment
Please, Sign In to add comment