extends SceneTree ## Matador stab-reliability test. The matador runs in, plants at mat_stab_standoff, and its stab ## damages off the sword's own BladeHitbox collider (armed only during the thrust) — NOT a distance ## check. This drives the attack tick against a STATIONARY, real-sized bull placed beyond the ## standoff and asserts it (a) gores the bull when the thrust physically reaches it, (b) lands the ## hit during the thrust and not the wind-up/walk-up, and (c) plants at the standoff, not inside the ## bull, and (d) keeps landing on repeat stabs from the same spot (the blade re-arms each swing). ## Run: godot --headless --script res://tests/matador_stab_test.gd var _pass := 0 var _fail := 0 func _init() -> void: _run.call_deferred() func _ok(c: bool, m: String) -> void: if c: _pass += 1 print(" PASS: ", m) else: _fail += 1 print(" FAIL: ", m) func _run() -> void: var dp := root.get_node("/root/DP") var standoff: float = dp.f("mat_stab_standoff") var strike_at: float = dp.f("mat_stab_strike_at") # Stationary, real-sized bull beyond the standoff — the matador runs in, plants at the standoff, # and its THRUST (not the walk-up) has to reach across the gap to gore it. var bull := CharacterBody3D.new() bull.collision_layer = 2 bull.collision_mask = 0 bull.add_to_group(&"player") bull.set_script(load("res://tests/_fake_bull.gd")) var bcs := CollisionShape3D.new() var bshape := CapsuleShape3D.new() bshape.radius = 0.75 bshape.height = 1.845 bcs.shape = bshape bull.add_child(bcs) root.add_child(bull) bull.global_position = Vector3(0.0, 0.0, standoff + 3.0) var mat := (load("res://Matador.tscn") as PackedScene).instantiate() as CharacterBody3D root.add_child(mat) # _ready acquires the bull from the "player" group mat.global_position = Vector3.ZERO mat.set_physics_process(false) # we drive the attack tick ourselves, isolated from the AI await physics_frame mat.call("_acquire_bull") # normally done in _physics_process, which we disabled _ok(mat.get("_bull") == bull, "matador acquired the bull") mat.call("_carry_sword", true) # actually draw into the hand so the BladeHitbox rides the thrust mat.call("_start_attack") dp.call("set_value", "mat_stab_followup_chance", 0.0) # isolate repeat stabs from the break-off roll dp.call("set_value", "mat_stab_recovery", 0.0) # no recovery beat gating back-to-back stabs dp.call("set_value", "mat_taunt_after_hit", 0.0) # don't break off to taunt after a landed hit var min_dist := 999.0 var first_hit_phase := -1.0 var last_hits := 0 for i in 300: # several swings' worth of ticks (approach + repeated stabs) mat.call("_tick_attack", 1.0 / 60.0) var d := mat.global_position.distance_to(bull.global_position) min_dist = minf(min_dist, d) if bull.hits > last_hits: if first_hit_phase < 0.0: first_hit_phase = mat.call("_swing_phase") # phase on the frame the first hit landed last_hits = bull.hits await physics_frame _ok(bull.hits >= 1, "the sword's thrust reaches across the standoff and gores the bull") _ok(first_hit_phase >= strike_at - 0.1, "hit lands in the thrust, not the wind-up (phase %.2f)" % first_hit_phase) _ok(bull.hits >= 2, "repeat stabs from the same spot keep landing (%d hits)" % bull.hits) _ok(min_dist >= standoff - 0.5, "matador plants at the standoff, not inside the bull (closest %.2f m)" % min_dist) # Anti-spam: once a stab CONNECTS, a high mat_taunt_after_hit must break the matador off ATTACK # (into a taunt/retreat) instead of drilling the bull again. Force the roll and confirm it leaves. dp.call("set_value", "mat_taunt_after_hit", 1.0) bull.hits = 0 mat.call("_start_attack") var broke_off := false for i in 200: mat.call("_tick_attack", 1.0 / 60.0) if mat.call("ai_state_name") != "ATTACK": broke_off = true break await physics_frame _ok(broke_off, "a landed stab breaks the matador off ATTACK (taunt/retreat), not another thrust") _ok(bull.hits >= 1, "the break-off only fires after the stab actually connected (%d hits)" % bull.hits) _finish() func _finish() -> void: print("Results: %d passed, %d failed" % [_pass, _fail]) quit(1 if _fail > 0 else 0)