From a1fbfec457a62c8a1ebd1b5903ffe1b20f527dc4 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sat, 7 Jan 2023 20:47:48 +0100 Subject: [PATCH] feat(game): add api for mates (company, stay, send back) --- .../Apis/NostaleMatePacketApi.cs | 106 ++++++++++++++++++ .../Apis/NostaleMateSkillsPacketApi.cs | 16 +++ .../Attributes/UnsafeAttribute.cs | 28 +++++ 3 files changed, 150 insertions(+) create mode 100644 Core/NosSmooth.Game/Apis/NostaleMatePacketApi.cs create mode 100644 Core/NosSmooth.Game/Apis/NostaleMateSkillsPacketApi.cs create mode 100644 Core/NosSmooth.Game/Attributes/UnsafeAttribute.cs diff --git a/Core/NosSmooth.Game/Apis/NostaleMatePacketApi.cs b/Core/NosSmooth.Game/Apis/NostaleMatePacketApi.cs new file mode 100644 index 0000000000000000000000000000000000000000..1d2eb4652e028a2d97d54938ee2e582979572558 --- /dev/null +++ b/Core/NosSmooth.Game/Apis/NostaleMatePacketApi.cs @@ -0,0 +1,106 @@ +// +// NostaleMatePacketApi.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.Attributes; +using NosSmooth.Packets.Client; +using NosSmooth.Packets.Enums.Entities; +using NosSmooth.Packets.Enums.NRun; +using Remora.Results; + +namespace NosSmooth.Game.Apis; + +/// +/// Packet api for managing mates, company, stay, sending them back. +/// +public class NostaleMatePacketApi +{ + private readonly INostaleClient _client; + + /// + /// Initializes a new instance of the class. + /// + /// The client. + public NostaleMatePacketApi(INostaleClient client) + { + _client = client; + } + + /// + /// Make the given pet your company (possible only in miniland). + /// + /// + /// May be used only in miniland. + /// + /// Unsafe, does not check whether the mate exists + /// or whether the character is in miniland. + /// + /// The id of the mate to have company. + /// The cancellation token used for cancelling the operation. + /// A result that may or may not have succeeded. + public async Task CompanyAsync(long mateId, CancellationToken ct = default) + => await _client.SendPacketAsync + ( + new NRunPacket + ( + NRunType.Mate, + (short)MateNRunType.Company, + EntityType.Npc, + mateId, + null + ), + ct + ); + + /// + /// Make the given pet stay in your miniland (possible only in miniland). + /// + /// + /// May be used only in miniland. + /// + /// Unsafe, does not check whether the mate exists + /// or whether the character is in miniland. + /// + /// The id of the mate to have company. + /// The cancellation token used for cancelling the operation. + /// A result that may or may not have succeeded. + public async Task StayAsync(long mateId, CancellationToken ct = default) + => await _client.SendPacketAsync + ( + new NRunPacket + ( + NRunType.Mate, + (short)MateNRunType.Stay, + EntityType.Npc, + mateId, + null + ), + ct + ); + + /// + /// Save the given pet back to miniland. + /// + /// + /// Unsafe, does not check whether the mate exists. + /// + /// The id of the mate to have company. + /// The cancellation token used for cancelling the operation. + /// A result that may or may not have succeeded. + public async Task SendBackAsync(long mateId, CancellationToken ct = default) + => await _client.SendPacketAsync + ( + new NRunPacket + ( + NRunType.Mate, + (short)MateNRunType.RequestPetSendBack, + EntityType.Npc, + mateId, + null + ), + ct + ); +} \ No newline at end of file diff --git a/Core/NosSmooth.Game/Apis/NostaleMateSkillsPacketApi.cs b/Core/NosSmooth.Game/Apis/NostaleMateSkillsPacketApi.cs new file mode 100644 index 0000000000000000000000000000000000000000..47c283c7d54939c3bed950f9de4a37ef22ab605c --- /dev/null +++ b/Core/NosSmooth.Game/Apis/NostaleMateSkillsPacketApi.cs @@ -0,0 +1,16 @@ +// +// NostaleMateSkillsPacketApi.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. + +namespace NosSmooth.Game.Apis; + +/// +/// Packet api for using mate skills. +/// +public class NostaleMateSkillsPacketApi +{ + // use pet skill on + // use partner skill on +} \ No newline at end of file diff --git a/Core/NosSmooth.Game/Attributes/UnsafeAttribute.cs b/Core/NosSmooth.Game/Attributes/UnsafeAttribute.cs new file mode 100644 index 0000000000000000000000000000000000000000..da05990ed0335cc641ead2e49dc822f0c9a3b4ea --- /dev/null +++ b/Core/NosSmooth.Game/Attributes/UnsafeAttribute.cs @@ -0,0 +1,28 @@ +// +// UnsafeAttribute.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. + +namespace NosSmooth.Game.Attributes; + +/// +/// The given method does not do some checks. +/// +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Struct)] +public class UnsafeAttribute : Attribute +{ + /// + /// Initializes a new instance of the class. + /// + /// The reason. + public UnsafeAttribute(string reason) + { + Reason = reason; + } + + /// + /// Gets the unsafe reason. + /// + public string Reason { get; } +} \ No newline at end of file