npc
This commit is contained in:
Binary file not shown.
@@ -42,7 +42,6 @@ public class CECNPCMan : CECObject, IMsgHandler
|
||||
cmd_object_stop_move pCmd = EC_Utility.ByteArrayToStructure<cmd_object_stop_move>((byte[])msg.dwParam1);
|
||||
|
||||
CECNPC pNPC = SeekOutNPC(pCmd.id);
|
||||
BrewMonster.Logger.Log("HoangDev : OnMsgNPCStopMove pNPC:" + pNPC);
|
||||
if (pNPC)
|
||||
pNPC.StopMoveTo(pCmd);
|
||||
|
||||
@@ -51,14 +50,14 @@ public class CECNPCMan : CECObject, IMsgHandler
|
||||
|
||||
private bool OnMsgNPCMove(ECMSG msg)
|
||||
{
|
||||
cmd_object_move pCmd = EC_Utility.ByteArrayToStructure<cmd_object_move>((byte[])msg.dwParam1);
|
||||
var buffer = (byte[])msg.dwParam1;
|
||||
cmd_object_move pCmd = MemoryMarshal.Read<cmd_object_move>(buffer);
|
||||
|
||||
if (pCmd.use_time == 0)
|
||||
return true;
|
||||
|
||||
CECNPC pNPC = SeekOutNPC(pCmd.id);
|
||||
|
||||
BrewMonster.Logger.LogError("HoangDev: OnMsgNPCMove MPC : " + pNPC);
|
||||
|
||||
if (pNPC)
|
||||
pNPC.MoveTo(pCmd);
|
||||
|
||||
@@ -173,18 +173,18 @@ public class CECNPC : CECObject
|
||||
}
|
||||
public bool MovingTo(float deltaTime)
|
||||
{
|
||||
BrewMonster.Logger.LogError("HoangDev : MovingTo ");
|
||||
bool reachedDestination = false;
|
||||
Vector3 curPos = transform.position;
|
||||
|
||||
if (m_bStopMove)
|
||||
{
|
||||
|
||||
// Tính hướng đến serverPos
|
||||
Vector3 dir = (m_vServerPos - curPos);
|
||||
float dist = dir.magnitude;
|
||||
|
||||
if (dist > 0.001f)
|
||||
{
|
||||
|
||||
dir.Normalize();
|
||||
|
||||
// Di chuyển một bước
|
||||
@@ -196,10 +196,13 @@ public class CECNPC : CECObject
|
||||
transform.position = m_vServerPos;
|
||||
_characterController.enabled = true;
|
||||
reachedDestination = true;
|
||||
FaceDirectionImmediate(moveDelta);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_characterController.Move(moveDelta);
|
||||
FaceDirectionImmediate(moveDelta);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,7 +210,6 @@ public class CECNPC : CECObject
|
||||
{
|
||||
|
||||
float dist = (m_vServerPos - curPos).magnitude;
|
||||
BrewMonster.Logger.LogError("HoangDev : MovingTo dist : " + dist);
|
||||
|
||||
if (IsLag(dist))
|
||||
{
|
||||
@@ -222,13 +224,45 @@ public class CECNPC : CECObject
|
||||
|
||||
Vector3 dir = m_vMoveDir.normalized;
|
||||
Vector3 moveDelta = dir * m_fMoveSpeed * deltaTime;
|
||||
BrewMonster.Logger.LogError($"HoangDev : MovingTo dist : {moveDelta } speed : {m_fMoveSpeed} dir : {dir} " +
|
||||
$"deltaTime : {deltaTime}");
|
||||
_characterController.Move(moveDelta);
|
||||
// Thêm xoay theo trục Y
|
||||
FaceDirectionSmooth(dir, 10f, deltaTime);
|
||||
}
|
||||
|
||||
return reachedDestination;
|
||||
}
|
||||
/// <summary>
|
||||
/// Xoay model NGAY LẬP TỨC theo hướng chỉ định (giữ nguyên trục Y đứng thẳng).
|
||||
/// </summary>
|
||||
public void FaceDirectionImmediate(Vector3 dir)
|
||||
{
|
||||
if (dir.sqrMagnitude > 0.0001f)
|
||||
{
|
||||
Vector3 flatDir = new Vector3(dir.x, 0, dir.z);
|
||||
if (flatDir.sqrMagnitude > 0.0001f)
|
||||
{
|
||||
transform.rotation = Quaternion.LookRotation(flatDir, Vector3.up);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Xoay model TỪ TỪ (mượt) theo hướng chỉ định (giữ nguyên trục Y đứng thẳng).
|
||||
/// rotateSpeed = tốc độ xoay (độ mượt), ví dụ 10f.
|
||||
/// deltaTime = Time.deltaTime trong Update.
|
||||
/// </summary>
|
||||
public void FaceDirectionSmooth(Vector3 dir, float rotateSpeed, float deltaTime)
|
||||
{
|
||||
if (dir.sqrMagnitude > 0.0001f)
|
||||
{
|
||||
Vector3 flatDir = new Vector3(dir.x, 0, dir.z);
|
||||
if (flatDir.sqrMagnitude > 0.0001f)
|
||||
{
|
||||
Quaternion targetRot = Quaternion.LookRotation(flatDir, Vector3.up);
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, targetRot, deltaTime * rotateSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void WorkFinished(int iWorkID)
|
||||
{
|
||||
@@ -449,29 +483,6 @@ public class CECNPC : CECObject
|
||||
}
|
||||
}
|
||||
|
||||
m_cdr.bTraceGround = true;
|
||||
|
||||
if ((cmd.move_mode & (int)GPMoveMode.GP_MOVE_AIR) != 0)
|
||||
{
|
||||
m_iMoveEnv = (int) MoveEnvironment.MOVEENV_AIR;
|
||||
m_cdr.bTraceGround = false;
|
||||
}
|
||||
else if ((cmd.move_mode & (int)GPMoveMode.GP_MOVE_WATER) != 0)
|
||||
{
|
||||
m_iMoveEnv = (int)MoveEnvironment.MOVEENV_WATER;
|
||||
m_cdr.bTraceGround = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_iMoveEnv = (int)MoveEnvironment.MOVEENV_GROUND;
|
||||
|
||||
if (iMoveMode == (int)GPMoveMode.GP_MOVE_FALL ||
|
||||
iMoveMode == (int)GPMoveMode.GP_MOVE_FLYFALL)
|
||||
{
|
||||
m_cdr.bTraceGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsDirFixed() && m_iPassiveMove == 0)
|
||||
{
|
||||
Vector3 vDir = m_vMoveDir;
|
||||
@@ -488,7 +499,6 @@ public class CECNPC : CECObject
|
||||
|
||||
if (m_iPassiveMove == 0)
|
||||
{
|
||||
// Play run or walk action when not passive move
|
||||
PlayMoveAction(iMoveMode);
|
||||
}
|
||||
}
|
||||
@@ -499,7 +509,6 @@ public class CECNPC : CECObject
|
||||
}
|
||||
public void MoveTo(cmd_object_move Cmd)
|
||||
{
|
||||
BrewMonster.Logger.LogError("HoangDev : MoveTo");
|
||||
if (Cmd.use_time == 0)
|
||||
return;
|
||||
var dest = EC_Utility.ToVector3(Cmd.dest);
|
||||
@@ -548,7 +557,6 @@ public class CECNPC : CECObject
|
||||
}
|
||||
|
||||
m_fMoveSpeed = fDist / (Cmd.use_time * 0.001f);
|
||||
BrewMonster.Logger.LogError($"HoangDev: m_fMoveSpeed:{m_fMoveSpeed}\nfDist:{fDist}\nCmd.use_time:{Cmd.use_time}");
|
||||
// Adjust NPC's direction
|
||||
/*if (!IsDirFixed())
|
||||
{
|
||||
@@ -793,6 +801,7 @@ public class CECNPC : CECObject
|
||||
bool IsPetNPC() { return (int)ClassID.OCID_PET == m_iCID; }
|
||||
public void PlayMoveAction(int iMoveMode)
|
||||
{
|
||||
BrewMonster.Logger.LogError($"HoangDev: PlayMoveAction {iMoveMode}");
|
||||
// Play run or walk aciton
|
||||
if (iMoveMode == (int)GPMoveMode.GP_MOVE_RUN || iMoveMode == (int)GPMoveMode.GP_MOVE_RETURN)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CECNPCServer
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aebb5e19da26bb64c8d5620d35681a2b
|
||||
Reference in New Issue
Block a user