コード例 #1
0
ファイル: ItemList.cs プロジェクト: mythsya/db-plugins
 internal static bool EvaluateRule(LRule itemRule, CachedACDItem cItem)
 {
     return EvaluateRule(cItem, itemRule.ItemProperty, itemRule.Value, itemRule.Variant, itemRule.RuleType);
 }
コード例 #2
0
ファイル: ItemList.cs プロジェクト: MGramolini/Trinity
        private static bool EvaluateRule(LRule itemRule, CachedACDItem cItem)
        {
            var result = false;
            string friendlyVariant = string.Empty;
            double itemValue = 0;
            double ruleValue = 0;

            switch (itemRule.ItemProperty)
            {
                case ItemProperty.Ancient:
                    itemValue = cItem.IsAncient ? 1 : 0;
                    ruleValue = itemRule.Value;
                    result = cItem.IsAncient == (itemRule.Value == 1);
                    break;

                case ItemProperty.PrimaryStat:
                    itemValue = ItemDataUtils.GetMainStatValue(cItem.AcdItem);
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.CriticalHitChance:
                    itemValue = cItem.CritPercent;
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.CriticalHitDamage:
                    itemValue = cItem.CritDamagePercent;
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.AttackSpeed:
                    itemValue = ItemDataUtils.GetAttackSpeed(cItem.AcdItem);
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.ResourceCost:
                    itemValue = Math.Round(cItem.AcdItem.Stats.ResourceCostReductionPercent, MidpointRounding.AwayFromZero);
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.Cooldown:
                    itemValue = Math.Round(cItem.AcdItem.Stats.PowerCooldownReductionPercent, MidpointRounding.AwayFromZero);
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.ResistAll:
                    itemValue = cItem.AcdItem.Stats.ResistAll;
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.Sockets:
                    itemValue = cItem.AcdItem.Stats.Sockets;
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.Vitality:
                    itemValue = cItem.AcdItem.Stats.Vitality;
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.FireSkills:
                    itemValue = cItem.AcdItem.Stats.FireSkillDamagePercentBonus;
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.ColdSkills:
                    itemValue = cItem.AcdItem.Stats.ColdSkillDamagePercentBonus;
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.LightningSkills:
                    itemValue = cItem.AcdItem.Stats.LightningSkillDamagePercentBonus;
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.ArcaneSkills:
                    itemValue = cItem.AcdItem.Stats.ArcaneSkillDamagePercentBonus;
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.HolySkills:
                    itemValue = cItem.AcdItem.Stats.HolySkillDamagePercentBonus;
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.PoisonSkills:
                    itemValue = cItem.AcdItem.Stats.PosionSkillDamagePercentBonus;
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.PhysicalSkills:
                    itemValue = cItem.AcdItem.Stats.PhysicalSkillDamagePercentBonus;
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.DamageAgainstElites:
                    itemValue = Math.Round(cItem.AcdItem.Stats.DamagePercentBonusVsElites, MidpointRounding.AwayFromZero);
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.DamageFromElites:
                    itemValue = Math.Round(cItem.AcdItem.Stats.DamagePercentReductionFromElites, MidpointRounding.AwayFromZero);
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.BaseMaxDamage:
                    itemValue = ItemDataUtils.GetMaxBaseDamage(cItem.AcdItem);
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.SkillDamage:

                    var skillId = itemRule.Variant;
                    var skill = ItemDataUtils.GetSkillsForItemType(cItem.TrinityItemType, Trinity.Player.ActorClass).FirstOrDefault(s => s.Id == skillId);
                    if (skill != null)
                    {
                        friendlyVariant = skill.Name;
                        itemValue = cItem.AcdItem.SkillDamagePercent(skill.SNOPower);
                    }

                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.ElementalDamage:

                    var elementId = itemRule.Variant;
                    var element = (Element)elementId;
                    if (element != Element.Unknown)
                    {
                        friendlyVariant = ((EnumValue<Element>)element).Name;
                        itemValue = Math.Round(ItemDataUtils.GetElementalDamage(cItem.AcdItem, element), MidpointRounding.AwayFromZero);
                    }

                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

                case ItemProperty.PercentDamage:
                    itemValue = cItem.AcdItem.WeaponDamagePercent();
                    ruleValue = itemRule.Value;
                    result = itemValue >= ruleValue;
                    break;

            }

            Logger.LogVerbose("  >>  Evaluated {0} -- {1} {5} Type={6} (Item: {2} -v- Rule: {3}) = {4}",
                cItem.RealName,
                itemRule.ItemProperty.ToString().AddSpacesToSentence(),
                itemValue,
                ruleValue,
                result,
                friendlyVariant,
                itemRule.RuleType);

            return result;
        }