protected override async Task Handle(InventoryMoveEvent args, CancellationToken cancellation)
        {
            if (!(args.Sender is IPlayerEntity player))
            {
                return;
            }
            InventoryComponent inv = player.Inventory;

            ItemInstanceDto source = inv.GetSubInvFromInventoryType(args.InventoryType)[args.SourceSlot];
            ItemInstanceDto dest   = inv.GetSubInvFromInventoryType(args.InventoryType)[args.DestinationSlot];

            if (source == null)
            {
                return;
            }

            if (dest != null && (args.InventoryType == InventoryType.Main || args.InventoryType == InventoryType.Etc) && dest.ItemId == source.ItemId &&
                dest.Amount + source.Amount > _gameConfiguration.Inventory.MaxItemPerSlot)
            {
                // if both source & dest are stackable && slots combined are > max slots
                // should provide a "fill" possibility
                return;
            }

            if (dest == null)
            {
                await inv.MoveItem(source, args);
            }
            else
            {
                await inv.MoveItems(source, dest);
            }
        }
Example #2
0
        protected override async Task Handle(InventoryEqInfoEvent eqInfo, CancellationToken cancellation)
        {
            if (!(eqInfo.Sender is IPlayerEntity playerEntity))
            {
                return;
            }

            InventoryComponent inventory = playerEntity.Inventory;

            ItemInstanceDto[] subInv;
            ItemInstanceDto   itemInstance = null;

            switch (eqInfo.Type)
            {
            case 0:
                subInv = inventory.GetSubInvFromInventoryType(InventoryType.Wear);
                if (eqInfo.Slot > subInv.Length)
                {
                    return;
                }

                itemInstance = subInv[eqInfo.Slot];
                break;

            case 1:
                subInv = inventory.GetSubInvFromInventoryType(InventoryType.Equipment);
                if (eqInfo.Slot > subInv.Length)
                {
                    return;
                }

                itemInstance = subInv[eqInfo.Slot];
                break;

            case 7:
            case 10:
                subInv = inventory.GetSubInvFromInventoryType(InventoryType.Specialist);
                if (eqInfo.Slot > subInv.Length)
                {
                    return;
                }

                itemInstance = subInv[eqInfo.Slot];
                break;

            case 11:
                subInv = inventory.GetSubInvFromInventoryType(InventoryType.Costume);
                if (eqInfo.Slot > subInv.Length)
                {
                    return;
                }

                break;
            }

            if (itemInstance == null)
            {
                return;
            }

            if (itemInstance.Item.ItemType == ItemType.Specialist)
            {
                await playerEntity.SendPacketAsync(itemInstance.GenerateSlInfoPacket());

                return;
            }

            await playerEntity.SendPacketAsync(itemInstance.GenerateEInfoPacket());
        }
Example #3
0
 public static ItemInstanceDto GetItemFromSlotAndType(this InventoryComponent inventory, short itemSlot, InventoryType equipment)
 {
     ItemInstanceDto[] subInv = inventory.GetSubInvFromInventoryType(equipment);
     return(itemSlot >= subInv.Length ? null : subInv[itemSlot]);
 }