Пример #1
0
        // Drops item with option to drop bound items
        public static void DropItem(GameSession session, long uid, int amount, bool isbound)
        {
            if (!isbound)                                                                           // Drops Item
            {
                int remaining = session.Player.Inventory.Remove(uid, out Item droppedItem, amount); // Returns remaining amount of item
                if (remaining < 0)
                {
                    return;             // Removal failed
                }
                else if (remaining > 0) // Updates item
                {
                    session.Send(ItemInventoryPacket.Update(uid, remaining));
                    DatabaseManager.Items.Update(session.Player.Inventory.Items.Values.First(x => x.Uid == uid));
                }
                else // Removes item
                {
                    session.Send(ItemInventoryPacket.Remove(uid));
                    DatabaseManager.Items.Delete(droppedItem.Uid);
                }
                session.FieldManager.AddItem(session, droppedItem); // Drops item onto floor
            }
            else // Drops bound item.
            {
                if (session.Player.Inventory.Remove(uid, out Item droppedItem) != 0)
                {
                    return; // Removal from inventory failed
                }
                session.Send(ItemInventoryPacket.Remove(uid));
                DatabaseManager.Items.Delete(droppedItem.Uid);

                Remove(session, uid, out droppedItem);
            }
        }
        // Drops item with option to drop bound items
        public static void DropItem(GameSession session, long uid, int amount, bool isbound)
        {
            if (!isbound)                                                                           // Drops Item
            {
                int remaining = session.Player.Inventory.Remove(uid, out Item droppedItem, amount); // Returns remaining amount of item
                if (remaining < 0)
                {
                    return;             // Removal failed
                }
                else if (remaining > 0) // Updates item
                {
                    session.Send(ItemInventoryPacket.Update(uid, remaining));
                }
                else // Removes item
                {
                    session.Send(ItemInventoryPacket.Remove(uid));
                }
                session.FieldManager.AddItem(session, droppedItem); // Drops item onto floor
            }
            else // Drops bound item.
            {
                if (session.Player.Inventory.Remove(uid, out Item droppedItem) != 0)
                {
                    return; // Removal from inventory failed
                }
                session.Send(ItemInventoryPacket.Remove(uid));

                // Allow dropping bound items for now
                session.FieldManager.AddItem(session, droppedItem);
            }
        }
Пример #3
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            long boxUid = packet.ReadLong();

            if (!session.Player.Inventory.Items.ContainsKey(boxUid))
            {
                return;
            }

            // Get the box item
            Item box = session.Player.Inventory.Items[boxUid];

            // Remove box if amount is 1 or less
            if (box.Amount <= 1)
            {
                session.Player.Inventory.Remove(boxUid, out Item removed);
                session.Send(ItemInventoryPacket.Remove(boxUid));
            }
            // Decrement box amount to otherwise
            else
            {
                box.Amount -= 1;
                session.Send(ItemInventoryPacket.Update(boxUid, box.Amount));
            }

            // Normally would look up which item to create, instead always add poisonous mushroom
            Item item = new Item(30001001);

            InventoryController.Add(session, item);
        }
        // Removes Item from inventory by reference
        public static bool Remove(GameSession session, long uid, out Item item)
        {
            int amountRemoved = session.Player.Inventory.Remove(uid, out item);

            if (amountRemoved == -1)
            {
                return(false);
            }

            session.Send(ItemInventoryPacket.Remove(uid));
            return(true);
        }
        private void HandleDropBound(GameSession session, PacketReader packet, Inventory inventory)
        {
            long uid = packet.ReadLong();

            if (inventory.Remove(uid, out Item droppedItem) != 0)
            {
                return; // Removal from inventory failed
            }

            session.Send(ItemInventoryPacket.Remove(uid));

            // Allow dropping bound items for now
            session.FieldManager.AddItem(session, droppedItem);
        }
Пример #6
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            int boxId = packet.ReadInt();

            packet.ReadShort(); // Unknown
            int amount = packet.ReadInt();

            short       opened = 0;                                                       // Amount of opened boxes
            List <Item> items  = new List <Item> (session.Player.Inventory.Items.Values); // Make copy of items in-case new item is added

            foreach (Item item in items)
            {
                // Continue over non-matching item ids
                if (item.Id != boxId)
                {
                    continue;
                }

                for (int i = opened; i < amount; i++)
                {
                    // Create new item from opening box
                    Item newItem = new Item(30001001);

                    // Remove box if there is only 1 left
                    if (item.Amount <= 1)
                    {
                        session.Player.Inventory.Remove(item.Uid, out Item removed);
                        session.Send(ItemInventoryPacket.Remove(item.Uid));
                        InventoryController.Add(session, newItem);

                        opened++;

                        break; // Break out of the amount loop because this stack of boxes is empty, look for next stack
                    }

                    // Update box amount if there is more than 1
                    item.Amount -= 1;
                    session.Send(ItemInventoryPacket.Update(item.Uid, item.Amount));
                    InventoryController.Add(session, newItem);

                    opened++;
                }
            }

            session.Send(ItemUsePacket.Use(boxId, amount));

            // Need to handle opening boxes, probably serialize the item xml
        }
