示例#1
0
        public static void Reroll(IRandom random, Equipment item, Stat stat, CurrencyModifiers currencyModifiers)
        {
            if (stat?.Affix == null)
            {
                return;
            }

            if (stat.Affix.GenerationType == "prefix" && ItemHasGroup(item, _prefixesCannotBeChanged))
            {
                return;
            }

            if (stat.Affix.GenerationType == "suffix" && ItemHasGroup(item, _suffixesCannotBeChanged))
            {
                return;
            }

            var mod = stat.Affix;

            if (!string.IsNullOrEmpty(mod.StatName1))
            {
                stat.Value1 = random.Next(mod.StatMin1, mod.StatMax1);
            }
            if (!string.IsNullOrEmpty(mod.StatName2))
            {
                stat.Value2 = random.Next(mod.StatMin2, mod.StatMax2);
            }
            if (!string.IsNullOrEmpty(mod.StatName3))
            {
                stat.Value3 = random.Next(mod.StatMin3, mod.StatMax3);
            }
        }
        public void CurrencyWeightModifierTest()
        {
            String       item          = "Murderous Eye Jewel";
            String       defaultTag    = "abyss_jewel_melee";
            String       fossilTag     = "abyss_jewel";
            var          testItem      = _itemFactory.Jewel.First(x => x.Name == item);
            List <Affix> allAffixes    = new List <Affix>();
            var          fossilAffixes = new List <Affix>();

            var testAffix = GetTestAffix("test", "test", new Dictionary <string, int>()
            {
                { fossilTag, 100 }
            });

            allAffixes.Add(testAffix);

            for (int i = 0; i < 8; i++)
            {
                allAffixes.Add(GetTestAffix("test_" + i, "test" + i, new Dictionary <string, int>()
                {
                    { defaultTag, 100 }
                }));
            }

            AffixManager affixManager = new AffixManager(testItem, allAffixes, fossilAffixes, new Dictionary <Influence, List <Affix> >(), new Dictionary <Influence, string>());

            List <Affix> generated = new List <Affix>();
            IRandom      random    = SetupRandom().Object;

            CurrencyModifiers currencyModifiers = new CurrencyModifiers(
                null,
                new Dictionary <string, double>()
            {
                { fossilTag, 200 }
            },
                null,
                null,
                null);

            var equipmentModifiers = new EquipmentModifiers(new List <Influence>(),
                                                            new List <string>(),
                                                            new List <string>(),
                                                            100,
                                                            new Dictionary <string, int>());

            for (var i = 0; i < 10; i++)
            {
                generated.Add(affixManager.GetAffix(equipmentModifiers, currencyModifiers, new List <Affix>(), EquipmentRarity.Rare, random));
            }

            Assert.AreEqual(generated[0], testAffix);
            Assert.AreEqual(generated[1], testAffix);
        }
        public void AddedAffixesTest()
        {
            String item       = "Murderous Eye Jewel";
            String defaultTag = "abyss_jewel_melee";

            var          testItem   = _itemFactory.Jewel.First(x => x.Name == item);
            List <Affix> allAffixes = new List <Affix>();

            var testAffix = GetTestAffix("test", "test", new Dictionary <string, int>()
            {
                { defaultTag, 100 }
            });

            var addedAffixes = new List <Affix> {
                testAffix
            };

            CurrencyModifiers currencyModifiers = new CurrencyModifiers(
                addedAffixes,
                null,
                null,
                null,
                null);

            for (int i = 0; i < 9; i++)
            {
                allAffixes.Add(GetTestAffix("test_" + i, "test" + i, new Dictionary <string, int>()
                {
                    { defaultTag, 100 }
                }));
            }

            AffixManager affixManager = new AffixManager(testItem, allAffixes, addedAffixes, new Dictionary <Influence, List <Affix> >(), new Dictionary <Influence, string>());

            List <Affix> generated = new List <Affix>();
            IRandom      random    = SetupRandom().Object;

            var equipmentModifiers = new EquipmentModifiers(new List <Influence>(),
                                                            new List <string>(),
                                                            new List <string>(),
                                                            100,
                                                            new Dictionary <string, int>());

            for (var i = 0; i < 10; i++)
            {
                generated.Add(affixManager.GetAffix(equipmentModifiers, currencyModifiers, new List <Affix>(), EquipmentRarity.Rare, random));
            }

            Assert.IsTrue(generated.Contains(testAffix));
        }
