예제 #1
0
        private void OnInventoryDropItemMessage(InventoryDropItemMessage msg)
        {
            InventoryItem inv_item;

            if (!this.Contains(msg.ItemID))
            {
                if (this._equipment.ItemsEquiped.ContainsKey(msg.ItemID))
                {
                    inv_item = (InventoryItem)this._equipment.ItemsEquiped[msg.ItemID];
                }
                else
                {
                    Logging.LogManager.DefaultLogger.Error("Trying to DROP an item that is not in inventory or equipment!");
                    return;
                }
            }
            else
            {
                inv_item = (InventoryItem)this.Items[msg.ItemID];
            }


            if (inv_item.EquipmentSlot == EquipmentSlotId.Inventory)
            {
                //Inventory to ground!, so delete from inventory and drop item!
                if (!this.Contains(inv_item.DynamicID))
                {
                    Logging.LogManager.DefaultLogger.Error("Trying to DROP an item, from inventory to the ground but it is not in the inventory!");
                    return;
                }

                if (!this.removeItem(inv_item))
                {
                    Logging.LogManager.DefaultLogger.Error("could not remove item!, inventory to ground operation");
                    return;
                }

                Map  currentPlayerMap = (this.Owner as Player).World;
                Item item             = ItemFactory.CreateItem(inv_item.SNOId);
                currentPlayerMap.Enter(item, this.Owner.Position);

                DestroyInventoryItemMessage destroymsg = new DestroyInventoryItemMessage();
                destroymsg.InventorySlot     = new InventorySlot(0, 0);
                destroymsg.ItemID            = inv_item.DynamicID;
                destroymsg.inventoryWindowId = (int)InventoryWindowsID.PlayerInventory;
                destroymsg.SNO = inv_item.SNOId;
                (this.Owner as Player).GameClient.SendMessage(destroymsg);

                //this.broadcastVisualEquipment();
            }
            else
            {
                //Equipment to ground!, so delete from inventory and drop item!
            }
        }
