-- Shield bash: defensive skill that damages nearest opponent 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.duration = 0.4 self.damageDealt = false self.range = 30 self.multiplier = 0.8 combatant.skillAnimation = "skill" self.shieldImage = asset.imageLoader("shield") self.hitTargets = {} local opponents = self:getOpponents() for _, t in ipairs(opponents) do if self:isInFront(t, self.range) then table.insert(self.hitTargets, t) end end Sound.play("shield_bash") return self end function Skill:update(dt) self.timer = self.timer + dt self.combatant.velX = self.combatant.velX / 10 if not self.damageDealt then self.damageDealt = true for _, t in ipairs(self.hitTargets) do local damage = self:calcDamage(self.combatant, t) if damage > 0 then t:damage(damage) t:knockback(self.combatant.facing, 220) if t.behavior then t.behavior.disableTimer = .75 end end end end if self.timer >= self.duration then self.combatant.skillAnimation = nil return true end return false end function Skill:calcDamage(source, target) return BaseSkill.calcDamage(self, source, target) end function Skill:draw() local alpha = 1 - (self.timer / self.duration) local dir = self.combatant.facing local ex = self.combatant.x + (math.min(0, self.timer - .1) * 60 * dir) + ((dir == 1 and self.combatant.width) or 0) local ey = self.combatant.y --love.graphics.setColor(1, 1, 1, alpha) love.graphics.draw( self.shieldImage, ex, ey, 0, dir, 1 ) --love.graphics.setColor(1, 1, 1, 1) end return Skill