-- Base skill class BaseSkill = {} BaseSkill.__index = BaseSkill function BaseSkill:new(asset, combatant) self = setmetatable({}, BaseSkill) self.asset = asset self.combatant = combatant self.context = combatant.context self.timer = 0 self.duration = 0.5 self.multiplier = 1 self.config = asset.config or {} self.imageLoader = asset.imageLoader self.weapon = combatant and combatant.weapon self.power = self.config.power or 1 return self end function BaseSkill:calcDamage(source, target) if target.invincible then return 0 end local atk = (source.stats and source.stats.atk or 5) * self.power * self.multiplier local lck = source.stats and source.stats.lck or 0 local def = target.stats and target.stats.def or 0 local maxDmg = atk - def if maxDmg < lck then maxDmg = lck end return math.random(lck, maxDmg) end function BaseSkill:getOpponents() return Utils.filterCombatantsByOpposingTeams(self.context.combatants, self.combatant.team) end function BaseSkill:getAllies() return Utils.filterCombatantsByTeam(self.context.combatants, self.combatant.team) end function BaseSkill:getNearestCombatant(combatants) return Utils.findNearestCombatant(combatants, (self.combatant.x + self.combatant.width / 2), (self.combatant.y + self.combatant.height / 2)) end function BaseSkill:getCombatantsInRange(combatants, range) return Utils.findCombatantsWithinRange(combatants, (self.combatant.x + self.combatant.width / 2), (self.combatant.y + self.combatant.height / 2), range) end function BaseSkill:isInFront(target, range) local attCX = self.combatant.x + self.combatant.width / 2 local attCY = self.combatant.y + self.combatant.height / 2 local tgtCX = target.x + target.width / 2 local tgtCY = target.y + target.height / 2 local dx = tgtCX - attCX local dy = tgtCY - attCY if self.combatant.facing == 1 and dx < 0 then return false end if self.combatant.facing == -1 and dx > 0 then return false end local dist = math.sqrt(dx * dx + dy * dy) return not range or dist <= range end function BaseSkill:getWeapon() return self.combatant and self.combatant.weapon end function BaseSkill:getWeaponSprite() return self.combatant and self.combatant.weapon and self.combatant.weapon.sprite end function BaseSkill:updateWeaponSprite(dt) local sprite = self:getWeaponSprite() if sprite then sprite:update(dt) end end function BaseSkill:drawWeaponSpriteAnimation(x, y, options) local sprite = self:getWeaponSprite() if sprite then sprite:drawAnimationFrame(x, y, options) end end function BaseSkill:drawWeaponSpriteFrame(x, y, frame, options) local sprite = self:getWeaponSprite() if sprite then sprite:drawFrame(x, y, frame, options) end end function BaseSkill:update(dt) end function BaseSkill:draw() end return BaseSkill