-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AbilityMassUp and AbilityUp request handlers (excluding maxhp and…
… maxmp handling)
- Loading branch information
Showing
6 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...common/Edelstein.Common.Gameplay.Game/Handling/Packets/UserAbilityMassUpRequestHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Edelstein.Common.Gameplay.Handling; | ||
using Edelstein.Protocol.Gameplay.Game.Contracts; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.User; | ||
using Edelstein.Protocol.Gameplay.Models.Characters.Stats.Modify; | ||
using Edelstein.Protocol.Utilities.Packets; | ||
using Edelstein.Protocol.Utilities.Pipelines; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Handling.Packets; | ||
|
||
public class UserAbilityMassUpRequestHandler : AbstractPipedFieldHandler<FieldOnPacketUserAbilityMassUpRequest> | ||
{ | ||
public override short Operation => (short)PacketRecvOperations.UserAbilityMassUpRequest; | ||
|
||
public UserAbilityMassUpRequestHandler(IPipeline<FieldOnPacketUserAbilityMassUpRequest> pipeline) : base(pipeline) | ||
{ | ||
} | ||
|
||
protected override FieldOnPacketUserAbilityMassUpRequest? Serialize(IFieldUser user, IPacketReader reader) | ||
{ | ||
var count = reader.Skip(4).ReadInt(); | ||
var statUp = new Dictionary<ModifyStatType, int>(); | ||
|
||
for (var i = 0; i < count; i++) | ||
statUp.Add( | ||
(ModifyStatType)reader.ReadInt(), | ||
reader.ReadInt() | ||
); | ||
|
||
return new( | ||
user, | ||
statUp | ||
); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/common/Edelstein.Common.Gameplay.Game/Handling/Packets/UserAbilityUpRequestHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Edelstein.Common.Gameplay.Handling; | ||
using Edelstein.Protocol.Gameplay.Game.Contracts; | ||
using Edelstein.Protocol.Gameplay.Game.Objects.User; | ||
using Edelstein.Protocol.Gameplay.Models.Characters.Stats.Modify; | ||
using Edelstein.Protocol.Utilities.Packets; | ||
using Edelstein.Protocol.Utilities.Pipelines; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Handling.Packets; | ||
|
||
public class UserAbilityUpRequestHandler : AbstractPipedFieldHandler<FieldOnPacketUserAbilityUpRequest> | ||
{ | ||
public override short Operation => (short)PacketRecvOperations.UserAbilityUpRequest; | ||
|
||
public UserAbilityUpRequestHandler(IPipeline<FieldOnPacketUserAbilityUpRequest> pipeline) : base(pipeline) | ||
{ | ||
} | ||
|
||
protected override FieldOnPacketUserAbilityUpRequest? Serialize(IFieldUser user, IPacketReader reader) | ||
=> new( | ||
user, | ||
(ModifyStatType)reader.Skip(4).ReadInt() | ||
); | ||
} |
68 changes: 68 additions & 0 deletions
68
...delstein.Common.Gameplay.Game/Handling/Plugs/FieldOnPacketUserAbilityMassUpRequestPlug.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Edelstein.Common.Gameplay.Models.Characters.Stats.Modify; | ||
using Edelstein.Protocol.Gameplay.Game.Contracts; | ||
using Edelstein.Protocol.Gameplay.Models.Characters.Stats.Modify; | ||
using Edelstein.Protocol.Utilities.Pipelines; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Handling.Plugs; | ||
|
||
public class FieldOnPacketUserAbilityMassUpRequestPlug : IPipelinePlug<FieldOnPacketUserAbilityMassUpRequest> | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public FieldOnPacketUserAbilityMassUpRequestPlug(ILogger<FieldOnPacketUserAbilityMassUpRequestPlug> logger) | ||
=> _logger = logger; | ||
|
||
public async Task Handle(IPipelineContext ctx, FieldOnPacketUserAbilityMassUpRequest message) | ||
{ | ||
var stats = new ModifyStatContext(message.User.Character); | ||
|
||
foreach (var pair in message.StatUp) | ||
{ | ||
try | ||
{ | ||
HandleStatUp(stats, pair.Key, pair.Value); | ||
} | ||
catch (ArgumentOutOfRangeException) | ||
{ | ||
_logger.LogWarning("Unhandled ability up stat type {Type}", pair.Key); | ||
} | ||
} | ||
|
||
await message.User.ModifyStats(stats, exclRequest: true); | ||
} | ||
|
||
public static void HandleStatUp(ModifyStatContext stats, ModifyStatType type, int value = 1) | ||
{ | ||
switch (type) | ||
{ | ||
case ModifyStatType.STR: | ||
if (stats.STR + value > short.MaxValue) | ||
return; | ||
stats.STR += (short)value; | ||
break; | ||
case ModifyStatType.DEX: | ||
if (stats.DEX + value > short.MaxValue) | ||
return; | ||
stats.DEX += (short)value; | ||
break; | ||
case ModifyStatType.INT: | ||
if (stats.INT + value > short.MaxValue) | ||
return; | ||
stats.INT += (short)value; | ||
break; | ||
case ModifyStatType.LUK: | ||
if (stats.LUK + value > short.MaxValue) | ||
return; | ||
stats.LUK += (short)value; | ||
break; | ||
case ModifyStatType.MaxHP: | ||
case ModifyStatType.MaxMP: | ||
// TODO | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(type), type, null); | ||
} | ||
|
||
stats.AP -= (short)value; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...on/Edelstein.Common.Gameplay.Game/Handling/Plugs/FieldOnPacketUserAbilityUpRequestPlug.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Edelstein.Protocol.Gameplay.Game.Contracts; | ||
using Edelstein.Protocol.Gameplay.Models.Characters.Stats.Modify; | ||
using Edelstein.Protocol.Utilities.Pipelines; | ||
|
||
namespace Edelstein.Common.Gameplay.Game.Handling.Plugs; | ||
|
||
public class FieldOnPacketUserAbilityUpRequestPlug : IPipelinePlug<FieldOnPacketUserAbilityUpRequest> | ||
{ | ||
private readonly FieldOnPacketUserAbilityMassUpRequestPlug _plug; | ||
|
||
public FieldOnPacketUserAbilityUpRequestPlug(FieldOnPacketUserAbilityMassUpRequestPlug plug) | ||
=> _plug = plug; | ||
|
||
public Task Handle(IPipelineContext ctx, FieldOnPacketUserAbilityUpRequest message) | ||
=> _plug.Handle(ctx, new FieldOnPacketUserAbilityMassUpRequest( | ||
message.User, | ||
new Dictionary<ModifyStatType, int> | ||
{ | ||
[message.Type] = 1 | ||
} | ||
)); | ||
} |
9 changes: 9 additions & 0 deletions
9
...tocol/Edelstein.Protocol.Gameplay.Game/Contracts/FieldOnPacketUserAbilityMassUpRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Edelstein.Protocol.Gameplay.Game.Objects.User; | ||
using Edelstein.Protocol.Gameplay.Models.Characters.Stats.Modify; | ||
|
||
namespace Edelstein.Protocol.Gameplay.Game.Contracts; | ||
|
||
public record FieldOnPacketUserAbilityMassUpRequest( | ||
IFieldUser User, | ||
IDictionary<ModifyStatType, int> StatUp | ||
); |
9 changes: 9 additions & 0 deletions
9
src/protocol/Edelstein.Protocol.Gameplay.Game/Contracts/FieldOnPacketUserAbilityUpRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Edelstein.Protocol.Gameplay.Game.Objects.User; | ||
using Edelstein.Protocol.Gameplay.Models.Characters.Stats.Modify; | ||
|
||
namespace Edelstein.Protocol.Gameplay.Game.Contracts; | ||
|
||
public record FieldOnPacketUserAbilityUpRequest( | ||
IFieldUser User, | ||
ModifyStatType Type | ||
); |