示例#4
0
        private AffixPool GenerateAffixPool(EquipmentModifiers equipmentModifiers, CurrencyModifiers currencyModifiers)
        {
            var tags         = new HashSet <string>(_baseTags.Union(equipmentModifiers.AddedTags));
            var masterModSet = new HashSet <string>(equipmentModifiers.MasterMods);


            var addedAffixes = currencyModifiers.AddedExplicits
                               .Union(equipmentModifiers.Influence.SelectMany(x => _influenceAffixes[x]))
                               .Where(x => x.RequiredLevel <= equipmentModifiers.ItemLevel)
                               .ToList();

            var affixesToEvaluate = _itemAffixes.Union(addedAffixes).ToList();

            if (currencyModifiers.ItemLevelRestriction != null && currencyModifiers.ItemLevelRestriction < equipmentModifiers.ItemLevel)
            {
                affixesToEvaluate = affixesToEvaluate
                                    .Where(x => x.RequiredLevel <= currencyModifiers.ItemLevelRestriction)
                                    .ToList();
            }

            List <KeyValuePair <string, double> > qualityWeightModifiers = new List <KeyValuePair <string, double> >();

            if (currencyModifiers.QualityAffectsExplicitOdds)
            {
                qualityWeightModifiers.Add(equipmentModifiers.QualityGenerationWeight);
            }

            var weightModifiers = equipmentModifiers.GenerationWeights
                                  .Union(currencyModifiers.ExplicitWeightModifiers)
                                  .Union(qualityWeightModifiers)
                                  .GroupBy(x => x.Key)
                                  .ToDictionary(x => x.Key, x => x.Aggregate(1d, (y, z) => y * z.Value / 100d));

            AffixPool pool = new AffixPool();

            pool.PrefixGroupToAffixWeights = GroupToAffixWeights(affixesToEvaluate.Where(x => x.GenerationType == "prefix").ToList(), tags, weightModifiers, masterModSet);
            pool.SuffixGroupToAffixWeights = GroupToAffixWeights(affixesToEvaluate.Where(x => x.GenerationType == "suffix").ToList(), tags, weightModifiers, masterModSet);

            pool.PrefixGroupWeights = pool.PrefixGroupToAffixWeights.ToDictionary(x => x.Key, x => x.Value.Sum(y => y.Weight));
            pool.SuffixGroupWeights = pool.SuffixGroupToAffixWeights.ToDictionary(x => x.Key, x => x.Value.Sum(y => y.Weight));

            pool.PrefixWeight = pool.PrefixGroupWeights.Sum(x => x.Value);
            pool.SuffixWeight = pool.SuffixGroupWeights.Sum(x => x.Value);

            pool.TotalWeight = pool.PrefixWeight + pool.SuffixWeight;

            pool.AffixCount = pool.PrefixGroupToAffixWeights.Sum(x => x.Value.Count) + pool.SuffixGroupToAffixWeights.Sum(x => x.Value.Count);

            return(pool);
        }
示例#5
0
        public static void RemoveAllExplicits(Equipment item, CurrencyModifiers currencyModifiers)
        {
            bool canChangePrefixes = !ItemHasGroup(item, _prefixesCannotBeChanged);
            bool canChangeSuffixes = !ItemHasGroup(item, _suffixesCannotBeChanged);

            if (canChangePrefixes)
            {
                item.Stats = item.Stats.Where(x => x.Affix.GenerationType != "prefix").ToList();
            }

            if (canChangeSuffixes)
            {
                item.Stats = item.Stats.Where(x => x.Affix.GenerationType != "suffix").ToList();
            }
        }
