From 829e95c9afae2ffe37ed710f4a45e080f0e196c0 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Fri, 20 Jan 2023 19:11:52 +0100 Subject: [PATCH] feat(game): make sure skill cooldown reset is interpreted correctly when sent before "su" --- Core/NosSmooth.Game/Data/Characters/Skill.cs | 12 ++++- .../Entities/SkillUsedResponder.cs | 51 +++++++++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/Core/NosSmooth.Game/Data/Characters/Skill.cs b/Core/NosSmooth.Game/Data/Characters/Skill.cs index a9a55c5..4e28d86 100644 --- a/Core/NosSmooth.Game/Data/Characters/Skill.cs +++ b/Core/NosSmooth.Game/Data/Characters/Skill.cs @@ -17,10 +17,15 @@ namespace NosSmooth.Game.Data.Characters; public record Skill(int SkillVNum, int? Level = default, ISkillInfo? Info = default) { /// - /// Gets the last time this skill was used. + /// Gets the last time this skill was used. (su received). /// public DateTimeOffset LastUseTime { get; internal set; } + /// + /// Gets the last time this skill was requested to be used. (u_s sent). + /// + public DateTimeOffset? LastUseRequestTime { get; internal set; } + /// /// Gets whether the skill is on cooldown. /// @@ -29,4 +34,9 @@ public record Skill(int SkillVNum, int? Level = default, ISkillInfo? Info = defa /// prefer to use this instead of checking the LastUseTime and Cooldown. /// public bool IsOnCooldown { get; internal set; } + + /// + /// Gets the last time the cooldown was reset. + /// + public DateTimeOffset? LastCooldownReset { get; internal set; } } \ No newline at end of file diff --git a/Core/NosSmooth.Game/PacketHandlers/Entities/SkillUsedResponder.cs b/Core/NosSmooth.Game/PacketHandlers/Entities/SkillUsedResponder.cs index 15b2e22..98daad3 100644 --- a/Core/NosSmooth.Game/PacketHandlers/Entities/SkillUsedResponder.cs +++ b/Core/NosSmooth.Game/PacketHandlers/Entities/SkillUsedResponder.cs @@ -17,6 +17,7 @@ using NosSmooth.Game.Events.Core; using NosSmooth.Game.Events.Entities; using NosSmooth.Game.Extensions; using NosSmooth.Game.Helpers; +using NosSmooth.Packets.Client.Battle; using NosSmooth.Packets.Enums.Entities; using NosSmooth.Packets.Server.Battle; using NosSmooth.Packets.Server.Skills; @@ -27,7 +28,7 @@ namespace NosSmooth.Game.PacketHandlers.Entities; /// /// Responds to skill used packet. /// -public class SkillUsedResponder : IPacketResponder, IPacketResponder +public class SkillUsedResponder : IPacketResponder, IPacketResponder, IPacketResponder, IPacketResponder { private readonly Game _game; private readonly EventDispatcher _eventDispatcher; @@ -93,14 +94,19 @@ public class SkillUsedResponder : IPacketResponder, IPacketResponder skillEntity.LastCooldownReset) + { + skillEntity.IsOnCooldown = true; + } } else { @@ -179,6 +185,7 @@ public class SkillUsedResponder : IPacketResponder, IPacketResponder, IPacketResponder + public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default) + { + var packet = packetArgs.Packet; + + var skills = _game.Skills; + if (skills is not null) + { + var skillResult = skills.TryGetSkillByCastId((short)packet.SkillId); + + if (skillResult.IsDefined(out var skillEntity)) + { + skillEntity.LastUseRequestTime = DateTime.Now; + } + } + + return Task.FromResult(Result.FromSuccess()); + } + + /// + public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default) + { + var packet = packetArgs.Packet; + + var skills = _game.Skills; + if (skills is not null) + { + var skillResult = skills.TryGetSkillByCastId(packet.CastId); + + if (skillResult.IsDefined(out var skillEntity)) + { + skillEntity.LastUseRequestTime = DateTime.Now; + } + } + + return Task.FromResult(Result.FromSuccess()); + } } \ No newline at end of file -- 2.49.0