public void TakeDamage(GameState gameState, int amount, DamageType type, Permanent attacker)
        {
            if (type != DamageType.lightning && type != DamageType.acid)
            {
                amount -= stats.armor;
            }

            if (amount <= 0)
                return;

            if (stats.health > 0)
            {
                if (type == DamageType.fire)
                {
                    if (stats.hasKeyword(Keyword.fireproof))
                        return;

                    if (stats.hasKeyword(Keyword.fireform))
                    {
                        // fireform creatures are healed by fire
                        Heal(amount);
                        return;
                    }

                    if (stats.hasKeyword(Keyword.flammable))
                    {
                        permanentStats.burningNextTurn += amount;
                    }
                }

                if (type == DamageType.acid)
                {
                    stats.armor -= amount;
                    if (stats.armor < 0)
                    {
                        stats.health += stats.armor; // reduce health by the (negative) armor
                        stats.armor = 0;
                    }
                    permanentStats.armor = stats.armor;
                }
                else
                {
                    stats.health -= amount;
                }

                if (stats.health < 0)
                    stats.health = 0;
                permanentStats.health = stats.health;
                if (stats.health <= 0)
                {
                    gameState.Destroyed(position, attacker);
                }

                gameState.HandleTriggers(new TriggerEvent(TriggerType.onDamage, attacker, this));
            }
        }
 public Permanent(Permanent basis)
 {
     type = basis.type;
     position = basis.position;
     isEnemy = basis.isEnemy;
 }
 public void Destroyed(Point pos, Permanent killer)
 {
     killed.Add(pos);
     getMinionAt(pos).killedBy = killer;
 }
 public void HandleTriggers(TriggerType eventType, Permanent source, Permanent obj)
 {
     HandleTriggers(new TriggerEvent(eventType, source, obj));
 }
 public WaitingTrigger(TriggerEvent evt, TriggeredAbility ability, Permanent permanent, Point position)
 {
     this.evt = evt;
     this.ability = ability;
     this.permanent = permanent;
     this.position = position;
 }
 public TriggerItem_Permanent(Permanent permanent)
 {
     this.p = permanent;
 }
 public static TriggerItem create(Permanent permanent)
 {
     return new TriggerItem_Permanent(permanent);
 }
 public TriggerEvent(TriggerType type, Permanent a, Point b)
 {
     this.type = type;
     this.source = TriggerItem.create(a);
     this.target = TriggerItem.create(b);
 }
 public TriggerEvent(TriggerType type, Permanent a)
 {
     this.type = type;
     this.source = TriggerItem.create(a);
 }