Ejemplo n.º 1
0
        public void SendUpdateTrade(bool trader_data = true)
        {
            TradeData view_trade = trader_data ? GetPlayer().GetTradeData().GetTraderData() : GetPlayer().GetTradeData();

            TradeUpdated tradeUpdated = new TradeUpdated();

            tradeUpdated.WhichPlayer       = (byte)(trader_data ? 1 : 0);
            tradeUpdated.ClientStateIndex  = view_trade.GetClientStateIndex();
            tradeUpdated.CurrentStateIndex = view_trade.GetServerStateIndex();
            tradeUpdated.Gold = view_trade.GetMoney();
            tradeUpdated.ProposedEnchantment = (int)view_trade.GetSpell();

            for (byte i = 0; i < (byte)TradeSlots.Count; ++i)
            {
                Item item = view_trade.GetItem((TradeSlots)i);
                if (item)
                {
                    TradeUpdated.TradeItem tradeItem = new TradeUpdated.TradeItem();
                    tradeItem.Slot        = i;
                    tradeItem.Item        = new ItemInstance(item);
                    tradeItem.StackCount  = (int)item.GetCount();
                    tradeItem.GiftCreator = item.GetGiftCreator();
                    if (!item.HasItemFlag(ItemFieldFlags.Wrapped))
                    {
                        tradeItem.Unwrapped.HasValue = true;
                        TradeUpdated.UnwrappedTradeItem unwrappedItem = tradeItem.Unwrapped.Value;
                        unwrappedItem.EnchantID          = (int)item.GetEnchantmentId(EnchantmentSlot.Perm);
                        unwrappedItem.OnUseEnchantmentID = (int)item.GetEnchantmentId(EnchantmentSlot.Use);
                        unwrappedItem.Creator            = item.GetCreator();
                        unwrappedItem.Charges            = item.GetSpellCharges();
                        unwrappedItem.Lock          = item.GetTemplate().GetLockID() != 0 && !item.HasItemFlag(ItemFieldFlags.Unlocked);
                        unwrappedItem.MaxDurability = item.m_itemData.MaxDurability;
                        unwrappedItem.Durability    = item.m_itemData.Durability;

                        byte g = 0;
                        foreach (SocketedGem gemData in item.m_itemData.Gems)
                        {
                            if (gemData.ItemId != 0)
                            {
                                ItemGemData gem = new ItemGemData();
                                gem.Slot = g;
                                gem.Item = new ItemInstance(gemData);
                                tradeItem.Unwrapped.Value.Gems.Add(gem);
                            }
                            ++g;
                        }
                    }
                    tradeUpdated.Items.Add(tradeItem);
                }
            }

            SendPacket(tradeUpdated);
        }
