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:
@@ -1105,8 +1105,9 @@
|
||||
[
|
||||
new("Damage & Healing", ["DealDamage", "Heal", "DealDamageToSelf", "DOT", "HOT"]),
|
||||
new("Stat Modification", ["ModifyHealth", "ModifyDefense", "ModifyDamage", "ModifyMP",
|
||||
"GrantAdditionalAttack", "SetAttackRange", "SetMovementType",
|
||||
"ModifyCost", "SetStatModMultiplier"]),
|
||||
"GrantAdditionalAttack", "SetAttackRange",
|
||||
"ModifyMinAttackRange", "ModifyMaxAttackRange",
|
||||
"SetMovementType", "ModifyCost", "SetStatModMultiplier"]),
|
||||
new("Player Resources", ["ModifySP", "ModifyST", "ModifyCardsDrawnPerTurn", "ModifySPAccumulation"]),
|
||||
new("Unit Flags", ["SetCanMove", "SetCanAttack", "SetCanDefend", "SetCanBeAttacked",
|
||||
"SetCanBeBlocked", "SetCanBeObstructed", "SetCanUseAbility", "SetCanBeSacrificed"]),
|
||||
@@ -1142,7 +1143,8 @@
|
||||
// ── Effect type categories for rendering ─────────────────────────────────────
|
||||
|
||||
private static readonly HashSet<string> _amountBypassTypes = ["DealDamage", "DealDamageToSelf"];
|
||||
private static readonly HashSet<string> _amountOnlyTypes = ["Heal", "ModifyDamage", "ModifySP", "ModifyST", "ModifyCardsDrawnPerTurn", "ModifySPAccumulation"];
|
||||
private static readonly HashSet<string> _amountOnlyTypes = ["Heal", "ModifyDamage", "ModifySP", "ModifyST", "ModifyCardsDrawnPerTurn", "ModifySPAccumulation",
|
||||
"ModifyMinAttackRange", "ModifyMaxAttackRange"];
|
||||
private static readonly HashSet<string> _amountStatTypes = ["ModifyHealth", "ModifyDefense", "ModifyMP"];
|
||||
private static readonly HashSet<string> _valueTypes = [
|
||||
"SetCanMove", "SetCanAttack", "SetCanDefend", "SetCanBeAttacked",
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -749,6 +749,24 @@ public static class AbilitySystem
|
||||
ci.InstanceId, duration, ctx);
|
||||
break;
|
||||
}
|
||||
case ModifyMinAttackRangeEffect mmar when target is CardInstance ci:
|
||||
{
|
||||
int orig = ci.MinAttackRange ?? 0;
|
||||
int newVal = Math.Max(0, orig + ResolveValue(mmar.Amount, ctx));
|
||||
ci.MinAttackRange = newVal;
|
||||
TrackEffect(new ModifyMinAttackRangeEffect { Amount = V(orig - newVal) },
|
||||
ci.InstanceId, duration, ctx);
|
||||
break;
|
||||
}
|
||||
case ModifyMaxAttackRangeEffect mmax when target is CardInstance ci:
|
||||
{
|
||||
int orig = ci.MaxAttackRange ?? 1;
|
||||
int newVal = Math.Max(0, orig + ResolveValue(mmax.Amount, ctx));
|
||||
ci.MaxAttackRange = newVal;
|
||||
TrackEffect(new ModifyMaxAttackRangeEffect { Amount = V(orig - newVal) },
|
||||
ci.InstanceId, duration, ctx);
|
||||
break;
|
||||
}
|
||||
case ModifyCostEffect mc when target is CardInstance ci:
|
||||
{
|
||||
if (mc.Sp.HasValue) ci.SpCost = Math.Max(0, ci.SpCost + mc.Sp.Value);
|
||||
|
||||
@@ -16,6 +16,8 @@ using SOR.Database.Enums;
|
||||
[PolyType(typeof(ModifyMPEffect), "ModifyMP")]
|
||||
[PolyType(typeof(SetMovementTypeEffect), "SetMovementType")]
|
||||
[PolyType(typeof(SetAttackRangeEffect), "SetAttackRange")]
|
||||
[PolyType(typeof(ModifyMinAttackRangeEffect), "ModifyMinAttackRange")]
|
||||
[PolyType(typeof(ModifyMaxAttackRangeEffect), "ModifyMaxAttackRange")]
|
||||
[PolyType(typeof(ModifyCostEffect), "ModifyCost")]
|
||||
[PolyType(typeof(SetAffinityEffect), "SetAffinity")]
|
||||
[PolyType(typeof(GrantAdditionalAttackEffect), "GrantAdditionalAttack")]
|
||||
@@ -102,7 +104,9 @@ public sealed class ModifyDamageEffect : Effect { public ValueExpr Amount { get
|
||||
public sealed class ModifyMPEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatTarget StatTarget { get; set; } = StatTarget.Current; }
|
||||
|
||||
public sealed class SetMovementTypeEffect : Effect { public MovementType MovementType { get; set; } }
|
||||
public sealed class SetAttackRangeEffect : Effect { public int Min { get; set; } public int Max { get; set; } }
|
||||
public sealed class SetAttackRangeEffect : Effect { public int Min { get; set; } public int Max { get; set; } }
|
||||
public sealed class ModifyMinAttackRangeEffect : Effect { public ValueExpr Amount { get; set; } = new(); }
|
||||
public sealed class ModifyMaxAttackRangeEffect : Effect { public ValueExpr Amount { get; set; } = new(); }
|
||||
public sealed class ModifyCostEffect : Effect { public int? Sp { get; set; } public int? St { get; set; } }
|
||||
public sealed class SetAffinityEffect : Effect { public AffinityExpr Affinity { get; set; } = new(); }
|
||||
public sealed class GrantAdditionalAttackEffect : Effect { public int N { get; set; } = 1; }
|
||||
|
||||
Reference in New Issue
Block a user