~ruther/NosSmooth

a1fbfec457a62c8a1ebd1b5903ffe1b20f527dc4 — Rutherther 2 years ago cc1c243
feat(game): add api for mates (company, stay, send back)
A Core/NosSmooth.Game/Apis/NostaleMatePacketApi.cs => Core/NosSmooth.Game/Apis/NostaleMatePacketApi.cs +106 -0
@@ 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;

/// <summary>
/// Packet api for managing mates, company, stay, sending them back.
/// </summary>
public class NostaleMatePacketApi
{
    private readonly INostaleClient _client;

    /// <summary>
    /// Initializes a new instance of the <see cref="NostaleMatePacketApi"/> class.
    /// </summary>
    /// <param name="client">The client.</param>
    public NostaleMatePacketApi(INostaleClient client)
    {
        _client = client;
    }

    /// <summary>
    /// Make the given pet your company (possible only in miniland).
    /// </summary>
    /// <remarks>
    /// May be used only in miniland.
    ///
    /// Unsafe, does not check whether the mate exists
    /// or whether the character is in miniland.
    /// </remarks>
    /// <param name="mateId">The id of the mate to have company.</param>
    /// <param name="ct">The cancellation token used for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> CompanyAsync(long mateId, CancellationToken ct = default)
        => await _client.SendPacketAsync
        (
            new NRunPacket
            (
                NRunType.Mate,
                (short)MateNRunType.Company,
                EntityType.Npc,
                mateId,
                null
            ),
            ct
        );

    /// <summary>
    /// Make the given pet stay in your miniland (possible only in miniland).
    /// </summary>
    /// <remarks>
    /// May be used only in miniland.
    ///
    /// Unsafe, does not check whether the mate exists
    /// or whether the character is in miniland.
    /// </remarks>
    /// <param name="mateId">The id of the mate to have company.</param>
    /// <param name="ct">The cancellation token used for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> StayAsync(long mateId, CancellationToken ct = default)
        => await _client.SendPacketAsync
        (
            new NRunPacket
            (
                NRunType.Mate,
                (short)MateNRunType.Stay,
                EntityType.Npc,
                mateId,
                null
            ),
            ct
        );

    /// <summary>
    /// Save the given pet back to miniland.
    /// </summary>
    /// <remarks>
    /// Unsafe, does not check whether the mate exists.
    /// </remarks>
    /// <param name="mateId">The id of the mate to have company.</param>
    /// <param name="ct">The cancellation token used for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> 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

A Core/NosSmooth.Game/Apis/NostaleMateSkillsPacketApi.cs => Core/NosSmooth.Game/Apis/NostaleMateSkillsPacketApi.cs +16 -0
@@ 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;

/// <summary>
/// Packet api for using mate skills.
/// </summary>
public class NostaleMateSkillsPacketApi
{
    // use pet skill on
    // use partner skill on
}
\ No newline at end of file

A Core/NosSmooth.Game/Attributes/UnsafeAttribute.cs => Core/NosSmooth.Game/Attributes/UnsafeAttribute.cs +28 -0
@@ 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;

/// <summary>
/// The given method does not do some checks.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Struct)]
public class UnsafeAttribute : Attribute
{
    /// <summary>
    /// Initializes a new instance of the <see cref="UnsafeAttribute"/> class.
    /// </summary>
    /// <param name="reason">The reason.</param>
    public UnsafeAttribute(string reason)
    {
        Reason = reason;
    }

    /// <summary>
    /// Gets the unsafe reason.
    /// </summary>
    public string Reason { get; }
}
\ No newline at end of file

Do not follow this link