예제 #2
0
        public void Consume(GameClient client, GameMessage message)
        {
            switch (message.opcodes)
            {
            case Opcodes.InventoryRequestMoveMessage:
            {
                InventoryRequestMoveMessage msg         = (InventoryRequestMoveMessage)message;
                InventoryWindowsID          dest_window = (InventoryWindowsID)msg.inventoryWindowId;
                if (dest_window == InventoryWindowsID.Vault)
                {
                    this.Vault.OnInventoryRequestMoveMessage(msg);
                }

                if (dest_window == InventoryWindowsID.PlayerInventory)
                {
                    this.OnInventoryRequestMoveMessage(msg);
                }

                break;
            }

            case Opcodes.InventoryRequestBuyItemMessage:
            {
                InventoryRequestBuyItemMessage msg = (InventoryRequestBuyItemMessage)message;
                if (!this.Owner.IsShopOpened)
                {
                    Logging.LogManager.DefaultLogger.Error("Trying to buy but shop is not opened!");
                    break;
                }

                if (!this.Owner.OpenedNPC.ShopInventory.Contains(msg.ItemId))
                {
                    Logging.LogManager.DefaultLogger.Error("Trying to buy an item that is not in the SHOP!");
                    break;
                }

                InventoryItem shop_item = (InventoryItem)this.Owner.OpenedNPC.ShopInventory.Items[msg.ItemId];
                if (!this.hasFreeSpace(shop_item))
                {
                    Logging.LogManager.DefaultLogger.Error("could not buy the item, inventory has not enough space!");
                    return;
                }

                InventoryItem new_item = new InventoryItem(shop_item.SNOId);
                new_item.FillData(shop_item);
                //fill new_item specific data from shop_item, this would be like cloning shop_item!

                InventorySlot slot = this.findSlotForItem(new_item);
                if (!this.canPutitemThere_checking_self_item(new_item, slot.R, slot.C))
                {
                    Logging.LogManager.DefaultLogger.Error("could not put item there!");
                    return;
                }
                if (!this.addItemAtPosition(new_item, slot))
                {
                    Logging.LogManager.DefaultLogger.Error("could not add item at position, buying item error!");
                    return;
                }

                CreateInventoryItemMessage create_item_msg = new CreateInventoryItemMessage();

                create_item_msg.InventorySlot      = slot;
                create_item_msg.inventoryWindowsId = (int)InventoryWindowsID.PlayerInventory;
                create_item_msg.SNO    = new_item.SNOId;
                create_item_msg.ItemID = new_item.DynamicID;

                this.Owner.GameClient.SendMessage(create_item_msg);
                new_item.Attributes.BroadcastAllAttributestoPlayer(this.Owner);

                break;
            }

            case Opcodes.InventoryRequestSellItemMessage:
            {
                InventoryRequestSellItemMessage msg = (InventoryRequestSellItemMessage)message;

                InventoryItem inv_item;
                if (!this.Contains(msg.ItemId))
                {
                    Logging.LogManager.DefaultLogger.Error("Trying to SELL an item that is not in inventory!");
                    break;
                }
                else
                {
                    inv_item = (InventoryItem)this.Items[msg.ItemId];
                }


                if (!this.removeItem(inv_item))
                {
                    Logging.LogManager.DefaultLogger.Error("could not remove item!, sell item operation");
                    return;
                }

                DestroyInventoryItemMessage destroy_msg = new DestroyInventoryItemMessage();
                destroy_msg.inventoryWindowId = (int)InventoryWindowsID.PlayerInventory;
                destroy_msg.InventorySlot     = inv_item.InventorySlot;
                destroy_msg.ItemID            = inv_item.DynamicID;
                this.Owner.GameClient.SendMessage(destroy_msg);

                break;
            }

            case Opcodes.InventoryRequestQuickMoveMessage:
            {
                HandleInventoryRequestQuickMoveMessage(message as InventoryRequestQuickMoveMessage);
                break;
            }

            case Opcodes.InventoryDropItemMessage:
            {
                OnInventoryDropItemMessage(message as InventoryDropItemMessage);
                break;
            }

            case Opcodes.InventoryRequestJewelUse:
            {
                InventoryRequestJewelUse msg = (InventoryRequestJewelUse)message;
                Logging.LogManager.DefaultLogger.Trace("Item Blessed!, id ", msg.destItemId);

                InventoryItem source_jewel = (InventoryItem)this.Items[msg.sourceJewelId];
                InventoryItem dest_item    = (InventoryItem)this.Items[msg.destItemId];

                DestroyInventoryItemMessage response = new DestroyInventoryItemMessage();
                response.InventorySlot     = source_jewel.InventorySlot;
                response.inventoryWindowId = (int)InventoryWindowsID.PlayerInventory;
                response.ItemID            = source_jewel.DynamicID;
                response.SNO = source_jewel.SNOId;
                this.Owner.GameClient.SendMessage(response);

                this.removeItem(source_jewel);

                break;
            }

            case Opcodes.InventoryCloseWindowMessage:
            {
                InventoryCloseWindowMessage msg = (InventoryCloseWindowMessage)message;

                if (msg.windowId == InventoryWindowsID.Vault)
                {
                    Player player = (this.Owner as Player);
                    player.Busy          = false;
                    player.IsVaultOpened = false;

                    InventoryShowWindowMessage hide_vault_msg = new InventoryShowWindowMessage();
                    hide_vault_msg.windowId = InventoryWindowsID.Vault;
                    hide_vault_msg.visible  = false;
                    player.GameClient.SendMessage(hide_vault_msg);

                    InventoryShowWindowMessage hide_invent_msg = new InventoryShowWindowMessage();
                    hide_invent_msg.windowId = InventoryWindowsID.PlayerInventory;
                    hide_invent_msg.visible  = false;
                    player.GameClient.SendMessage(hide_invent_msg);
                }

                if (msg.windowId == InventoryWindowsID._SHOP)
                {
                    Player player = (this.Owner as Player);
                    player.Busy         = false;
                    player.IsShopOpened = false;

                    InventoryShowWindowMessage hide_shop_msg = new InventoryShowWindowMessage();
                    hide_shop_msg.windowId = InventoryWindowsID._SHOP;
                    hide_shop_msg.visible  = false;
                    player.GameClient.SendMessage(hide_shop_msg);

                    InventoryShowWindowMessage hide_invent_msg = new InventoryShowWindowMessage();
                    hide_invent_msg.windowId = InventoryWindowsID.PlayerInventory;
                    hide_invent_msg.visible  = false;
                    player.GameClient.SendMessage(hide_invent_msg);
                }

                if (msg.windowId == InventoryWindowsID.PlayerInventory)
                {
                    Player player = (this.Owner as Player);
                    player.Busy = false;


                    if (player.IsShopOpened)
                    {
                        player.IsShopOpened = false;
                        InventoryShowWindowMessage hide_shop_msg = new InventoryShowWindowMessage();
                        hide_shop_msg.windowId = InventoryWindowsID._SHOP;
                        hide_shop_msg.visible  = false;
                        player.GameClient.SendMessage(hide_shop_msg);
                    }

                    if (player.IsVaultOpened)
                    {
                        player.IsVaultOpened = false;
                        InventoryShowWindowMessage hide_shop_msg = new InventoryShowWindowMessage();
                        hide_shop_msg.windowId = InventoryWindowsID.Vault;
                        hide_shop_msg.visible  = false;
                        player.GameClient.SendMessage(hide_shop_msg);
                    }

                    InventoryShowWindowMessage hide_invent_msg = new InventoryShowWindowMessage();
                    hide_invent_msg.windowId = InventoryWindowsID.PlayerInventory;
                    hide_invent_msg.visible  = false;
                    player.GameClient.SendMessage(hide_invent_msg);
                }

                break;
            }
            }
        }