Interum manual push
This commit is contained in:
@@ -69,6 +69,8 @@ public enum TriggerEventKind
|
||||
TileAffinityChanged,
|
||||
EnterAuraRange,
|
||||
LeaveAuraRange,
|
||||
RuinActivation,
|
||||
UnitOccupyRuin,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -141,6 +141,72 @@ public static class AbilitySystem
|
||||
return state;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// At the start of each turn: for every Ruin on the battlefield whose tile is occupied
|
||||
/// by a Spirit or ArchSpirit, pick ONE of the Ruin's OnRuinActivationTrigger abilities
|
||||
/// at random and execute it. Then fire RuinActivation for any observer cards.
|
||||
/// </summary>
|
||||
public static GameState FireRuinAbilities(GameState state)
|
||||
{
|
||||
foreach (var (ownerId, player) in state.Players)
|
||||
{
|
||||
var ruins = player.Field
|
||||
.OfType<FieldCard>()
|
||||
.Where(c => c.CardType == "Ruin" && c.Position.HasValue)
|
||||
.ToList();
|
||||
|
||||
foreach (var ruin in ruins)
|
||||
{
|
||||
var tile = state.Board?.GetTile(ruin.Position!.Value);
|
||||
if (tile?.OccupantId is null) continue;
|
||||
|
||||
// Only fires if a Spirit or ArchSpirit is on the tile.
|
||||
var occupantType = FindUnitType(state, tile.OccupantId);
|
||||
if (occupantType is not ("Spirit" or "ArchSpirit" or "SpiritToken")) continue;
|
||||
|
||||
var abilities = ParseAbilities(ruin.AbilitiesJson);
|
||||
var ctx = new AbilityContext { State = state, ActorId = ownerId, Source = ruin };
|
||||
|
||||
var eligible = abilities
|
||||
.Where(a => a.Type == AbilityType.Triggered
|
||||
&& a.TriggerEvent is OnRuinActivationTrigger)
|
||||
.Where(a => a.ActivationConditions is not { Length: > 0 }
|
||||
|| a.ActivationConditions.All(c => EvaluateCondition(c, ctx, ruin)))
|
||||
.ToList();
|
||||
|
||||
if (eligible.Count == 0) continue;
|
||||
|
||||
// Select exactly one ability at random.
|
||||
var chosen = eligible[Random.Shared.Next(eligible.Count)];
|
||||
ExecuteActions(chosen.Actions, ctx, clientTargets: null);
|
||||
|
||||
// Notify observer cards that the ruin activated.
|
||||
FireTrigger(state, new TriggerOccurrence
|
||||
{
|
||||
Kind = TriggerEventKind.RuinActivation,
|
||||
ActorId = ownerId,
|
||||
Data = new TriggerEventData
|
||||
{
|
||||
SourceId = ruin.InstanceId,
|
||||
TargetId = tile.OccupantId,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private static string? FindUnitType(GameState state, string instanceId)
|
||||
{
|
||||
foreach (var player in state.Players.Values)
|
||||
{
|
||||
var c = player.Field.FirstOrDefault(x => x.InstanceId == instanceId)
|
||||
?? player.ArchSpirit as CardInstance;
|
||||
if (c?.InstanceId == instanceId) return c.CardType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ── Cost payment ──────────────────────────────────────────────────────────
|
||||
|
||||
private static void PayCost(CostEntry[] costs, AbilityContext ctx)
|
||||
@@ -699,7 +765,10 @@ public static class AbilitySystem
|
||||
|
||||
// Fire leave-aura triggers before removing from board.
|
||||
EvaluateAurasOnLeave(ctx.State, unit.InstanceId);
|
||||
ctx.State.Board?.RemoveUnit(unit.InstanceId);
|
||||
if (unit.CardType == "Ruin")
|
||||
ctx.State.Board?.RemoveRuin(unit.InstanceId);
|
||||
else
|
||||
ctx.State.Board?.RemoveUnit(unit.InstanceId);
|
||||
RemoveFromAllZones(owner, unit, board: null); // board already handled above
|
||||
unit.CurrentHealth = 0;
|
||||
owner.Discard.Add(unit);
|
||||
@@ -781,7 +850,11 @@ public static class AbilitySystem
|
||||
|
||||
private static void RemoveFromAllZones(PlayerState player, CardInstance card, Board? board)
|
||||
{
|
||||
if (board is not null) board.RemoveUnit(card.InstanceId);
|
||||
if (board is not null)
|
||||
{
|
||||
board.RemoveUnit(card.InstanceId);
|
||||
if (card.CardType == "Ruin") board.RemoveRuin(card.InstanceId);
|
||||
}
|
||||
player.Hand.Remove(card);
|
||||
player.Deck.Remove(card);
|
||||
player.Field.Remove(card);
|
||||
@@ -989,6 +1062,14 @@ public static class AbilitySystem
|
||||
occurrence.Kind == TriggerEventKind.LeaveAuraRange
|
||||
&& Own(lat.AuraOwnership, occurrence, ownerId, state)
|
||||
&& UnitOwnerMatches(lat.UnitOwnership, occurrence.Data?.TargetId, state, ownerId),
|
||||
OnRuinActivationTrigger rat =>
|
||||
occurrence.Kind == TriggerEventKind.RuinActivation
|
||||
&& Own(rat.RuinOwnership, occurrence, ownerId, state)
|
||||
&& (rat.OccupantOwnership is null
|
||||
|| UnitOwnerMatches(rat.OccupantOwnership, occurrence.Data?.TargetId, state, ownerId)),
|
||||
OnUnitOccupyRuinTrigger uor =>
|
||||
occurrence.Kind == TriggerEventKind.UnitOccupyRuin
|
||||
&& Own(uor.UnitOwnership, occurrence, ownerId, state),
|
||||
_ => false,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user