Add Ascend, Transition, and Terramorpha implementations
- CardInstance: add Tier, PreviousTierId (ascension chain), TerramorphaMode - GameEngine.Ascend (§6.7.2): any-zone search, tier+lineage validation, full HP/Def/MP on entry - GameEngine.Transition (§6.7.1): hand-only, Tier 1 guard, full HP/Def/MP on entry - GameEngine.ChannelCard: Terramorpha path (Mono/Di/Tri tile count + adjacency + affinity push); non-Spirit, non-Terramorpha cards now correctly go to Discard instead of Field - GamePlayCardRequest: add TargetTiles for multi-tile Terramorpha; handler routes accordingly - CardInstanceDto: expose Tier and TerramorphaMode to clients - New handlers: game.ascend, game.transition Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
namespace SOR.Game.Handlers;
|
||||
|
||||
using System.Text.Json;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Push;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// game.ascend — active player upgrades their ArchSpirit by exactly one tier (§6.7.2).
|
||||
///
|
||||
/// The incoming higher-tier ArchSpirit must be the direct next tier in the ascension chain
|
||||
/// (Tier+1, PreviousTierId == current ArchSpirit's CardDefinitionId). It may come from
|
||||
/// any zone (hand, deck, or discard). Cost is the incoming ArchSpirit's SP/ST cost.
|
||||
/// The new ArchSpirit enters at the current position with full HP, Defense, and MP.
|
||||
/// </summary>
|
||||
internal sealed class GameAscendHandler : GameHandlerBase, IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly GameDbContext _gameDb;
|
||||
private readonly IClientPush _clientPush;
|
||||
|
||||
public GameAscendHandler(
|
||||
IMessageSerializer serializer,
|
||||
GameDbContext gameDb,
|
||||
IClientPush clientPush)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_gameDb = gameDb;
|
||||
_clientPush = clientPush;
|
||||
}
|
||||
|
||||
public string MessageType => "game.ascend";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<GameAscendRequest>(message.Payload);
|
||||
var actorId = connection.UserId;
|
||||
|
||||
var session = await LoadActiveSessionAsync(_gameDb, req.SessionId, actorId, ct);
|
||||
var state = GameEngine.Deserialize(session.StateJson!);
|
||||
var newState = GameEngine.Ascend(state, actorId, req.IncomingCardInstanceId);
|
||||
|
||||
await SaveStateAsync(_gameDb, session, newState, actorId, "game.ascend",
|
||||
JsonSerializer.Serialize(req), ct);
|
||||
|
||||
await PushStateToPlayersAsync(_clientPush, session, newState, ct);
|
||||
|
||||
return ServerMessage.Reply("game.ascend.ack", message.Seq,
|
||||
new GameAscendResponse(GameEngine.ToDto(newState, actorId)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user