Ejemplo n.º 1
0
        public float GetResistance(Creature_BodyPart part, DamageType damageType)
        {
            var resistance = 1.0f;

            switch (damageType)
            {
            case DamageType.Slash:
                resistance = part.ArmorVsSlash;
                break;

            case DamageType.Pierce:
                resistance = part.ArmorVsPierce;
                break;

            case DamageType.Bludgeon:
                resistance = part.ArmorVsBludgeon;
                break;

            case DamageType.Fire:
                resistance = part.ArmorVsFire;
                break;

            case DamageType.Cold:
                resistance = part.ArmorVsCold;
                break;

            case DamageType.Acid:
                resistance = part.ArmorVsAcid;
                break;

            case DamageType.Electric:
                resistance = part.ArmorVsElectric;
                break;

            case DamageType.Nether:
                resistance = part.ArmorVsNether;
                break;
            }

            return(resistance);
        }
Ejemplo n.º 2
0
        public float CalculateDamage(WorldObject target, WorldObject damageSource, ref bool criticalHit, ref bool sneakAttack)
        {
            var creature = target as Creature;

            // evasion chance
            var evadeChance = GetEvadeChance(target);

            if (Physics.Common.Random.RollDice(0.0f, 1.0f) < evadeChance)
            {
                return(0.0f);
            }

            // get weapon base damage
            var baseDamageRange = GetBaseDamage();
            var baseDamage      = Physics.Common.Random.RollDice(baseDamageRange.Min, baseDamageRange.Max);

            // get damage mods
            var attackType       = GetAttackType();
            var attributeMod     = GetAttributeMod(attackType);
            var powerAccuracyMod = GetPowerAccuracyMod();
            var recklessnessMod  = GetRecklessnessMod(this, creature);
            var sneakAttackMod   = GetSneakAttackMod(target);

            sneakAttack = sneakAttackMod > 1.0f;

            var damageRatingMod = AdditiveCombine(recklessnessMod, sneakAttackMod, GetRatingMod(EnchantmentManager.GetDamageRating()));
            //Console.WriteLine("Damage rating: " + ModToRating(damageRatingMod));

            var damage = baseDamage * attributeMod * powerAccuracyMod * damageRatingMod;

            // critical hit
            var critical = GetWeaponPhysicalCritFrequencyModifier(this);

            if (Physics.Common.Random.RollDice(0.0f, 1.0f) < critical)
            {
                damage      = baseDamageRange.Max * attributeMod * powerAccuracyMod * sneakAttackMod * (2.0f + GetWeaponCritMultiplierModifier(this));
                criticalHit = true;
            }

            // get random body part @ attack height
            var bodyPart = BodyParts.GetBodyPart(target, AttackHeight.Value);

            if (bodyPart == null)
            {
                return(0.0f);
            }

            var creaturePart = new Creature_BodyPart(creature, bodyPart);

            // get target armor
            var armor = creaturePart.BaseArmorMod;

            // get target resistance
            DamageType damageType;

            if (damageSource?.ItemType == ItemType.MissileWeapon)
            {
                damageType = (DamageType)damageSource.GetProperty(PropertyInt.DamageType);
            }
            else
            {
                damageType = GetDamageType();
            }

            creaturePart.WeaponResistanceMod = GetWeaponResistanceModifier(this, damageType);
            var resistance = GetResistance(creaturePart, damageType);

            // ratings
            var damageResistRatingMod = GetNegativeRatingMod(creature.EnchantmentManager.GetDamageResistRating());
            //Console.WriteLine("Damage resistance rating: " + NegativeModToRating(damageResistRatingMod));

            // scale damage for armor and shield
            var armorMod  = SkillFormula.CalcArmorMod(resistance);
            var shieldMod = creature.GetShieldMod(this, damageType);

            var slayerMod          = GetWeaponCreatureSlayerModifier(this, target as Creature);
            var elementalDamageMod = GetMissileElementalDamageModifier(this, target as Creature, damageType);

            return((damage + elementalDamageMod) * armorMod * shieldMod * slayerMod * damageResistRatingMod);
        }
