diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 9921507..0c762b9 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -39,7 +39,7 @@ 4. Show scenario briefing with the campaign chapter header, battle header, objective summary, chapter overview, selectable camp Talk conversations, manual checkpoint menu, and optional pre-battle shop, Armory, Roster, and Formation setup. 5. Player selects a unit. 6. Briefing completion dispatches battle-begin events, including opening dialogue. -7. Unit moves, attacks, chooses a tactic or consumable item from the side menu, changes equipment, counters, gains EXP, levels up, promotes at class thresholds, or waits. Tactic buttons show MP cost, kind, range, area radius, and power, support, debuff, movement modifier, accuracy/evasion modifier, damage-over-time, or action-lock effect. Physical attacks roll hit chance from unit agility and target terrain avoid, add facing-based side/rear damage bonuses, and equipped weapons can add small damage bonuses against matching target move types; misses give reduced EXP. The scene plays placeholder SFX, a short movement slide, class-specific physical attack motion profiles, low-HP warning rings, hover target preview badges, area tactic overlays, an enemy threat overlay with physical damage and hostile tactic hints, selected/hover unit role, movement, facing, terrain, status, and equipment details, and floating combat text for core action and UI feedback. +7. Unit moves, attacks, chooses a tactic or consumable item from the side menu, changes equipment, counters, gains EXP, levels up, promotes at class thresholds, or waits. Clicking an enemy that can be reached by moving first performs the combined move-and-attack action directly, while the map marks those targets with compact move-attack badges before the click. Tactic buttons show MP cost, kind, range, area radius, and power, support, debuff, movement modifier, accuracy/evasion modifier, damage-over-time, or action-lock effect. Physical attacks roll hit chance from unit agility and target terrain avoid, add facing-based side/rear damage bonuses, and equipped weapons can add small damage bonuses against matching target move types; misses give reduced EXP. The scene plays placeholder SFX, a short movement slide, class-specific physical attack motion profiles, low-HP warning rings, hover target preview badges, area tactic overlays, an enemy threat overlay with physical damage and hostile tactic hints, selected/hover unit role, movement, facing, terrain, status, and equipment details, and floating combat text for core action and UI feedback. 8. Player ends turn. 9. Enemy AI moves, picks physical attacks from damage, defeat, priority, and weapon-effectiveness scores, and can cast single-target or area damage, healing, support, debuff, movement-modifier, accuracy/evasion-modifier, damage-over-time, or action-lock tactics through the same combat and skill resolvers. 10. Battle checks scenario-defined defeat conditions first, including commander loss and turn limits, then victory conditions such as enemy defeat or reaching a marked destination tile. @@ -59,7 +59,7 @@ Joined officers gate whether `requires_joined` player deployments are loaded at Inventory and campaign flags are copied from `CampaignState` into `BattleState` when a scenario starts. The pre-battle Chapters overview reads `CampaignState` chapter progress and can load completed or current battles without mutating the save. Briefings preview first-clear rewards, can expose `briefing.camp_conversations` through a selectable Talk menu with `briefing.camp_dialogue` as a fallback, can filter those conversations by saved campaign flags, can claim saved one-time camp conversation supply effects through `CampaignState` and refresh the loaded battle inventory copy, and show completed replay rewards as already claimed. The pre-battle Save menu can write the current campaign state to `user://campaign_manual_save.json`, and loading that checkpoint restores it into `user://campaign_save.json` before re-entering the same pending-choice, completion, or current-briefing branch as startup. Pre-battle shop stock comes from the loaded scenario's `shop.items` list plus matching `shop.conditional_items` blocks, with optional finite limits from item entries or `stock` maps, and `shop.merchant` lines are presentation-only camp flavor. Shop purchases and 50% sell-back are campaign transactions: they update saved gold, unequipped inventory, and finite-stock purchase counts immediately, write the save file, and refresh the already-loaded battle inventory before the player begins the battle. Camp conversation supply claims are also campaign transactions: they save a per-scenario conversation claim ledger and inventory immediately, then refresh the already-loaded battle inventory. Pre-battle Armory equipment changes use the same equipment rules as battle HUD equipment changes, then immediately save merged roster equipment/stat snapshots and inventory stock. Pre-battle Roster uses scenario `roster.max_units`, `roster.required_officers`, and `roster.required_units` to mark optional player deployments as sortie or reserve; reserve units remain in the candidate list but are excluded from board occupancy, drawing, selection, AI targeting, and living-unit victory checks. Non-controllable player units can act as protected escort targets: enemies can attack them and conditions can reference them, but they are skipped by player selection, Armory, Formation, counterattacks, and campaign roster progression snapshots when `persist_progression` is false. Scenario `ai_target_priority` nudges enemy movement and damage-skill scoring toward important targets such as envoys without overriding defeat bonuses or range checks, and `set_ai_target_priority` events can retune that battle-only pressure after an ambush, gate closure, or escort exposure. Pre-battle Formation uses the loaded scenario's `formation.cells` and only mutates current battle unit positions before battle-begin events fire. Destination victory cells from `unit_reaches_tile` conditions are exposed to the scene for objective overlays and tile info, and can be expressed as one `pos` or a multi-cell `cells` list; gated victory conditions can also expose the `unit_reaches_tile` event that unlocks them as the next visible objective marker. Rewarding movement events that grant items or gold can expose optional battlefield side markers and Korean tile-info labels through `when.label`, without being treated as victory objectives. Movement-triggered `unit_reaches_tile` events receive the unit that just moved, so ambushes and pickup events fire on entry rather than from units already standing on a marker; `unit_defeated` events receive the fallen unit before final victory/defeat checks, allowing named-officer reactions and last-moment reinforcements. Briefing data can append matching `briefing.conditional_lines`, and scenario events can use `when.campaign_flags` to branch dialogue, objective changes, item and gold pickups, AI target-priority shifts, and reinforcements from saved campaign choices or `when.after_event` to wait for earlier scenario beats. Consumable use can restore HP or MP, cure matching poison/seal/snare/disarm statuses, or cleanse negative stat debuffs, and in-battle item use, event pickup grants, event gold pickups, plus equipment swaps mutate only the battle copy until victory; defeats and restarts do not spend saved items, keep picked-up items or gold, or preserve in-battle gear changes. Post-battle choices write campaign `flags` only after the result-panel button is pressed; if the player reloads after rewards are saved but before selecting, the pending scenario id restores the victory choice panel without replaying rewards. The next battle button stays locked until the campaign choice save succeeds. Equipment rewards share the same `item_id -> count` inventory stock, cover weapon, armor, and accessory slots, can be equipped from the side HUD before the selected unit moves or acts, and do not appear in the consumable action menu. Named equipment currently uses the same stock model with a presentation-only rarity tag rather than unique item instances. Already completed scenarios can be replayed without granting duplicate rewards, choices, replay inventory consumption, event gold pickups, save writes, current-scenario advancement, finite-stock purchases, or camp conversation supply claims; pre-battle Shop, Armory, Roster, Formation, and Save are disabled on completed-scenario replays to avoid side effects. -The battle scene owns presentation feedback: briefing and result states use menu BGM, briefing headers combine `CampaignState` chapter ranges, campaign order, and title data with `BattleState` briefing, objective text, condition-progress text, and defeat-risk text, active battles use battle BGM and show an objective/progress/risk panel fed by `BattleState`, objective-update signals show a short HUD notice and refresh the objective panel immediately, dialogue lines can show optional cached portrait textures or speaker-initial fallback panels in an expanded visual-novel-style panel, can place the portrait on the left or right side of that panel, and expose progress plus previous-line controls while a sequence is open, the side HUD reuses cached officer portrait textures or class sprites for the selected unit or hovered unit and formats focus text with role, movement type, facing, current terrain move cost, defense/avoid bonuses, core stats, status effects, guard-zone AI hints, and gear, board maps can draw a scenario background texture under translucent terrain overlays, connected road segments, terrain detail patterns, shoreline/castle/forest/hill edge blends, compact recovery markers for healing terrain, and compact side-event markers for visible item/gold pickups, board units render class sprite tokens or generic-enemy transparent class cutouts, team rings, class badges, facing markers, generic-enemy marks, officer pins, low-HP warning rings, HP bar color states, and active support/debuff/poison/seal/snare/disarm status pips from battle state fields, item buttons can show optional cached item icons, hover previews are rendered as target badges from existing `BattleState` forecast APIs, equipment option menus show stat/range/effect deltas, result and inventory summaries show named equipment with compact rarity tags, selected area tactics highlight their affected cells, the Threat toggle overlays enemy physical and hostile tactic reach while tile info names threat sources, estimates physical damage, and summarizes hostile tactic damage or status effects against occupied cells, log/result hooks trigger placeholder SFX, support, debuff, poison, seal, snare, disarm, objective updates, AI target-focus changes, and item/gold pickup effects use distinct feedback, `BattleState.unit_motion_requested` asks the scene to interpolate a unit's draw position during movement, `BattleState.unit_action_motion_requested` keeps its rules-facing signal shape while the scene maps attacker class ids to infantry, archer, cavalry, command, and heavy attack presentation profiles, and `BattleState.combat_feedback_requested` asks the scene to draw transient floating combat text without changing battle rules. +The battle scene owns presentation feedback: briefing and result states use menu BGM, briefing headers combine `CampaignState` chapter ranges, campaign order, and title data with `BattleState` briefing, objective text, condition-progress text, and defeat-risk text, active battles use battle BGM and show an objective/progress/risk panel fed by `BattleState`, objective-update signals show a short HUD notice and refresh the objective panel immediately, dialogue lines can show optional cached portrait textures or speaker-initial fallback panels in an expanded visual-novel-style panel, can place the portrait on the left or right side of that panel, and expose progress plus previous-line controls while a sequence is open, the side HUD reuses cached officer portrait textures or class sprites for the selected unit or hovered unit and formats focus text with role, movement type, facing, current terrain move cost, defense/avoid bonuses, core stats, status effects, guard-zone AI hints, and gear, board maps can draw a scenario background texture under translucent terrain overlays, connected road segments, terrain detail patterns, shoreline/castle/forest/hill edge blends, compact recovery markers for healing terrain, compact side-event markers for visible item/gold pickups, and move-attack target badges for enemies that can be struck after movement, board units render class sprite tokens or generic-enemy transparent class cutouts, team rings, class badges, facing markers, generic-enemy marks, officer pins, low-HP warning rings, HP bar color states, and active support/debuff/poison/seal/snare/disarm status pips from battle state fields, item buttons can show optional cached item icons, hover previews are rendered as target badges from existing `BattleState` forecast APIs, equipment option menus show stat/range/effect deltas, result and inventory summaries show named equipment with compact rarity tags, selected area tactics highlight their affected cells, the Threat toggle overlays enemy physical and hostile tactic reach while tile info names threat sources, estimates physical damage, and summarizes hostile tactic damage or status effects against occupied cells, log/result hooks trigger placeholder SFX, support, debuff, poison, seal, snare, disarm, objective updates, AI target-focus changes, and item/gold pickup effects use distinct feedback, `BattleState.unit_motion_requested` asks the scene to interpolate a unit's draw position during movement, `BattleState.unit_action_motion_requested` keeps its rules-facing signal shape while the scene maps attacker class ids to infantry, archer, cavalry, command, and heavy attack presentation profiles, and `BattleState.combat_feedback_requested` asks the scene to draw transient floating combat text without changing battle rules. Large tactical maps are presented through a fixed visible map window rather than by shrinking the whole board. `BattleScene` keeps a clamped `board_scroll_offset`, scrolls the board while the mouse is near or slightly outside the visible map edge, brightens the scrollable frame edge under the cursor, ignores board clicks outside the visible map window, and draws a small minimap plate inside the map view; clicking or dragging the minimap recenters the tactical viewport, while action feedback can focus the board on off-screen cells before motion or combat effects play. diff --git a/scripts/scenes/battle_scene.gd b/scripts/scenes/battle_scene.gd index 28d380e..c010ca7 100644 --- a/scripts/scenes/battle_scene.gd +++ b/scripts/scenes/battle_scene.gd @@ -3460,12 +3460,13 @@ func _draw_units() -> void: func _draw_target_selection_markers() -> void: - if not _is_targeting_mode(): + var markers := _target_selection_marker_entries() + if markers.is_empty(): return var font := _draw_ui_font(true) - for marker in _target_selection_marker_entries(): + for marker in markers: var cell: Vector2i = marker.get("cell", Vector2i(-1, -1)) - if not state.is_inside(cell): + if not state.is_inside(cell) or not _cell_is_in_visible_bounds(cell): continue var rect := _rect_for_cell(cell) var marker_rect := Rect2(rect.position + Vector2(7.0, TILE_SIZE - 24.0), Vector2(TILE_SIZE - 14.0, 18.0)) @@ -3521,9 +3522,49 @@ func _attack_target_marker_entries() -> Array[Dictionary]: "text": "%s %d%%" % [result_text, hit_chance], "kind": _attack_preview_badge_kind(preview) }) + if not basic_attack_targeting and not _has_pending_move(): + _append_auto_attack_target_marker_entries(result, selected) return result +func _append_auto_attack_target_marker_entries(result: Array[Dictionary], selected: Dictionary) -> void: + if selected.is_empty() or bool(selected.get("moved", false)) or bool(selected.get("acted", false)): + return + var current_cell: Vector2i = selected.get("pos", Vector2i(-1, -1)) + for target in state.units: + if not bool(target.get("alive", false)) or not bool(target.get("deployed", true)): + continue + if target.get("team", "") == selected.get("team", ""): + continue + var target_id := str(target.get("id", "")) + if target_id.is_empty() or _marker_entries_have_target(result, target_id): + continue + var attack_origin := _best_auto_attack_origin(selected, target) + if attack_origin == Vector2i(-1, -1) or attack_origin == current_cell: + continue + var target_cell: Vector2i = target.get("pos", Vector2i(-1, -1)) + if not state.is_inside(target_cell): + continue + var badge := _auto_attack_target_preview_badge_for_origin(selected, target, attack_origin) + if badge.is_empty(): + continue + result.append({ + "cell": target_cell, + "target_id": target_id, + "text": "행공", + "kind": str(badge.get("kind", "advance")), + "origin": attack_origin, + "requires_move": true + }) + + +func _marker_entries_have_target(entries: Array[Dictionary], target_id: String) -> bool: + for entry in entries: + if str(entry.get("target_id", "")) == target_id: + return true + return false + + func _skill_target_marker_entries() -> Array[Dictionary]: var result: Array[Dictionary] = [] if selected_skill_id.is_empty(): @@ -3630,7 +3671,11 @@ func _try_auto_move_attack(selected: Dictionary, target: Dictionary) -> bool: func _best_auto_attack_origin(selected: Dictionary, target: Dictionary) -> Vector2i: var unit_id := str(selected.get("id", "")) - if unit_id.is_empty(): + var target_id := str(target.get("id", "")) + if unit_id.is_empty() or target_id.is_empty(): + return Vector2i(-1, -1) + var base_preview := state.get_damage_preview(unit_id, target_id) + if base_preview.is_empty() or bool(base_preview.get("attack_locked", false)): return Vector2i(-1, -1) var current_cell: Vector2i = selected.get("pos", Vector2i(-1, -1)) var target_cell: Vector2i = target.get("pos", Vector2i(-1, -1)) @@ -4605,6 +4650,11 @@ func _target_preview_badge() -> Dictionary: if _has_pending_move() and not basic_attack_targeting: return {} var attack_badge := _attack_target_preview_badge(selected, target) + if not attack_badge.is_empty() and (str(attack_badge.get("kind", "")) != "invalid" or basic_attack_targeting or _has_pending_move()): + return attack_badge + var auto_attack_badge := _auto_attack_target_preview_badge(selected, target) + if not auto_attack_badge.is_empty(): + return auto_attack_badge if not attack_badge.is_empty(): return attack_badge return _hover_intent_preview_badge(selected, target) @@ -4645,6 +4695,59 @@ func _attack_preview_badge_kind(preview: Dictionary) -> String: return "damage" +func _auto_attack_target_preview_badge(selected: Dictionary, target: Dictionary) -> Dictionary: + if selected.is_empty() or target.is_empty(): + return {} + if selected.get("team", "") == target.get("team", ""): + return {} + if bool(selected.get("moved", false)) or bool(selected.get("acted", false)): + return {} + var current_cell: Vector2i = selected.get("pos", Vector2i(-1, -1)) + var attack_origin := _best_auto_attack_origin(selected, target) + if attack_origin == Vector2i(-1, -1) or attack_origin == current_cell: + return {} + return _auto_attack_target_preview_badge_for_origin(selected, target, attack_origin) + + +func _auto_attack_target_preview_badge_for_origin(selected: Dictionary, target: Dictionary, attack_origin: Vector2i) -> Dictionary: + var target_cell: Vector2i = target.get("pos", Vector2i(-1, -1)) + if not state.is_inside(attack_origin) or not state.is_inside(target_cell): + return {} + var candidate_attacker := selected.duplicate(true) + candidate_attacker["pos"] = attack_origin + var damage := state.calculate_damage(candidate_attacker, target) + var hit_chance := state.calculate_hit_chance(candidate_attacker, target) + var result_text := "행공 퇴각" if int(target.get("hp", 0)) - damage <= 0 else "행공 -%d" % damage + var counter_text := _format_auto_attack_counter_badge_suffix(candidate_attacker, target, damage) + return _make_target_preview_badge_at("%s %d%%%s" % [result_text, hit_chance, counter_text], _auto_attack_preview_badge_kind(candidate_attacker, target, damage), target_cell) + + +func _format_auto_attack_counter_badge_suffix(candidate_attacker: Dictionary, target: Dictionary, damage: int) -> String: + if int(target.get("hp", 0)) - damage <= 0: + return "" + var origin: Vector2i = candidate_attacker.get("pos", Vector2i(-1, -1)) + var target_cell: Vector2i = target.get("pos", Vector2i(-1, -1)) + if not _can_attack_target_from(target, target_cell, origin): + return "" + var counter_damage := state.calculate_damage(target, candidate_attacker) + if int(candidate_attacker.get("hp", 0)) - counter_damage <= 0: + return " 반격!" + return " 반%d" % counter_damage + + +func _auto_attack_preview_badge_kind(candidate_attacker: Dictionary, target: Dictionary, damage: int) -> String: + if int(target.get("hp", 0)) - damage <= 0: + return "advance" + var origin: Vector2i = candidate_attacker.get("pos", Vector2i(-1, -1)) + var target_cell: Vector2i = target.get("pos", Vector2i(-1, -1)) + if not _can_attack_target_from(target, target_cell, origin): + return "advance" + var counter_damage := state.calculate_damage(target, candidate_attacker) + if int(candidate_attacker.get("hp", 0)) - counter_damage <= 0: + return "danger" + return "counter" + + func _skill_target_preview_badge(selected: Dictionary, target: Dictionary) -> Dictionary: return _skill_target_preview_badge_for_cell(selected, target, hover_cell) @@ -4810,6 +4913,8 @@ func _target_preview_badge_color(kind: String) -> Color: return Color(1.0, 0.64, 0.22) if kind == "danger": return Color(1.0, 0.18, 0.14) + if kind == "advance": + return Color(0.44, 0.82, 0.76) if kind == "move": return Color(0.38, 0.70, 1.0) if kind == "select": diff --git a/tools/smoke_post_move_action_flow.gd b/tools/smoke_post_move_action_flow.gd index ae7d6c7..c0249b4 100644 --- a/tools/smoke_post_move_action_flow.gd +++ b/tools/smoke_post_move_action_flow.gd @@ -384,8 +384,54 @@ func _check_scene_enemy_click_auto_attack(failures: Array[String]) -> void: scene.free() return scene._refresh_ranges() + if scene._is_targeting_mode(): + failures.append("move+attack marker setup should not enter formal targeting mode") if scene.attack_cells.has(Vector2i(4, 3)): failures.append("auto attack setup enemy should start outside current attack range") + var auto_markers := scene._target_selection_marker_entries() + var found_auto_marker := false + for marker in auto_markers: + if marker.get("cell", Vector2i.ZERO) != Vector2i(4, 3): + continue + found_auto_marker = true + if marker.get("target_id", "") != "yellow_turban_1": + failures.append("move+attack marker should keep the clicked target id: %s" % str(marker)) + if marker.get("text", "") != "행공": + failures.append("move+attack marker should use compact battlefield text: %s" % str(marker)) + if marker.get("origin", Vector2i.ZERO) != Vector2i(3, 3): + failures.append("move+attack marker should expose the chosen attack origin: %s" % str(marker)) + if marker.get("origin", Vector2i.ZERO) == Vector2i(1, 3): + failures.append("move+attack marker origin should differ from the current cell: %s" % str(marker)) + if not bool(marker.get("requires_move", false)): + failures.append("move+attack marker should flag that movement is required: %s" % str(marker)) + if not found_auto_marker: + failures.append("selected unit should mark enemies reachable by move+attack: %s" % str(auto_markers)) + scene.hover_cell = Vector2i(4, 3) + var auto_badge := scene._target_preview_badge() + if not str(auto_badge.get("text", "")).contains("행공"): + failures.append("hovering a move+attack target should explain the combined action: %s" % str(auto_badge)) + if not ["advance", "counter", "danger"].has(str(auto_badge.get("kind", ""))): + failures.append("move+attack hover badge should use an attack-risk color kind: %s" % str(auto_badge)) + + cao_cao["status_effects"] = [{ + "type": "action_lock", + "status": "disarm", + "action": "attack", + "remaining_phases": 2 + }] + scene._refresh_ranges() + for marker in scene._target_selection_marker_entries(): + if marker.get("target_id", "") == "yellow_turban_1": + failures.append("attack-locked units should not mark move+attack targets: %s" % str(marker)) + scene.hover_cell = Vector2i(4, 3) + var locked_badge := scene._target_preview_badge() + if str(locked_badge.get("text", "")).contains("행공"): + failures.append("attack-locked hover badge should not offer move+attack: %s" % str(locked_badge)) + scene._handle_board_click(_screen_for_cell(Vector2i(4, 3))) + if cao_cao.get("pos", Vector2i.ZERO) != Vector2i(1, 3) or int(enemy.get("hp", 0)) != 24: + failures.append("attack-locked enemy click should not auto-move or attack") + cao_cao["status_effects"] = [] + scene._refresh_ranges() scene._handle_board_click(_screen_for_cell(Vector2i(4, 3))) cao_cao = scene.state.get_unit("cao_cao") enemy = scene.state.get_unit("yellow_turban_1")