Beispiel #1
0
        public bool TryHandleStat(D2Stat stat, out string description)
        {
            description = null;

            if (!stat.HasValidLoStatIdentifier())
            {
                return(false);
            }

            switch ((StatIdentifier)stat.LoStatID)
            {
            // Handle one and two handed damage.
            case StatIdentifier.DamageMin:
            case StatIdentifier.DamageMax:
            case StatIdentifier.SecondaryDamageMin:
            case StatIdentifier.SecondaryDamageMax:
                // Only print once if it's a range.
                if (HasHandledDamageRange)
                {
                    return(true);
                }

                // Skip two-handed damage if there is a one-handed damage source or if no damage is defined.
                if (stat.IsOfType(StatIdentifier.SecondaryDamageMin) && !IsDamageMinSecondary)
                {
                    return(true);
                }
                if (stat.IsOfType(StatIdentifier.SecondaryDamageMax) && !IsDamageMaxSecondary)
                {
                    return(true);
                }

                // If not a range, print normally.
                if (!damage.HasRange())
                {
                    return(false);
                }

                // We also print twice if they are the same.
                if (damage.min == damage.max)
                {
                    return(false);
                }

                HasHandledDamageRange = true;
                description           = damage.ToString(stringReader);
                return(true);

            // Handle enhanced damage.
            case StatIdentifier.ItemDamageMinPercent:
                if (!damagePercent.HasRange())
                {
                    return(false);
                }
                description = string.Format(
                    "+{0}% {1}",
                    stat.Value,
                    stringReader.GetString(StringConstants.EnhancedDamage).TrimEnd()
                    );
                return(true);

            case StatIdentifier.ItemDamageMaxPercent:
                return(damagePercent.HasRange());

            // Handle fire damage ranges.
            case StatIdentifier.FireDamageMin:
                if (!fireDamage.HasRange())
                {
                    return(false);
                }
                description = fireDamage.ToString(stringReader);
                return(true);

            case StatIdentifier.FireDamageMax:
                return(fireDamage.HasRange());

            // Handle lightning damage ranges.
            case StatIdentifier.LightningDamageMin:
                if (!lightningDamage.HasRange())
                {
                    return(false);
                }
                description = lightningDamage.ToString(stringReader);
                return(true);

            case StatIdentifier.LightningDamageMax:
                return(lightningDamage.HasRange());

            // Handle magic damage ranges.
            case StatIdentifier.MagicDamageMin:
                if (!magicDamage.HasRange())
                {
                    return(false);
                }
                description = magicDamage.ToString(stringReader);
                return(true);

            case StatIdentifier.MagicDamageMax:
                return(magicDamage.HasRange());

            // Handle cold damage ranges.
            case StatIdentifier.ColdDamageMin:
                if (!coldDamage.HasRange())
                {
                    return(false);
                }
                description = coldDamage.ToString(stringReader);
                return(true);

            case StatIdentifier.ColdDamageMax:
                return(coldDamage.HasRange());

            // Handle poison damage ranges.
            case StatIdentifier.PoisonDamageMax:
            case StatIdentifier.PoisonDamageDuration:
                return(poisonDamage.HasRange());

            case StatIdentifier.PoisonDamageMin:
                if (!poisonDamage.HasRange())
                {
                    return(false);
                }
                description = poisonDamage.ToString(stringReader);
                return(true);

            // By default, the stat is not handled.
            default:
                return(false);
            }
        }
