Add class-specific attack presentation

This commit is contained in:
2026-06-18 17:37:47 +09:00
parent c928bb64b7
commit 84ccead01c
5 changed files with 244 additions and 23 deletions

View File

@@ -121,7 +121,7 @@ Godot 4 tactical RPG prototype inspired by classic turn-based Romance of the Thr
- Placeholder menu/battle BGM plus UI, movement, attack, tactic, item, victory, and defeat SFX.
- Floating combat text for damage, recovery, misses, support effects, poison ticks, action locks, level-ups, and promotions.
- Short unit slide animation for board movement.
- Board attacks now request a short strike animation, with melee lunges and ranged attack traces drawn by the battle scene.
- Board attacks now request class-specific motion profiles, with infantry strikes, archer traces, cavalry charges, command flashes, and heavy warrior/bandit impacts drawn by the battle scene.
- Battle maps can use a high-resolution background image with translucent terrain overlays and terrain-specific detail patterns.
- Hover target preview badges for attacks, tactics, and items.
- Low-HP board unit warning rings, HP bar color states, and board status pips plus HUD duration summaries for support, debuff, poison, seal, snare, and disarm effects.

View File

@@ -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, 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, a short attack motion, 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, 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. 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, 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, 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,6 +59,6 @@ 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, 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. 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. 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, or finite-stock purchases; 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, current terrain move cost, defense/avoid bonuses, core stats, status effects, and gear, board maps can draw a scenario background texture under translucent terrain overlays and terrain detail patterns, board units render class sprite tokens, team rings, class badges, 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` asks the scene to render a short attack motion, 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, current terrain move cost, defense/avoid bonuses, core stats, status effects, and gear, board maps can draw a scenario background texture under translucent terrain overlays and terrain detail patterns, board units render class sprite tokens, team rings, class badges, 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 `New Campaign` button clears `user://campaign_save.json`, resets campaign state to the first scenario, and reloads the opening briefing.

View File

@@ -135,7 +135,7 @@
## Milestone 5: Presentation
- Portrait and art pipeline. Officer definitions can provide default portrait paths, classes can provide board `sprite` paths, items can provide `icon` paths, scenarios can provide map `background` paths, and the first generated officer portraits, unit sprites, item icons, and battlefield background are in `art/`.
- Unit sprites and animations. Board movement now has a short slide animation, attacks request a short strike animation, and board units show class sprite tokens, team rings, class badges, low-HP warning rings, and small status pips for active support, debuff, poison, seal, snare, and disarm effects, with HUD summaries showing remaining phases.
- Unit sprites and animations. Board movement now has a short slide animation, attacks request class-specific motion profiles for infantry, archers, cavalry, command units, and heavy warrior/bandit units, and board units show class sprite tokens, team rings, class badges, low-HP warning rings, and small status pips for active support, debuff, poison, seal, snare, and disarm effects, with HUD summaries showing remaining phases.
- Battlefield presentation. Maps can draw a high-resolution background under translucent terrain overlays, with first terrain-specific detail patterns for plains, forest, hill, road, water, and castle cells.
- Battle HUD presentation. Selected and hovered units now summarize battlefield role, movement type, current terrain move cost, defense/avoid bonuses, core stats, status effects, and gear so class identity reads alongside the visual tokens.
- Battle effects. First floating combat text now covers damage, recovery, misses, support effects, poison ticks, item and gold pickups, AI target-focus changes, level-ups, and promotions. Hover target preview badges summarize attacks, tactics, and items, and the board can overlay enemy threat ranges with physical damage and hostile tactic hints.

View File

@@ -47,6 +47,11 @@ const UNIT_STATUS_MARKER_OFFSET_Y := 14.0
const MAX_UNIT_STATUS_MARKERS := 4
const UNIT_ATTACK_ANIMATION_DURATION := 0.30
const UNIT_ATTACK_LUNGE_DISTANCE := 15.0
const UNIT_INFANTRY_ATTACK_DURATION := 0.32
const UNIT_CAVALRY_ATTACK_DURATION := 0.42
const UNIT_ARROW_ATTACK_DURATION := 0.36
const UNIT_COMMAND_ATTACK_DURATION := 0.38
const UNIT_HEAVY_ATTACK_DURATION := 0.34
const DIALOGUE_PANEL_POSITION := Vector2(96, 448)
const DIALOGUE_PANEL_SIZE := Vector2(1040, 210)
const DIALOGUE_PORTRAIT_SIZE := Vector2(164, 186)
@@ -956,9 +961,6 @@ func _handle_board_click(screen_position: Vector2) -> void:
return
if not clicked_unit.is_empty() and clicked_unit.get("team", "") != selected_unit.get("team", ""):
var attack_sfx := "bow_release" if int(selected_unit.get("range", 1)) > 1 else "slash"
if attack_cells.has(clicked_unit.get("pos", Vector2i(-1, -1))):
_play_sfx(attack_sfx)
if state.try_attack_selected(clicked_unit["id"]):
selected_skill_id = ""
selected_item_id = ""
@@ -1406,7 +1408,7 @@ func _visual_rect_for_unit(unit: Dictionary) -> Rect2:
var action_duration: float = maxf(0.01, float(action_motion.get("duration", UNIT_ATTACK_ANIMATION_DURATION)))
var action_age := float(action_motion.get("age", 0.0))
var action_progress := clampf(action_age / action_duration, 0.0, 1.0)
var lunge_scale := 0.35 if str(action_motion.get("style", "melee")) == "ranged" else 1.0
var lunge_scale := _action_motion_lunge_scale(str(action_motion.get("profile", "slash")))
rect.position += direction * sin(action_progress * PI) * UNIT_ATTACK_LUNGE_DISTANCE * lunge_scale
return rect
@@ -1437,17 +1439,94 @@ func _draw_attack_effects() -> void:
var unit := state.get_unit(str(unit_id))
if not unit.is_empty() and unit.get("team", "") == BattleState.TEAM_ENEMY:
team_color = ENEMY_COLOR
var flash := team_color.lightened(0.45)
flash.a = 0.55 * peak
if str(motion.get("style", "melee")) == "ranged":
var head := start.lerp(end, clampf(progress + 0.18, 0.0, 1.0))
var tail := start.lerp(end, clampf(progress - 0.18, 0.0, 1.0))
draw_line(tail, head, flash, 3.0)
draw_circle(head, 4.0 + 4.0 * peak, Color(1.0, 0.92, 0.52, 0.42 * peak))
else:
draw_line(end + Vector2(-18, -13), end + Vector2(18, 13), flash, 3.0)
draw_line(end + Vector2(16, -14), end + Vector2(-14, 15), Color(1.0, 0.88, 0.42, 0.38 * peak), 2.0)
draw_circle(end, 8.0 + 8.0 * peak, Color(1.0, 0.82, 0.34, 0.20 * peak))
_draw_action_effect(str(motion.get("profile", "slash")), start, end, progress, peak, team_color)
func _draw_action_effect(profile: String, start: Vector2, end: Vector2, progress: float, peak: float, team_color: Color) -> void:
if profile == "arrow":
_draw_arrow_attack_effect(start, end, progress, peak, team_color)
elif profile == "cavalry_charge":
_draw_cavalry_attack_effect(start, end, progress, peak, team_color)
elif profile == "infantry_strike":
_draw_infantry_attack_effect(end, peak, team_color)
elif profile == "command_strike":
_draw_command_attack_effect(start, end, progress, peak, team_color)
elif profile == "heavy_strike":
_draw_heavy_attack_effect(end, peak, team_color)
else:
_draw_slash_attack_effect(end, peak, team_color)
func _draw_arrow_attack_effect(start: Vector2, end: Vector2, progress: float, peak: float, team_color: Color) -> void:
var direction := end - start
if direction.length() <= 0.01:
return
direction = direction.normalized()
var side := Vector2(-direction.y, direction.x)
var head := start.lerp(end, clampf(progress + 0.20, 0.0, 1.0))
var tail := start.lerp(end, clampf(progress - 0.18, 0.0, 1.0))
var shaft := Color(1.0, 0.86, 0.42, 0.76 * peak)
draw_line(tail, head, shaft, 3.0)
draw_line(head, head - direction * 9.0 + side * 4.5, Color(1.0, 0.96, 0.66, 0.70 * peak), 2.0)
draw_line(head, head - direction * 9.0 - side * 4.5, Color(1.0, 0.96, 0.66, 0.70 * peak), 2.0)
var wake := team_color.lightened(0.48)
wake.a = 0.22 * peak
draw_line(tail - side * 5.0, head - side * 5.0, wake, 1.5)
draw_line(tail + side * 5.0, head + side * 5.0, wake, 1.5)
draw_circle(head, 3.5 + 4.0 * peak, Color(1.0, 0.92, 0.52, 0.36 * peak))
func _draw_cavalry_attack_effect(start: Vector2, end: Vector2, progress: float, peak: float, team_color: Color) -> void:
var direction := end - start
if direction.length() <= 0.01:
return
direction = direction.normalized()
var side := Vector2(-direction.y, direction.x)
for index in range(3):
var lane_offset := side * float(index - 1) * 7.0
var dust_head := start.lerp(end, clampf(progress - float(index) * 0.05, 0.0, 1.0))
var dust_tail := dust_head - direction * (16.0 + float(index) * 5.0)
draw_line(dust_tail + lane_offset, dust_head + lane_offset, Color(0.86, 0.72, 0.42, 0.24 * peak), 2.0)
var lance := team_color.lightened(0.52)
lance.a = 0.68 * peak
draw_line(end - direction * 22.0, end + direction * 12.0, lance, 4.0)
draw_line(end - side * 15.0, end + side * 15.0, Color(1.0, 0.88, 0.34, 0.34 * peak), 2.0)
draw_circle(end, 9.0 + 13.0 * peak, Color(1.0, 0.66, 0.22, 0.18 * peak))
func _draw_infantry_attack_effect(end: Vector2, peak: float, team_color: Color) -> void:
var guard_flash := team_color.lightened(0.48)
guard_flash.a = 0.58 * peak
draw_line(end + Vector2(-16, -10), end + Vector2(17, 11), guard_flash, 3.0)
draw_line(end + Vector2(-14, 10), end + Vector2(14, -10), Color(1.0, 0.88, 0.42, 0.32 * peak), 2.0)
draw_rect(Rect2(end + Vector2(-9, -14), Vector2(18, 20)), Color(0.72, 0.82, 0.94, 0.16 * peak), false, 2.0)
draw_arc(end, 8.0 + 9.0 * peak, -PI * 0.80, PI * 0.20, 24, Color(1.0, 0.92, 0.54, 0.34 * peak), 2.0)
func _draw_command_attack_effect(start: Vector2, end: Vector2, progress: float, peak: float, team_color: Color) -> void:
var beam := Color(0.72, 0.92, 1.0, 0.34 * peak)
draw_line(start, end, beam, 2.0)
var command_color := team_color.lightened(0.58)
command_color.a = 0.56 * peak
draw_arc(end, 10.0 + 12.0 * peak, 0.0, TAU, 48, command_color, 2.0)
draw_arc(end, 20.0 - 6.0 * peak, progress * TAU, progress * TAU + PI * 1.35, 36, Color(1.0, 0.96, 0.62, 0.42 * peak), 2.0)
draw_circle(end, 6.0 + 8.0 * peak, Color(0.72, 0.92, 1.0, 0.18 * peak))
func _draw_heavy_attack_effect(end: Vector2, peak: float, team_color: Color) -> void:
var heavy := team_color.lightened(0.42)
heavy.a = 0.62 * peak
draw_line(end + Vector2(-20, -16), end + Vector2(20, 16), heavy, 5.0)
draw_line(end + Vector2(18, -18), end + Vector2(-18, 18), Color(1.0, 0.82, 0.28, 0.48 * peak), 4.0)
draw_arc(end, 10.0 + 18.0 * peak, 0.0, TAU, 48, Color(1.0, 0.68, 0.24, 0.26 * peak), 3.0)
func _draw_slash_attack_effect(end: Vector2, peak: float, team_color: Color) -> void:
var flash := team_color.lightened(0.45)
flash.a = 0.55 * peak
draw_line(end + Vector2(-18, -13), end + Vector2(18, 13), flash, 3.0)
draw_line(end + Vector2(16, -14), end + Vector2(-14, 15), Color(1.0, 0.88, 0.42, 0.38 * peak), 2.0)
draw_circle(end, 8.0 + 8.0 * peak, Color(1.0, 0.82, 0.34, 0.20 * peak))
func _draw_floating_texts() -> void:
@@ -2370,19 +2449,86 @@ func _on_unit_action_motion_requested(unit_id: String, from_cell: Vector2i, to_c
if unit_id.is_empty() or from_cell == to_cell:
return
var unit := state.get_unit(unit_id)
var distance := absi(from_cell.x - to_cell.x) + absi(from_cell.y - to_cell.y)
var style := "ranged" if int(unit.get("range", 1)) > 1 and distance > 1 else "melee"
var profile := _unit_action_motion_profile(unit, from_cell, to_cell, action_kind)
unit_action_motion_by_unit[unit_id] = {
"from": from_cell,
"to": to_cell,
"kind": action_kind,
"style": style,
"profile": profile,
"attack_family": profile,
"style": _action_motion_style(profile),
"age": 0.0,
"duration": UNIT_ATTACK_ANIMATION_DURATION
"duration": _action_motion_duration(profile)
}
if is_inside_tree():
_play_sfx(_action_motion_sfx(profile))
queue_redraw()
func _unit_action_motion_profile(unit: Dictionary, from_cell: Vector2i, to_cell: Vector2i, _action_kind: String) -> String:
var class_id := str(unit.get("class_id", ""))
var distance := absi(from_cell.x - to_cell.x) + absi(from_cell.y - to_cell.y)
if class_id.contains("archer") or class_id.contains("marksman") or (int(unit.get("range", 1)) > 1 and distance > 1):
return "arrow"
if class_id.contains("cavalry"):
return "cavalry_charge"
if class_id == "infantry" or class_id == "guard_captain":
return "infantry_strike"
if class_id.contains("strategist") or class_id.contains("advisor") or class_id.contains("hero") or class_id.contains("commander"):
return "command_strike"
if class_id.contains("warrior") or class_id.contains("champion") or class_id.contains("bandit"):
return "heavy_strike"
return "slash"
func _action_motion_style(profile: String) -> String:
if profile == "arrow":
return "ranged"
return "melee"
func _action_motion_duration(profile: String) -> float:
if profile == "arrow":
return UNIT_ARROW_ATTACK_DURATION
if profile == "cavalry_charge":
return UNIT_CAVALRY_ATTACK_DURATION
if profile == "infantry_strike":
return UNIT_INFANTRY_ATTACK_DURATION
if profile == "command_strike":
return UNIT_COMMAND_ATTACK_DURATION
if profile == "heavy_strike":
return UNIT_HEAVY_ATTACK_DURATION
return UNIT_ATTACK_ANIMATION_DURATION
func _action_motion_lunge_scale(profile: String) -> float:
if profile == "arrow":
return 0.22
if profile == "cavalry_charge":
return 1.65
if profile == "infantry_strike":
return 0.95
if profile == "command_strike":
return 0.20
if profile == "heavy_strike":
return 1.15
return 1.0
func _action_motion_sfx(profile: String) -> String:
if profile == "arrow":
return "bow_release"
if profile == "cavalry_charge":
return "footstep"
if profile == "infantry_strike":
return "slash"
if profile == "command_strike":
return "skill_cast"
if profile == "heavy_strike":
return "slash"
return "slash"
func _floating_text_origin(cell: Vector2i) -> Vector2:
var rect := _rect_for_cell(cell)
return rect.position + Vector2(TILE_SIZE * 0.5, 18.0)

View File

@@ -9,6 +9,7 @@ func _init() -> void:
_check_battle_visual_data(failures)
_check_scene_texture_loading(failures)
_check_hud_focus_text(failures)
_check_attack_motion_profiles(failures)
_check_attack_motion_signal(failures)
if failures.is_empty():
@@ -119,6 +120,80 @@ func _check_hud_focus_text(failures: Array[String]) -> void:
scene.free()
func _check_attack_motion_profiles(failures: Array[String]) -> void:
var scene = BattleSceneScript.new()
if not scene.state.load_battle("res://data/scenarios/001_yellow_turbans.json"):
failures.append("could not load battle scene state for attack profiles")
scene.free()
return
_check_attack_profile(failures, scene, "cao_cao", Vector2i(1, 3), Vector2i(2, 3), "command_strike")
_check_attack_profile(failures, scene, "xiahou_dun", Vector2i(1, 4), Vector2i(2, 4), "cavalry_charge")
_check_attack_profile(failures, scene, "yellow_turban_1", Vector2i(7, 2), Vector2i(6, 2), "heavy_strike")
_check_attack_profile(failures, scene, "yellow_turban_2", Vector2i(8, 5), Vector2i(7, 5), "infantry_strike")
_check_attack_profile(failures, scene, "yellow_turban_3", Vector2i(7, 6), Vector2i(7, 4), "arrow")
_check_synthetic_attack_profile(failures, scene, "elite_cavalry", "cavalry_charge")
_check_synthetic_attack_profile(failures, scene, "guard_captain", "infantry_strike")
_check_synthetic_attack_profile(failures, scene, "marksman", "arrow", 2)
_check_synthetic_attack_profile(failures, scene, "military_advisor", "command_strike")
_check_synthetic_attack_profile(failures, scene, "commander", "command_strike")
_check_synthetic_attack_profile(failures, scene, "champion", "heavy_strike")
_check_synthetic_attack_profile(failures, scene, "bandit", "heavy_strike")
scene._on_unit_action_motion_requested("xiahou_dun", Vector2i(1, 4), Vector2i(2, 4), "attack")
_check_stored_attack_motion(failures, scene, "xiahou_dun", "cavalry_charge", "melee", "attack")
scene._on_unit_action_motion_requested("yellow_turban_3", Vector2i(7, 6), Vector2i(7, 4), "attack")
_check_stored_attack_motion(failures, scene, "yellow_turban_3", "arrow", "ranged", "attack")
if scene._action_motion_duration("cavalry_charge") <= scene._action_motion_duration("slash"):
failures.append("cavalry charge animation should last longer than default slash")
if scene._action_motion_lunge_scale("arrow") >= scene._action_motion_lunge_scale("slash"):
failures.append("arrow animation should keep the archer mostly planted")
if scene._action_motion_sfx("arrow") != "bow_release":
failures.append("arrow animation should use bow SFX")
if scene._action_motion_sfx("infantry_strike") != "slash":
failures.append("infantry animation should use slash SFX")
if scene._action_motion_sfx("heavy_strike") != "slash":
failures.append("heavy animation should use swing SFX before hit resolution")
scene.free()
func _check_attack_profile(failures: Array[String], scene, unit_id: String, from_cell: Vector2i, to_cell: Vector2i, expected_profile: String) -> void:
var unit: Dictionary = scene.state.get_unit(unit_id)
if unit.is_empty():
failures.append("missing unit for attack profile: %s" % unit_id)
return
var profile: String = scene._unit_action_motion_profile(unit, from_cell, to_cell, "attack")
if profile != expected_profile:
failures.append("%s attack profile mismatch: expected %s got %s" % [unit_id, expected_profile, profile])
func _check_synthetic_attack_profile(failures: Array[String], scene, class_id: String, expected_profile: String, attack_range := 1) -> void:
var unit := {
"class_id": class_id,
"range": attack_range
}
var profile: String = scene._unit_action_motion_profile(unit, Vector2i(0, 0), Vector2i(0, max(1, attack_range)), "attack")
if profile != expected_profile:
failures.append("%s synthetic attack profile mismatch: expected %s got %s" % [class_id, expected_profile, profile])
func _check_stored_attack_motion(failures: Array[String], scene, unit_id: String, expected_profile: String, expected_style: String, expected_kind: String) -> void:
if not scene.unit_action_motion_by_unit.has(unit_id):
failures.append("%s should store an action motion" % unit_id)
return
var motion: Dictionary = scene.unit_action_motion_by_unit[unit_id]
var profile := str(motion.get("profile", ""))
var family := str(motion.get("attack_family", ""))
var style := str(motion.get("style", ""))
var kind := str(motion.get("kind", ""))
if profile != expected_profile or family != expected_profile:
failures.append("%s stored motion profile mismatch: %s" % [unit_id, str(motion)])
if style != expected_style:
failures.append("%s stored motion style mismatch: %s" % [unit_id, str(motion)])
if kind != expected_kind:
failures.append("%s stored motion kind mismatch: %s" % [unit_id, str(motion)])
if float(motion.get("duration", 0.0)) <= 0.0:
failures.append("%s stored motion duration should be positive: %s" % [unit_id, str(motion)])
func _check_attack_motion_signal(failures: Array[String]) -> void:
var state = BattleStateScript.new()
if not state.load_battle("res://data/scenarios/001_yellow_turbans.json"):