Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RunService = game:GetService("RunService")
- local CollectionService = game:GetService("CollectionService")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Debris = game:GetService("Debris")
- local RotatedRegion3 = require(ReplicatedStorage.SharedModules.RotatedRegion3)
- local EffectsManager = require(ReplicatedStorage.SharedModules.EffectsManager)
- local Constants = require(ReplicatedStorage.SharedModules.Constants)
- local isServer = RunService:IsServer()
- local remotes = ReplicatedStorage.Remotes
- local abilityRE = remotes.Ability
- local PlayerManager
- local Bite = setmetatable({}, require(script.Parent.Ability))
- Bite.__index = Bite
- Bite.Cooldown = .5
- Bite.Range = 5
- Bite.Damage = 5
- Bite.MaxDamage = 15
- function Bite.new(player, creature, abilitySlot)
- local self = setmetatable({}, Bite)
- self.Player = player
- self.Creature = creature
- self.AbilitySlot = abilitySlot
- return self
- end
- function Bite:Activate(...)
- if not self:CanActivate() then return end
- self:SetActivateDebounce()
- local creatureCharacter = self.Creature.Character
- local creatureData = self.Creature.Data
- local stage = self.Creature.Stage
- if isServer then
- local targetCharacter = unpack({...})
- local primaryPart = targetCharacter.PrimaryPart
- if not primaryPart then return end
- if targetCharacter:GetAttribute("Creature") then
- local targetPlayer = targetCharacter and PlayerManager.GetPlayerFromCharacter(targetCharacter)
- local targetCreature = targetPlayer and targetPlayer.Creature
- local damage = math.random(self.Damage, self.MaxDamage)
- local intensity = damage / self.MaxDamage
- if targetCreature then
- targetCreature:IncrementHealth(-damage)
- EffectsManager.CastEffectToAll("Hitmarker", primaryPart.Position + Vector3.new(0, .5, 0), damage, intensity)
- end
- elseif targetCharacter:GetAttribute("Corpse") then
- local health = targetCharacter:GetAttribute("Health")
- local healthToTake = math.clamp(self.Damage, 0, math.min(stage.Attributes.MaxHunger-creatureData.Attributes.Hunger, health))
- local intensity = .5
- self.Creature:IncrementHealth(healthToTake * 3)
- targetCharacter:SetAttribute("Health", health-healthToTake)
- self.Creature:IncrementHunger(healthToTake)
- EffectsManager.CastEffectToAll("Hitmarker", primaryPart.Position + Vector3.new(0, .5, 0), healthToTake, intensity, true)
- end
- else
- local humanoid = self.Creature.Character.Humanoid
- humanoid:LoadAnimation(self.Creature.Character.Animations.Attack):Play()
- local stage = self.Creature.Stage
- local cf, size = self.Creature.Character:GetBoundingBox()
- local hitboxSize = stage.Attributes.HitboxMin:Lerp(stage.Attributes.HitboxMax, creatureCharacter:GetAttribute("Exp")/stage.Attributes.MaxExp)
- cf = cf + humanoid.MoveDirection * (humanoid.WalkSpeed/10)
- local regionCFrame = cf * CFrame.new(0, 0, -hitboxSize.Z/2)
- local region = RotatedRegion3.new(regionCFrame, hitboxSize)
- local whiteList = CollectionService:GetTagged(Constants.ATTACKABLE) or {}
- local selfIndex = table.find(whiteList, creatureCharacter)
- if selfIndex then
- table.remove(whiteList, selfIndex)
- end
- local partsInRegion = region:FindPartsInRegion3WithWhiteList(whiteList, 1)
- local targetCharacter = partsInRegion[1] and partsInRegion[1].Parent
- if targetCharacter and targetCharacter.PrimaryPart then
- abilityRE:FireServer(self.AbilitySlot, targetCharacter)
- end
- if Constants.DEBUG_HITBOXS_ENABLED then
- local part = Instance.new("Part")
- part.Size = hitboxSize
- part.CFrame = regionCFrame
- part.Anchored = true
- part.Transparency = .6
- part.CanCollide = false
- part.Material = Enum.Material.SmoothPlastic
- part.BrickColor = targetCharacter and BrickColor.Red() or BrickColor.White()
- part.Parent = workspace
- Debris:AddItem(part, 1)
- end
- end
- end
- function Bite:Destroy()
- self.Player = nil
- self.Creature = nil
- end
- if isServer then
- local ServerScriptService = game:GetService("ServerScriptService")
- PlayerManager = require(ServerScriptService.Services.PlayerManager)
- else
- end
- return Bite
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement