Client fixes, and ability fixes
This commit is contained in:
@@ -5109,6 +5109,27 @@ public static class AbilitySystem
|
||||
/// moving unit's own auras sweeping over stationary units.
|
||||
/// Call after updating the unit's position on the board.
|
||||
/// </summary>
|
||||
|
||||
// Returns all units currently on the board for a given player, including ArchSpirit.
|
||||
private static IEnumerable<FieldCard> BoardUnits(PlayerState player)
|
||||
{
|
||||
if (player.ArchSpirit?.Position.HasValue == true)
|
||||
yield return player.ArchSpirit;
|
||||
foreach (var fc in player.Field.OfType<FieldCard>().Where(f => f.Position.HasValue))
|
||||
yield return fc;
|
||||
}
|
||||
|
||||
// Finds the owner account-id of a unit, checking ArchSpirit and Field.
|
||||
private static string? FindUnitOwner(GameState state, string unitId)
|
||||
{
|
||||
foreach (var (oid, pl) in state.Players)
|
||||
{
|
||||
if (pl.ArchSpirit?.InstanceId == unitId) return oid;
|
||||
if (pl.Field.Any(c => c.InstanceId == unitId)) return oid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static GameState EvaluateAuraTransitions(
|
||||
GameState state,
|
||||
string movingUnitId,
|
||||
@@ -5117,8 +5138,8 @@ public static class AbilitySystem
|
||||
{
|
||||
// Part 1: stationary aura-bearing units vs. moving unit's position change.
|
||||
foreach (var (auraOwnerId, player) in state.Players)
|
||||
foreach (var auraUnit in player.Field.OfType<FieldCard>()
|
||||
.Where(f => f.Position.HasValue && f.InstanceId != movingUnitId).ToList())
|
||||
foreach (var auraUnit in BoardUnits(player)
|
||||
.Where(f => f.InstanceId != movingUnitId).ToList())
|
||||
{
|
||||
foreach (var def in ParseAbilities(auraUnit.AbilitiesJson)
|
||||
.Where(d => d.Type == AbilityType.Aura && d.AuraRange is not null))
|
||||
@@ -5133,13 +5154,11 @@ public static class AbilitySystem
|
||||
|
||||
// Part 2: moving unit's own auras vs. stationary units.
|
||||
var movingUnit = state.Players.Values
|
||||
.SelectMany(p => p.Field.OfType<FieldCard>())
|
||||
.SelectMany(p => BoardUnits(p))
|
||||
.FirstOrDefault(f => f.InstanceId == movingUnitId);
|
||||
if (movingUnit is null) return state;
|
||||
|
||||
string? movingOwnerId = null;
|
||||
foreach (var (oid, pl) in state.Players)
|
||||
if (pl.Field.Any(c => c.InstanceId == movingUnitId)) { movingOwnerId = oid; break; }
|
||||
var movingOwnerId = FindUnitOwner(state, movingUnitId);
|
||||
if (movingOwnerId is null) return state;
|
||||
|
||||
foreach (var def in ParseAbilities(movingUnit.AbilitiesJson)
|
||||
@@ -5147,8 +5166,8 @@ public static class AbilitySystem
|
||||
{
|
||||
int min = def.AuraRange!.Min, max = def.AuraRange.Max;
|
||||
foreach (var (_, pl) in state.Players)
|
||||
foreach (var other in pl.Field.OfType<FieldCard>()
|
||||
.Where(f => f.Position.HasValue && f.InstanceId != movingUnitId).ToList())
|
||||
foreach (var other in BoardUnits(pl)
|
||||
.Where(f => f.InstanceId != movingUnitId).ToList())
|
||||
{
|
||||
var otherPos = other.Position!.Value;
|
||||
FireAuraTransition(state, movingOwnerId, movingUnit, def, other.InstanceId,
|
||||
@@ -5176,8 +5195,8 @@ public static class AbilitySystem
|
||||
|
||||
// Part 1: existing aura units — check if new unit entered their range.
|
||||
foreach (var (auraOwnerId, player) in state.Players)
|
||||
foreach (var auraUnit in player.Field.OfType<FieldCard>()
|
||||
.Where(f => f.Position.HasValue && f.InstanceId != newUnitId).ToList())
|
||||
foreach (var auraUnit in BoardUnits(player)
|
||||
.Where(f => f.InstanceId != newUnitId).ToList())
|
||||
{
|
||||
foreach (var def in ParseAbilities(auraUnit.AbilitiesJson)
|
||||
.Where(d => d.Type == AbilityType.Aura && d.AuraRange is not null))
|
||||
@@ -5189,17 +5208,15 @@ public static class AbilitySystem
|
||||
}
|
||||
|
||||
// Part 2: new unit's own auras — check all existing units.
|
||||
string? newUnitOwnerId = null;
|
||||
foreach (var (oid, pl) in state.Players)
|
||||
if (pl.Field.Any(c => c.InstanceId == newUnitId)) { newUnitOwnerId = oid; break; }
|
||||
var newUnitOwnerId = FindUnitOwner(state, newUnitId);
|
||||
if (newUnitOwnerId is null) return state;
|
||||
|
||||
foreach (var def in ParseAbilities(newUnit.AbilitiesJson)
|
||||
.Where(d => d.Type == AbilityType.Aura && d.AuraRange is not null))
|
||||
{
|
||||
foreach (var (_, pl) in state.Players)
|
||||
foreach (var other in pl.Field.OfType<FieldCard>()
|
||||
.Where(f => f.Position.HasValue && f.InstanceId != newUnitId).ToList())
|
||||
foreach (var other in BoardUnits(pl)
|
||||
.Where(f => f.InstanceId != newUnitId).ToList())
|
||||
{
|
||||
int dist = newPos.ManhattanDistance(other.Position!.Value);
|
||||
if (dist >= def.AuraRange!.Min && dist <= def.AuraRange.Max)
|
||||
@@ -5218,15 +5235,15 @@ public static class AbilitySystem
|
||||
public static GameState EvaluateAurasOnLeave(GameState state, string leavingUnitId)
|
||||
{
|
||||
var leavingUnit = state.Players.Values
|
||||
.SelectMany(p => p.Field.OfType<FieldCard>())
|
||||
.SelectMany(p => BoardUnits(p))
|
||||
.FirstOrDefault(f => f.InstanceId == leavingUnitId);
|
||||
if (leavingUnit?.Position is null) return state;
|
||||
var leavingPos = leavingUnit.Position.Value;
|
||||
|
||||
// Part 1: existing aura units — check if leaving unit was in their range.
|
||||
foreach (var (auraOwnerId, player) in state.Players)
|
||||
foreach (var auraUnit in player.Field.OfType<FieldCard>()
|
||||
.Where(f => f.Position.HasValue && f.InstanceId != leavingUnitId).ToList())
|
||||
foreach (var auraUnit in BoardUnits(player)
|
||||
.Where(f => f.InstanceId != leavingUnitId).ToList())
|
||||
{
|
||||
foreach (var def in ParseAbilities(auraUnit.AbilitiesJson)
|
||||
.Where(d => d.Type == AbilityType.Aura && d.AuraRange is not null))
|
||||
@@ -5238,17 +5255,15 @@ public static class AbilitySystem
|
||||
}
|
||||
|
||||
// Part 2: leaving unit's own auras — fire LeaveAuraRange for each in-range unit.
|
||||
string? leavingOwnerId = null;
|
||||
foreach (var (oid, pl) in state.Players)
|
||||
if (pl.Field.Any(c => c.InstanceId == leavingUnitId)) { leavingOwnerId = oid; break; }
|
||||
var leavingOwnerId = FindUnitOwner(state, leavingUnitId);
|
||||
if (leavingOwnerId is null) return state;
|
||||
|
||||
foreach (var def in ParseAbilities(leavingUnit.AbilitiesJson)
|
||||
.Where(d => d.Type == AbilityType.Aura && d.AuraRange is not null))
|
||||
{
|
||||
foreach (var (_, pl) in state.Players)
|
||||
foreach (var other in pl.Field.OfType<FieldCard>()
|
||||
.Where(f => f.Position.HasValue && f.InstanceId != leavingUnitId).ToList())
|
||||
foreach (var other in BoardUnits(pl)
|
||||
.Where(f => f.InstanceId != leavingUnitId).ToList())
|
||||
{
|
||||
int dist = leavingPos.ManhattanDistance(other.Position!.Value);
|
||||
if (dist >= def.AuraRange!.Min && dist <= def.AuraRange.Max)
|
||||
|
||||
@@ -770,26 +770,33 @@ public static class GameEngine
|
||||
|
||||
if (attacker.CurrentHealth <= 0)
|
||||
{
|
||||
AbilitySystem.EvaluateAurasOnLeave(state, attacker.InstanceId);
|
||||
AbilitySystem.RevokePassivesForSource(state, attacker.InstanceId);
|
||||
if (state.Board is not null) state.Board.RemoveUnit(attacker.InstanceId);
|
||||
MoveToDiscard(activePlayer, attacker);
|
||||
if (attacker.IsLeader)
|
||||
{
|
||||
EliminatePlayer(state, activePlayer, out gameOver);
|
||||
}
|
||||
else
|
||||
{
|
||||
AbilitySystem.EvaluateAurasOnLeave(state, attacker.InstanceId);
|
||||
AbilitySystem.RevokePassivesForSource(state, attacker.InstanceId);
|
||||
if (state.Board is not null) state.Board.RemoveUnit(attacker.InstanceId);
|
||||
MoveToDiscard(activePlayer, attacker);
|
||||
|
||||
AbilitySystem.FireTrigger(state, new TriggerOccurrence
|
||||
{
|
||||
Kind = TriggerEventKind.UnitDeath,
|
||||
ActorId = actorId,
|
||||
UnitType = attacker.CardType,
|
||||
Data = new TriggerEventData { TargetId = attacker.InstanceId },
|
||||
});
|
||||
// Attacker was killed by the target's counterattack.
|
||||
AbilitySystem.FireTrigger(state, new TriggerOccurrence
|
||||
{
|
||||
Kind = TriggerEventKind.UnitSentToDiscard,
|
||||
ActorId = actorId, // victim's player
|
||||
UnitType = attacker.CardType,
|
||||
Data = new TriggerEventData { TargetId = attacker.InstanceId, SourceId = target.InstanceId },
|
||||
});
|
||||
AbilitySystem.FireTrigger(state, new TriggerOccurrence
|
||||
{
|
||||
Kind = TriggerEventKind.UnitDeath,
|
||||
ActorId = actorId,
|
||||
UnitType = attacker.CardType,
|
||||
Data = new TriggerEventData { TargetId = attacker.InstanceId },
|
||||
});
|
||||
// Attacker was killed by the target's counterattack.
|
||||
AbilitySystem.FireTrigger(state, new TriggerOccurrence
|
||||
{
|
||||
Kind = TriggerEventKind.UnitSentToDiscard,
|
||||
ActorId = actorId, // victim's player
|
||||
UnitType = attacker.CardType,
|
||||
Data = new TriggerEventData { TargetId = attacker.InstanceId, SourceId = target.InstanceId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (target.CurrentHealth <= 0)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"profiles": {
|
||||
"SOR.Website": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:52569;http://localhost:52570"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user