예제 #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);
        }
예제 #4
0
        // Adds item
        public static void Add(GameSession session, Item item, bool isNew)
        {
            // Checks if item is stackable or not
            if (item.StackLimit > 1)
            {
                foreach (Item i in session.Player.Inventory.Items.Values)
                {
                    // Checks to see if item exists in database (dictionary)
                    if (i.Id != item.Id || i.Amount >= i.StackLimit)
                    {
                        continue;
                    }
                    // Updates inventory for item amount overflow
                    if ((i.Amount + item.Amount) > i.StackLimit)
                    {
                        int added = i.StackLimit - i.Amount;
                        item.Amount -= added;
                        i.Amount     = i.StackLimit;
                        session.Send(ItemInventoryPacket.Update(i.Uid, i.Amount));
                        session.Send(ItemInventoryPacket.MarkItemNew(i, added));
                    }
                    // Updates item amount
                    else
                    {
                        i.Amount += item.Amount;
                        session.Send(ItemInventoryPacket.Update(i.Uid, i.Amount));
                        session.Send(ItemInventoryPacket.MarkItemNew(i, item.Amount));
                        return;
                    }
                }

                session.Player.Inventory.Add(item);          // Adds item into internal database
                session.Send(ItemInventoryPacket.Add(item)); // Sends packet to add item clientside
                if (isNew)
                {
                    session.Send(ItemInventoryPacket.MarkItemNew(item, item.Amount)); // Marks Item as New
                }
            }
            else
            {
                for (int i = 0; i < item.Amount; i++)
                {
                    Item newItem = new Item(item)
                    {
                        Amount = 1,
                        Slot   = session.Player.Inventory.SlotTaken(item, item.Slot) ? -1 : item.Slot,
                        Uid    = GuidGenerator.Long()
                    };

                    session.Player.Inventory.Add(newItem);
                    session.Send(ItemInventoryPacket.Add(newItem));
                    if (isNew)
                    {
                        session.Send(ItemInventoryPacket.MarkItemNew(newItem, newItem.Amount));
                    }
                }
            }
        }
예제 #5
0
    public void Add(GameSession session, long uid, int amount, short slot)
    {
        Item item = session.Player.Inventory.Items[uid];

        if (amount < item.Amount)
        {
            item.TrySplit(amount, out Item splitItem);
            session.Send(ItemInventoryPacket.Update(uid, item.Amount));
            item = splitItem;
        }
        else
        {
            session.Player.Inventory.RemoveItem(session, uid, out Item removedItem);
            item = removedItem;
        }

        // If slot is free, add item to it
        if (Items[slot] is null)
        {
            item.Slot   = slot;
            Items[slot] = item;
            session.Send(StorageInventoryPacket.Add(item));
            return;
        }

        // Find first item with the same id, if true update the amount
        Item existingItem = Items.FirstOrDefault(x => x is not null && x.Id == item.Id && x.Rarity == item.Rarity);

        if (existingItem is not null)
        {
            if (existingItem.Amount + item.Amount <= existingItem.StackLimit)
            {
                existingItem.Amount += item.Amount;
                session.Send(StorageInventoryPacket.UpdateItem(existingItem));
                return;
            }

            existingItem.Amount = existingItem.StackLimit;
            item.Amount         = existingItem.Amount + item.Amount - existingItem.StackLimit;
            session.Send(StorageInventoryPacket.UpdateItem(existingItem));
        }

        // Find first free slot
        for (short i = 0; i < Items.Length; i++)
        {
            if (Items[i] is not null)
            {
                continue;
            }

            item.Slot = i;
            Items[i]  = item;
            session.Send(StorageInventoryPacket.Add(item));
            return;
        }
    }
예제 #6
0
 // Updates item information
 public static void Update(GameSession session, long uid, int amount)
 {
     if ((GetItemAmount(session, uid) + amount) >= GetItemMax(session, uid))
     {
         session.Player.Inventory.Items[uid].Amount = session.Player.Inventory.Items[uid].SlotMax;
         session.Send(ItemInventoryPacket.Update(uid, session.Player.Inventory.Items[uid].SlotMax));
     }
     session.Player.Inventory.Items[uid].Amount = amount;
     session.Send(ItemInventoryPacket.Update(uid, amount));
 }
        // Updates item information
        public static void Update(GameSession session, long uid, int amount)
        {
            Item item = session.Player.Inventory.Items[uid];

            if ((item.Amount + amount) >= item.StackLimit)
            {
                item.Amount = item.StackLimit;
            }
            else
            {
                item.Amount = amount;
            }
            session.Send(ItemInventoryPacket.Update(uid, amount));
        }
예제 #8
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
        }
예제 #9
0
        public void Add(GameSession session, long uid, int amount, short slot)
        {
            Item item = session.Player.Inventory.Items[uid];

            if (amount < item.Amount)
            {
                item.TrySplit(amount, out Item splitItem);
                session.Send(ItemInventoryPacket.Update(uid, item.Amount));
                item = splitItem;
            }
            else
            {
                InventoryController.Remove(session, uid, out Item removedItem);
                item = removedItem;
            }

            if (slot >= 0)
            {
                if (Items[slot] == null)
                {
                    item.Slot   = slot;
                    Items[slot] = item;
                    session.Send(StorageInventoryPacket.Add(item));
                    return;
                }
                else
                {
                    slot = -1;
                }
            }

            if (slot == -1)
            {
                for (slot = 0; slot < Items.Length; slot++)
                {
                    if (Items[slot] != null)
                    {
                        continue;
                    }
                    item.Slot   = slot;
                    Items[slot] = item;
                    session.Send(StorageInventoryPacket.Add(item));
                    return;
                }
            }
        }
예제 #10
0
    private static void HandleCreateListing(GameSession session, PacketReader packet)
    {
        long itemUid  = packet.ReadLong();
        long price    = packet.ReadLong();
        int  quantity = packet.ReadInt();

        if (!session.Player.Inventory.Items.ContainsKey(itemUid))
        {
            session.Send(BlackMarketPacket.Error((int)BlackMarketError.ItemNotInInventory));
            return;
        }

        double depositRate = 0.01; // 1% deposit rate
        int    maxDeposit  = 100000;

        int calculatedDeposit = (int)(depositRate * (price * quantity));
        int deposit           = Math.Min(calculatedDeposit, maxDeposit);

        if (!session.Player.Wallet.Meso.Modify(-deposit))
        {
            return;
        }

        Item item = session.Player.Inventory.Items[itemUid];

        if (item.Amount < quantity)
        {
            return;
        }

        if (item.Amount > quantity)
        {
            item.TrySplit(quantity, out Item newStack);
            session.Send(ItemInventoryPacket.Update(item.Uid, item.Amount));
            item = newStack;
        }
        else
        {
            session.Player.Inventory.ConsumeItem(session, item.Uid, quantity);
        }

        BlackMarketListing listing = new(session.Player, item, quantity, price, deposit);

        session.Send(BlackMarketPacket.CreateListing(listing));
    }
예제 #11
0
        // Removes item based on quantity
        public static void Consume(GameSession session, long uid, int amount)
        {
            Item item = session.Player.Inventory.Items[uid];

            if (amount > item.Amount)
            {
                return;
            }
            if (amount == item.Amount)
            {
                Remove(session, uid, out Item _);
                return;
            }

            item.Amount -= amount;
            session.Send(ItemInventoryPacket.Update(uid, item.Amount));
            return;
        }
예제 #12
0
 // Adds item
 public static void Add(GameSession session, Item item, bool isNew)
 {
     // Checks if item is stackable or not
     if (item.SlotMax > 1)
     {
         foreach (Item i in session.Player.Inventory.Items.Values)
         {
             // Checks to see if item exists in database (dictionary)
             if (i.Id != item.Id || i.Amount >= i.SlotMax)
             {
                 continue;
             }
             // Updates inventory for item amount overflow
             if ((i.Amount + item.Amount) > i.SlotMax)
             {
                 int added = i.SlotMax - i.Amount;
                 item.Amount -= added;
                 i.Amount     = i.SlotMax;
                 session.Send(ItemInventoryPacket.Update(i.Uid, i.Amount));
                 session.Send(ItemInventoryPacket.MarkItemNew(i, added));
             }
             // Updates item amount
             else
             {
                 i.Amount += item.Amount;
                 session.Send(ItemInventoryPacket.Update(i.Uid, i.Amount));
                 session.Send(ItemInventoryPacket.MarkItemNew(i, item.Amount));
                 return;
             }
         }
     }
     session.Player.Inventory.Add(item);          // Adds item into internal database
     session.Send(ItemInventoryPacket.Add(item)); // Sends packet to add item clientside
     if (isNew)
     {
         session.Send(ItemInventoryPacket.MarkItemNew(item, item.Amount)); // Marks Item as New
     }
 }
        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);
        }
    public static void Add(GameSession session, Item item)
    {
        // Checks if item is stackable or not
        if (item.SlotMax > 1)
        {
            foreach (Item i in session.Player.Inventory.Items.Values)
            {
                // Continue if inventory item id doesn't match or it is at max amount
                if (i.Id != item.Id || i.Amount >= i.SlotMax)
                {
                    continue;
                }
                // Updates inventory for item amount overflow
                if ((i.Amount + item.Amount) > i.SlotMax)
                {
                    int added = i.SlotMax - i.Amount; // For marking item new with correct added amount

                    item.Amount = item.Amount - (i.SlotMax - i.Amount);
                    i.Amount    = i.SlotMax;
                    session.Send(ItemInventoryPacket.Update(i.Uid, i.Amount));
                    session.Send(ItemInventoryPacket.MarkItemNew(i, added));
                }
                // Updates item amount
                else
                {
                    i.Amount = i.Amount + item.Amount;
                    session.Send(ItemInventoryPacket.Update(i.Uid, i.Amount));
                    session.Send(ItemInventoryPacket.MarkItemNew(i, item.Amount));
                    return;
                }
            }
        }
        // Add item to inventory if cannot stack any further
        session.Player.Inventory.Add(item);
        session.Send(ItemInventoryPacket.Add(item));
        session.Send(ItemInventoryPacket.MarkItemNew(item, item.Amount));
    }
예제 #15
0
        // Adds item
        public static void Add(GameSession session, Item item, bool isNew)
        {
            // item is currency
            if (item.Id.ToString().StartsWith("9"))
            {
                switch (item.Id)
                {
                case 90000001:     // Meso
                    session.Player.Wallet.Meso.Modify(item.Amount);
                    break;

                case 90000006:     // Valor Token
                    session.Player.Wallet.ValorToken.Modify(item.Amount);
                    break;

                case 90000004:     // Meret
                case 90000011:     // Meret
                case 90000015:     // Meret
                case 90000016:     // Meret
                    session.Player.Account.Meret.Modify(item.Amount);
                    break;

                case 90000013:     // Rue
                    session.Player.Wallet.Rue.Modify(item.Amount);
                    break;

                case 90000014:     // Havi
                    session.Player.Wallet.HaviFruit.Modify(item.Amount);
                    break;

                case 90000017:     // Treva
                    session.Player.Wallet.Treva.Modify(item.Amount);
                    break;

                case 90000021:     // Guild Funds
                    if (session.Player.Guild != null)
                    {
                        session.Player.Guild.Funds += item.Amount;
                        session.Player.Guild.BroadcastPacketGuild(GuildPacket.UpdateGuildFunds(session.Player.Guild.Funds));
                        DatabaseManager.Guilds.Update(session.Player.Guild);
                    }
                    break;
                }
                return;
            }
            // TODO: Find a way to categorize items appropriately
            else if (item.Id.ToString().StartsWith("501") ||
                     item.Id.ToString().StartsWith("502") ||
                     item.Id.ToString().StartsWith("503") ||
                     item.Id.ToString().StartsWith("504") ||
                     item.Id.ToString().StartsWith("505"))
            {
                if (session.Player.Account.Home == null)
                {
                    return;
                }

                Home home = GameServer.HomeManager.GetHomeById(session.Player.Account.Home.Id);
                if (home == null)
                {
                    return;
                }

                _ = home.AddWarehouseItem(session, item.Id, item.Amount, item);
                session.Send(WarehouseInventoryPacket.GainItemMessage(item, item.Amount));
                return;
            }

            // Checks if item is stackable or not
            if (item.StackLimit > 1)
            {
                foreach (Item i in session.Player.Inventory.Items.Values)
                {
                    // Checks to see if item exists in database (dictionary)
                    if (i.Id != item.Id || i.Amount >= i.StackLimit || i.Rarity != item.Rarity)
                    {
                        continue;
                    }
                    // Updates inventory for item amount overflow
                    if ((i.Amount + item.Amount) > i.StackLimit)
                    {
                        int added = i.StackLimit - i.Amount;
                        item.Amount -= added;
                        i.Amount     = i.StackLimit;
                        session.Send(ItemInventoryPacket.Update(i.Uid, i.Amount));
                        session.Send(ItemInventoryPacket.MarkItemNew(i, added));
                    }
                    // Updates item amount
                    else
                    {
                        i.Amount += item.Amount;
                        session.Send(ItemInventoryPacket.Update(i.Uid, i.Amount));
                        session.Send(ItemInventoryPacket.MarkItemNew(i, item.Amount));
                        return;
                    }
                }

                if (!session.Player.Inventory.Add(item)) // Adds item into internal database
                {
                    return;
                }
                session.Send(ItemInventoryPacket.Add(item)); // Sends packet to add item clientside
                if (isNew)
                {
                    session.Send(ItemInventoryPacket.MarkItemNew(item, item.Amount)); // Marks Item as New
                }
                return;
            }

            if (item.Amount == 1)
            {
                if (!session.Player.Inventory.Add(item))
                {
                    return;
                }

                session.Send(ItemInventoryPacket.Add(item));
                if (isNew)
                {
                    session.Send(ItemInventoryPacket.MarkItemNew(item, item.Amount));
                }
                return;
            }

            for (int i = 0; i < item.Amount; i++)
            {
                Item newItem = new Item(item)
                {
                    Amount = 1,
                    Uid    = 0
                };
                newItem.Uid = DatabaseManager.Items.Insert(newItem);

                if (!session.Player.Inventory.Add(newItem))
                {
                    continue;
                }

                session.Send(ItemInventoryPacket.Add(newItem));
                if (isNew)
                {
                    session.Send(ItemInventoryPacket.MarkItemNew(newItem, newItem.Amount));
                }
            }
        }
예제 #16
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;
            }
            }
        }