Beispiel #1
0
    public void TakeDamage(int damage, EquipmentType type)
    {
        // Invincible?
        if (Invincibility)
        {
            return;
        }

        CharacterStat stat = null;

        switch (type)
        {
        case EquipmentType.FrontArmor:
            stat = FrontBumperArmor;
            break;

        case EquipmentType.RearArmor:
            stat = RearBumperArmor;
            break;

        case EquipmentType.RightArmor:
            stat = RightFlankArmor;
            break;

        case EquipmentType.LeftArmor:
            stat = LeftFlankArmor;
            break;

        default:
            Debug.Log($"No equipped armor.Taking full damage");
            break;
        }

        if (stat != null)
        {
            damage -= ( int )stat.Value;
            damage  = Mathf.Clamp(damage, 0, int.MaxValue);
        }

        // Get armor
        var armor = equipmentPanel.GetEquipmentType(type);

        // Armor equipped?
        if (armor == null)
        {
            EngineHealth -= damage;
            return;
        }

        armor.CurrentArmorDurability -= damage;

        // Armor destroyed?
        if (armor.CurrentArmorDurability <= 0)
        {
            EngineHealth -= Mathf.Abs(armor.CurrentArmorDurability);
            armor.CurrentArmorDurability = 0;
        }
    }