diff --git a/Client/origin-client/scenes/game/components/selection/ability_targeting.gd b/Client/origin-client/scenes/game/components/selection/ability_targeting.gd index 227b787..32ca752 100644 --- a/Client/origin-client/scenes/game/components/selection/ability_targeting.gd +++ b/Client/origin-client/scenes/game/components/selection/ability_targeting.gd @@ -89,7 +89,8 @@ func show_ability_panel(unit_id: String, unit: Dictionary) -> void: "index": i, "name": ab.get("name", "Ability %d" % i), "desc": ab.get("description", ""), - "def": ab + "def": ab, + "exhausted": _ability_uses_exhausted(unit, i, ab) }) # Collect ArchSpirit actions (Sacrifice / Ascend / Transition). @@ -113,7 +114,8 @@ func show_ability_panel(unit_id: String, unit: Dictionary) -> void: if card.get("cardType", "") != "ArchSpirit": continue var t: int = int(card.get("tier", 0)) - if t == cur_tier + 1: can_ascend = true + if t == cur_tier + 1 and _card_previous_tier_matches_unit(card, unit): + can_ascend = true if t == 1: can_trans = true if can_ascend: arch_actions.append({ @@ -145,11 +147,18 @@ func show_ability_panel(unit_id: String, unit: Dictionary) -> void: for ab: Dictionary in actives: var btn: Button = Button.new() btn.text = ab.get("name", "") - btn.tooltip_text = ab.get("desc", "") btn.add_theme_font_size_override("font_size", 12) + var is_exhausted: bool = bool(ab.get("exhausted", false)) + if is_exhausted: + btn.disabled = true + btn.tooltip_text = "No more uses available this turn" + else: + btn.tooltip_text = ab.get("desc", "") var idx: int = ab.get("index", 0) var ab_def: Dictionary = ab.get("def", {}) btn.pressed.connect(func() -> void: + if btn.disabled: + return hide_ability_panel() ability_unit_id = unit_id ability_idx = idx @@ -199,6 +208,39 @@ func hide_ability_panel() -> void: ability_panel = null +func _ability_uses_exhausted(unit: Dictionary, ability_index: int, ab: Dictionary) -> bool: + var uses_per_turn: int = int(ab.get("usesperturn", 1)) + var used_this_turn: int = _ability_uses_this_turn(unit, ability_index) + return used_this_turn >= uses_per_turn + + +func _ability_uses_this_turn(unit: Dictionary, ability_index: int) -> int: + var raw_uses: Variant = unit.get("abilityUsesJson", "{}") + if raw_uses == null: + return 0 + var uses_json: String = str(raw_uses) + if uses_json.is_empty() or uses_json == "null" or uses_json == "": + return 0 + var parsed: Variant = JSON.parse_string(uses_json) + if not (parsed is Dictionary): + return 0 + var uses: Dictionary = parsed as Dictionary + var idx_key: String = str(ability_index) + if uses.has(idx_key): + return int(uses[idx_key]) + if uses.has(ability_index): + return int(uses[ability_index]) + return 0 + + +func _card_previous_tier_matches_unit(card: Dictionary, unit: Dictionary) -> bool: + var unit_def_id: String = str(unit.get("cardDefinitionId", unit.get("CardDefinitionId", ""))) + if unit_def_id.is_empty(): + return false + var prev_tier_id: String = str(card.get("previousTierId", card.get("PreviousTierId", ""))) + return not prev_tier_id.is_empty() and prev_tier_id == unit_def_id + + func current_target_mode() -> SelectionController.Mode: if is_triggered_target or is_target_pick or is_tile_pick: return SelectionController.Mode.ABILITY_TARGET_FORCED @@ -446,7 +488,7 @@ func unit_passes_filters(unit: Dictionary, filters: Array) -> bool: var src: Dictionary = Game.get_unit_by_id(ability_unit_id) var src_pos: Dictionary = src.get("position", {}) for f: Dictionary in filters: - match f.get("$type", ""): + match str(f.get("$type", "")).to_lower(): "withinrange": if src_pos.is_empty(): return false var tgt_pos: Dictionary = unit.get("position", {}) @@ -470,23 +512,42 @@ func unit_passes_filters(unit: Dictionary, filters: Array) -> bool: if dist != 1: return false for cond: Dictionary in ability_target_conditions: - match cond.get("$type", ""): - "IsOnTileWithAffinity": + match str(cond.get("$type", "")).to_lower(): + "isontilewithaffinity": var upos: Dictionary = unit.get("position", {}) if upos.is_empty(): return false var tile: Dictionary = Game.get_tile(int(upos.get("x", 0)), int(upos.get("y", 0))) - if tile.get("affinity", "") != cond.get("affinity", ""): + var affinity: String = str(cond.get("affinity", cond.get("Affinity", ""))) + if not tile_matches_channel_affinity(tile, affinity): return false return true ## Collects all effect-level tile filters from a single action's effects array. -## Currently supports SummonToken.tileFilter. +## Supports SummonToken.tileFilter. Also synthesises filters for SummonToken's +## required empty tile and token affinity constraints. func _collect_effect_tile_filters(action: Dictionary) -> Array: var result: Array = [] var effects_v: Variant = action.get("effects", []) var effects: Array = effects_v as Array if effects_v is Array else [] for fx: Dictionary in effects: + var type_: String = str(fx.get("$type", "")).to_lower() + if type_ == "summontoken": + result.append({"$type": "tileisunoccupied"}) + var token_affinity: String = "" + var token_def_json: String = str(fx.get( + "tokendefjson", + fx.get("tokenDefJson", fx.get("TokenDefJson", "")))) + if not token_def_json.is_empty(): + var token_def_v: Variant = JSON.parse_string(token_def_json) + if token_def_v is Dictionary: + var token_def: Dictionary = token_def_v as Dictionary + token_affinity = str(token_def.get("Affinity", token_def.get("affinity", ""))) + if not token_affinity.is_empty() and token_affinity != "Void": + result.append({ + "$type": "tileaffinitymatches", + "affinity": token_affinity + }) var tile_filter_v: Variant = fx.get("tilefilter", []) var tile_filter: Array = tile_filter_v as Array if tile_filter_v is Array else [] result.append_array(tile_filter) @@ -499,7 +560,7 @@ func tile_passes_filters(tx: int, ty: int, filters: Array) -> bool: var src: Dictionary = Game.get_unit_by_id(ability_unit_id) var src_pos: Dictionary = src.get("position", {}) for f: Dictionary in filters: - match f.get("$type", ""): + match str(f.get("$type", "")).to_lower(): "tilewithinrange": if src_pos.is_empty(): return false var dist: int = 0 @@ -510,11 +571,33 @@ func tile_passes_filters(tx: int, ty: int, filters: Array) -> bool: return false "tileaffinitymatches": var tile: Dictionary = Game.get_tile(tx, ty) - if tile.get("affinity", "") != f.get("affinity", ""): + var affinity: String = str(f.get("affinity", f.get("Affinity", ""))) + if not tile_matches_channel_affinity(tile, affinity): + return false + "tileisunoccupied": + var tile: Dictionary = Game.get_tile(tx, ty) + if tile.get("occupantId", null) != null: return false return true +## Uses the same affinity semantics as TileTargetResolver channel targeting. +func tile_matches_channel_affinity(tile: Dictionary, card_affinity: String) -> bool: + if selection_controller != null and selection_controller.tile_target_resolver != null: + return selection_controller.tile_target_resolver.tile_matches_channel_affinity(tile, card_affinity) + + var resolved_affinity: String = str(tile.get("resolvedAffinity", "Void")) + if resolved_affinity == "PerfectAether" and card_affinity in ["Lake", "Hill", "Forest", "Field"]: + return true + if resolved_affinity == "UnstableAether": + return false + if card_affinity in ["Lake", "Hill", "Forest", "Field"]: + var base1: String = str(tile.get("base1", "Void")) + var base2: String = str(tile.get("base2", "Void")) + return base1 == card_affinity or base2 == card_affinity + return resolved_affinity == card_affinity + + func is_linear(sx: int, sy: int, tx: int, ty: int) -> bool: return sx == tx or sy == ty or absi(tx - sx) == absi(ty - sy) diff --git a/Client/origin-client/scenes/game/components/selection/selection_controller.gd b/Client/origin-client/scenes/game/components/selection/selection_controller.gd index c9e05d6..33e5cb7 100644 --- a/Client/origin-client/scenes/game/components/selection/selection_controller.gd +++ b/Client/origin-client/scenes/game/components/selection/selection_controller.gd @@ -395,7 +395,7 @@ func show_arch_spirit_menu(unit_id: String, unit: Dictionary) -> void: if card.get("cardType", "") != "ArchSpirit": continue var t: int = int(card.get("tier", 0)) - if t == cur_tier + 1: + if t == cur_tier + 1 and _card_previous_tier_matches_unit(card, unit): can_ascend = true if t == 1: can_transition = true @@ -453,9 +453,12 @@ func _confirm_sacrifice(unit_id: String, unit_name: String) -> void: # ── Ascend / Transition ─────────────────────────────────────────────────────── func _pick_ascend_card() -> void: - var cur_tier: int = _get_my_arch_tier() + var arch: Dictionary = _get_my_arch_spirit() + var cur_tier: int = int(arch.get("tier", 1)) var candidates: Array = Game.get_hand().filter(func(c: Dictionary) -> bool: - return c.get("cardType", "") == "ArchSpirit" and int(c.get("tier", 0)) == cur_tier + 1) + return c.get("cardType", "") == "ArchSpirit" \ + and int(c.get("tier", 0)) == cur_tier + 1 \ + and _card_previous_tier_matches_unit(c, arch)) if candidates.is_empty(): return if candidates.size() == 1: @@ -551,9 +554,20 @@ func _tile_matches_channel_affinity(tile: Dictionary, card_affinity: String) -> func _get_my_arch_tier() -> int: + return int(_get_my_arch_spirit().get("tier", 1)) + + +func _get_my_arch_spirit() -> Dictionary: var player: Dictionary = Game.get_my_player() - var arch: Dictionary = player.get("archSpirit", {}) as Dictionary - return int(arch.get("tier", 1)) + return player.get("archSpirit", {}) as Dictionary + + +func _card_previous_tier_matches_unit(card: Dictionary, unit: Dictionary) -> bool: + var unit_def_id: String = str(unit.get("cardDefinitionId", unit.get("CardDefinitionId", ""))) + if unit_def_id.is_empty(): + return false + var prev_tier_id: String = str(card.get("previousTierId", card.get("PreviousTierId", ""))) + return not prev_tier_id.is_empty() and prev_tier_id == unit_def_id func _show_card_picker(title: String, cards: Array, on_pick: Callable) -> void: diff --git a/Server/src/SOR.Game/GameEngine.cs b/Server/src/SOR.Game/GameEngine.cs index bdfc5c3..222bb63 100644 --- a/Server/src/SOR.Game/GameEngine.cs +++ b/Server/src/SOR.Game/GameEngine.cs @@ -1688,6 +1688,7 @@ public static class GameEngine MaxMp : c.MaxMp, MovementType : c.MovementType?.ToString(), Tier : c.Tier, + PreviousTierId : c.PreviousTierId, TerramorphaMode : c.TerramorphaMode?.ToString(), SpCost : c.SpCost, StCost : c.StCost, @@ -1702,6 +1703,9 @@ public static class GameEngine ExtraAttacksRemaining : c.ExtraAttacksRemaining, CanBeAttacked : c.CanBeAttacked, AbilitiesJson : c.AbilitiesJson, + AbilityUsesJson : c.AbilityUsesThisTurn is not null + ? JsonSerializer.Serialize(c.AbilityUsesThisTurn, _json) + : null, Art2dUrl : c.Art2dUrl, ModelUrl : c.ModelUrl); } diff --git a/Server/src/SOR.Game/GameMessages.cs b/Server/src/SOR.Game/GameMessages.cs index 33e6243..6490a47 100644 --- a/Server/src/SOR.Game/GameMessages.cs +++ b/Server/src/SOR.Game/GameMessages.cs @@ -713,6 +713,7 @@ public sealed record CardInstanceDto( int? MaxMp, string? MovementType, // enum as string, null for non-unit cards int? Tier, // ArchSpirit only; 1 = base form + Guid? PreviousTierId, // Tier 2+ ArchSpirit lineage string? TerramorphaMode, // Terramorpha only: "Mono" | "Di" | "Tri" // --- fields needed for client-side display and valid-tile computation --- int SpCost, @@ -728,6 +729,7 @@ public sealed record CardInstanceDto( int ExtraAttacksRemaining, bool CanBeAttacked, string? AbilitiesJson, + string? AbilityUsesJson, string? Art2dUrl, string? ModelUrl); diff --git a/Server/src/SOR.Game/GameStateDiffer.cs b/Server/src/SOR.Game/GameStateDiffer.cs index 35a1e4c..5ef3d16 100644 --- a/Server/src/SOR.Game/GameStateDiffer.cs +++ b/Server/src/SOR.Game/GameStateDiffer.cs @@ -261,8 +261,8 @@ internal static class GameStateDiffer if (prevFc?.Position != nextFc?.Position && nextFc?.Position is { } pos) positionDelta = new CoordDto(pos.X, pos.Y); - string? abilityUsesJson = abilityUsesChanged && nextC.AbilityUsesThisTurn != null - ? JsonSerializer.Serialize(nextC.AbilityUsesThisTurn, _json) + string? abilityUsesJson = abilityUsesChanged + ? JsonSerializer.Serialize(nextC.AbilityUsesThisTurn ?? new Dictionary(), _json) : null; return new UnitDelta(