local I=game:GetService("\080\108\097\121\101\114\115")local x=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local u=require((x:WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101"))local U=u:GetResource("\069\120\116\101\114\110\097\108\085\116\105\108\046\078\101\120\117\115\073\110\115\116\097\110\099\101\046\078\101\120\117\115\079\098\106\101\099\116")local k=u:GetResource("\069\110\118\105\114\111\110\109\101\110\116\067\111\110\102\105\103\117\114\097\116\105\111\110")local R=U:Extend()R:SetClassName("\083\119\111\114\100\065\116\116\097\099\107")local p={{AnimationId=k.Animations.SwordAttack,SoundId="\114\098\120\097\115\115\101\116\058\047\047\115\111\117\110\100\115\047\047\115\119\111\114\100\115\108\097\115\104\046\119\097\118",Damage=50};{AnimationId=k.Animations.SwordLunge,SoundId="\114\098\120\097\115\115\101\116\058\047\047\115\111\117\110\100\115\047\047\115\119\111\114\100\115\108\097\115\104\046\119\097\118";Damage=50};{AnimationId=k.Animations.SwordOverhead,SoundId="\114\098\120\097\115\115\101\116\058\047\047\115\111\117\110\100\115\047\047\115\119\111\114\100\108\117\110\103\101\046\119\097\118";Damage=100}}function R.PerformClientAttack(x)local u=I.LocalPlayer.Character if u then local I=u:FindFirstChild("\072\117\109\097\110\111\105\100")if I and I.Health>0 then local u=p[math.max(1,math.ceil((x.X+x.Z)%#p))]local U=Instance.new("\065\110\105\109\097\116\105\111\110")U.AnimationId=u.AnimationId local k=I:LoadAnimation(U)k:Play()end end end function R.PerformServerAttack(I,x,u)local U=I.Character if U then local I=U:FindFirstChild("\072\117\109\097\110\111\105\100")if I and I.Health>0 then local I=U:WaitForChild("\083\119\111\114\100")local k={}local R=p[math.max(math.ceil((u.X+u.Z)%#p))]local z=I.Touched:Connect(function(I)local u=I.Parent if u and(u:IsDescendantOf(x)and not k[u])then local I=u:FindFirstChild("\072\117\109\097\110\111\105\100")if I then k[u]=true I:TakeDamage(R.Damage*(U:FindFirstChild("\066\111\111\115\116\069\102\102\101\099\116")and 2 or 1))end end end)local n=Instance.new("\083\111\117\110\100")n.SoundId=R.SoundId n.Parent=I n:Play()delay(2,function()n:Destroy()end)wait(.7)z:Disconnect()end end end return R
--[[
TheNexusAvenger

Attack for a sword.
Class is static (should not be created).
--]]

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ReplicatedStorageProject = require(ReplicatedStorage:WaitForChild("Project"):WaitForChild("ReplicatedStorage"))

local NexusObject = ReplicatedStorageProject:GetResource("ExternalUtil.NexusInstance.NexusObject")
local EnvironmentConfiguration = ReplicatedStorageProject:GetResource("EnvironmentConfiguration")

local SwordAttack = NexusObject:Extend()
SwordAttack:SetClassName("SwordAttack")

local SwordAnimations = {
    {
        AnimationId = EnvironmentConfiguration.Animations.SwordAttack,
        SoundId = "rbxasset://sounds//swordslash.wav",
        Damage = 50,
    },
    {
        AnimationId = EnvironmentConfiguration.Animations.SwordLunge,
        SoundId = "rbxasset://sounds//swordslash.wav",
        Damage = 50,
    },
    {
        AnimationId = EnvironmentConfiguration.Animations.SwordOverhead,
        SoundId = "rbxasset://sounds//swordlunge.wav",
        Damage = 100,
    },
}



--[[
Performs the attack on the client.
--]]
function SwordAttack.PerformClientAttack(Target)
    --Play a "random" animation.
    local Character = Players.LocalPlayer.Character
    if Character then
        local Humanoid = Character:FindFirstChild("Humanoid")
        if Humanoid and Humanoid.Health > 0 then
            local RandomAnimation = SwordAnimations[math.max(1,math.ceil((Target.X + Target.Z) % #SwordAnimations))]
            local Animation = Instance.new("Animation")
            Animation.AnimationId = RandomAnimation.AnimationId
            local AnimationTrack = Humanoid:LoadAnimation(Animation)
            AnimationTrack:Play()
        end
    end
end

--[[
Performs the attack on the server.
--]]
function SwordAttack.PerformServerAttack(Player,DungeonModel,Target)
    local Character = Player.Character
    if Character then
        local Humanoid = Character:FindFirstChild("Humanoid")
        if Humanoid and Humanoid.Health > 0 then
            local Sword = Character:WaitForChild("Sword")

            --Connect damaging the sword.
            local MonsterDBs = {}
            local RandomAnimation = SwordAnimations[math.max(math.ceil((Target.X + Target.Z) % #SwordAnimations))]
            local TouchEvent = Sword.Touched:Connect(function(TouchPart)
                local MonsterCharacter = TouchPart.Parent
                if MonsterCharacter and MonsterCharacter:IsDescendantOf(DungeonModel) and not MonsterDBs[MonsterCharacter] then
                    local MonsterHumanoid = MonsterCharacter:FindFirstChild("Humanoid")
                    if MonsterHumanoid then
                        MonsterDBs[MonsterCharacter] = true
                        MonsterHumanoid:TakeDamage(RandomAnimation.Damage * (Character:FindFirstChild("BoostEffect") and 2 or 1))
                    end
                end
            end)

            --Play a "random" sound.
            local Sound = Instance.new("Sound")
            Sound.SoundId = RandomAnimation.SoundId
            Sound.Parent = Sword
            Sound:Play()
            delay(2,function()
                Sound:Destroy()
            end)

            --Clear the touch event.
            wait(0.7)
            TouchEvent:Disconnect()
        end
    end
end



return SwordAttack