示例#6
0
        public static void RemoveExplicit(IRandom random, Equipment item, CurrencyModifiers currencyModifiers)
        {
            bool cannotChangePrefixes = ItemHasGroup(item, _prefixesCannotBeChanged);
            bool cannotChangeSuffixes = ItemHasGroup(item, _suffixesCannotBeChanged);

            List <Stat> statPool = new List <Stat>();

            if (!cannotChangePrefixes)
            {
                statPool.AddRange(item.Prefixes);
            }

            if (!cannotChangeSuffixes)
            {
                statPool.AddRange(item.Suffixes);
            }

            if (currencyModifiers.QualityAffectsExplicitOdds && item.Quality > 0 &&
                item.QualityType != QualityType.Default)
            {
                var statOdds = statPool.ToDictionary(
                    x => x,
                    x => x.Affix.Tags.Contains(QualityTags[item.QualityType]) ? 100 - item.Quality : 100);

                var randomValue = random.Next(statOdds.Sum(x => x.Value));

                foreach (var statOdd in statOdds)
                {
                    if (randomValue < statOdd.Value)
                    {
                        item.Stats.Remove(statOdd.Key);
                        break;
                    }

                    randomValue -= statOdd.Value;
                }
            }

            var index = random.Next(statPool.Count);

            item.Stats.Remove(statPool[index]);
        }
示例#7
0
        public Affix GetAffix(EquipmentModifiers equipmentModifiers, CurrencyModifiers currencyModifiers, List <Affix> affixes, EquipmentRarity rarity, IRandom random)
        {
            PoolKey key = new PoolKey(equipmentModifiers, currencyModifiers);

            if (!_poolDic.ContainsKey(key))
            {
                _poolDic.Add(key, GenerateAffixPool(equipmentModifiers, currencyModifiers));
            }

            AffixPool pool           = _poolDic[key];
            var       existingGroups = new HashSet <string>(affixes.Select(x => x.Group));

            int affixesCount = rarity == EquipmentRarity.Normal ? 0 :
                               rarity == EquipmentRarity.Magic ? 1 :
                               rarity == EquipmentRarity.Rare ? 3 : 0;

            double prefixSkipAmount = CalculateSkipAmount("prefix", pool.PrefixWeight, pool.PrefixGroupWeights, affixes, affixesCount);
            double suffixSkipAmount = CalculateSkipAmount("suffix", pool.SuffixWeight, pool.SuffixGroupWeights, affixes, affixesCount);

            var targetWeight = random.NextDouble() * (pool.TotalWeight - prefixSkipAmount - suffixSkipAmount);

            return(GetRandomAffixFromPool(pool, targetWeight, existingGroups, prefixSkipAmount, suffixSkipAmount));
        }
示例#8
0
        public static bool AddExplicit(IRandom random, Equipment item, AffixManager affixManager, CurrencyModifiers currencyModifiers)
        {
            var equipmentModifiers = new EquipmentModifiers(item);
            var affix = affixManager.GetAffix(equipmentModifiers, currencyModifiers, item.Stats.Select(x => x.Affix).ToList(), item.Rarity, random);

            if (affix == null)
            {
                return(false);
            }

            var stat = AffixToStat(random, item, affix);

            item.Stats.Add(stat);

            return(true);
        }
示例#9
0
        /*
         * Add explicits until the item has an amount equal to the selected count
         */
        public static void AddExplicits(IRandom random, Equipment item, AffixManager affixManager, Dictionary <int, int> affixCountOdds, CurrencyModifiers currencyModifiers)
        {
            var sum  = affixCountOdds.Sum(x => x.Value);
            var roll = random.Next(sum);

            var affixCount = 0;
            int count      = 0;

            foreach (var weight in affixCountOdds)
            {
                count += weight.Value;

                if (roll < count)
                {
                    affixCount = weight.Key;
                    break;
                }
            }

            while (item.Stats.Count < affixCount)
            {
                bool successful = StatFactory.AddExplicit(random, item, affixManager, currencyModifiers);

                if (!successful)
                {
                    break;
                }
            }
        }
示例#10
0
 public PoolKey(EquipmentModifiers equipmentModifiers, CurrencyModifiers currencyModifiers)
 {
     this.EquipmentModifiers = equipmentModifiers;
     this.CurrencyModifiers  = currencyModifiers;
 }