Skip to content

Commit

Permalink
修改了测试客户端代码
Browse files Browse the repository at this point in the history
  • Loading branch information
ylmbtm committed May 5, 2019
1 parent 91d1395 commit ac1da4b
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 101 deletions.
134 changes: 85 additions & 49 deletions Server/Client/PressureTest/PressureTest/ClientObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ CClientObject::CClientObject(void)
m_dwAccountID = 0;
m_dwHostState = ST_NONE;
m_x = 0;
m_y = 0;
m_z = 13;
m_y = -2;
m_z = 11;
m_dwCarrerID = 0;
m_ft = PI * 2 * (rand() % 360) / 360;
m_ft = rand() % 360;
m_uSkillTime = 0;
m_SkillID = 0;
m_uMoveTime = 0;
m_ClientConnector.RegisterMsgHandler((IMessageHandler*)this);
}

CClientObject::~CClientObject(void)
{
m_uMoveTime = 0;
}

BOOL CClientObject::DispatchPacket(UINT32 dwMsgID, CHAR* PacketBuf, INT32 BufLen)
Expand Down Expand Up @@ -168,7 +171,8 @@ BOOL CClientObject::OnUpdate( UINT32 dwTick )
if(m_ClientConnector.GetConnectState() == ECS_NO_CONNECT)
{
m_ClientConnector.ConnectTo("127.0.0.1", 9001);
//m_ClientConnector.ConnectToServer("47.93.31.69", 9001);
//m_ClientConnector.ConnectTo("47.93.31.69", 9001);
//m_ClientConnector.ConnectTo("47.105.89.43", 9001);
}
else if (m_ClientConnector.GetConnectState() == ECS_CONNECTED)
{
Expand Down Expand Up @@ -408,69 +412,90 @@ VOID CClientObject::TestMove()
{
ObjectActionReq Req;
ActionReqItem* pItem = Req.add_actionlist();
pItem->set_actionid(AT_WALK);
pItem->set_actionid(AT_RUN);
pItem->set_objectguid(m_RoleIDList[0]);

UINT64 dwTimeDiff = CommonFunc::GetTickCount() - m_uMoveTime;
if(dwTimeDiff < 160)
if (m_uMoveTime <= 0)
{
return ;
m_uMoveTime = CommonFunc::GetTickCount();
}

if (m_uSkillTime == 0)
{
m_uSkillTime = CommonFunc::GetTickCount();
}

dwTimeDiff = CommonFunc::GetTickCount() - m_uSkillTime;
if (dwTimeDiff > 10000)
UINT64 dwTimeDiff = CommonFunc::GetTickCount() - m_uMoveTime;
if (dwTimeDiff > 100)
{
TestCastSkill();
m_uSkillTime = CommonFunc::GetTickCount();
}
FLOAT fSpeed = 6.25f;

m_uMoveTime = CommonFunc::GetTickCount();
FLOAT fTime = dwTimeDiff;

MoveForward(1.0f);
fTime = fTime / 1000.0f;

if(m_x > 10)
{
m_x = 10;
m_ft += rand() % 10000;
m_ft = (int)m_ft % 360;
}
if(m_z > 20)
{
m_z = 20;
m_ft += rand() % 10000;
m_ft = (int)m_ft % 360;
}
if(m_x < -10)
{
m_x = -10;
m_ft += rand() % 10000;
m_ft = (int)m_ft % 360;
}
if(m_z < 0)
{
m_z = 0;
m_ft += rand() % 10000;
m_ft = (int)m_ft % 360;
}
printf("Distance:%f", fSpeed * fTime);

MoveForward(fSpeed * fTime);

m_uMoveTime = CommonFunc::GetTickCount();

bool bTrun = false;

if (m_x > 10)
{
bTrun = true;
m_x = 10;
}

if (m_z > 20)
{
bTrun = true;
m_z = 20;
}

if (m_x < -10)
{
bTrun = true;
m_x = -10;
}

pItem->set_hostx(m_x);
pItem->set_hosty(-2.45);
pItem->set_hostz(m_z);
pItem->set_hostft(m_ft);
if (m_z < 0)
{
bTrun = true;
m_z = 0;
}

if (bTrun)
{
m_ft += 180;
}

m_ClientConnector.SendData(MSG_OBJECT_ACTION_REQ, Req, m_RoleIDList[0], m_dwCopyGuid);
m_ft = m_ft > 360 ? (m_ft - 360) : m_ft;

pItem->set_hostx(m_x);
pItem->set_hosty(-2.45);
pItem->set_hostz(m_z);
pItem->set_hostft(m_ft);
m_ClientConnector.SendData(MSG_OBJECT_ACTION_REQ, Req, m_RoleIDList[0], m_dwCopyGuid);
}
}

