예제 #1
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 LootItem(item);
                generatedLoot.context = _itemContext;
                generatedLoot.count   = (byte)Math.Min(count, proto.GetMaxStackSize());
                if (_itemContext != 0)
                {
                    List <uint> bonusListIDs = Global.DB2Mgr.GetItemBonusTree(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;
                }
            }
        }
예제 #2
0
        public void BuildLootResponse(LootResponse packet, Player viewer, PermissionTypes permission)
        {
            if (permission == PermissionTypes.None)
            {
                return;
            }

            packet.Coins = gold;

            switch (permission)
            {
            case PermissionTypes.Group:
            case PermissionTypes.Master:
            case PermissionTypes.Restricted:
            {
                // if you are not the round-robin group looter, you can only see
                // blocked rolled items and quest items, and !ffa items
                for (byte i = 0; i < items.Count; ++i)
                {
                    if (!items[i].is_looted && !items[i].freeforall && items[i].conditions.Empty() && items[i].AllowedForPlayer(viewer))
                    {
                        LootSlotType slot_type;

                        if (items[i].is_blocked)         // for ML & restricted is_blocked = !is_underthreshold
                        {
                            switch (permission)
                            {
                            case PermissionTypes.Group:
                                slot_type = LootSlotType.RollOngoing;
                                break;

                            case PermissionTypes.Master:
                            {
                                if (viewer.GetGroup() && viewer.GetGroup().GetMasterLooterGuid() == viewer.GetGUID())
                                {
                                    slot_type = LootSlotType.Master;
                                }
                                else
                                {
                                    slot_type = LootSlotType.Locked;
                                }
                                break;
                            }

                            case PermissionTypes.Restricted:
                                slot_type = LootSlotType.Locked;
                                break;

                            default:
                                continue;
                            }
                        }
                        else if (roundRobinPlayer.IsEmpty() || viewer.GetGUID() == roundRobinPlayer || !items[i].is_underthreshold)
                        {
                            // no round robin owner or he has released the loot
                            // or it IS the round robin group owner
                            // => item is lootable
                            slot_type = LootSlotType.AllowLoot;
                        }
                        else if (!items[i].rollWinnerGUID.IsEmpty())
                        {
                            if (items[i].rollWinnerGUID == viewer.GetGUID())
                            {
                                slot_type = LootSlotType.Owner;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            // item shall not be displayed.
                            continue;
                        }

                        LootItemData lootItem = new LootItemData();
                        lootItem.LootListID = (byte)(i + 1);
                        lootItem.UIType     = slot_type;
                        lootItem.Quantity   = items[i].count;
                        lootItem.Loot       = new ItemInstance(items[i]);
                        packet.Items.Add(lootItem);
                    }
                }
                break;
            }

            case PermissionTypes.All:
            case PermissionTypes.Owner:
            {
                for (byte i = 0; i < items.Count; ++i)
                {
                    if (!items[i].is_looted && !items[i].freeforall && items[i].conditions.Empty() && items[i].AllowedForPlayer(viewer))
                    {
                        LootItemData lootItem = new LootItemData();
                        lootItem.LootListID = (byte)(i + 1);
                        lootItem.UIType     = (permission == PermissionTypes.Owner ? LootSlotType.Owner : LootSlotType.AllowLoot);
                        lootItem.Quantity   = items[i].count;
                        lootItem.Loot       = new ItemInstance(items[i]);
                        packet.Items.Add(lootItem);
                    }
                }
                break;
            }

            default:
                return;
            }

            LootSlotType slotType             = permission == PermissionTypes.Owner ? LootSlotType.Owner : LootSlotType.AllowLoot;
            var          lootPlayerQuestItems = GetPlayerQuestItems();
            var          q_list = lootPlayerQuestItems.LookupByKey(viewer.GetGUID());

            if (!q_list.Empty())
            {
                for (var i = 0; i < q_list.Count; ++i)
                {
                    NotNormalLootItem qi   = q_list[i];
                    LootItem          item = quest_items[qi.index];
                    if (!qi.is_looted && !item.is_looted)
                    {
                        LootItemData lootItem = new LootItemData();
                        lootItem.LootListID = (byte)(items.Count + i + 1);
                        lootItem.Quantity   = item.count;
                        lootItem.Loot       = new ItemInstance(item);

                        switch (permission)
                        {
                        case PermissionTypes.Master:
                            lootItem.UIType = LootSlotType.Master;
                            break;

                        case PermissionTypes.Restricted:
                            lootItem.UIType = item.is_blocked ? LootSlotType.Locked : LootSlotType.AllowLoot;
                            break;

                        case PermissionTypes.Group:
                            if (!item.is_blocked)
                            {
                                lootItem.UIType = LootSlotType.AllowLoot;
                            }
                            else
                            {
                                lootItem.UIType = LootSlotType.RollOngoing;
                            }
                            break;

                        default:
                            lootItem.UIType = slotType;
                            break;
                        }

                        packet.Items.Add(lootItem);
                    }
                }
            }

            var lootPlayerFFAItems = GetPlayerFFAItems();
            var ffa_list           = lootPlayerFFAItems.LookupByKey(viewer.GetGUID());

            if (!ffa_list.Empty())
            {
                foreach (var fi in ffa_list)
                {
                    LootItem item = items[fi.index];
                    if (!fi.is_looted && !item.is_looted)
                    {
                        LootItemData lootItem = new LootItemData();
                        lootItem.LootListID = (byte)(fi.index + 1);
                        lootItem.UIType     = slotType;
                        lootItem.Quantity   = item.count;
                        lootItem.Loot       = new ItemInstance(item);
                        packet.Items.Add(lootItem);
                    }
                }
            }

            var lootPlayerNonQuestNonFFAConditionalItems = GetPlayerNonQuestNonFFAConditionalItems();
            var conditional_list = lootPlayerNonQuestNonFFAConditionalItems.LookupByKey(viewer.GetGUID());

            if (!conditional_list.Empty())
            {
                foreach (var ci in conditional_list)
                {
                    LootItem item = items[ci.index];
                    if (!ci.is_looted && !item.is_looted)
                    {
                        LootItemData lootItem = new LootItemData();
                        lootItem.LootListID = (byte)(ci.index + 1);
                        lootItem.Quantity   = item.count;
                        lootItem.Loot       = new ItemInstance(item);

                        if (item.follow_loot_rules)
                        {
                            switch (permission)
                            {
                            case PermissionTypes.Master:
                                lootItem.UIType = LootSlotType.Master;
                                break;

                            case PermissionTypes.Restricted:
                                lootItem.UIType = item.is_blocked ? LootSlotType.Locked : LootSlotType.AllowLoot;
                                break;

                            case PermissionTypes.Group:
                                if (!item.is_blocked)
                                {
                                    lootItem.UIType = LootSlotType.AllowLoot;
                                }
                                else
                                {
                                    lootItem.UIType = LootSlotType.RollOngoing;
                                }
                                break;

                            default:
                                lootItem.UIType = slotType;
                                break;
                            }
                        }
                        else
                        {
                            lootItem.UIType = slotType;
                        }

                        packet.Items.Add(lootItem);
                    }
                }
            }
        }
예제 #3
0
        public LootItem LootItemInSlot(uint lootSlot, Player player, out NotNormalLootItem qitem, out NotNormalLootItem ffaitem, out NotNormalLootItem conditem)
        {
            qitem    = null;
            ffaitem  = null;
            conditem = null;

            LootItem item      = null;
            bool     is_looted = true;

            if (lootSlot >= items.Count)
            {
                uint questSlot  = (uint)(lootSlot - items.Count);
                var  questItems = PlayerQuestItems.LookupByKey(player.GetGUID());
                if (!questItems.Empty())
                {
                    NotNormalLootItem qitem2 = questItems.Find(p => p.index == questSlot);
                    if (qitem2 != null)
                    {
                        qitem     = qitem2;
                        item      = quest_items[qitem2.index];
                        is_looted = qitem2.is_looted;
                    }
                }
            }
            else
            {
                item      = items[(int)lootSlot];
                is_looted = item.is_looted;
                if (item.freeforall)
                {
                    var questItemList = PlayerFFAItems.LookupByKey(player.GetGUID());
                    if (!questItemList.Empty())
                    {
                        foreach (var c in questItemList)
                        {
                            if (c.index == lootSlot)
                            {
                                NotNormalLootItem ffaitem2 = c;
                                ffaitem   = ffaitem2;
                                is_looted = ffaitem2.is_looted;
                                break;
                            }
                        }
                    }
                }
                else if (!item.conditions.Empty())
                {
                    var questItemList = PlayerNonQuestNonFFAConditionalItems.LookupByKey(player.GetGUID());
                    if (!questItemList.Empty())
                    {
                        foreach (var iter in questItemList)
                        {
                            if (iter.index == lootSlot)
                            {
                                NotNormalLootItem conditem2 = iter;
                                conditem  = conditem2;
                                is_looted = conditem2.is_looted;
                                break;
                            }
                        }
                    }
                }
            }

            if (is_looted)
            {
                return(null);
            }

            return(item);
        }
예제 #4
0
        public void LoadStorageFromDB()
        {
            uint oldMSTime = Time.GetMSTime();

            _lootItemStorage.Clear();
            uint count = 0;

            PreparedStatement stmt   = DB.Characters.GetPreparedStatement(CharStatements.SEL_ITEMCONTAINER_ITEMS);
            SQLResult         result = DB.Characters.Query(stmt);

            if (!result.IsEmpty())
            {
                do
                {
                    ulong key = result.Read <ulong>(0);
                    var   itr = _lootItemStorage.LookupByKey(key);
                    if (!_lootItemStorage.ContainsKey(key))
                    {
                        _lootItemStorage[key] = new StoredLootContainer(key);
                    }

                    StoredLootContainer storedContainer = _lootItemStorage[key];

                    LootItem lootItem = new LootItem();
                    lootItem.itemid            = result.Read <uint>(1);
                    lootItem.count             = result.Read <byte>(2);
                    lootItem.follow_loot_rules = result.Read <bool>(3);
                    lootItem.freeforall        = result.Read <bool>(4);
                    lootItem.is_blocked        = result.Read <bool>(5);
                    lootItem.is_counted        = result.Read <bool>(6);
                    lootItem.is_underthreshold = result.Read <bool>(7);
                    lootItem.needs_quest       = result.Read <bool>(8);
                    lootItem.randomBonusListId = result.Read <uint>(9);
                    lootItem.context           = (ItemContext)result.Read <byte>(10);
                    StringArray bonusLists = new StringArray(result.Read <string>(11), ' ');

                    foreach (string str in bonusLists)
                    {
                        lootItem.BonusListIDs.Add(uint.Parse(str));
                    }

                    storedContainer.AddLootItem(lootItem, null);

                    ++count;
                } while (result.NextRow());

                Log.outInfo(LogFilter.ServerLoading, $"Loaded {count} stored item loots in {Time.GetMSTimeDiffToNow(oldMSTime)} ms");
            }
            else
            {
                Log.outInfo(LogFilter.ServerLoading, "Loaded 0 stored item loots");
            }

            stmt   = DB.Characters.GetPreparedStatement(CharStatements.SEL_ITEMCONTAINER_MONEY);
            result = DB.Characters.Query(stmt);
            if (!result.IsEmpty())
            {
                count = 0;
                do
                {
                    ulong key = result.Read <ulong>(0);
                    if (!_lootItemStorage.ContainsKey(key))
                    {
                        _lootItemStorage.TryAdd(key, new StoredLootContainer(key));
                    }

                    StoredLootContainer storedContainer = _lootItemStorage[key];
                    storedContainer.AddMoney(result.Read <uint>(1), null);

                    ++count;
                } while (result.NextRow());

                Log.outInfo(LogFilter.ServerLoading, $"Loaded {count} stored item money in {Time.GetMSTimeDiffToNow(oldMSTime)} ms");
            }
            else
            {
                Log.outInfo(LogFilter.ServerLoading, "Loaded 0 stored item money");
            }
        }