Ejemplo n.º 2
0
        void HandleAutoEquipItem(AutoEquipItem autoEquipItem)
        {
            if (autoEquipItem.Inv.Items.Count != 1)
            {
                Log.outError(LogFilter.Network, "WORLD: HandleAutoEquipItem - Invalid itemCount ({0})", autoEquipItem.Inv.Items.Count);
                return;
            }

            var  pl      = GetPlayer();
            Item srcItem = pl.GetItemByPos(autoEquipItem.PackSlot, autoEquipItem.Slot);

            if (srcItem == null)
            {
                return;                                             // only at cheat
            }
            ushort          dest;
            InventoryResult msg = pl.CanEquipItem(ItemConst.NullSlot, out dest, srcItem, !srcItem.IsBag());

            if (msg != InventoryResult.Ok)
            {
                pl.SendEquipError(msg, srcItem);
                return;
            }

            ushort src = srcItem.GetPos();

            if (dest == src)                                           // prevent equip in same slot, only at cheat
            {
                return;
            }

            Item dstItem = pl.GetItemByPos(dest);

            if (dstItem == null)                                         // empty slot, simple case
            {
                if (!srcItem.GetChildItem().IsEmpty())
                {
                    InventoryResult childEquipResult = _player.CanEquipChildItem(srcItem);
                    if (childEquipResult != InventoryResult.Ok)
                    {
                        _player.SendEquipError(msg, srcItem);
                        return;
                    }
                }

                pl.RemoveItem(autoEquipItem.PackSlot, autoEquipItem.Slot, true);
                pl.EquipItem(dest, srcItem, true);
                if (!srcItem.GetChildItem().IsEmpty())
                {
                    _player.EquipChildItem(autoEquipItem.PackSlot, autoEquipItem.Slot, srcItem);
                }

                pl.AutoUnequipOffhandIfNeed();
            }
            else                                                    // have currently equipped item, not simple case
            {
                byte dstbag  = dstItem.GetBagSlot();
                byte dstslot = dstItem.GetSlot();

                msg = pl.CanUnequipItem(dest, !srcItem.IsBag());
                if (msg != InventoryResult.Ok)
                {
                    pl.SendEquipError(msg, dstItem);
                    return;
                }

                if (!dstItem.HasItemFlag(ItemFieldFlags.Child))
                {
                    // check dest.src move possibility
                    List <ItemPosCount> sSrc = new();
                    ushort eSrc = 0;
                    if (pl.IsInventoryPos(src))
                    {
                        msg = pl.CanStoreItem(autoEquipItem.PackSlot, autoEquipItem.Slot, sSrc, dstItem, true);
                        if (msg != InventoryResult.Ok)
                        {
                            msg = pl.CanStoreItem(autoEquipItem.PackSlot, ItemConst.NullSlot, sSrc, dstItem, true);
                        }
                        if (msg != InventoryResult.Ok)
                        {
                            msg = pl.CanStoreItem(ItemConst.NullBag, ItemConst.NullSlot, sSrc, dstItem, true);
                        }
                    }
                    else if (Player.IsBankPos(src))
                    {
                        msg = pl.CanBankItem(autoEquipItem.PackSlot, autoEquipItem.Slot, sSrc, dstItem, true);
                        if (msg != InventoryResult.Ok)
                        {
                            msg = pl.CanBankItem(autoEquipItem.PackSlot, ItemConst.NullSlot, sSrc, dstItem, true);
                        }
                        if (msg != InventoryResult.Ok)
                        {
                            msg = pl.CanBankItem(ItemConst.NullBag, ItemConst.NullSlot, sSrc, dstItem, true);
                        }
                    }
                    else if (Player.IsEquipmentPos(src))
                    {
                        msg = pl.CanEquipItem(autoEquipItem.Slot, out eSrc, dstItem, true);
                        if (msg == InventoryResult.Ok)
                        {
                            msg = pl.CanUnequipItem(eSrc, true);
                        }
                    }

                    if (msg == InventoryResult.Ok && Player.IsEquipmentPos(dest) && !srcItem.GetChildItem().IsEmpty())
                    {
                        msg = _player.CanEquipChildItem(srcItem);
                    }

                    if (msg != InventoryResult.Ok)
                    {
                        pl.SendEquipError(msg, dstItem, srcItem);
                        return;
                    }

                    // now do moves, remove...
                    pl.RemoveItem(dstbag, dstslot, false);
                    pl.RemoveItem(autoEquipItem.PackSlot, autoEquipItem.Slot, false);

                    // add to dest
                    pl.EquipItem(dest, srcItem, true);

                    // add to src
                    if (pl.IsInventoryPos(src))
                    {
                        pl.StoreItem(sSrc, dstItem, true);
                    }
                    else if (Player.IsBankPos(src))
                    {
                        pl.BankItem(sSrc, dstItem, true);
                    }
                    else if (Player.IsEquipmentPos(src))
                    {
                        pl.EquipItem(eSrc, dstItem, true);
                    }

                    if (Player.IsEquipmentPos(dest) && !srcItem.GetChildItem().IsEmpty())
                    {
                        _player.EquipChildItem(autoEquipItem.PackSlot, autoEquipItem.Slot, srcItem);
                    }
                }
                else
                {
                    Item parentItem = _player.GetItemByGuid(dstItem.GetCreator());
                    if (parentItem)
                    {
                        if (Player.IsEquipmentPos(dest))
                        {
                            _player.AutoUnequipChildItem(parentItem);
                            // dest is now empty
                            _player.SwapItem(src, dest);
                            // src is now empty
                            _player.SwapItem(parentItem.GetPos(), src);
                        }
                    }
                }

                pl.AutoUnequipOffhandIfNeed();

                // if inventory item was moved, check if we can remove dependent auras, because they were not removed in Player::RemoveItem (update was set to false)
                // do this after swaps are done, we pass nullptr because both weapons could be swapped and none of them should be ignored
                if ((autoEquipItem.PackSlot == InventorySlots.Bag0 && autoEquipItem.Slot < InventorySlots.BagEnd) || (dstbag == InventorySlots.Bag0 && dstslot < InventorySlots.BagEnd))
                {
                    pl.ApplyItemDependentAuras(null, false);
                }
            }
        }
