Fix crashes, add ModifyAttackRange effects, ArchSpirit swap in deck editor
- Bazaar Deck tab crash: null-safe float conversion for usdPrice in store_item_row.gd - Leaderboard crash: freed-object guard in _on_leaderboard_ok (is_instance_valid check) - Add ModifyMinAttackRangeEffect / ModifyMaxAttackRangeEffect with clamp-to-0 and correct reversal tracking - AbilityBuilder: add new range effects to Stat Modification group + _amountOnlyTypes - collection.set_arch_spirit: new handler, request record, and service registration - Deck editor: show Tier-1 commander row with Change button + ArchSpirit picker panel 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:
@@ -34,6 +34,12 @@ public sealed record CreateDeckRequest(string Name, Guid ArchSpiritCardDefinitio
|
||||
/// <summary>Renames an existing deck the player owns.</summary>
|
||||
public sealed record RenameDeckRequest(Guid DeckId, string Name);
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the Tier-1 ArchSpirit commander of an existing deck.
|
||||
/// ArchSpiritCardDefinitionId must be an ArchSpirit the player owns.
|
||||
/// </summary>
|
||||
public sealed record SetArchSpiritRequest(Guid DeckId, Guid ArchSpiritCardDefinitionId);
|
||||
|
||||
/// <summary>Permanently deletes a deck and all its DeckCard rows.</summary>
|
||||
public sealed record DeleteDeckRequest(Guid DeckId);
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
namespace SOR.Collection.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Enums;
|
||||
using SOR.Networking.Abstractions.Messaging;
|
||||
using SOR.Networking.Abstractions.Transport;
|
||||
using SOR.Shared.Networking;
|
||||
|
||||
/// <summary>
|
||||
/// collection.set_arch_spirit — replaces the Tier-1 ArchSpirit commander of an existing deck.
|
||||
///
|
||||
/// Validation:
|
||||
/// - Deck must exist and belong to the player.
|
||||
/// - New ArchSpirit must exist in the catalog as CardType.ArchSpirit.
|
||||
/// - Player must own at least one copy of the chosen ArchSpirit.
|
||||
/// </summary>
|
||||
internal sealed class CollectionSetArchSpiritHandler : CollectionHandlerBase, IMessageHandler
|
||||
{
|
||||
private readonly IMessageSerializer _serializer;
|
||||
private readonly CollectionDbContext _collectionDb;
|
||||
private readonly CatalogDbContext _catalogDb;
|
||||
|
||||
public CollectionSetArchSpiritHandler(
|
||||
IMessageSerializer serializer,
|
||||
CollectionDbContext collectionDb,
|
||||
CatalogDbContext catalogDb)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_collectionDb = collectionDb;
|
||||
_catalogDb = catalogDb;
|
||||
}
|
||||
|
||||
public string MessageType => "collection.set_arch_spirit";
|
||||
|
||||
public async Task<IServerMessage?> HandleAsync(
|
||||
IClientMessage message,
|
||||
AuthenticatedConnection connection,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var req = _serializer.DeserializePayload<SetArchSpiritRequest>(message.Payload);
|
||||
var accountId = Guid.Parse(connection.UserId);
|
||||
|
||||
// ── Validate deck ownership ────────────────────────────────────────────
|
||||
var deck = await _collectionDb.Decks
|
||||
.Include(d => d.Cards)
|
||||
.FirstOrDefaultAsync(
|
||||
d => d.Id == req.DeckId && d.AccountId == accountId,
|
||||
cancellationToken);
|
||||
if (deck is null)
|
||||
return ServerMessage.Error(message.Seq, "DECK_NOT_FOUND", "Deck not found.");
|
||||
|
||||
// ── Validate ArchSpirit exists in catalog ──────────────────────────────
|
||||
var archDef = await _catalogDb.CardDefinitions
|
||||
.FirstOrDefaultAsync(
|
||||
cd => cd.Id == req.ArchSpiritCardDefinitionId
|
||||
&& cd.CardType == CardType.ArchSpirit,
|
||||
cancellationToken);
|
||||
if (archDef is null)
|
||||
return ServerMessage.Error(message.Seq, "INVALID_ARCH_SPIRIT",
|
||||
"That card is not a valid ArchSpirit.");
|
||||
|
||||
// ── Validate player owns the ArchSpirit ────────────────────────────────
|
||||
var ownsArch = await _collectionDb.PlayerCards
|
||||
.AnyAsync(
|
||||
pc => pc.AccountId == accountId
|
||||
&& pc.CardDefinitionId == req.ArchSpiritCardDefinitionId,
|
||||
cancellationToken);
|
||||
if (!ownsArch)
|
||||
return ServerMessage.Error(message.Seq, "ARCH_SPIRIT_NOT_OWNED",
|
||||
"You do not own that ArchSpirit card.");
|
||||
|
||||
// ── Apply change ───────────────────────────────────────────────────────
|
||||
deck.ArchSpiritCardDefinitionId = req.ArchSpiritCardDefinitionId;
|
||||
deck.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
await _collectionDb.SaveChangesAsync(cancellationToken);
|
||||
|
||||
var summary = new DeckSummaryDto(
|
||||
Id: deck.Id,
|
||||
Name: deck.Name,
|
||||
ArchSpiritCardDefinitionId: deck.ArchSpiritCardDefinitionId,
|
||||
CardCount: deck.Cards.Sum(c => c.Quantity),
|
||||
IsValid: deck.IsValid,
|
||||
CreatedAt: deck.CreatedAt,
|
||||
UpdatedAt: deck.UpdatedAt);
|
||||
|
||||
return ServerMessage.Reply("collection.set_arch_spirit.ack", message.Seq,
|
||||
new DeckMutationResponse(summary));
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ public static class ServiceRegistration
|
||||
services.AddTransient<IMessageHandler, CollectionGetDeckHandler>();
|
||||
services.AddTransient<IMessageHandler, CollectionCreateDeckHandler>();
|
||||
services.AddTransient<IMessageHandler, CollectionRenameDeckHandler>();
|
||||
services.AddTransient<IMessageHandler, CollectionSetArchSpiritHandler>();
|
||||
services.AddTransient<IMessageHandler, CollectionDeleteDeckHandler>();
|
||||
services.AddTransient<IMessageHandler, CollectionAddCardHandler>();
|
||||
services.AddTransient<IMessageHandler, CollectionRemoveCardHandler>();
|
||||
|
||||
Reference in New Issue
Block a user