Beispiel #1
0
        protected override async Task Handle(InventoryDestroyItemEvent e, CancellationToken cancellation)
        {
            if (!(e.Sender is IPlayerEntity player))
            {
                return;
            }

            InventoryComponent inv = player.Inventory;

            ItemInstanceDto[] subinv = inv.GetSubInvFromItemInstance(e.ItemInstance);

            subinv[e.ItemInstance.Slot] = null;
            await player.ActualizeUiInventorySlot(e.ItemInstance.Type, e.ItemInstance.Slot);

            await player.SendChatMessageAsync("ITEM_DESTROYED", SayColorType.Yellow);
        }
Beispiel #2
0
        public static async Task MoveItem(this InventoryComponent inv, ItemInstanceDto source, InventoryMoveEvent args)
        {
            ItemInstanceDto[] subInv = inv.GetSubInvFromItemInstance(source);
            subInv[args.DestinationSlot] = source;
            subInv[args.SourceSlot]      = null;

            source.Slot = args.DestinationSlot;
            if (!(inv.Entity is IPlayerEntity player))
            {
                return;
            }

            await player.SendPacketAsync(player.GenerateEmptyIvnPacket(args.InventoryType, args.SourceSlot));

            await player.SendPacketAsync(source.GenerateIvnPacket());
        }
Beispiel #3
0
        public static async Task MoveItems(this InventoryComponent inv, ItemInstanceDto source, ItemInstanceDto dest)
        {
            ItemInstanceDto[] subInv = inv.GetSubInvFromItemInstance(source);
            subInv[dest.Slot]   = source;
            subInv[source.Slot] = dest;

            short tmp = dest.Slot;

            dest.Slot   = source.Slot;
            source.Slot = tmp;

            if (!(inv.Entity is IPlayerEntity player))
            {
                return;
            }

            await player.SendPacketAsync(source.GenerateIvnPacket());

            await player.SendPacketAsync(dest.GenerateIvnPacket());
        }
Beispiel #4
0
        protected override async Task Handle(InventoryAddItemEvent e, CancellationToken cancellation)
        {
            if (!(e.Sender is IInventoriedEntity inventoried))
            {
                return;
            }

            InventoryComponent inv = inventoried.Inventory;

            ItemInstanceDto[] subinv = inv.GetSubInvFromItemInstance(e.ItemInstance);

            short slot = inv.GetFirstFreeSlot(subinv, e.ItemInstance);

            if (slot == -1)
            {
                Log.Info("No available slot");
                //Not enough space
                return;
            }

            ItemInstanceDto mergeable = subinv[slot];

            if (mergeable != null)
            {
                mergeable.Amount += e.ItemInstance.Amount;
                e.ItemInstance    = mergeable;
            }
            else
            {
                e.ItemInstance.Slot = slot;
                subinv[slot]        = e.ItemInstance;
            }

            if (!(inv.Entity is IPlayerEntity player))
            {
                return;
            }

            e.ItemInstance.CharacterId = player.Character.Id;
            await player.ActualizeUiInventorySlot(e.ItemInstance.Type, e.ItemInstance.Slot);
        }