示例#1
0
        public static Affixes.Items.Affix RollNewSuffix(AffixItemItem pomItem, Item item)
        {
            if (pomItem.FreeSuffixes <= 0)
            {
                return(null);
            }
            Tuple <Affixes.Items.Affix, double>[] tuples = PoMDataLoader.affixesItem
                                                           .Where(a => a.AffixSpaceAvailable(pomItem) &&
                                                                  a.Weight > 0 &&
                                                                  a.CanBeRolled(pomItem, item) &&
                                                                  a is Affixes.ISuffix &&
                                                                  !pomItem.affixes.Exists(ia => ia.GetType() == a.GetType()))
                                                           .Select(a => new Tuple <Affixes.Items.Affix, double>(a, a.Weight))
                                                           .ToArray();
            if (tuples.Length == 0)
            {
                return(null);
            }
            WeightedRandom <Affixes.Items.Affix> weightedRandom = new WeightedRandom <Affixes.Items.Affix>(Main.rand, tuples);

            Affixes.Items.Affix suffix = weightedRandom;
            suffix = suffix.Clone();
            suffix.InitializeItem(pomItem);
            return(suffix);
        }
示例#2
0
        /// <summary>
        /// Returns a valid affix for the item or null.
        /// </summary>
        public static Affixes.Items.Affix RollNewAffix(AffixItemItem pomItem, Item item)
        {
            Affixes.Items.Affix affix;

            float prefixChance = pomItem.FreeSuffixes > 0 ? pomItem.rarity.chanceToRollPrefixInsteadOfSuffix : 1;

            if (Main.rand.NextFloat(1) < prefixChance)
            {
                affix = RollNewPrefix(pomItem, item);
            }
            else
            {
                affix = RollNewSuffix(pomItem, item);
            }

            return(affix);
        }
示例#3
0
        public override GlobalItem Clone(Item item, Item itemClone)
        {
            AffixItemItem newItem = (AffixItemItem)NewInstance(itemClone);

            newItem.rarity = rarity;

            Affix affixClone;

            foreach (Affix affix in affixes)
            {
                affixClone = affix.Clone();
                newItem.AddAffix(affixClone, item, true);
            }
            newItem.UpdateName(itemClone);

            return(newItem);
        }
示例#4
0
        /// <summary>
        /// Returns a new instance of the affix based on class name
        /// </summary>
        public static Affixes.Items.Affix GetAffix(AffixItemItem pomItem, string name, bool isPrefix)
        {
            string namespaceQualifiedTypeName;

            if (isPrefix)
            {
                namespaceQualifiedTypeName = typeof(Affixes.Items.Prefixes.AccessoryConsumeAmmo).Namespace;
            }
            else
            {
                namespaceQualifiedTypeName = typeof(Affixes.Items.Suffixes.WeaponAssistance).Namespace;
            }
            namespaceQualifiedTypeName = $"{ namespaceQualifiedTypeName }.{ name }";

            Type affixType = Type.GetType(namespaceQualifiedTypeName);

            Affixes.Items.Affix affix = PoMDataLoader.affixesItem[PoMDataLoader.affixItemMap[affixType]];
            affix = affix.Clone();
            affix.InitializeItem(pomItem);
            return(affix);
        }