85 lines
3.7 KiB
C#
85 lines
3.7 KiB
C#
using UnityEngine;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
/// <summary>
|
|
/// Straight-line projectile movement.
|
|
/// Mirrors C++ CGfxLinearMove exactly (A3DSkillGfxEvent2.cpp:22-52).
|
|
/// 直线弹道移动,完全镜像C++ CGfxLinearMove。
|
|
/// </summary>
|
|
public class CGfxLinearMove : CGfxMoveBase
|
|
{
|
|
protected float m_fSpeed;
|
|
private const float _fly_speed = 20.0f / 1000.0f; // units per ms, same as C++
|
|
|
|
public CGfxLinearMove(GfxMoveMode mode) : base(mode) { }
|
|
|
|
/// <summary>
|
|
/// Initialize movement from host to target.
|
|
/// 初始化从施法者到目标的移动。
|
|
/// </summary>
|
|
public override void StartMove(Vector3 vHost, Vector3 vTarget)
|
|
{
|
|
BMLogger.LogError($"[SKILL_GFX_DEBUG] CGfxLinearMove.StartMove: Entry - host={vHost}, target={vTarget}, area={m_bArea}, maxFlyTime={m_dwMaxFlyTime}");
|
|
|
|
if (m_bArea)
|
|
{
|
|
BMLogger.LogError($"[SKILL_GFX_DEBUG] CGfxLinearMove.StartMove: Area skill - calculating range and random offset");
|
|
CalcRange((vTarget - vHost).normalized);
|
|
m_vPos = vHost + GetRandOff();
|
|
BMLogger.LogError($"[SKILL_GFX_DEBUG] CGfxLinearMove.StartMove: Area skill - startPos={m_vPos} (host={vHost} + offset)");
|
|
}
|
|
else
|
|
{
|
|
m_vPos = vHost;
|
|
BMLogger.LogError($"[SKILL_GFX_DEBUG] CGfxLinearMove.StartMove: Non-area skill - startPos={m_vPos} (same as host)");
|
|
}
|
|
|
|
m_vMoveDir = vTarget - m_vPos;
|
|
float fDist = Normalize(ref m_vMoveDir);
|
|
float fMax = _fly_speed * m_dwMaxFlyTime;
|
|
|
|
BMLogger.LogError($"[SKILL_GFX_DEBUG] CGfxLinearMove.StartMove: Distance={fDist}, maxDistance={fMax} (speed={_fly_speed} * time={m_dwMaxFlyTime}), moveDir={m_vMoveDir}");
|
|
|
|
if (fMax >= fDist)
|
|
{
|
|
m_fSpeed = _fly_speed;
|
|
BMLogger.LogError($"[SKILL_GFX_DEBUG] CGfxLinearMove.StartMove: Using default speed={m_fSpeed} (distance fits in time)");
|
|
}
|
|
else
|
|
{
|
|
m_fSpeed = fDist / m_dwMaxFlyTime;
|
|
BMLogger.LogError($"[SKILL_GFX_DEBUG] CGfxLinearMove.StartMove: Using calculated speed={m_fSpeed} (distance={fDist} / time={m_dwMaxFlyTime})");
|
|
}
|
|
|
|
BMLogger.LogError($"[SKILL_GFX_DEBUG] CGfxLinearMove.StartMove: Complete - pos={m_vPos}, dir={m_vMoveDir}, speed={m_fSpeed}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tick movement. Returns true when target is hit.
|
|
/// 更新移动。当命中目标时返回true。
|
|
/// </summary>
|
|
public override bool TickMove(uint dwDeltaTime, Vector3 vHostPos, Vector3 vTargetPos)
|
|
{
|
|
Vector3 oldPos = m_vPos;
|
|
Vector3 vFlyDir = vTargetPos - m_vPos;
|
|
float fDist = Normalize(ref vFlyDir);
|
|
float fFlyDist = m_fSpeed * dwDeltaTime;
|
|
|
|
BMLogger.LogError($"[SKILL_GFX_DEBUG] CGfxLinearMove.TickMove: Entry - oldPos={oldPos}, targetPos={vTargetPos}, deltaTime={dwDeltaTime}, speed={m_fSpeed}, distance={fDist}, flyDist={fFlyDist}");
|
|
|
|
if (fFlyDist >= fDist)
|
|
{
|
|
BMLogger.LogError($"[SKILL_GFX_DEBUG] CGfxLinearMove.TickMove: Target HIT! (flyDist={fFlyDist} >= distance={fDist})");
|
|
return true; // target hit / 命中目标
|
|
}
|
|
|
|
m_vPos += vFlyDir * fFlyDist;
|
|
m_vMoveDir = vFlyDir;
|
|
|
|
BMLogger.LogError($"[SKILL_GFX_DEBUG] CGfxLinearMove.TickMove: Moved - newPos={m_vPos}, moveDir={m_vMoveDir}, distanceRemaining={fDist - fFlyDist}");
|
|
return false;
|
|
}
|
|
}
|
|
}
|