Ejemplo n.º 3
0
        void HandleVoidStorageTransfer(VoidStorageTransfer voidStorageTransfer)
        {
            Player player = GetPlayer();

            Creature unit = player.GetNPCIfCanInteractWith(voidStorageTransfer.Npc, NPCFlags.VaultKeeper, NPCFlags2.None);

            if (!unit)
            {
                Log.outDebug(LogFilter.Network, "WORLD: HandleVoidStorageTransfer - {0} not found or player can't interact with it.", voidStorageTransfer.Npc.ToString());
                return;
            }

            if (!player.IsVoidStorageUnlocked())
            {
                Log.outDebug(LogFilter.Network, "WORLD: HandleVoidStorageTransfer - Player ({0}, name: {1}) queried void storage without unlocking it.", player.GetGUID().ToString(), player.GetName());
                return;
            }

            if (voidStorageTransfer.Deposits.Length > player.GetNumOfVoidStorageFreeSlots())
            {
                SendVoidStorageTransferResult(VoidTransferError.Full);
                return;
            }

            uint freeBagSlots = 0;

            if (!voidStorageTransfer.Withdrawals.Empty())
            {
                // make this a Player function
                for (byte i = InventorySlots.BagStart; i < InventorySlots.BagEnd; i++)
                {
                    Bag bag = player.GetBagByPos(i);
                    if (bag)
                    {
                        freeBagSlots += bag.GetFreeSlots();
                    }
                }
                int inventoryEnd = InventorySlots.ItemStart + _player.GetInventorySlotCount();
                for (byte i = InventorySlots.ItemStart; i < inventoryEnd; i++)
                {
                    if (!player.GetItemByPos(InventorySlots.Bag0, i))
                    {
                        ++freeBagSlots;
                    }
                }
            }

            if (voidStorageTransfer.Withdrawals.Length > freeBagSlots)
            {
                SendVoidStorageTransferResult(VoidTransferError.InventoryFull);
                return;
            }

            if (!player.HasEnoughMoney((voidStorageTransfer.Deposits.Length * SharedConst.VoidStorageStoreItemCost)))
            {
                SendVoidStorageTransferResult(VoidTransferError.NotEnoughMoney);
                return;
            }

            VoidStorageTransferChanges voidStorageTransferChanges = new VoidStorageTransferChanges();

            byte depositCount = 0;

            for (int i = 0; i < voidStorageTransfer.Deposits.Length; ++i)
            {
                Item item = player.GetItemByGuid(voidStorageTransfer.Deposits[i]);
                if (!item)
                {
                    Log.outDebug(LogFilter.Network, "WORLD: HandleVoidStorageTransfer - {0} {1} wants to deposit an invalid item ({2}).", player.GetGUID().ToString(), player.GetName(), voidStorageTransfer.Deposits[i].ToString());
                    continue;
                }

                VoidStorageItem itemVS = new VoidStorageItem(Global.ObjectMgr.GenerateVoidStorageItemId(), item.GetEntry(), item.GetCreator(),
                                                             item.GetItemRandomBonusListId(), item.GetModifier(ItemModifier.TimewalkerLevel), item.GetModifier(ItemModifier.ArtifactKnowledgeLevel),
                                                             item.GetContext(), item.m_itemData.BonusListIDs);

                VoidItem voidItem;
                voidItem.Guid    = ObjectGuid.Create(HighGuid.Item, itemVS.ItemId);
                voidItem.Creator = item.GetCreator();
                voidItem.Item    = new ItemInstance(itemVS);
                voidItem.Slot    = _player.AddVoidStorageItem(itemVS);

                voidStorageTransferChanges.AddedItems.Add(voidItem);

                player.DestroyItem(item.GetBagSlot(), item.GetSlot(), true);
                ++depositCount;
            }

            long cost = depositCount * SharedConst.VoidStorageStoreItemCost;

            player.ModifyMoney(-cost);

            for (int i = 0; i < voidStorageTransfer.Withdrawals.Length; ++i)
            {
                byte            slot;
                VoidStorageItem itemVS = player.GetVoidStorageItem(voidStorageTransfer.Withdrawals[i].GetCounter(), out slot);
                if (itemVS == null)
                {
                    Log.outDebug(LogFilter.Network, "WORLD: HandleVoidStorageTransfer - {0} {1} tried to withdraw an invalid item ({2})", player.GetGUID().ToString(), player.GetName(), voidStorageTransfer.Withdrawals[i].ToString());
                    continue;
                }

                List <ItemPosCount> dest = new List <ItemPosCount>();
                InventoryResult     msg  = player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, itemVS.ItemEntry, 1);
                if (msg != InventoryResult.Ok)
                {
                    SendVoidStorageTransferResult(VoidTransferError.InventoryFull);
                    Log.outDebug(LogFilter.Network, "WORLD: HandleVoidStorageTransfer - {0} {1} couldn't withdraw {2} because inventory was full.", player.GetGUID().ToString(), player.GetName(), voidStorageTransfer.Withdrawals[i].ToString());
                    return;
                }

                Item item = player.StoreNewItem(dest, itemVS.ItemEntry, true, itemVS.RandomBonusListId, null, itemVS.Context, itemVS.BonusListIDs);
                item.SetCreator(itemVS.CreatorGuid);
                item.SetBinding(true);
                GetCollectionMgr().AddItemAppearance(item);

                voidStorageTransferChanges.RemovedItems.Add(ObjectGuid.Create(HighGuid.Item, itemVS.ItemId));

                player.DeleteVoidStorageItem(slot);
            }

            SendPacket(voidStorageTransferChanges);
            SendVoidStorageTransferResult(VoidTransferError.Ok);
        }