From bda9e1c8c25fc3d4b082e47200fb7d9aafb8acbd Mon Sep 17 00:00:00 2001 From: Rutherther Date: Fri, 20 Jan 2023 15:46:50 +0100 Subject: [PATCH] fix(game): using dash on character produced an error --- .../Apis/Safe/NostaleSkillsApi.cs | 50 ++++++++++++++++--- Core/NosSmooth.Game/NosSmooth.Game.csproj | 4 +- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/Core/NosSmooth.Game/Apis/Safe/NostaleSkillsApi.cs b/Core/NosSmooth.Game/Apis/Safe/NostaleSkillsApi.cs index 6f24b19..ea6a2af 100644 --- a/Core/NosSmooth.Game/Apis/Safe/NostaleSkillsApi.cs +++ b/Core/NosSmooth.Game/Apis/Safe/NostaleSkillsApi.cs @@ -45,11 +45,15 @@ public class NostaleSkillsApi /// Use the given (targetable) skill on character himself. /// /// The skill to use. + /// 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.) /// The cancellation token for cancelling the operation. /// A result that may or may not have succeeded. public Task UseSkillOnCharacter ( Skill skill, + short? mapX = default, + short? mapY = default, CancellationToken ct = default ) { @@ -85,11 +89,39 @@ public class NostaleSkillsApi return Task.FromResult(new WrongSkillTypeError(SkillType.Player, skill.Info.SkillType)); } - if (skill.Info.AttackType == AttackType.Dash) + if (skill.Info.AttackType == AttackType.Dash && (mapX is null || mapY is null)) + { + return Task.FromResult(new WrongSkillPositionError(skill.Info.AttackType)); + } + if (skill.Info.AttackType != AttackType.Dash && (mapX is not null || mapY is not null)) { return Task.FromResult(new WrongSkillPositionError(skill.Info.AttackType)); } + var characterPosition = _game.Character?.Position; + if (characterPosition is null) + { + return Task.FromResult(new NotInitializedError("character position")); + } + + if (mapX != null && mapY != null) + { + var mapPosition = new Position(mapX.Value, mapY.Value); + if (!mapPosition.IsInRange(characterPosition.Value, skill.Info.Range)) + { + return Task.FromResult + ( + new NotInRangeError + ( + "Character", + characterPosition.Value, + mapPosition, + skill.Info.Range + ) + ); + } + } + return _client.SendPacketAsync ( new UseSkillPacket @@ -97,8 +129,8 @@ public class NostaleSkillsApi skill.Info.CastId, character.Type, character.Id, - null, - null + mapX, + mapY ), ct ); @@ -129,7 +161,7 @@ public class NostaleSkillsApi { if (entity == _game.Character) { - return UseSkillOnCharacter(skill, ct); + return UseSkillOnCharacter(skill, mapX, mapY, ct); } var skills = _game.Skills; @@ -162,7 +194,7 @@ public class NostaleSkillsApi { return Task.FromResult(new WrongSkillPositionError(skill.Info.AttackType)); } - else if (skill.Info.AttackType != AttackType.Dash && (mapX is not null || mapY is not null)) + if (skill.Info.AttackType != AttackType.Dash && (mapX is not null || mapY is not null)) { return Task.FromResult(new WrongSkillPositionError(skill.Info.AttackType)); } @@ -346,10 +378,14 @@ public class NostaleSkillsApi /// Creates a contract for using a skill on character himself. /// /// The skill to use. + /// The x coordinate to use the skill at. + /// The y coordinate to use the skill at. /// The contract or an error. public Result> ContractUseSkillOnCharacter ( - Skill skill + Skill skill, + short? mapX = default, + short? mapY = default ) { var characterId = _game?.Character?.Id; @@ -368,6 +404,8 @@ public class NostaleSkillsApi ct => UseSkillOnCharacter ( skill, + mapX, + mapY, ct ) ) diff --git a/Core/NosSmooth.Game/NosSmooth.Game.csproj b/Core/NosSmooth.Game/NosSmooth.Game.csproj index 9e1a6a5..c2691e7 100644 --- a/Core/NosSmooth.Game/NosSmooth.Game.csproj +++ b/Core/NosSmooth.Game/NosSmooth.Game.csproj @@ -8,8 +8,8 @@ NosSmooth Game library handling the current game state by responding to packets. https://github.com/Rutherther/NosSmooth/ MIT - 2.4.0 - Add safe checks for skill attack type + 2.4.1 + Fix using dash on character itself. -- 2.49.0