Beispiel #2
0
        public bool TryHandleStat(D2Stat stat, out string description)
        {
            description = null;
            StatIdentifier statId = 0;

            if (Enum.IsDefined(typeof(StatIdentifier), stat.LoStatID))
            {
                statId = (StatIdentifier)stat.LoStatID;
            }
            else
            {
                return(false);
            }

            switch (statId)
            {
            //Handle one and two handed damage.
            case StatIdentifier.DamageMin:
            case StatIdentifier.DamageMax:
            case StatIdentifier.SecondaryDamageMin:
            case StatIdentifier.SecondaryDamageMax:
                // Only print once if it's a range.
                if (HasHandledDamageRange)
                {
                    return(true);
                }

                // Skip two-handed damage if there is a one-handed damage source or if no damage is defined.
                if (stat.IsOfType(StatIdentifier.SecondaryDamageMin) && !IsDamageMinSecondary)
                {
                    return(true);
                }
                if (stat.IsOfType(StatIdentifier.SecondaryDamageMax) && !IsDamageMaxSecondary)
                {
                    return(true);
                }

                // If not a range, print normally.
                if (!HasDamageRange)
                {
                    return(false);
                }
                // We also print twice if they are the same.
                if (DamageMin == DamageMax)
                {
                    return(false);
                }

                HasHandledDamageRange = true;
                description           = FormatSimpleDamage(DamageMin, DamageMax,
                                                           StringConstants.DamageRange,
                                                           StringConstants.DamageRange);
                return(true);

            // Handle enhanced damage.
            case StatIdentifier.ItemDamageMinPercent:
            {
                if (!HasDamagePercentRange)
                {
                    return(false);
                }
                string enhanced = stringReader.GetString(StringConstants.EnhancedDamage);
                description = string.Format("+{0}% {1}", stat.Value, enhanced.TrimEnd());
                return(true);
            }

            case StatIdentifier.ItemDamageMaxPercent:
                return(HasDamagePercentRange);

            // Handle fire damage ranges.
            case StatIdentifier.FireDamageMin:
                if (!HasFireRange)
                {
                    return(false);
                }
                description = FormatSimpleDamage(
                    FireMinDamage,
                    FireMaxDamage,
                    StringConstants.FireDamageRange,
                    StringConstants.FireDamage);
                return(true);

            case StatIdentifier.FireDamageMax:
                return(HasFireRange);

            // Handle lightning damage ranges.
            case StatIdentifier.LightningDamageMin:
                if (!HasLightningRange)
                {
                    return(false);
                }
                description = FormatSimpleDamage(
                    LightningMinDamage,
                    LightningMaxDamage,
                    StringConstants.LightningDamageRange,
                    StringConstants.LightningDamage);
                return(true);

            case StatIdentifier.LightningDamageMax:
                return(HasLightningRange);

            // Handle magic damage ranges.
            case StatIdentifier.MagicDamageMin:
                if (!HasMagicRange)
                {
                    return(false);
                }
                description = FormatSimpleDamage(
                    MagicMinDamage,
                    MagicMaxDamage,
                    StringConstants.MagicDamageRange,
                    StringConstants.MagicDamage);
                return(true);

            case StatIdentifier.MagicDamageMax:
                return(HasMagicRange);

            // Handle cold damage ranges.
            case StatIdentifier.ColdDamageMin:
                if (!HasColdRange)
                {
                    return(false);
                }
                description = FormatSimpleDamage(
                    ColdMinDamage,
                    ColdMaxDamage,
                    StringConstants.ColdDamageRange,
                    StringConstants.ColdDamage);
                return(true);

            case StatIdentifier.ColdDamageMax:
                return(HasColdRange);

            // Handle poison damage ranges.
            case StatIdentifier.PoisonDamageMax:
            case StatIdentifier.PoisonDamageDuration:
                return(HasPoisonRange);

            case StatIdentifier.PoisonDamageMin:
            {
                if (!HasPoisonRange)
                {
                    return(false);
                }
                int divisor  = PoisonDivisor == 0 ? 1 : PoisonDivisor;
                int duration = PoisonDuration / divisor;
                int min      = (PoisonMinDamage * duration + 128) / 256;
                int max      = (PoisonMaxDamage * duration + 128) / 256;
                duration /= 25;

                if (min == max)
                {
                    // Example: "6 Poison damage over 2 seconds"
                    int    arguments;
                    string format = stringReader.GetString(StringConstants.PoisonOverTimeSame);
                    format = stringReader.ConvertCFormatString(format, out arguments);
                    if (arguments != 2)
                    {
                        return(true);
                    }
                    description = string.Format(format, min, duration).TrimEnd();
                }
                else
                {
                    // Example: "2-10 Poison damage over 2 seconds"
                    int    arguments;
                    string format = stringReader.GetString(StringConstants.PoisonOverTime);
                    format = stringReader.ConvertCFormatString(format, out arguments);
                    if (arguments != 3)
                    {
                        return(true);
                    }
                    description = string.Format(format, min, max, duration).TrimEnd();
                }

                return(true);
            }

            // By default, the stat is not handled.
            default: return(false);
            }
        }