📄 msgaction.cpp
字号:
// MsgAction.cpp: implementation of the CMsgAction class.
//
//////////////////////////////////////////////////////////////////////
#include "AllMsg.h"
#include "GamePlayerSet.h"
#include "Hero.h"
#include "3DGameMap.h"
#include "GameMsg.h"
#include "Pet.h"
#include "NDsound.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMsgAction::CMsgAction()
{
Init();
m_pInfo =(MSG_Info *)m_bufMsg;
}
CMsgAction::~CMsgAction()
{
}
//////////////////////////////////////////////////////////////////////
BOOL CMsgAction::Create(OBJID idPlayer, int nPosX, int nPosY, USHORT usDir, USHORT usAction, DWORD dwData)
{
// param check
if (idPlayer == ID_NONE)
return false;
// init
this->Init();
// fill info now
m_pInfo->unMsgSize =sizeof(MSG_Info);
m_pInfo->unMsgType =_MSG_ACTION;
m_pInfo->dwTimeStamp =::TimeGet();
m_pInfo->idUser =idPlayer;
m_pInfo->unPosX =(USHORT)nPosX;
m_pInfo->unPosY =(USHORT)nPosY;
m_pInfo->unDir =usDir;
m_pInfo->dwData =dwData;
m_pInfo->usAction =usAction;
return true;
}
//////////////////////////////////////////////////////////////////////
BOOL CMsgAction::Create(OBJID idPlayer, int nPosX, int nPosY, USHORT usDir, USHORT usAction, USHORT usTargetPosX, USHORT usTargetPosY, DWORD dwTimeStamp/*=0*/)
{
// param check
if (idPlayer == ID_NONE)
return false;
// init
this->Init();
// fill info now
m_pInfo->unMsgSize =sizeof(MSG_Info);
m_pInfo->unMsgType =_MSG_ACTION;
if (0 == dwTimeStamp)
m_pInfo->dwTimeStamp =::TimeGet();
else
m_pInfo->dwTimeStamp =dwTimeStamp;
m_pInfo->idUser =idPlayer;
m_pInfo->unPosX =(USHORT)nPosX;
m_pInfo->unPosY =(USHORT)nPosY;
m_pInfo->unDir =usDir;
m_pInfo->usAction =usAction;
m_pInfo->usTargetPosX =usTargetPosX;
m_pInfo->usTargetPosY =usTargetPosY;
return true;
}
//////////////////////////////////////////////////////////////////////
BOOL CMsgAction::Create(char* pbufMsg, DWORD dwMsgSize)
{
if (!CNetMsg::Create(pbufMsg, dwMsgSize))
return false;
if(_MSG_ACTION != this->GetType())
return false;
return true;
}
//////////////////////////////////////////////////////////////////////
void CMsgAction::Process(void* pInfo)
{
#ifdef _MSGDEBUG
::LogMsg("Process CMsgAction, idUser:%u, data:%u",
m_pInfo->idUser,
m_pInfo->dwData);
#endif
// get obj
if(m_pInfo->usAction == actionDisappear)
{
if(m_pInfo->dwData == 0)
{
CPlayer* pPlayer = g_objPlayerSet.GetPlayer(m_pInfo->idUser);
if(pPlayer && !pPlayer->IsMyPet())
{
g_objGameMap.DelInteractiveObj(pPlayer);
g_objPlayerSet.DelPlayer(pPlayer->GetID());
}
g_objGameMap.EndMapMagicItem(m_pInfo->idUser);
}
else
{
g_objGameMap.DelMapItem(m_pInfo->idUser);
}
return;
}
if (m_pInfo->usAction == actionChangeFace)
g_objHero.SetTeamMemberFace(m_pInfo->idUser, m_pInfo->dwData);
if (m_pInfo->usAction == actionTeamMemeberPos)
{
if (!g_objHero.IsTeamLeader())
{
CMyPos pos = { m_pInfo->unPosX, m_pInfo->unPosY };
g_objHero.SetTeamLeaderPos(pos);
}
}
if(m_pInfo->usAction == actionQueryTeamMember)
{
CMyPos posTeamMember;
posTeamMember.x = m_pInfo->unPosX;
posTeamMember.y = m_pInfo->unPosY;
g_objGameMap.SetFriendPos(posTeamMember);
}
if(m_pInfo->usAction == actionEnterMap)
{
m_pInfo->idUser = g_objHero.GetID();
}
CPlayer* pPlayer =g_objPlayerSet.GetPlayer(m_pInfo->idUser, true);
if (!pPlayer)
{
switch(m_pInfo->usAction)
{
case actionJump:
case actionMine:
case actionChgDir:
case actionEmotion:
{
CMyPos posHero = g_objHero.GetAlignPos();
//if (abs(posHero.x-(int)m_pInfo->unPosX) <= _BLOCK_SIZE
// && abs(posHero.y-(int)m_pInfo->unPosY) <= _BLOCK_SIZE)
{
CMsgAction msg;
if (msg.Create(g_objHero.GetID(), posHero.x, posHero.y, g_objHero.GetDir(), actionQueryPlayer, m_pInfo->idUser))
msg.Send();
}
if (strstr(g_objHero.GetName(), "PM"))
g_objGameMsg.AddMsg("QueryPlayer: %u", m_pInfo->idUser);
}
break;
case actionMapARGB:
{
g_objGameMap.SetARGB(m_pInfo->dwData);
}
break;
default:
break;
}
return;
}
// actions...
switch(m_pInfo->usAction)
{
case actionPostCmd:
::PostCmd(m_pInfo->dwData);
break;
case actionSynchro:
{
if (pPlayer->GetID() != g_objHero.GetID() && !pPlayer->IsMyPet())
{
pPlayer->ResetStepDir();
CMyPos posPlayer;
pPlayer->GetPos(posPlayer);
if (posPlayer.x != m_pInfo->usTargetPosX
|| posPlayer.y != m_pInfo->usTargetPosY)
{
pPlayer->SetActionCmd(_ACTION_STANDBY);
pPlayer->SetPos(m_pInfo->usTargetPosX, m_pInfo->usTargetPosY);
}
}
else if(pPlayer->GetID() == g_objHero.GetID())
{
g_objHero.ResetActionData();
CMyPos posHero;
g_objHero.GetPos(posHero);
if (posHero.x != m_pInfo->usTargetPosX
|| posHero.y != m_pInfo->usTargetPosY)
{
m_pInfo->usTargetPosX = posHero.x;
m_pInfo->usTargetPosY = posHero.y;
this->Send();
}
}
else
{
CPet* pPet = (CPet*)pPlayer;
if(pPet && pPet->IsMyPet())
{
#ifdef LW_DEBUG
g_objGameMsg.AddMsg("PET POS TICK BACK!");
#endif
return;
}
pPet->ResetActionData();
CMyPos posHero;
pPet->GetPos(posHero);
if (posHero.x != m_pInfo->usTargetPosX
|| posHero.y != m_pInfo->usTargetPosY)
{
m_pInfo->usTargetPosX = posHero.x;
m_pInfo->usTargetPosY = posHero.y;
this->Send();
}
}
}
break;
case actionMine:
{
pPlayer->ResetStepDir();
pPlayer->SetActionCmd(_ACTION_MINE);
int nChance = m_pInfo->dwData/30;
if (::RandGet(5) < nChance)
{
int nPosX, nPosY;
pPlayer->GetPos(nPosX, nPosY);
const int _DELTA_X[8]={0,-1,-1,-1,0,1,1,1};
const int _DELTA_Y[8]={1,1,0,-1,-1,-1,0,1};
nPosX += _DELTA_X[pPlayer->GetDir()];
nPosY += _DELTA_Y[pPlayer->GetDir()];
CMyPos posWorld;
g_objGameMap.Cell2World(nPosX, nPosY, posWorld.x, posWorld.y);
g_objGameMap.Add3DMapEffect(posWorld, "Mine");
}
}
break;
case actionChgDir:
{
pPlayer->SetDir(m_pInfo->unDir);
}
break;
case actionEmotion:
{
if(m_pInfo->dwData == 180)
return;
struct {
WORD wEmotion;
BYTE btProf;
BYTE btFlagAllNosuch;
} infoEmotion;
memcpy(&infoEmotion, &m_pInfo->dwData, sizeof(DWORD));
if (g_objHero.GetID() != m_pInfo->idUser)
{
CCommand cmdDemo;
cmdDemo.iType =_COMMAND_EMOTION;
cmdDemo.iStatus =_CMDSTATUS_BEGIN;
cmdDemo.nData =infoEmotion.wEmotion;
cmdDemo.idTarget =ID_NONE;
cmdDemo.nDir =m_pInfo->unDir;
pPlayer->SetCommand(&cmdDemo);
}
if (infoEmotion.btProf)
pPlayer->AddProfessionalCoolposEffect(infoEmotion.btProf/10, infoEmotion.btFlagAllNosuch);
}
break;
case actionPosition:
{
}
break;
case actionRun:
case actionWalk:
{
/*
int nPosX, nPosY;
pPlayer->GetPos(nPosX, nPosY);
int nLocalDistance =CGameMap::GetDistance(nPosX, nPosY, (int)m_pInfo->usTargetPosX, (int)m_pInfo->usTargetPosY);
int nRemoteDistance =CGameMap::GetDistance((int)m_pInfo->unPosX, (int)m_pInfo->unPosY, (int)m_pInfo->usTargetPosX, (int)m_pInfo->usTargetPosY);
if (nLocalDistance > nRemoteDistance)
{
pPlayer->SetPos(m_pInfo->unPosX, m_pInfo->unPosY);
pPlayer->ResetActionData();
}
CCommand cmd;
if (m_pInfo->usAction == actionWalk)
cmd.iType =_COMMAND_WALK;
else
cmd.iType =_COMMAND_RUN;
cmd.iStatus =_CMDSTATUS_BEGIN;
cmd.posTarget.x =m_pInfo->usTargetPosX;
cmd.posTarget.y =m_pInfo->usTargetPosY;
pPlayer->SetCommand(&cmd);
*/
}
break;
case actionJump:
{
// align pos?
if (g_objHero.GetID() == m_pInfo->idUser)
{
g_objHero.SetAlignPos(m_pInfo->usTargetPosX, m_pInfo->usTargetPosY);
}
else if(pPlayer->IsMyPet())
{
CPet* pPet = (CPet*)pPlayer;
//pPet->SetAlignPos(m_pInfo->usTargetPosX, m_pInfo->usTargetPosY);
}
else
{
pPlayer->ResetStepDir();
pPlayer->SetPos(m_pInfo->usTargetPosX, m_pInfo->usTargetPosY);
/*
CCommand cmd;
cmd.iType =_COMMAND_JUMP;
cmd.iStatus =_CMDSTATUS_BEGIN;
cmd.posTarget.x =m_pInfo->usTargetPosX;
cmd.posTarget.y =m_pInfo->usTargetPosY;
pPlayer->SetCommand(&cmd);*/
}
}
break;
case actionEnterMap: // map info end
{
extern unsigned int g_uStatus;
g_uStatus =_STATUS_NORMAL;
//MYASSERT (m_pInfo->idUser == g_objHero.GetID());
//m_pInfo->idUser is map id
{
MYASSERT (g_objGameMap.Create(m_pInfo->dwData));
// set position and dir
int nPosX =m_pInfo->unPosX;
int nPosY =m_pInfo->unPosY;
g_objHero.SetPos(nPosX, nPosY);
g_objHero.SetAlignPos(nPosX, nPosY);
g_objHero.SetDir(m_pInfo->unDir);
// set command
CCommand cmd;
cmd.iType =_COMMAND_STANDBY;
cmd.iStatus =_CMDSTATUS_BEGIN;
g_objHero.SetCommand(&cmd);
// get to the next step
CMsgAction msg;
MYASSERT (msg.Create(g_objHero.GetID(), 0, 0, 0, actionGetItemSet));
msg.Send();
}
}
break;
case actionFlyMap:
{
MYASSERT (m_pInfo->idUser == g_objHero.GetID());
{
extern UINT g_uStatus;
g_uStatus = _STATUS_WAITING;
// load map
MYASSERT (g_objGameMap.Create(m_pInfo->dwData));
// set position and dir
g_objHero.SetPos(m_pInfo->unPosX, m_pInfo->unPosY);
g_objHero.SetAlignPos(m_pInfo->unPosX, m_pInfo->unPosY);
g_objHero.SetDir(m_pInfo->unDir);
int nAmount = g_objPlayerSet.GetPlayerAmount();
for(int i = 0; i < nAmount; i ++)
{
CPlayer* pPlayer = g_objPlayerSet.GetPlayerByIndex(i);
if(pPlayer && pPlayer->IsMyPet() && !pPlayer->IsDead())
{
pPlayer->ResetActionData();
pPlayer->ResetStepDir();
pPlayer->SetPos(m_pInfo->unPosX, m_pInfo->unPosY);
CPet* pPet = (CPet*)pPlayer;
//pPet->SetAlignPos(m_pInfo->unPosX, m_pInfo->unPosY);
}
}
g_objHero.ResetActionData();
// view port
CMyPos posWorld;
g_objHero.GetWorldPos(posWorld);
posWorld.x -=_SCR_WIDTH/2;
posWorld.y -=_SCR_HEIGHT/2;
g_objGameMap.SetViewPos(posWorld);
// set command
CCommand cmd;
cmd.iType =_COMMAND_STANDBY;
cmd.iStatus =_CMDSTATUS_BEGIN;
g_objHero.SetCommand(&cmd);
g_uStatus = _STATUS_NORMAL;
}
}
break;
case actionLeaveMap:
{
CPlayer* pPlayer = g_objPlayerSet.GetPlayer(m_pInfo->idUser);
if (pPlayer)
{
if (pPlayer->IsNpc() && pPlayer->IsDead())
{
CMyPos posWorld;
pPlayer->GetWorldPos(posWorld);
g_objGameMap.Add3DMapEffect(posWorld, "BodyDisapear");
}
BOOL bDelObj =true;
g_objPlayerSet.DelPlayer(m_pInfo->idUser, bDelObj);
}
}
break;
case actionGetItemSet: // items info end
{
CMsgAction msg;
MYASSERT (msg.Create(g_objHero.GetID(), 0, 0, 0, actionGetGoodFriend));
msg.Send();
// 要求界面同步PK状态
PostCmd(CMD_SETPKMODE);
}
break;
case actionGetGoodFriend: // friends info end
{
CMsgAction msg;
MYASSERT (msg.Create(g_objHero.GetID(), 0, 0, 0, actionGetWeaponSkillSet));
msg.Send();
}
break;
case actionGetWeaponSkillSet:
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -