-- Attack: melee strike with configurable power, range, and speed local BaseSkill = require("skills.base") local Skill = {} Skill.__index = Skill setmetatable(Skill, { __index = BaseSkill }) function Skill:new(asset, combatant) self = setmetatable(BaseSkill:new(asset, combatant), Skill) self.originalDir = self.combatant.facing self.duration = 0.5 self.damageDealt = false self.range = 32 combatant.skillAnimation = "attack" Sound.play("sword") local hit = {} local opponents = self:getOpponents() for _, t in ipairs(opponents) do if self:isInFront(t, self.range) then table.insert(hit, t) end end self.hitTargets = hit return self end function Skill:update(dt) self.timer = self.timer + dt self.combatant.moveX = 0 if not self.damageDealt then self.damageDealt = true for _, target in ipairs(self.hitTargets) do local damage = self:calcDamage(self.combatant, target) if damage > 0 then target:damage(damage) target:knockback(self.combatant.facing, 180) end end end self:updateWeaponSprite(dt) if self.timer >= self.duration then self.combatant.skillAnimation = nil return true end return false end function Skill:draw() local weapon = self:getWeapon() if weapon then local offset = weapon.config.offset or { 0, 0 } local wX = self.combatant.x + (self.combatant.facing * ((math.cos(self.timer * 30) * 3) + 5 + offset[1])) local wY = self.combatant.y + self.combatant.visualOffsetY + offset[2] if self.combatant.facing == -1 then wX = wX + self.combatant.width end self:drawWeaponSpriteAnimation(wX, wY, { scale = { self.combatant.facing, 1 } }) end end return Skill