Ejemplo n.º 3
0
        public float?CalculateDamage(WorldObject target, WorldObject damageSource, ref bool criticalHit, ref bool sneakAttack)
        {
            var creature = target as Creature;

            // evasion chance
            var evadeChance = GetEvadeChance(target);

            if (ThreadSafeRandom.Next(0.0f, 1.0f) < evadeChance)
            {
                return(null);
            }

            // get weapon base damage
            var weapon          = GetEquippedWeapon();
            var baseDamageRange = GetBaseDamage();
            var baseDamage      = ThreadSafeRandom.Next(baseDamageRange.Min, baseDamageRange.Max);

            // get damage mods
            var attackType       = GetCombatType();
            var attributeMod     = GetAttributeMod(weapon);
            var powerAccuracyMod = GetPowerMod(weapon);
            var recklessnessMod  = GetRecklessnessMod(this, creature);
            var sneakAttackMod   = GetSneakAttackMod(target);

            sneakAttack = sneakAttackMod > 1.0f;

            // heritage damge mod
            var heritageMod = GetHeritageBonus(weapon) ? 1.05f : 1.0f;

            var damageRatingMod = AdditiveCombine(recklessnessMod, sneakAttackMod, heritageMod, GetRatingMod(EnchantmentManager.GetDamageRating()));
            //Console.WriteLine("Damage rating: " + ModToRating(damageRatingMod));

            var damage = baseDamage * attributeMod * powerAccuracyMod * damageRatingMod;

            // critical hit
            var attackSkill = GetCreatureSkill(GetCurrentWeaponSkill());
            var critical    = GetWeaponCritChanceModifier(this, attackSkill);

            if (ThreadSafeRandom.Next(0.0f, 1.0f) < critical)
            {
                var criticalDamageMod = 1.0f + GetWeaponCritDamageMod(this, attackSkill);
                damage      = baseDamageRange.Max * attributeMod * powerAccuracyMod * sneakAttackMod * criticalDamageMod;
                criticalHit = true;
            }

            // get random body part @ attack height
            var bodyPart = BodyParts.GetBodyPart(target, AttackHeight.Value);

            if (bodyPart == null)
            {
                return(null);
            }

            var creaturePart = new Creature_BodyPart(creature, bodyPart, damageSource != null ? damageSource.IgnoreMagicArmor : false, damageSource != null ? damageSource.IgnoreMagicResist : false);

            if (weapon != null && weapon.HasImbuedEffect(ImbuedEffectType.ArmorRending))
            {
                creaturePart.WeaponArmorMod = GetArmorRendingMod(attackSkill);
            }

            // get target armor
            var armor = creaturePart.BaseArmorMod;

            // get target resistance
            DamageType damageType;

            if (damageSource?.ItemType == ItemType.MissileWeapon)
            {
                damageType = (DamageType)damageSource.GetProperty(PropertyInt.DamageType);
            }
            else
            {
                damageType = GetDamageType();
            }

            creaturePart.WeaponResistanceMod = GetWeaponResistanceModifier(this, attackSkill, damageType);
            var resistance = GetResistance(creaturePart, damageType);

            // ratings
            var damageResistRatingMod = GetNegativeRatingMod(creature.EnchantmentManager.GetDamageResistRating());
            //Console.WriteLine("Damage resistance rating: " + NegativeModToRating(damageResistRatingMod));

            // scale damage for armor and shield
            var armorMod  = SkillFormula.CalcArmorMod(resistance);
            var shieldMod = creature.GetShieldMod(this, damageType);

            var slayerMod          = GetWeaponCreatureSlayerModifier(this, target as Creature);
            var elementalDamageMod = GetMissileElementalDamageModifier(this, target as Creature, damageType);

            return((damage + elementalDamageMod) * armorMod * shieldMod * slayerMod * damageResistRatingMod);
        }