//
// NostaleSkillsPacketApi.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 NosCore.Packets.ClientPackets.Battle;
using NosCore.Shared.Enumerations;
using NosSmooth.Core.Client;
using NosSmooth.Game.Data.Characters;
using NosSmooth.Game.Data.Entities;
using NosSmooth.Game.Errors;
using Remora.Results;
namespace NosSmooth.Game.Apis;
///
/// Packet api for using character skills.
///
public class NostaleSkillsPacketApi
{
private readonly INostaleClient _client;
///
/// Initializes a new instance of the class.
///
/// The nostale client.
public NostaleSkillsPacketApi(INostaleClient client)
{
_client = client;
}
///
/// Use the given (targetable) skill on specified entity.
///
///
/// For skills that can be used only on self, use of the character.
/// For skills that cannot be targeted on an entity, proceed to .
///
/// The id of the skill.
/// The id of the entity to use the skill on.
/// The type of the supplied entity.
/// The x coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)
/// The y coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)
/// A result that may or may not have succeeded.
public Task UseSkillOn(long skillVNum, long entityId, VisualType entityType, short? mapX = default, short? mapY = default)
{
return _client.SendPacketAsync(new UseSkillPacket
{
CastId = skillVNum,
MapX = mapX,
MapY = mapY,
TargetId = entityId,
TargetVisualType = entityType
});
}
///
/// Use the given (targetable) skill on specified entity.
///
///
/// For skills that can be used only on self, use of the character.
/// For skills that cannot be targeted on an entity, proceed to .
///
/// The id of the skill.
/// The entity to use the skill on.
/// The x coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)
/// The y coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)
/// A result that may or may not have succeeded.
public Task UseSkillOn(long skillVNum, ILivingEntity entity, short? mapX = default, short? mapY = default)
{
return _client.SendPacketAsync(new UseSkillPacket
{
CastId = skillVNum,
MapX = mapX,
MapY = mapY,
TargetId = entity.Id,
TargetVisualType = entity.Type
});
}
///
/// Use the given (targetable) skill on specified entity.
///
///
/// The skill won't be used if it is on cooldown.
/// For skills that can be used only on self, use of the character.
/// For skills that cannot be targeted on an entity, proceed to .
///
/// The skill to use.
/// The entity to use the skill on.
/// The x coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)
/// The y coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)
/// A result that may or may not have succeeded.
public Task UseSkillOn(Skill skill, ILivingEntity entity, short? mapX = default, short? mapY = default)
{
if (skill.IsOnCooldown)
{
return Task.FromResult(new SkillOnCooldownError(skill));
}
return _client.SendPacketAsync(new UseSkillPacket
{
CastId = skill.SkillVNum,
MapX = mapX,
MapY = mapY,
TargetId = entity.Id,
TargetVisualType = entity.Type
});
}
///
/// Use the given (targetable) skill on specified entity.
///
///
/// For skills that can be used only on self, use of the character.
/// For skills that cannot be targeted on an entity, proceed to .
///
/// The skill to use.
/// The id of the entity to use the skill on.
/// The type of the supplied entity.
/// The x coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)
/// The y coordinate on the map. (Used for non targeted dashes etc., says where the dash will be to.)
/// A result that may or may not have succeeded.
public Task UseSkillOn(Skill skill, long entityId, VisualType entityType, short? mapX = default, short? mapY = default)
{
if (skill.IsOnCooldown)
{
return Task.FromResult(new SkillOnCooldownError(skill));
}
return _client.SendPacketAsync(new UseSkillPacket
{
CastId = skill.SkillVNum,
MapX = mapX,
MapY = mapY,
TargetId = entityId,
TargetVisualType = entityType
});
}
///
/// Use the given (aoe) skill on the specified place.
///
///
/// For skills that can have targets, proceed to .
///
/// The id of the skill.
/// The x coordinate to use the skill at.
/// The y coordinate to use the skill at.
/// A result that may or may not have succeeded.
public Task UseSkillAt(long skillVNum, short mapX, short mapY)
{
return _client.SendPacketAsync(new UseAoeSkillPacket
{
CastId = skillVNum, MapX = mapX, MapY = mapY
});
}
///
/// Use the given (aoe) skill on the specified place.
///
///
/// For skills that can have targets, proceed to .
///
/// The skill to use.
/// The x coordinate to use the skill at.
/// The y coordinate to use the skill at.
/// A result that may or may not have succeeded.
public Task UseSkillAt(Skill skill, short mapX, short mapY)
{
if (skill.IsOnCooldown)
{
return Task.FromResult(new SkillOnCooldownError(skill));
}
return _client.SendPacketAsync(new UseAoeSkillPacket
{
CastId = skill.SkillVNum, MapX = mapX, MapY = mapY
});
}
}