/// <summary>
        /// Update armor values after equipping or unequipping a piece of armor.
        /// </summary>
        public void UpdateEquippedArmorValues(DaggerfallUnityItem armor, bool equipping)
        {
            if (armor.ItemGroup == ItemGroups.Armor ||
                (armor.ItemGroup == ItemGroups.MensClothing && armor.GroupIndex >= 6 && armor.GroupIndex <= 8) ||
                (armor.ItemGroup == ItemGroups.WomensClothing && armor.GroupIndex >= 4 && armor.GroupIndex <= 6)
                )
            {
                if (!armor.IsShield)
                {
                    // Get slot used by this armor
                    EquipSlots slot = ItemEquipTable.GetEquipSlot(armor);

                    // Get equip index with out of range check
                    int index = (int)DaggerfallUnityItem.GetBodyPartForEquipSlot(slot);
                    if (armorValues == null || index < 0 || index >= armorValues.Length)
                    {
                        return;
                    }

                    if (equipping)
                    {
                        armorValues[index] -= (sbyte)(armor.GetMaterialArmorValue() * 5);
                    }
                    else
                    {
                        armorValues[index] += (sbyte)(armor.GetMaterialArmorValue() * 5);
                    }
                }
                else
                {
                    // Shield armor values in classic are unaffected by their material type.
                    int[]       values             = { 0, 0, 0, 0, 0, 0, 0 }; // shield's effect on the 7 armor values
                    int         armorBonus         = armor.GetShieldArmorValue();
                    BodyParts[] protectedBodyParts = armor.GetShieldProtectedBodyParts();

                    foreach (var BodyPart in protectedBodyParts)
                    {
                        values[(int)BodyPart] = armorBonus;
                    }

                    for (int i = 0; i < armorValues.Length; i++)
                    {
                        if (equipping)
                        {
                            armorValues[i] -= (sbyte)(values[i] * 5);
                        }
                        else
                        {
                            armorValues[i] += (sbyte)(values[i] * 5);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        // Refresh armour value labels
        void RefreshArmourValues(PlayerEntity playerEntity, bool suppress = false)
        {
            DaggerfallUnityItem shield = playerEntity.ItemEquipTable.GetItem(EquipSlots.LeftHand); // Checks if character is using a shield or not.

            if (shield != null && !shield.IsShield)
            {
                shield = null;
            }
            bool hasShield = (shield != null) ? true : false; // if shield has a value, then true, if not, false.

            int[] shieldCovered = { 0, 0, 0, 0, 0, 0, 0 };    // shield's effect on the 7 armor values
            if (hasShield)
            {
                int         armorBonus         = shield.GetShieldArmorValue();
                BodyParts[] protectedBodyParts = shield.GetShieldProtectedBodyParts();

                foreach (var BodyPart in protectedBodyParts)
                {
                    shieldCovered[(int)BodyPart] = armorBonus;
                }
            }


            for (int bpIdx = 0; bpIdx < DaggerfallEntity.NumberBodyParts; bpIdx++)
            {
                int    armorMod      = playerEntity.DecreasedArmorValueModifier - playerEntity.IncreasedArmorValueModifier;
                float  armorDamReduc = 0f;
                float  bpAvB         = 0;
                float  bpAvS         = 0;
                float  bpAvP         = 0;
                string bludResist    = "";
                string slasResist    = "";
                string pierResist    = "";

                EquipSlots          hitSlot = DaggerfallUnityItem.GetEquipSlotForBodyPart((BodyParts)bpIdx);
                DaggerfallUnityItem armor   = playerEntity.ItemEquipTable.GetItem(hitSlot);
                if (armor != null)
                {
                    armorDamReduc = FormulaHelper.PercentageDamageReductionCalculation(armor, false, 0f, 1);
                    bpAvB         = (int)Mathf.Round((armorDamReduc - 1) * -100f) - armorMod;

                    armorDamReduc = FormulaHelper.PercentageDamageReductionCalculation(armor, false, 0f, 2);
                    bpAvS         = (int)Mathf.Round((armorDamReduc - 1) * -100f) - armorMod;

                    armorDamReduc = FormulaHelper.PercentageDamageReductionCalculation(armor, false, 0f, 3);
                    bpAvP         = (int)Mathf.Round((armorDamReduc - 1) * -100f) - armorMod;

                    bludResist = "B: " + bpAvB + "%";
                    slasResist = "S: " + bpAvS + "%";
                    pierResist = "P: " + bpAvP + "%";

                    if (armor.ItemGroup == ItemGroups.Tiara_Jewelry || armor.ItemGroup == ItemGroups.Crown_Jewelry)
                    {
                        bludResist = "";
                        slasResist = "";
                        pierResist = "";
                    }
                }
                armourLabelsB[bpIdx].Text = (!suppress) ? bludResist : string.Empty;
                armourLabelsS[bpIdx].Text = (!suppress) ? slasResist : string.Empty;
                armourLabelsP[bpIdx].Text = (!suppress) ? pierResist : string.Empty;

                if (armorMod < 0)
                {
                    armourLabelsB[bpIdx].TextColor = DaggerfallUI.DaggerfallUnityStatDrainedTextColor2;
                    armourLabelsS[bpIdx].TextColor = DaggerfallUI.DaggerfallUnityStatDrainedTextColor2;
                    armourLabelsP[bpIdx].TextColor = DaggerfallUI.DaggerfallUnityStatDrainedTextColor2;
                }
                else if (armorMod > 0)
                {
                    armourLabelsB[bpIdx].TextColor = DaggerfallUI.DaggerfallUnityStatIncreasedTextColor2;
                    armourLabelsS[bpIdx].TextColor = DaggerfallUI.DaggerfallUnityStatIncreasedTextColor2;
                    armourLabelsP[bpIdx].TextColor = DaggerfallUI.DaggerfallUnityStatIncreasedTextColor2;
                }
                else
                {
                    armourLabelsB[bpIdx].TextColor = DaggerfallUI.DaggerfallDefaultTextColor;
                    armourLabelsS[bpIdx].TextColor = DaggerfallUI.DaggerfallDefaultTextColor;
                    armourLabelsP[bpIdx].TextColor = DaggerfallUI.DaggerfallDefaultTextColor;
                }

                if (hasShield)
                {
                    bool   covered         = (shieldCovered[bpIdx] > 0) ? true : false;
                    float  shieldBlockChan = (int)Mathf.Round(FormulaHelper.ShieldBlockChance(shield, playerEntity, covered));
                    string shieldText      = "Bk:" + shieldBlockChan + "%";

                    if (covered)
                    {
                        shieldLabels[bpIdx].Text      = (!suppress) ? shieldText : string.Empty;
                        shieldLabels[bpIdx].TextColor = DaggerfallUI.DaggerfallDefaultTextColor;
                    }
                    else
                    {
                        shieldLabels[bpIdx].Text      = (!suppress) ? shieldText : string.Empty;
                        shieldLabels[bpIdx].TextColor = DaggerfallUI.DaggerfallDefaultTextColor;
                    }
                }
                else
                {
                    shieldLabels[bpIdx].Text = "";
                }
            }
        }