// // NostaleInventoryPacketApi.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using NosSmooth.Core.Client; using NosSmooth.Packets.Client.Inventory; using NosSmooth.Packets.Enums.Inventory; using Remora.Results; namespace NosSmooth.Game.Apis; /// /// Packet api for managing items in inventory. /// public class NostaleInventoryPacketApi { private readonly INostaleClient _client; /// /// Initializes a new instance of the class. /// /// The nostale client. public NostaleInventoryPacketApi(INostaleClient client) { _client = client; } /// /// Drop the given item. /// /// The bag where the item is located. /// The slot the item is at. /// The amount to drop. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. public Task DropItemAsync ( BagType bag, short slot, short amount, CancellationToken ct = default ) => _client.SendPacketAsync(new PutPacket(bag, slot, amount), ct); /// /// Move the given item within one bag. /// /// The bag the item is in. /// The source slot to move the item from. /// The destination slot to move the item to. /// The amount to move. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. public Task MoveItemAsync ( BagType bag, short sourceSlot, short destinationSlot, short amount, CancellationToken ct = default ) => MoveItemAsync ( bag, sourceSlot, bag, destinationSlot, amount, ct ); /// /// Move an item from the given source bag and slot to the given destination bag and slot. /// /// The bag the item is in. /// The source slot to move the item from. /// The destination bag to move the item to. /// The destination slot to move the item to. /// The amount to move. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. public Task MoveItemAsync ( BagType sourceBag, short sourceSlot, BagType destinationBag, short destinationSlot, short amount, CancellationToken ct = default ) { if (sourceBag == destinationBag) { return _client.SendPacketAsync(new MviPacket(sourceBag, sourceSlot, amount, destinationSlot), ct); } return _client.SendPacketAsync(new MvePacket(sourceBag, sourceSlot, destinationBag, destinationSlot), ct); } }