from core.tuning.skill import SkillTuning
from siege import game


class Veil(object):
    NAME = "Veil"
    ICON = SkillTuning.VEIL.ICON
    VEIL_AMOUNT = 2

    def __init__(self, owner, level, duration):
        self.ownerId = owner.id
        self.amount = self.VEIL_AMOUNT + (level - 1) / 2
        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 self.ownerId == target.id:
            self.amount -= 1
            results.damage = 0
            # TODO: Consider showing animation on top of target
            if self.amount == 0:
                target.effects.remove(self.NAME)

    def isPositive(self):
        return True

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