Beispiel #1
0
        // generates a random item from given type category.
        // we can also set a difficulty mode parameter here, but it seems current db doesnt have nightmare or hell-mode items with valid snoId's /raist.
        public static Item GenerateRandom(NullD.Core.GS.Actors.Actor player, ItemTypeTable type)
        {
            var itemDefinition = GetRandom(Items.Values
                                           .Where(def => ItemGroup
                                                  .HierarchyToHashList(ItemGroup.FromHash(def.ItemType1)).Contains(type.Hash)).ToList(), (player as Player));

            return(CreateItem(player, itemDefinition));
        }
Beispiel #2
0
        public static Type GetItemClass(ItemTable definition)
        {
            Type type = typeof(Item);

            if (GBIDHandlers.ContainsKey(definition.Hash))
            {
                type = GBIDHandlers[definition.Hash];
            }
            else
            {
                foreach (var hash in ItemGroup.HierarchyToHashList(ItemGroup.FromHash(definition.ItemType1)))
                {
                    if (TypeHandlers.ContainsKey(hash))
                    {
                        type = TypeHandlers[hash];
                        break;
                    }
                }
            }

            return(type);
        }
Beispiel #3
0
        public static void Generate(Item item, int affixesCount)
        {
            if (!Item.IsWeapon(item.ItemType) &&
                !Item.IsArmor(item.ItemType) &&
                !Item.IsOffhand(item.ItemType) &&
                !Item.IsAccessory(item.ItemType))
            {
                return;
            }

            var itemTypes       = ItemGroup.HierarchyToHashList(item.ItemType);
            int itemQualityMask = 1 << item.Attributes[GameAttribute.Item_Quality_Level];

            var filteredList = AffixList.Where(a =>
                                               a.QualityMask.HasFlag((QualityMask)itemQualityMask) &&
                                               itemTypes.ContainsAtLeastOne(a.ItemGroup) &&
                                               a.AffixLevel <= item.ItemLevel);

            Dictionary <int, AffixTable> bestDefinitions = new Dictionary <int, AffixTable>();

            foreach (var affix in filteredList)
            {
                bestDefinitions[affix.AffixFamily0] = affix;
            }

            var selectedGroups = bestDefinitions.Values.OrderBy(x => RandomHelper.Next()).Take(affixesCount);

            foreach (var def in selectedGroups)
            {
                if (def != null)
                {
                    //Logger.Debug("Generating affix " + def.Name + " (aLvl:" + def.AffixLevel + ")");
                    item.AffixList.Add(new Affix(def.Hash));
                    foreach (var effect in def.AttributeSpecifier)
                    {
                        if (effect.AttributeId > 0)
                        {
                            float result;
                            if (FormulaScript.Evaluate(effect.Formula.ToArray(), item.RandomGenerator, out result))
                            {
                                //Logger.Debug("Randomized value for attribute " + GameAttribute.Attributes[effect.AttributeId].Name + " is " + result);
                                var tmpAttr  = GameAttribute.Attributes[effect.AttributeId];
                                var attrName = tmpAttr.Name;

                                if (GameAttribute.Attributes[effect.AttributeId] is GameAttributeF)
                                {
                                    var attr = GameAttribute.Attributes[effect.AttributeId] as GameAttributeF;
                                    if (effect.SNOParam != -1)
                                    {
                                        item.Attributes[attr, effect.SNOParam] += result;
                                    }
                                    else
                                    {
                                        item.Attributes[attr] += result;
                                    }
                                }
                                else if (GameAttribute.Attributes[effect.AttributeId] is GameAttributeI)
                                {
                                    var attr = GameAttribute.Attributes[effect.AttributeId] as GameAttributeI;
                                    if (effect.SNOParam != -1)
                                    {
                                        item.Attributes[attr, effect.SNOParam] += (int)result;
                                    }
                                    else
                                    {
                                        item.Attributes[attr] += (int)result;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }