from core.combat import AttackType
from core.tuning.skill import SkillTuning

from siege import game


class Shell(object):
    NAME = "Shell"
    ICON = SkillTuning.SHELL.ICON
    SHELL_AMOUNT = 100

    def __init__(self, owner, level, duration):
        self.ownerId = owner.id
        self.percentage = 0.1 + level * 0.02
        game.events['deal_damage'].listen(self.handleDealDamage)

    def onRemove(self, owner):
        game.events['deal_damage'].remove(self.handleDealDamage)

    def handleDealDamage(self, player, results, attacker, target, data, isCritical, damage):
        if data.attackType is AttackType.Magic and self.ownerId == target.id:
            results.damage -= results.damage * self.percentage
            # TODO: Consider showing animation on top of target

    def isPositive(self):
        return True

    @staticmethod
    def register():
        game.effects.register(Shell.NAME, Shell)
