tesst send move

This commit is contained in:
VDH
2025-09-10 14:23:25 +07:00
parent a4c4c4fa71
commit 4a9d07bc89
9 changed files with 286 additions and 77 deletions
Binary file not shown.
@@ -48,6 +48,7 @@ namespace PerfectWorld.Scripts.Managers
public void OnMsgPlayerInfo(ECMSG Msg)
{
Debug.LogWarning("OnMsgPlayerInfo ");
int iHostID = Convert.ToInt32(Msg.dwParam3);
int lenghtByte = Marshal.SizeOf<int>();
byte[] byteArray = new byte[lenghtByte];
@@ -4,6 +4,7 @@ using CSNetwork.Protocols;
using CSNetwork.Protocols.RPCData;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace BrewMonster.UI
+9 -7
View File
@@ -27,6 +27,7 @@ public class CECHostPlayer : MonoBehaviour
PlayerStateMachine playerStateMachine;
PlayerMoveState moveState;
CECHostMove m_MoveCtrl;
float playerSpeed = 5.0f;
float jumpHeight = 1.5f;
@@ -57,6 +58,7 @@ public class CECHostPlayer : MonoBehaviour
{
moveState = new PlayerMoveState(this);
playerStateMachine = new PlayerStateMachine();
m_MoveCtrl = new CECHostMove(this);
// Cache: không bắt buộc, nhưng gọn tay và ít gọi property lặp.
if (controller != null)
@@ -83,6 +85,7 @@ public class CECHostPlayer : MonoBehaviour
private void Update()
{
m_MoveCtrl.Tick((ulong)Time.deltaTime);
// Nếu có thay đổi runtime, có thể lấy lại mỗi vài giây/Start nếu bạn thích:
// ccRadius = controller.radius; ccSkin = controller.skinWidth;
@@ -120,9 +123,13 @@ public class CECHostPlayer : MonoBehaviour
if (move != Vector3.zero)
{
transform.forward = move;
Debug.LogWarning("HoangDev :HandleMovement");
m_MoveCtrl.SendMoveCmd(transform.position, controller.velocity, (int)MoveMode.GP_MOVE_WALK);
}
else
{
}
Vector3 finalMove = (move * playerSpeed) + (playerVelocity.y * Vector3.up);
@@ -181,13 +188,8 @@ public class CECHostPlayer : MonoBehaviour
case int value when value == EC_MsgDef.MSG_HST_CORRECTPOS: OnMsgHstCorrectPos(Msg); break;
}
}
private void c2s_CmdPlayerMove(in Vector3 vCurPos, in Vector3 vDest,
int iTime, float fSpeed, int iMoveMode, ushort wStamp)
{
gamedatasend gamedatasend = new gamedatasend();
//gamedatasend.Data = C2SCommandFactory.CreatePlayerMove();
UnityGameSession.SendProtocol(gamedatasend);
}
public void OnMsgHstCorrectPos(in ECMSG Msg)
{
Debug.Log("OnMsgHstCorrectPos");
+23 -1
View File
@@ -14,4 +14,26 @@ struct cmd_host_correct_pos
{
public Vector3 pos;
public ushort stamp;
};
};
enum MoveMode
{
GP_MOVE_WALK = 0,
GP_MOVE_RUN = 1,
GP_MOVE_STAND = 2,
GP_MOVE_FALL = 3,
GP_MOVE_SLIDE = 4,
GP_MOVE_PUSH = 5, // only sent to NPC
GP_MOVE_FLYFALL = 6,
GP_MOVE_RETURN = 7,
GP_MOVE_JUMP = 8,
GP_MOVE_PULL = 9, // only sent to NPC
GP_MOVE_BLINK = 10, // only sent to NPC£¨Ë²ÒÆ£©
GP_MOVE_MASK = 0x0f,
GP_MOVE_TURN = 0x10, // Turnaround
GP_MOVE_DEAD = 0x20,
GP_MOVE_AIR = 0x40,
GP_MOVE_WATER = 0x80,
GP_MOVE_ENVMASK = 0xc0,
};
+53
View File
@@ -0,0 +1,53 @@
using UnityEngine;
public class CECCounter
{
// Thuộc tính
protected ulong m_dwCounter; // Counter
protected ulong m_dwPeriod; // Count period
// Constructor
public CECCounter()
{
m_dwCounter = 0;
m_dwPeriod = 0;
}
// Set / Get period
public void SetPeriod(ulong dwPeriod) { m_dwPeriod = dwPeriod; }
public ulong GetPeriod() { return m_dwPeriod; }
// Set / Get counter
public void SetCounter(ulong dwCounter) { m_dwCounter = dwCounter; }
public ulong GetCounter() { return m_dwCounter; }
// Has counter reached period ?
public bool IsFull()
{
Debug.LogWarning($"HoangDev : {m_dwCounter} {m_dwPeriod} ");
return (m_dwCounter >= m_dwPeriod);
}
// Reset counter
public void Reset(bool bFull = false)
{
m_dwCounter = bFull ? m_dwPeriod : 0;
}
// Increase counter
public bool IncCounter(ulong dwCounter)
{
m_dwCounter += dwCounter;
return (m_dwCounter >= m_dwPeriod);
}
// Decrease counter
public void DecCounter(ulong dwCounter)
{
if (m_dwCounter <= dwCounter)
m_dwCounter = 0;
else
m_dwCounter -= dwCounter;
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 6f330a50f34b90341a81715e467a1e7d
+88 -3
View File
@@ -1,13 +1,98 @@
using System;
using BrewMonster.Network;
using CSNetwork.C2SCommand;
using CSNetwork.GPDataType;
using System;
using System.Collections.Generic;
using System.Runtime.ConstrainedExecution;
using System.Text;
using UnityEngine;
using CSNetwork.Protocols;
using UnityEngine.LightTransport;
public class CECHostMove
{
// Giữ reference tới CECHostPlayer y như bản gốc
ushort m_wMoveStamp;
float m_fMoveTime;
CECHostPlayer m_pHost;
CECCounter m_CmdTimeCnt;
bool m_bStop;
const int MOVECMD_INTERVAL = 500;
Vector3 m_vLastSevPos;
public CECHostMove(CECHostPlayer pHost)
{
m_wMoveStamp = 0;
m_fMoveTime = 0.0f;
m_pHost = pHost;
m_bStop = true;
m_CmdTimeCnt = new CECCounter();
m_CmdTimeCnt.SetPeriod(MOVECMD_INTERVAL);
}
public void Tick(ulong dwDeltaTime)
{
m_CmdTimeCnt.IncCounter(dwDeltaTime);
}
public void SendMoveCmd(in Vector3 vCurPos, in Vector3 vVel, int iMoveMode, bool bForceSend = false)
{
Vector3 vMoveDir = vVel;
float fSpeed = vMoveDir.magnitude;
SendMoveCmd(vCurPos, fSpeed, iMoveMode, bForceSend);
Debug.LogWarning("HoangDev :SendMoveCmd 111");
}
void SendMoveCmd(in Vector3 vCurPos,
float fSpeed, int iMoveMode, bool bForceSend)
{
if (m_bStop)
{
// m_CmdTimeCnt.Reset();
m_CmdTimeCnt.SetCounter((ulong)(m_fMoveTime * 1000));
m_bStop = false;
}
Debug.LogWarning("HoangDev :SendMoveCmd 2222");
if (!bForceSend && !m_CmdTimeCnt.IsFull())
return;
Debug.LogWarning("HoangDev :SendMoveCmd 3333");
int iTime = (int)(m_fMoveTime * 1000);
if (iTime < 200)
{
if (iTime == 0 || !bForceSend)
{
// if time is too little, wait again
m_CmdTimeCnt.SetCounter((ulong)iTime);
return;
}
}
Debug.LogWarning("HoangDev :SendMoveCmd 4444");
m_CmdTimeCnt.Reset();
c2s_CmdPlayerMove(vCurPos, vCurPos, iTime/* MOVECMD_INTERVAL */, fSpeed, iMoveMode, m_wMoveStamp++);
m_vLastSevPos = vCurPos;
}
private void Reset()
{
m_bStop = true;
}
private void c2s_CmdPlayerMove(in Vector3 vCurPos, in Vector3 vDest,
int iTime, float fSpeed, int iMoveMode, ushort wStamp)
{
gamedatasend gamedatasend = new gamedatasend();
//TODO: tim cach convert vector 3 unity sang System.Numerics.Vector3
gamedatasend.Data = C2SCommandFactory.CreatePlayerMove(ToSysVec3(vCurPos), ToSysVec3(vDest), (ushort)iTime, (short)fSpeed, (byte)iMoveMode, wStamp);
UnityGameSession.SendProtocol(gamedatasend);
Debug.Log("HoangDev : SendProtocolSendProtocolSendProtocol");
}
public void GroundMove(float ftime)
{
m_fMoveTime += ftime;
}
public System.Numerics.Vector3 ToSysVec3(UnityEngine.Vector3 v)
=> new System.Numerics.Vector3(v.x, v.y, v.z);
}
public struct CDR_INFO
{
File diff suppressed because one or more lines are too long