Пример #7
0
        private void HandleEquipItem(GameSession session, PacketReader packet)
        {
            long   itemUid      = packet.ReadLong();
            string equipSlotStr = packet.ReadUnicodeString();

            if (!Enum.TryParse(equipSlotStr, out ItemSlot equipSlot))
            {
                logger.Warning("Unknown equip slot: " + equipSlotStr);
                return;
            }

            // Remove the item from the users inventory
            session.Player.Inventory.Remove(itemUid, out Item item);
            session.Send(ItemInventoryPacket.Remove(itemUid));

            // TODO: Move unequipped item into the correct slot
            // Move previously equipped item back to inventory
            if (session.Player.Equips.Remove(equipSlot, out Item prevItem))
            {
                session.Player.Inventory.Add(prevItem);
                session.Send(ItemInventoryPacket.Add(prevItem));
                session.FieldManager.BroadcastPacket(EquipmentPacket.UnequipItem(session.FieldPlayer, prevItem));
            }

            // Equip new item
            session.Player.Equips[equipSlot] = item;
            session.FieldManager.BroadcastPacket(EquipmentPacket.EquipItem(session.FieldPlayer, item, equipSlot));

            // TODO - Increase stats based on the item stats itself
            session.Player.Stats.CritRate.Max   += 12;
            session.Player.Stats.CritRate.Total += 12;

            session.Player.Stats.MinAtk.Max   += 15;
            session.Player.Stats.MinAtk.Total += 15;

            session.Player.Stats.MaxAtk.Max   += 17;
            session.Player.Stats.MaxAtk.Total += 17;

            session.Send(FieldObjectPacket.SetStats(session.FieldPlayer));
        }
        private void HandleDrop(GameSession session, PacketReader packet, Inventory inventory)
        {
            // TODO: Make sure items are tradable?
            long uid       = packet.ReadLong();
            int  amount    = packet.ReadInt();
            int  remaining = inventory.Remove(uid, out Item droppedItem, amount);

            if (remaining < 0)
            {
                return; // Removal failed
            }

            if (remaining > 0)
            {
                session.Send(ItemInventoryPacket.Update(uid, remaining));
            }
            else
            {
                session.Send(ItemInventoryPacket.Remove(uid));
            }

            session.FieldManager.AddItem(session, droppedItem);
        }
Пример #9
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();

            Inventory inventory = session.Player.Inventory;

            switch (function)
            {
            case 0: {
                break;
            }

            case 3: {     // Move
                long  uid     = packet.ReadLong();
                short dstSlot = packet.ReadShort();
                Tuple <long, short> result = inventory.Move(uid, dstSlot);
                if (result == null)
                {
                    break;
                }

                // send updated move
                session.Send(ItemInventoryPacket.Move(result.Item1, result.Item2, uid, dstSlot));
                break;
            }

            case 4: {     // Drop
                // TODO: Make sure items are tradable?
                long uid       = packet.ReadLong();
                int  amount    = packet.ReadInt();
                int  remaining = inventory.Remove(uid, out Item droppedItem, amount);
                if (remaining < 0)
                {
                    break;     // Removal failed
                }

                session.Send(remaining > 0
                        ? ItemInventoryPacket.Update(uid, remaining)
                        : ItemInventoryPacket.Remove(uid));
                session.FieldManager.AddItem(session, droppedItem);
                break;
            }

            case 5: {     // Drop Bound
                long uid = packet.ReadLong();
                if (inventory.Remove(uid, out Item droppedItem) != 0)
                {
                    break;     // Removal from inventory failed
                }

                session.Send(ItemInventoryPacket.Remove(uid));
                // Allow dropping bound items for now
                session.FieldManager.AddItem(session, droppedItem);
                break;
            }

            case 10: {     // Sort
                var tab = (InventoryTab)packet.ReadShort();
                inventory.Sort(tab);
                session.Send(ItemInventoryPacket.ResetTab(tab));
                session.Send(ItemInventoryPacket.LoadItemsToTab(tab, inventory.GetItems(tab)));
                break;
            }
            }
        }
Пример #10
0
 // Removes Item from inventory by reference
 public static void Remove(GameSession session, long uid, out Item item)
 {
     session.Player.Inventory.Remove(uid, out item);
     session.Send(ItemInventoryPacket.Remove(uid));
 }