Example #1
0
    public void RepairArmor(int index)
    {
        var item = ItemContainer.ItemSearch("Item repair kit");

        if (item != null)
        {
            // Get armor
            EquipmentType  type  = (EquipmentType)index;
            EquippableItem armor = equipmentPanel.ContainsEquipmentType(type);

            // Armor equipped ?
            if (armor != null)
            {
                Debug.Log("Durability before repair: " + armor.CurrentArmorDurability);

                // Armor need repair ?
                if (armor.CurrentArmorDurability < armor.ArmorDurability)
                {
                    armor.CurrentArmorDurability = armor.ArmorDurability;

                    Item oldItem = ItemContainer.RemoveItem(item.ID);
                    oldItem.Destroy();

                    Debug.Log("Durability after repair: " + armor.CurrentArmorDurability);
                }
                else
                {
                    Debug.Log("Armor don't need repair");
                }
            }
            else
            {
                Debug.Log($"No {type} is currently equipped. Cannot repair armor");
            }
        }
        else
        {
            Debug.Log("You don't have a repair kit");
        }
    }
Example #2
0
    public void TakeDamage(int damage, EquipmentType equipmentType)
    {
        if (Invincibility)
        {
            return;
        }

        CharacterStat stat = null;

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

        case EquipmentType.RearArmor:
            stat = RearBumperArmor;
            break;

        case EquipmentType.RightArmor:
            stat = RightFlankArmor;
            break;

        case EquipmentType.LeftArmor:
            stat = LeftFlankArmor;
            break;

        case EquipmentType.Wheel:
            stat = WheelArmor;
            break;

        case EquipmentType.Tires:
            stat = TiresArmor;
            break;

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

        // Reduce damage taken by armor value
        if (stat != null)
        {
            damage -= (int)stat.Value;
            damage  = Mathf.Clamp(damage, 0, int.MaxValue);
        }

        // Get armor
        var armor = equipmentPanel.ContainsEquipmentType(equipmentType);

        Debug.Log($"{equipmentType} : {armor}");

        // Armor equipped ?
        if (armor != null)
        {
            // Reduce the armor durability first from damage
            Debug.Log($"{equipmentType} Durability before hit: " + armor.CurrentArmorDurability);
            armor.CurrentArmorDurability -= damage;
            Debug.Log($"{equipmentType} Durability after hit: " + armor.CurrentArmorDurability);

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