Advertisement
Quoteory

Bite

Mar 14th, 2021
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.11 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local CollectionService = game:GetService("CollectionService")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. local Debris = game:GetService("Debris")
  5. local RotatedRegion3 = require(ReplicatedStorage.SharedModules.RotatedRegion3)
  6. local EffectsManager = require(ReplicatedStorage.SharedModules.EffectsManager)
  7. local Constants = require(ReplicatedStorage.SharedModules.Constants)
  8. local isServer = RunService:IsServer()
  9. local remotes = ReplicatedStorage.Remotes
  10. local abilityRE = remotes.Ability
  11.  
  12. local PlayerManager
  13.  
  14. local Bite = setmetatable({}, require(script.Parent.Ability))
  15. Bite.__index = Bite
  16.  
  17. Bite.Cooldown = .5
  18. Bite.Range = 5
  19. Bite.Damage = 5
  20. Bite.MaxDamage = 15
  21.  
  22. function Bite.new(player, creature, abilitySlot)
  23.     local self = setmetatable({}, Bite)
  24.     self.Player = player
  25.     self.Creature = creature
  26.     self.AbilitySlot = abilitySlot
  27.     return self
  28. end
  29.  
  30.  
  31. function Bite:Activate(...)
  32.     if not self:CanActivate() then return end
  33.     self:SetActivateDebounce()
  34.    
  35.     local creatureCharacter = self.Creature.Character
  36.     local creatureData = self.Creature.Data
  37.     local stage = self.Creature.Stage
  38.    
  39.     if isServer then
  40.         local targetCharacter = unpack({...})
  41.         local primaryPart = targetCharacter.PrimaryPart
  42.        
  43.         if not primaryPart then return end
  44.        
  45.         if targetCharacter:GetAttribute("Creature") then
  46.             local targetPlayer = targetCharacter and PlayerManager.GetPlayerFromCharacter(targetCharacter)
  47.             local targetCreature = targetPlayer and targetPlayer.Creature
  48.  
  49.             local damage = math.random(self.Damage, self.MaxDamage)
  50.             local intensity = damage / self.MaxDamage
  51.  
  52.             if targetCreature then
  53.                 targetCreature:IncrementHealth(-damage)
  54.                 EffectsManager.CastEffectToAll("Hitmarker", primaryPart.Position + Vector3.new(0, .5, 0), damage, intensity)
  55.             end
  56.  
  57.         elseif targetCharacter:GetAttribute("Corpse") then
  58.             local health = targetCharacter:GetAttribute("Health")
  59.             local healthToTake = math.clamp(self.Damage, 0, math.min(stage.Attributes.MaxHunger-creatureData.Attributes.Hunger, health))
  60.             local intensity = .5
  61.            
  62.             self.Creature:IncrementHealth(healthToTake * 3)
  63.             targetCharacter:SetAttribute("Health", health-healthToTake)
  64.             self.Creature:IncrementHunger(healthToTake)
  65.             EffectsManager.CastEffectToAll("Hitmarker", primaryPart.Position + Vector3.new(0, .5, 0), healthToTake, intensity, true)
  66.         end
  67.  
  68.     else
  69.         local humanoid = self.Creature.Character.Humanoid
  70.        
  71.         humanoid:LoadAnimation(self.Creature.Character.Animations.Attack):Play()
  72.        
  73.         local stage = self.Creature.Stage
  74.         local cf, size = self.Creature.Character:GetBoundingBox()
  75.         local hitboxSize = stage.Attributes.HitboxMin:Lerp(stage.Attributes.HitboxMax, creatureCharacter:GetAttribute("Exp")/stage.Attributes.MaxExp)
  76.        
  77.        
  78.         cf = cf + humanoid.MoveDirection * (humanoid.WalkSpeed/10)
  79.        
  80.         local regionCFrame = cf * CFrame.new(0, 0, -hitboxSize.Z/2)
  81.         local region = RotatedRegion3.new(regionCFrame, hitboxSize)
  82.         local whiteList = CollectionService:GetTagged(Constants.ATTACKABLE) or {}
  83.        
  84.         local selfIndex = table.find(whiteList, creatureCharacter)
  85.         if selfIndex then
  86.             table.remove(whiteList, selfIndex)
  87.         end
  88.        
  89.         local partsInRegion = region:FindPartsInRegion3WithWhiteList(whiteList, 1)
  90.        
  91.         local targetCharacter = partsInRegion[1] and partsInRegion[1].Parent
  92.         if targetCharacter and targetCharacter.PrimaryPart then
  93.             abilityRE:FireServer(self.AbilitySlot, targetCharacter)
  94.         end
  95.        
  96.         if Constants.DEBUG_HITBOXS_ENABLED then
  97.             local part = Instance.new("Part")
  98.             part.Size = hitboxSize
  99.             part.CFrame = regionCFrame
  100.             part.Anchored = true
  101.             part.Transparency = .6
  102.             part.CanCollide = false
  103.             part.Material = Enum.Material.SmoothPlastic
  104.             part.BrickColor = targetCharacter and BrickColor.Red() or BrickColor.White()
  105.             part.Parent = workspace
  106.             Debris:AddItem(part, 1)
  107.         end
  108.        
  109.     end
  110. end
  111.  
  112. function Bite:Destroy()
  113.     self.Player = nil
  114.     self.Creature = nil
  115. end
  116.  
  117.  
  118. if isServer then
  119.     local ServerScriptService = game:GetService("ServerScriptService")
  120.     PlayerManager = require(ServerScriptService.Services.PlayerManager)
  121. else
  122.    
  123. end
  124.  
  125. return Bite
  126.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement