private void HandleEquipItem(GameSession session, PacketReader packet)
        {
            long itemUid = packet.ReadLong();

            // Remove from inventory
            bool success = InventoryController.Remove(session, itemUid, out Item item);

            if (!success)
            {
                return;
            }

            // Unequip existing item in slot
            int index = session.Player.Badges.FindIndex(i => i.GemSlot == item.GemSlot);

            if (index >= 0)
            {
                // Add to inventory
                InventoryController.Add(session, session.Player.Badges[index], false);

                // Unequip
                session.Player.Badges.RemoveAt(index);
                session.FieldManager.BroadcastPacket(GemPacket.UnequipItem(session, (byte)item.GemSlot));
            }

            // Equip
            session.Player.Badges.Add(item);
            session.FieldManager.BroadcastPacket(GemPacket.EquipItem(session, item));
        }
Exemple #2
0
        private static void HandleUnequipItem(GameSession session, PacketReader packet)
        {
            byte index = packet.ReadByte();

            List <Item> badges = session.Player.Inventory.Badges;

            if (badges.Count < index + 1)
            {
                return;
            }

            Item item = badges[index];

            // Add to inventory
            item.IsEquipped = false;
            InventoryController.Add(session, item, false);

            // Unequip
            bool removed = badges.Remove(item);

            if (removed)
            {
                session.FieldManager.BroadcastPacket(GemPacket.UnequipItem(session, (byte)item.GemSlot));
            }
        }
Exemple #3
0
    private static void HandleUnequipItem(GameSession session, PacketReader packet)
    {
        byte index = packet.ReadByte();

        Item[] badges = session.Player.Inventory.Badges;

        Item item = badges[index];

        if (item == null)
        {
            return;
        }
        // Add to inventory
        item.IsEquipped = false;
        session.Player.Inventory.AddItem(session, item, false);

        // Unequip
        badges[index] = default;
        session.FieldManager.BroadcastPacket(GemPacket.UnequipItem(session, item.GemSlot));
    }
Exemple #4
0
    private static void HandleEquipItem(GameSession session, PacketReader packet)
    {
        long itemUid = packet.ReadLong();

        // Remove from inventory
        bool success = session.Player.Inventory.RemoveItem(session, itemUid, out Item item);

        if (!success)
        {
            return;
        }

        // Unequip existing item in slot
        Item[] badges = session.Player.Inventory.Badges;
        int    index  = Array.FindIndex(badges, x => x != null && x.GemSlot == item.GemSlot);

        if (index >= 0)
        {
            // Add to inventory
            badges[index].IsEquipped = false;
            session.Player.Inventory.AddItem(session, badges[index], false);

            // Unequip
            badges[index] = default;
            session.FieldManager.BroadcastPacket(GemPacket.UnequipItem(session, item.GemSlot));
        }

        // Equip
        item.IsEquipped = true;
        int emptyIndex = Array.FindIndex(badges, x => x == default);

        if (emptyIndex == -1)
        {
            return;
        }
        badges[emptyIndex] = item;
        session.FieldManager.BroadcastPacket(GemPacket.EquipItem(session, item, emptyIndex));
    }