VOID CClientObject::TestCastSkill()
{
if (m_uSkillTime == 0)
{
m_uSkillTime = CommonFunc::GetTickCount();
}

UINT64 dwTimeDiff = CommonFunc::GetTickCount() - m_uSkillTime;
if (dwTimeDiff < 10000)
{

return;
}

SkillCastReq Req;
Req.set_objectguid(m_RoleIDList[0]);
Req.set_skillid(2004);
Req.set_skillid(m_SkillID);

m_uSkillTime = CommonFunc::GetTickCount();

m_ClientConnector.SendData(MSG_SKILL_CAST_REQ, Req, m_RoleIDList[0], m_dwCopyGuid);
}
Expand Down Expand Up @@ -536,6 +561,17 @@ BOOL CClientObject::OnMsgRoleLoginAck(UINT32 dwMsgID, CHAR* PacketBuf, INT32 Buf
PacketHeader* pHeader = (PacketHeader*)PacketBuf;
m_RoleIDList.push_back(Ack.roleid());

for (int i = 0; i < Ack.skilllist_size(); i++)
{
const SkillItem skillItem = Ack.skilllist(i);
if (skillItem.keypos() == 1)
{
m_SkillID = skillItem.skillid();
}

}


static int loginnum = 0;

loginnum++;
Expand Down
2 changes: 2 additions & 0 deletions Server/Client/PressureTest/PressureTest/ClientObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class CClientObject : public IMessageHandler
std::string m_strRoleName;
UINT32 m_dwCarrerID;

UINT32 m_SkillID;

FLOAT m_x;
FLOAT m_y;
FLOAT m_z;
Expand Down
2 changes: 1 addition & 1 deletion Server/Client/PressureTest/PressureTest/PressureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int _tmain(int argc, _TCHAR* argv[])
sprintf(szBuff, "zhang%d", i);
pClientSpaceObject->m_strRoleName = szBuff;

pClientSpaceObject->m_dwCarrerID = rand() % 4 + 1;;
pClientSpaceObject->m_dwCarrerID = rand() % 4 + 1;

g_vtClientList.push_back(pClientSpaceObject);
}
Expand Down
15 changes: 12 additions & 3 deletions Server/Client/SmartClient/SmartClient/ClientObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@
#include "..\Src\Message\Msg_LoginCltData.pb.h"
#include "..\Src\ServerEngine\XMath.h"
#include "..\Src\ServerEngine\CommonFunc.h"
#include "..\Src\ServerEngine\CommandDef.h"
#include "..\Src\ServerEngine\PacketHeader.h"

#define PROCESS_MESSAGE_ITEM_CLIENT__(dwMsgID, Func) \
case dwMsgID:{\
if(Func(dwMsgID, PacketBuf, BufLen)){return TRUE;}}break;


#define PROCESS_MESSAGE_ITEM_CLIENT(dwMsgID, Func) \
case dwMsgID:{\
printf("---Receive Message:[%s]---- \n", #dwMsgID); \
if(Func(dwMsgID, PacketBuf, BufLen)){return TRUE;}}break;

int g_LoginReqCount = 0;
int g_LoginCount = 0;
int g_EnterCount = 0;
Expand Down Expand Up @@ -145,13 +154,13 @@ BOOL CClientObject::OnUpdate( UINT32 dwTick )

if(m_dwHostState == ST_NONE)
{
if(m_ClientConnector.GetConnectState() == Not_Connect)
if(m_ClientConnector.GetConnectState() == ECS_NO_CONNECT)
{
m_ClientConnector.ConnectTo("127.0.0.1", 5678);
//m_ClientConnector.ConnectToServer("47.93.31.69", 5678);
}

if(m_ClientConnector.GetConnectState() == Succ_Connect)
if(m_ClientConnector.GetConnectState() == ECS_CONNECTED)
{
SendNewAccountReq(m_strAccountName, m_strPassword);

Expand Down
Loading

0 comments on commit ac1da4b

Please sign in to comment.