Example #1
0
        /// Allocate any equipment damage from a strike, and reduce item condition.
        private static bool DamageEquipment(DaggerfallEntity attacker, DaggerfallEntity target, int damage, DaggerfallUnityItem weapon, int struckBodyPart)
        {
            int   atkStrength    = attacker.Stats.LiveStrength;
            int   tarMatMod      = 0;
            int   matDifference  = 0;
            bool  bluntWep       = false;
            bool  shtbladeWep    = false;
            bool  missileWep     = false;
            int   wepEqualize    = 1;
            int   wepWeight      = 1;
            float wepDamResist   = 1f;
            float armorDamResist = 1f;

            // If damage was done by a weapon, damage the weapon and armor of the hit body part.
            if (weapon != null && damage > 0)
            {
                int atkMatMod = weapon.GetWeaponMaterialModifier() + 2;
                int wepDam    = damage;
                wepEqualize = EqualizeMaterialConditions(weapon);
                wepDam     *= wepEqualize;

                if (weapon.GetWeaponSkillIDAsShort() == 32)                 // Checks if the weapon being used is in the Blunt Weapon category, then sets a bool value to true.
                {
                    wepDam      += (atkStrength / 10);
                    wepDamResist = (wepEqualize * .20f) + 1;
                    wepDam       = (int)Mathf.Ceil(wepDam / wepDamResist);
                    bluntWep     = true;
                    wepWeight    = (int)Mathf.Ceil(weapon.EffectiveUnitWeightInKg());

                    ApplyConditionDamageThroughWeaponDamage(weapon, attacker, wepDam, bluntWep, shtbladeWep, missileWep, wepEqualize); // Does condition damage to the attackers weapon.
                }
                else if (weapon.GetWeaponSkillIDAsShort() == 28)                                                                       // Checks if the weapon being used is in the Short Blade category, then sets a bool value to true.
                {
                    if (weapon.TemplateIndex == (int)Weapons.Dagger || weapon.TemplateIndex == (int)Weapons.Tanto)
                    {
                        wepDam      += (atkStrength / 30);
                        wepDamResist = (wepEqualize * .90f) + 1;
                        wepDam       = (int)Mathf.Ceil(wepDam / wepDamResist);
                        shtbladeWep  = true;
                    }
                    else
                    {
                        wepDam      += (atkStrength / 30);
                        wepDamResist = (wepEqualize * .30f) + 1;
                        wepDam       = (int)Mathf.Ceil(wepDam / wepDamResist);
                        shtbladeWep  = true;
                    }

                    ApplyConditionDamageThroughWeaponDamage(weapon, attacker, wepDam, bluntWep, shtbladeWep, missileWep, wepEqualize); // Does condition damage to the attackers weapon.
                }
                else if (weapon.GetWeaponSkillIDAsShort() == 33)                                                                       // Checks if the weapon being used is in the Missile Weapon category, then sets a bool value to true.
                {
                    missileWep = true;

                    ApplyConditionDamageThroughWeaponDamage(weapon, attacker, wepDam, bluntWep, shtbladeWep, missileWep, wepEqualize); // Does condition damage to the attackers weapon.
                }
                else                                                                                                                   // If all other weapons categories have not been found, it defaults to this, which currently includes long blades and axes.
                {
                    wepDam      += (atkStrength / 10);
                    wepDamResist = (wepEqualize * .20f) + 1;
                    wepDam       = (int)Mathf.Ceil(wepDam / wepDamResist);

                    ApplyConditionDamageThroughWeaponDamage(weapon, attacker, wepDam, bluntWep, shtbladeWep, missileWep, wepEqualize);                     // Does condition damage to the attackers weapon.
                }

                if (attacker == GameManager.Instance.PlayerEntity)
                {
                    WarningMessagePlayerEquipmentCondition(weapon);
                }

                DaggerfallUnityItem shield = target.ItemEquipTable.GetItem(EquipSlots.LeftHand);                 // Checks if character is using a shield or not.
                bool shieldTakesDamage     = false;
                if (shield != null)
                {
                    BodyParts[] protectedBodyParts = shield.GetShieldProtectedBodyParts();

                    for (int i = 0; (i < protectedBodyParts.Length) && !shieldTakesDamage; i++)
                    {
                        if (protectedBodyParts[i] == (BodyParts)struckBodyPart)
                        {
                            shieldTakesDamage = true;
                        }
                    }
                }

                if (shieldTakesDamage)
                {
                    int shieldEqualize = EqualizeMaterialConditions(shield);
                    damage       *= shieldEqualize;
                    tarMatMod     = ArmorMaterialModifierFinder(shield);
                    matDifference = tarMatMod - atkMatMod;
                    damage        = MaterialDifferenceDamageCalculation(shield, matDifference, atkStrength, damage, bluntWep, wepWeight, shieldTakesDamage);

                    ApplyConditionDamageThroughWeaponDamage(shield, target, damage, bluntWep, shtbladeWep, missileWep, wepEqualize);

                    if (target == GameManager.Instance.PlayerEntity)
                    {
                        WarningMessagePlayerEquipmentCondition(shield);
                    }
                }
                else
                {
                    EquipSlots          hitSlot = DaggerfallUnityItem.GetEquipSlotForBodyPart((BodyParts)struckBodyPart);
                    DaggerfallUnityItem armor   = target.ItemEquipTable.GetItem(hitSlot);
                    if (armor != null)
                    {
                        int armorEqualize = EqualizeMaterialConditions(armor);
                        damage       *= armorEqualize;
                        tarMatMod     = ArmorMaterialModifierFinder(armor);
                        matDifference = tarMatMod - atkMatMod;
                        damage        = MaterialDifferenceDamageCalculation(armor, matDifference, atkStrength, damage, bluntWep, wepWeight, shieldTakesDamage);

                        ApplyConditionDamageThroughWeaponDamage(armor, target, damage, bluntWep, shtbladeWep, missileWep, wepEqualize);

                        if (target == GameManager.Instance.PlayerEntity)
                        {
                            WarningMessagePlayerEquipmentCondition(armor);
                        }
                    }
                }
                return(false);
            }
            else if (weapon == null && damage > 0)             // Handles Unarmed attacks.
            {
                DaggerfallUnityItem shield = target.ItemEquipTable.GetItem(EquipSlots.LeftHand);
                bool shieldTakesDamage     = false;
                if (shield != null)
                {
                    BodyParts[] protectedBodyParts = shield.GetShieldProtectedBodyParts();

                    for (int i = 0; (i < protectedBodyParts.Length) && !shieldTakesDamage; i++)
                    {
                        if (protectedBodyParts[i] == (BodyParts)struckBodyPart)
                        {
                            shieldTakesDamage = true;
                        }
                    }
                }

                if (shieldTakesDamage)
                {
                    int shieldEqualize = EqualizeMaterialConditions(shield);
                    damage        *= shieldEqualize;
                    tarMatMod      = ArmorMaterialModifierFinder(shield);
                    atkStrength   /= 5;
                    armorDamResist = (tarMatMod * .35f) + 1;
                    damage         = (int)Mathf.Ceil((damage + atkStrength) / armorDamResist);

                    ApplyConditionDamageThroughUnarmedDamage(shield, target, damage);

                    if (target == GameManager.Instance.PlayerEntity)
                    {
                        WarningMessagePlayerEquipmentCondition(shield);
                    }
                }
                else
                {
                    EquipSlots          hitSlot = DaggerfallUnityItem.GetEquipSlotForBodyPart((BodyParts)struckBodyPart);
                    DaggerfallUnityItem armor   = target.ItemEquipTable.GetItem(hitSlot);
                    if (armor != null)
                    {
                        int armorEqualize = EqualizeMaterialConditions(armor);
                        damage        *= armorEqualize;
                        tarMatMod      = ArmorMaterialModifierFinder(armor);
                        atkStrength   /= 5;
                        armorDamResist = (tarMatMod * .20f) + 1;
                        damage         = (int)Mathf.Ceil((damage + atkStrength) / armorDamResist);

                        ApplyConditionDamageThroughUnarmedDamage(armor, target, damage);

                        if (target == GameManager.Instance.PlayerEntity)
                        {
                            WarningMessagePlayerEquipmentCondition(armor);
                        }
                    }
                }
                return(false);
            }
            return(false);
        }
Example #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 = "";
                }
            }
        }