Пример #1
0
            public void Process(ref LootObject Loot)
            {
                LootStoreItem Item = Roll();

                if (Item != null)
                {
                    Loot.Items.Add(new LootItem(ref Item));
                }
            }
Пример #2
0
 public LootItem(ref LootStoreItem Item)
 {
     ItemID    = 0;
     ItemCount = 0;
     ItemID    = Item.ItemID;
     checked
     {
         ItemCount = (byte)WorldServiceLocator._WorldServer.Rnd.Next(Item.MinCountOrRef, Item.MaxCount + 1);
     }
 }
Пример #3
0
 public void AddItem(ref LootStoreItem Item)
 {
     if (Item.Chance != 0f)
     {
         ExplicitlyChanced.Add(Item);
     }
     else
     {
         EqualChanced.Add(Item);
     }
 }
Пример #4
0
            private LootTemplate CreateTemplate(int Entry)
            {
                LootTemplate newTemplate = new LootTemplate();

                Templates.Add(Entry, newTemplate);
                DataTable MysqlQuery = new DataTable();

                WorldServiceLocator._WorldServer.WorldDatabase.Query(string.Format("SELECT {0}.*,conditions.type,conditions.value1, conditions.value2 FROM {0} LEFT JOIN conditions ON {0}.`condition_id`=conditions.`condition_entry` WHERE entry = {1};", Name, Entry), ref MysqlQuery);
                if (MysqlQuery.Rows.Count == 0)
                {
                    Templates[Entry] = null;
                    return(null);
                }
                IEnumerator enumerator = default;

                try
                {
                    enumerator = MysqlQuery.Rows.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        DataRow       row  = (DataRow)enumerator.Current;
                        int           Item = row.As <int>("item");
                        float         ChanceOrQuestChance = row.As <float>("ChanceOrQuestChance");
                        byte          GroupID             = row.As <byte>("groupid");
                        int           MinCountOrRef       = row.As <int>("mincountOrRef");
                        byte          MaxCount            = row.As <byte>("maxcount");
                        ConditionType LootCondition       = ConditionType.CONDITION_NONE;
                        if (!Information.IsDBNull(RuntimeHelpers.GetObjectValue(row["type"])))
                        {
                            LootCondition = (ConditionType)row.As <int>("type");
                        }
                        int ConditionValue1 = 0;
                        if (!Information.IsDBNull(RuntimeHelpers.GetObjectValue(row["value1"])))
                        {
                            ConditionValue1 = row.As <int>("value1");
                        }
                        int ConditionValue2 = 0;
                        if (!Information.IsDBNull(RuntimeHelpers.GetObjectValue(row["value2"])))
                        {
                            ConditionValue2 = row.As <int>("value2");
                        }
                        LootStoreItem newItem = new LootStoreItem(Item, Math.Abs(ChanceOrQuestChance), GroupID, MinCountOrRef, MaxCount, LootCondition, ConditionValue1, ConditionValue2, ChanceOrQuestChance < 0f);
                        newTemplate.AddItem(ref newItem);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                return(newTemplate);
            }
Пример #5
0
 public void AddItem(ref LootStoreItem Item)
 {
     if (Item.Group > 0 && Item.MinCountOrRef > 0)
     {
         if (!Groups.ContainsKey(Item.Group))
         {
             Groups.Add(Item.Group, new LootGroup());
         }
         Groups[Item.Group].AddItem(ref Item);
     }
     else
     {
         Items.Add(Item);
     }
 }
Пример #6
0
 public void Process(ref LootObject Loot, byte GroupID)
 {
     if (GroupID > 0)
     {
         if (Groups.ContainsKey(GroupID))
         {
             Groups[GroupID].Process(ref Loot);
         }
         return;
     }
     checked
     {
         int num = Items.Count - 1;
         for (int i = 0; i <= num; i++)
         {
             if (!Items[i].Roll())
             {
                 continue;
             }
             if (Items[i].MinCountOrRef < 0)
             {
                 LootTemplate Referenced = WorldServiceLocator._WS_Loot.LootTemplates_Reference.GetLoot(-Items[i].MinCountOrRef);
                 if (Referenced != null)
                 {
                     int maxCount = Items[i].MaxCount;
                     for (int j = 1; j <= maxCount; j++)
                     {
                         Referenced.Process(ref Loot, Items[i].Group);
                     }
                 }
             }
             else
             {
                 List <LootItem>      items = Loot.Items;
                 List <LootStoreItem> items2;
                 int           index;
                 LootStoreItem Item = (items2 = Items)[index = i];
                 LootItem      item = new LootItem(ref Item);
                 items2[index] = Item;
                 items.Add(item);
             }
         }
         foreach (KeyValuePair <byte, LootGroup> group in Groups)
         {
             group.Value.Process(ref Loot);
         }
     }
 }
Пример #7
0
        public void AddItem(ref LootStoreItem Item)
        {
            switch (Item.Group)
            {
            case > 0 when Item.MinCountOrRef > 0:
                if (!Groups.ContainsKey(Item.Group))
                {
                    Groups.Add(Item.Group, new LootGroup());
                }
                Groups[Item.Group].AddItem(ref Item);
                break;

            default:
                Items.Add(Item);
                break;
            }
        }
Пример #8
0
        // Inserts the item into the loot (called by LootTemplate processors)
        public void AddItem(LootStoreItem item)
        {
            ItemTemplate proto = Global.ObjectMgr.GetItemTemplate(item.itemid);

            if (proto == null)
            {
                return;
            }

            uint count  = RandomHelper.URand(item.mincount, item.maxcount);
            uint stacks = (uint)(count / proto.GetMaxStackSize() + (Convert.ToBoolean(count % proto.GetMaxStackSize()) ? 1 : 0));

            List <LootItem> lootItems = item.needs_quest ? quest_items : items;
            uint            limit     = (uint)(item.needs_quest ? SharedConst.MaxNRQuestItems : SharedConst.MaxNRLootItems);

            for (uint i = 0; i < stacks && lootItems.Count < limit; ++i)
            {
                LootItem generatedLoot = new(item);
                generatedLoot.context = _itemContext;
                generatedLoot.count   = (byte)Math.Min(count, proto.GetMaxStackSize());
                if (_itemContext != 0)
                {
                    List <uint> bonusListIDs = Global.DB2Mgr.GetDefaultItemBonusTree(generatedLoot.itemid, _itemContext);
                    generatedLoot.BonusListIDs.AddRange(bonusListIDs);
                }
                lootItems.Add(generatedLoot);
                count -= proto.GetMaxStackSize();

                // non-conditional one-player only items are counted here,
                // free for all items are counted in FillFFALoot(),
                // non-ffa conditionals are counted in FillNonQuestNonFFAConditionalLoot()
                if (!item.needs_quest && item.conditions.Empty() && !proto.GetFlags().HasAnyFlag(ItemFlags.MultiDrop))
                {
                    ++unlootedCount;
                }
            }
        }
Пример #9
0
        // Inserts the item into the loot (called by LootTemplate processors)
        public void AddItem(LootStoreItem item)
        {
            ItemTemplate proto = Global.ObjectMgr.GetItemTemplate(item.itemid);

            if (proto == null)
            {
                return;
            }

            uint count  = RandomHelper.URand(item.mincount, item.maxcount);
            uint stacks = (uint)(count / proto.GetMaxStackSize() + (Convert.ToBoolean(count % proto.GetMaxStackSize()) ? 1 : 0));

            List <LootItem> lootItems = item.needs_quest ? quest_items : items;
            uint            limit     = (uint)(item.needs_quest ? SharedConst.MaxNRQuestItems : SharedConst.MaxNRLootItems);

            for (uint i = 0; i < stacks && lootItems.Count < limit; ++i)
            {
                LootItem generatedLoot = new(item);
                generatedLoot.context = _itemContext;
                generatedLoot.count   = (byte)Math.Min(count, proto.GetMaxStackSize());
                if (_itemContext != 0)
                {
                    List <uint> bonusListIDs = Global.DB2Mgr.GetDefaultItemBonusTree(generatedLoot.itemid, _itemContext);
                    generatedLoot.BonusListIDs.AddRange(bonusListIDs);
                }
                lootItems.Add(generatedLoot);
                count -= proto.GetMaxStackSize();

                // In some cases, a dropped item should be visible/lootable only for some players in group
                bool   canSeeItemInLootWindow = false;
                Player player = Global.ObjAccessor.FindPlayer(lootOwnerGUID);
                if (player != null)
                {
                    Group group = player.GetGroup();
                    if (group != null)
                    {
                        for (GroupReference itr = group.GetFirstMember(); itr != null; itr = itr.Next())
                        {
                            Player member = itr.GetSource();
                            if (member != null)
                            {
                                if (generatedLoot.AllowedForPlayer(member))
                                {
                                    canSeeItemInLootWindow = true;
                                }
                            }
                        }
                    }
                    else if (generatedLoot.AllowedForPlayer(player))
                    {
                        canSeeItemInLootWindow = true;
                    }
                }

                if (!canSeeItemInLootWindow)
                {
                    continue;
                }

                // non-conditional one-player only items are counted here,
                // free for all items are counted in FillFFALoot(),
                // non-ffa conditionals are counted in FillNonQuestNonFFAConditionalLoot()
                if (!item.needs_quest && item.conditions.Empty() && !proto.HasFlag(ItemFlags.MultiDrop))
                {
                    ++unlootedCount;
                }
            }
        }