Exemplo n.º 1
0
        private GridEquipStats ComputeDisplayStats(DataEquipmentInformation equip)
        {
            ViewUpgradeModeComboIndex upgrade_type = (ViewUpgradeModeComboIndex)comboBoxUpgradeMode.SelectedIndex;

            RealmSynergy.SynergyValue synergy = RealmSynergy.Values.ElementAt(comboBoxSynergy.SelectedIndex);
            bool has_synergy = equip.SeriesId == synergy.GameSeries;

            DataCache.Items.Key cache_key = new DataCache.Items.Key {
                ItemId = equip.EquipmentId
            };
            DataCache.Items.Data cache_value;
            bool in_cache = FFRKProxy.Instance.Cache.Items.TryGetValue(cache_key, out cache_value);

            GridEquipStats result = new GridEquipStats();

            if (upgrade_type == ViewUpgradeModeComboIndex.CurrentUpgradeCurrentLevel)
            {
                result.Stats.Atk = (has_synergy) ? equip.SeriesAtk : equip.Atk;
                result.Stats.Mag = (has_synergy) ? equip.SeriesMag : equip.Mag;
                result.Stats.Acc = (has_synergy) ? equip.SeriesAcc : equip.Acc;
                result.Stats.Def = (has_synergy) ? equip.SeriesDef : equip.Def;
                result.Stats.Res = (has_synergy) ? equip.SeriesRes : equip.Res;
                result.Stats.Eva = (has_synergy) ? equip.SeriesEva : equip.Eva;
                result.Stats.Mnd = (has_synergy) ? equip.SeriesMnd : equip.Mnd;
                result.Level     = equip.Level;
                result.MaxLevel  = equip.LevelMax;
                if (equip.SeriesId == synergy.GameSeries)
                {
                    result.Level = StatCalculator.EffectiveLevelWithSynergy(result.Level);
                }
            }
            else
            {
                if (upgrade_type == ViewUpgradeModeComboIndex.CurrentUpgradeMaxLevel)
                {
                    result.MaxLevel = StatCalculator.MaxLevel(equip.Rarity);
                }
                else if (upgrade_type == ViewUpgradeModeComboIndex.MaxLevelThroughExistingCombine)
                {
                    // Valid candidates for combining items into this are only those items with matching
                    // equipment id and rarity LESS THAN OR EQUAL TO current item's rarity
                    int candidates = mEquipments.Count(x => x.EquipmentId == equip.EquipmentId && x.InstanceId != equip.InstanceId && x.Rarity <= equip.Rarity);
                    result.MaxLevel = StatCalculator.MaxLevel(StatCalculator.EvolveAsMuchAsPossible(equip.BaseRarity, equip.Rarity, candidates));
                }
                else
                {
                    result.MaxLevel = StatCalculator.MaxLevel(StatCalculator.Evolve(equip.BaseRarity, SchemaConstants.EvolutionLevel.PlusPlus));
                }
                result.Level = result.MaxLevel;
                if (has_synergy)
                {
                    result.Level = StatCalculator.EffectiveLevelWithSynergy(result.Level);
                }

                if (in_cache && cache_value.AreStatsValid)
                {
                    // Try to get the equipment stats from the database
                    result.Stats.Atk = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Atk, cache_value.MaxStats.Atk, result.Level);
                    result.Stats.Mag = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Mag, cache_value.MaxStats.Mag, result.Level);
                    result.Stats.Acc = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Acc, cache_value.MaxStats.Acc, result.Level);
                    result.Stats.Def = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Def, cache_value.MaxStats.Def, result.Level);
                    result.Stats.Res = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Res, cache_value.MaxStats.Res, result.Level);
                    result.Stats.Eva = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Eva, cache_value.MaxStats.Eva, result.Level);
                    result.Stats.Mnd = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Mnd, cache_value.MaxStats.Mnd, result.Level);
                }
                else
                {
                    // If they aren't there, fall back to trying to compute effective stats from the ifnormation in the JSON.  This will lead to some
                    // rounding error due to the fact that the values for Atk and SeriesAtk etc are all rounded, so the division will be less precise
                    // than doing it over the entire range of Max stats and base stats, but it's the best we can do in this case.
                    byte series_effective_level = StatCalculator.EffectiveLevelWithSynergy(equip.Level);
                    result.Stats.Atk = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesAtk : equip.Atk) : StatCalculator.ComputeStatForLevel2(equip.Atk, equip.Level, equip.SeriesAtk, series_effective_level, result.Level);
                    result.Stats.Mag = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesMag : equip.Mag) : StatCalculator.ComputeStatForLevel2(equip.Mag, equip.Level, equip.SeriesMag, series_effective_level, result.Level);
                    result.Stats.Acc = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesAcc : equip.Acc) : StatCalculator.ComputeStatForLevel2(equip.Acc, equip.Level, equip.SeriesAcc, series_effective_level, result.Level);
                    result.Stats.Def = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesDef : equip.Def) : StatCalculator.ComputeStatForLevel2(equip.Def, equip.Level, equip.SeriesDef, series_effective_level, result.Level);
                    result.Stats.Res = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesRes : equip.Res) : StatCalculator.ComputeStatForLevel2(equip.Res, equip.Level, equip.SeriesRes, series_effective_level, result.Level);
                    result.Stats.Eva = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesEva : equip.Eva) : StatCalculator.ComputeStatForLevel2(equip.Eva, equip.Level, equip.SeriesEva, series_effective_level, result.Level);
                    result.Stats.Mnd = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesMnd : equip.Mnd) : StatCalculator.ComputeStatForLevel2(equip.Mnd, equip.Level, equip.SeriesMnd, series_effective_level, result.Level);
                }
            }

            if (equip.AugmentStat != null && equip.Augment > 0)
            {
                double bonus = (has_synergy) ? equip.Augment * 1.5 : (double)equip.Augment;

                System.Reflection.FieldInfo augmentField = typeof(EquipStats).GetField(equip.AugmentStat);
                short val = (short)augmentField.GetValue(result.Stats);
                augmentField.SetValue(result.Stats, (short)Math.Ceiling(val + bonus));
            }
            return(result);
        }