152 lines
8.5 KiB
C#
152 lines
8.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using NUnit.Framework;
|
|
using TKS.OutGame;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.TestTools;
|
|
|
|
namespace TKS.Tests
|
|
{
|
|
/// <summary>
|
|
/// 끌기 조준(PD 2026-11-18 게임성 변경안 · AimRules.DragMode) 확인 캡처 — 환경 변수 TKS_AIMCAP(저장 폴더)이 있을 때만.
|
|
/// 아군 원거리·근접 유닛을 실제 조준 루틴(OnHold · RefreshGauge)으로 끌어 놓은 상태를 찍고, 끈 거리별 이동 거리 · 판정 칸을 aim_log.txt 에 쓴다.
|
|
/// </summary>
|
|
public class AimCaptureTests
|
|
{
|
|
static readonly BindingFlags NP = BindingFlags.NonPublic | BindingFlags.Instance;
|
|
|
|
[UnityTest, Category("AimCapture")]
|
|
public IEnumerator DragAim_Capture()
|
|
{
|
|
string dir = Environment.GetEnvironmentVariable("TKS_AIMCAP");
|
|
if (string.IsNullOrEmpty(dir))
|
|
{
|
|
Assert.Ignore("끌기 조준 캡처 = 환경 변수 TKS_AIMCAP 이 있을 때만");
|
|
yield break;
|
|
}
|
|
Directory.CreateDirectory(dir);
|
|
LogAssert.ignoreFailingMessages = true;
|
|
int prevMode = TestOptions.AimModeOverride;
|
|
TestOptions.AimModeOverride = 1;
|
|
WorldProgress.Reset();
|
|
SaveStore.UseMemory(true);
|
|
SceneManager.LoadScene("Battle");
|
|
yield return null;
|
|
yield return null;
|
|
var bm = BattleManager.Instance;
|
|
var session = OutGameSession.Current;
|
|
var lineup = new List<LineupEntry>();
|
|
foreach (var id in new[] { "liubei", "guanyu", "zhangfei", "huangzhong", "zhugeliang" })
|
|
{
|
|
var h = session.Def(id);
|
|
if (h == null) continue;
|
|
var e = new LineupEntry { slot = lineup.Count, id = h.id, name = h.nameKo, type = h.type, art = h.art, hpMult = h.hpMult, atkMult = h.atkMult, defMult = h.defMult };
|
|
SkillRules.FillLineup(session.Db, session.Save, h, e);
|
|
lineup.Add(e);
|
|
}
|
|
bm.LineupProvider = () => lineup;
|
|
int idx = Array.FindIndex(bm.Config.stages, s => s.chapter == 2 && s.stage == 1);
|
|
bm.StartStage(Mathf.Max(0, idx));
|
|
BossIntro.Abort();
|
|
if (bm.Phase == BattlePhase.Setup) bm.ForcePhase(BattlePhase.PlayerTurn);
|
|
yield return null;
|
|
var input = UnityEngine.Object.FindFirstObjectByType<SlingshotInput>();
|
|
Assert.IsNotNull(input);
|
|
var log = new StringBuilder();
|
|
log.AppendLine("aim_mode=" + AimRules.Mode + " drag_gain=" + IbUi.Num("drag_gain", 0f) + " sweep=" + IbUi.Num("crit_sweep_sec", 0f));
|
|
var alive = bm.AliveUnits(Faction.Player);
|
|
var targets = new List<Unit>();
|
|
var r0 = alive.Find(x => UnitTypeInfo.IsRanged(x.Type));
|
|
var m0 = alive.Find(x => !UnitTypeInfo.IsRanged(x.Type));
|
|
if (r0 != null) targets.Add(r0);
|
|
if (m0 != null) targets.Add(m0);
|
|
foreach (var u in targets)
|
|
{
|
|
bool ranged = UnitTypeInfo.IsRanged(u.Type);
|
|
// 끈 거리별 이동 거리(화살표 길이)
|
|
foreach (var pull in new[] { 0.5f, 1.5f, 2.5f, 3.5f, 5f })
|
|
{
|
|
var p = input.DragPoint(u, u.Position + Vector2.up * (u.Radius * bm.Config.aimStartRadiusRatio + pull));
|
|
log.AppendLine(u.DisplayName + " " + u.Type + " 끈 거리 " + pull + " → 이동 " + (p.HasValue ? Vector2.Distance(u.Position, p.Value).ToString("0.00") : "-") + " (최대 " + SkillMods.SlingMax(u).ToString("0.00") + ")");
|
|
}
|
|
// 실제 조준 상태 만들기: 누름 → 끌기 → 0.2 초 뒤 게이지
|
|
input.Select(u);
|
|
typeof(SlingshotInput).GetField("aiming", NP).SetValue(input, false); // 누름 = 조준 꺼진 상태에서 시작(OnPress 와 같게)
|
|
typeof(SlingshotInput).GetField("dragging", NP).SetValue(input, true);
|
|
typeof(SlingshotInput).GetField("aimArmed", NP).SetValue(input, true);
|
|
var hold = typeof(SlingshotInput).GetMethod("OnHold", NP);
|
|
if (u.View != null) u.View.SetAiming(true); // 누름 = 조준 자세 · 조준 중 유닛을 화살표 위로(SetAimLift)
|
|
Vector2 finger = u.Position + new Vector2(0.6f, 1f).normalized * (u.Radius * bm.Config.aimStartRadiusRatio + 4f);
|
|
hold.Invoke(input, new object[] { finger });
|
|
typeof(SlingshotInput).GetField("aimStart", NP).SetValue(input, Time.unscaledTime - 0.2f);
|
|
hold.Invoke(input, new object[] { finger });
|
|
typeof(SlingshotInput).GetMethod("RefreshGauge", NP).Invoke(input, null);
|
|
float lo = (float)typeof(SlingshotInput).GetField("hitLo", NP).GetValue(input), hi = (float)typeof(SlingshotInput).GetField("hitHi", NP).GetValue(input);
|
|
float clo = (float)typeof(SlingshotInput).GetField("critLo", NP).GetValue(input), chi = (float)typeof(SlingshotInput).GetField("critHi", NP).GetValue(input);
|
|
log.AppendLine(u.DisplayName + " 게이지 " + input.Gauge.ToString("0.00") + " · 회색 " + lo.ToString("0.00") + "~" + hi.ToString("0.00") + " · 빨강 " + clo.ToString("0.00") + "~" + chi.ToString("0.00") + " · 게이지 보임 " + input.GaugeVisible + " · 화살표 " + input.AimArrowVisible);
|
|
var cam = Camera.main;
|
|
var cc = UnityEngine.Object.FindFirstObjectByType<CameraController>();
|
|
if (cc != null) cc.enabled = false;
|
|
cam.transform.position = new Vector3(u.Position.x + 1f, u.Position.y + 1.5f, cam.transform.position.z);
|
|
cam.orthographicSize = 4.5f;
|
|
yield return null;
|
|
hold.Invoke(input, new object[] { finger }); // 프레임이 지나 게이지가 움직였으니 다시 맞춤
|
|
typeof(SlingshotInput).GetMethod("RefreshGauge", NP).Invoke(input, null);
|
|
Capture(cam, Path.Combine(dir, (ranged ? "aim_ranged_" : "aim_melee_") + u.HeroId + ".png"));
|
|
if (cc != null) cc.enabled = true;
|
|
typeof(SlingshotInput).GetMethod("CancelAim", NP).Invoke(input, null);
|
|
if (u.View != null) u.View.SetAiming(false);
|
|
typeof(SlingshotInput).GetField("dragging", NP).SetValue(input, false);
|
|
input.Select(null);
|
|
}
|
|
// 원거리 빈 방향 사격(적 없음 · 아래쪽): 명중 칸 = 제자리 발사 · 빈 칸(moveOnly) = 이동만
|
|
if (r0 != null)
|
|
{
|
|
Vector2 start = r0.Position;
|
|
Vector2 tgt = bm.Board.ClampInside(start + Vector2.down * 3f, r0.Radius);
|
|
var snap = Sim.Take(bm);
|
|
Sim.Active = true;
|
|
try
|
|
{
|
|
var o1 = new ActionOutcome();
|
|
Sim.Run(bm.Resolver.Resolve(r0, tgt, false, o1));
|
|
log.AppendLine("빈 방향 · 명중 칸: 움직인 거리 " + Vector2.Distance(start, r0.Position).ToString("0.00") + " · 발사 " + o1.Fired + " · MovedOnly " + o1.MovedOnly);
|
|
Sim.Restore(bm, snap);
|
|
var o2 = new ActionOutcome();
|
|
Sim.Run(bm.Resolver.Resolve(r0, tgt, true, o2));
|
|
log.AppendLine("빈 방향 · 빈 칸(이동만): 움직인 거리 " + Vector2.Distance(start, r0.Position).ToString("0.00"));
|
|
}
|
|
finally
|
|
{
|
|
Sim.Active = false;
|
|
Sim.Restore(bm, snap);
|
|
}
|
|
}
|
|
File.WriteAllText(Path.Combine(dir, "aim_log.txt"), log.ToString(), Encoding.UTF8);
|
|
TestOptions.AimModeOverride = prevMode;
|
|
}
|
|
|
|
static void Capture(Camera cam, string path)
|
|
{
|
|
var rt = new RenderTexture(720, 1280, 24);
|
|
var prev = cam.targetTexture;
|
|
cam.targetTexture = rt;
|
|
cam.Render();
|
|
RenderTexture.active = rt;
|
|
var tex = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
|
|
tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
|
|
tex.Apply();
|
|
File.WriteAllBytes(path, tex.EncodeToPNG());
|
|
cam.targetTexture = prev;
|
|
RenderTexture.active = null;
|
|
UnityEngine.Object.Destroy(rt);
|
|
UnityEngine.Object.Destroy(tex);
|
|
}
|
|
}
|
|
}
|