// // UnsafeMapApi.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.Game.Errors; using NosSmooth.Packets.Client.Inventory; using NosSmooth.Packets.Client.Movement; using NosSmooth.Packets.Enums.Entities; using Remora.Results; namespace NosSmooth.Game.Apis.Unsafe; /// /// Packet api for managing maps in inventory. /// public class UnsafeMapApi { private readonly Game _game; private readonly INostaleClient _client; /// /// Initializes a new instance of the class. /// /// The game. /// The client. public UnsafeMapApi(Game game, INostaleClient client) { _game = game; _client = client; } /// /// Use the given portal. /// /// The cancellation token for cancelling the operation. /// A result that may or may not have succeeded. public Task UsePortalAsync(CancellationToken ct = default) => _client.SendPacketAsync(new PreqPacket(), ct); /// /// Pick up the given item by character. /// /// /// Unsafe, does not check anything. /// /// The id of the item. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. public async Task CharacterPickUpAsync(long itemId, CancellationToken ct = default) { var character = _game.Character; if (character is null) { return new NotInitializedError("Character"); } return await _client.SendPacketAsync(new GetPacket(EntityType.Player, character.Id, itemId), ct); } /// /// Pick up the given item by pet. /// /// /// Unsafe, does not check anything. /// /// The id of the item. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. public async Task PetPickUpAsync(long itemId, CancellationToken ct = default) { var mates = _game.Mates; if (mates is null) { return new NotInitializedError("Game.Mates"); } var pet = mates.CurrentPet; if (pet is null) { return new NotInitializedError("Game.Mates.CurrentPet"); } return await _client.SendPacketAsync(new GetPacket(EntityType.Player, pet.Pet.MateId, itemId), ct); } }