📄 player.cpp
字号:
for (int i=0; i<nCmds; i++)
{
CCommand cmd = m_infoPlayer.setCmd[i];
CRole::SetCommand(&cmd);
CRole::ProcessCommand();
this->ResetActionData();
}
m_infoPlayer.setCmd.clear();
while(true)
{
if(m_setLife.size() > 0)
{
int nLife = m_setLife.front();
m_setLife.erase(m_setLife.begin());
this->AddZoomNum(nLife, 0xff0000ff, 300, 30);
int nRealLife = (int)this->GetData(CPlayer::_PLAYER_LIFE)-nLife;
this->SetData(CPlayer::_PLAYER_LIFE, __max(0, nRealLife));
}
else
{
break;
}
}
return;
}
this->SetWorldPos(m_Info.posActionEnd);
CMyPos posCell;
g_objGameMap.World2Cell(m_Info.posActionEnd.x, m_Info.posActionEnd.y, posCell.x, posCell.y);
this->SetPos(posCell);
if (_CMDSTATUS_BEGIN == m_Info.cmdProc.iStatus)
this->ProcessCommand();
m_Info.iActFrameIndex = m_Info.iActFrameAmount;
if(m_setCmd.size() > 0)
{
CCommand* pCmd = m_setCmd.front();
if(m_setLife.size() > 0)
{
int nLife = m_setLife.front();
m_setLife.erase(m_setLife.begin());
this->AddZoomNum(nLife, 0xff0000ff, 300, 30);
int nRealLife = (int)this->GetData(CPlayer::_PLAYER_LIFE)-nLife;
this->SetData(CPlayer::_PLAYER_LIFE, __max(0, nRealLife));
}
CRole::SetCommand(pCmd);
if(strcmp(pCmd->szString0, "NULL") != 0)
m_objEffect.Add(pCmd->szString0,false,0,this->GetLook());
if(strcmp(pCmd->szString1, "NULL") != 0)
::DXPlaySound(pCmd->szString1);
delete pCmd;
m_setCmd.erase(m_setCmd.begin());
}
else
{
if(m_setLife.size() > 0)
{
int nLife = m_setLife.front();
m_setLife.erase(m_setLife.begin());
this->AddZoomNum(nLife, 0xff0000ff, 300, 30);
int nRealLife = (int)this->GetData(CPlayer::_PLAYER_LIFE)-nLife;
this->SetData(CPlayer::_PLAYER_LIFE, __max(0, nRealLife));
}
}
}//////////////////////////////////////////////////////////////////////
void CPlayer::SetTimerCommand(CCommand& cmd, DWORD tmExecute, const char* pszEffect, const char* pszSound)
{
TimerCmdInfo info;
info.cmd = cmd;
info.tmExecute = tmExecute;
if (pszEffect)
info.strEffect = pszEffect;
if (pszSound)
info.strSound = pszSound;
m_setCmdList.push_back(info);
}
//////////////////////////////////////////////////////////////////////
void CPlayer::ClrTimerCommand()
{
m_setCmdList.clear();
}
//////////////////////////////////////////////////////////////////////
bool CPlayer::ProcessTimerCommand(void)
{
if (m_setCmdList.size() <= 0)
return false;
std::list< TimerCmdInfo >::iterator iter = m_setCmdList.begin();
for ( ; iter != m_setCmdList.end(); iter++)
{
TimerCmdInfo& info = (*iter);
if (::TimeGet() >= info.tmExecute)
{
CRole::SetCommand(&info.cmd);
// 播放特效
if (info.strEffect.size())
{
// g_objGameMap.Add3DMapEffect(m_Info.posWorld, info.strEffect.c_str(), TRUE, this->GetDir());
m_objEffect.Add((char*)info.strEffect.c_str(),false,0,this->GetLook());
}
// 播放声效
if (info.strSound.size())
{
CMyPos pos;
this->GetWorldPos(pos);
::DXPlaySound((char*)info.strSound.c_str(), pos.x, pos.y, 2000);
}
// 从时间命令列表中删除
m_setCmdList.erase(iter);
return true;
}
}
return false;
}
//////////////////////////////////////////////////////////////////////
void CPlayer::Process(void* pInfo)
{
if(!m_pIRoleView)
return;
if(!(m_Info.cmdProc.iType == _COMMAND_EMOTION && (m_Info.cmdProc.nData == _ACTION_INTONE
|| m_Info.cmdProc.nData == _ACTION_INTONE_DURATION) || (m_Info.cmdProc.iType == _COMMAND_INTONE &&
m_Info.cmdProc.nData == _ACTION_INTONE_LAUNCH)))
m_Info.nFlyOffsetGoal = 0;
/* if(!this->TestStatus(USERSTATUS_FLY))
this->SetFlyOffsetGoal(0);
else
this->SetFlyOffsetGoal(100);
*/
this->ProcessAniEffect();
if (this->ProcessAction())
{
BOOL bProcess = true;
if(g_objPlayerSet.GetPlayer(m_idLocker, true) && m_idLocker != this->GetID())
bProcess = false;
if(m_setCmd.size() > 0 && bProcess)
{
CCommand* pCmd = m_setCmd.front();
if(m_setLife.size() > 0)
{
int nLife = m_setLife.front();
m_setLife.erase(m_setLife.begin());
this->AddZoomNum(nLife, 0xff0000ff, 300, 30);
}
if(strcmp(pCmd->szString0, "NULL") != 0)
m_objEffect.Add(pCmd->szString0,false,0,this->GetLook());
if(strcmp(pCmd->szString1, "NULL") != 0)
::DXPlaySound(pCmd->szString1);
CRole::SetCommand(pCmd);
delete pCmd;
m_setCmd.erase(m_setCmd.begin());
if(m_idLocker == this->GetID())
{
// 告诉所有被我锁定者,同步动作
int nAmount = g_objPlayerSet.GetPlayerAmount();
for(int i = 0; i < nAmount+1; i ++)
{
CPlayer* pPlayer;
if(i < nAmount)
pPlayer = g_objPlayerSet.GetPlayerByIndex(i);
else
pPlayer = &g_objHero;
if(pPlayer && pPlayer->m_idLocker == this->GetID()
&& pPlayer->GetID() != this->GetID())
{
pPlayer->SynTrack();
}
/* else if(pPlayer && pPlayer->GetID() != this->GetID())
{
pPlayer->SynTrack(false);
}*/
}
}
}
else
if (m_infoPlayer.setCmd.size() > 0)
{
CCommand cmd = m_infoPlayer.setCmd.front();
CRole::SetCommand(&cmd);
m_infoPlayer.setCmd.pop_front();
}
this->ProcessCommand();
this->SetActionData();
}
else
{
// 只有在没有命令执行的时候才去找延时的命令执行
if (this->IsIdle())
{
if (this->ProcessTimerCommand())
{
this->ProcessCommand();
this->SetActionData();
}
}
}
if (this->GetActionType() == _ACTION_WALKL ||
this->GetActionType() == _ACTION_WALKR ||
this->GetActionType() == _ACTION_RUNL ||
this->GetActionType() == _ACTION_RUNR)
{
CMyPos posCurrent = m_Info.posMap;
CMyPos posPreStep;
int nDir = this->GetDir();
if(nDir > 3)
g_objGameMap.World2Cell(m_Info.posActionEnd.x, m_Info.posActionEnd.y, posPreStep.x, posPreStep.y);
else
g_objGameMap.World2Cell(m_Info.posActionBegin.x, m_Info.posActionBegin.y, posPreStep.x, posPreStep.y);
m_Info.posMap = posPreStep;
if (g_objGameMap.IsPosVisible(m_Info.posMap, 2))
g_objGameMap.ApplyObjShow(this);
m_Info.posMap = posCurrent;
}
else
{
if (g_objGameMap.IsPosVisible(m_Info.posMap, 2))
g_objGameMap.ApplyObjShow(this);
}
if (strlen(m_szCryOut) > 0)
{
if (RandGet(100) == 1)
{
this->Say(m_szCryOut);
}
}
m_objFStr.Process();
// flyoffset ...
const int nStepUp = 1;
const int nStepDn = 4;
if(m_Info.nFlyOffset < m_Info.nFlyOffsetGoal)
{
m_Info.nFlyOffset += nStepUp;
if(m_Info.nFlyOffset > m_Info.nFlyOffsetGoal)
m_Info.nFlyOffset = m_Info.nFlyOffsetGoal;
}
if(m_Info.nFlyOffset > m_Info.nFlyOffsetGoal)
{
m_Info.nFlyOffset -= nStepDn;
if(m_Info.nFlyOffset < m_Info.nFlyOffsetGoal)
m_Info.nFlyOffset = m_Info.nFlyOffsetGoal;
}
}
//////////////////////////////////////////////////////////////////////
void CPlayer::SetMate(const char* pszMate)
{
if(!pszMate || _MAX_NAMESIZE < strlen(pszMate))
return;
strcpy(m_infoPlayer.szMate, pszMate);
}
//-------------------------------------------------------------------------------
void CPlayer::DoLevelUp()
{
m_infoPlayer.nExp = 0;
if(this->IsPet())
this->m_objEffect.Add("petLevelup",false,0,this->GetLook());
else
{
if (this->GetID() == g_objHero.GetID())
this->m_objEffect.Add("Levelup_self",false,0,this->GetLook());
this->m_objEffect.Add("Levelup",false,0,this->GetLook());
}
if (this->IsVisible())
{
CMyPos posWorld = { 0, 0 };
this->GetWorldPos(posWorld);
if (this->IsPet())
::DXPlaySound("sound/monster_lev_up.wav", posWorld.x, posWorld.y, 2000);
else if (this->IsPlayer())
::DXPlaySound("sound/role_lev_up.wav", posWorld.x, posWorld.y, 2000);
}
}
//-------------------------------------------------------------------------------
void CPlayer::SetFlashCrime ()
{
if (!this->TestStatus(USERSTATUS_CRIME))
return;
if (!m_bFlashCrime && m_dwFlashCrimeTime == 0)
{
m_dwFlashCrimeTime = ::TimeGet();
m_bFlashCrime = TRUE;
}
else if (m_dwFlashCrimeTime != 0
&& ::TimeGet () - m_dwFlashCrimeTime<FLASHCRIME_TIME
&& m_bFlashCrime)
{
m_dwFlashCrimeTime = ::TimeGet ();
}
}
//-------------------------------------------------------------------------------
BOOL CPlayer::IsFlashCrime ()
{
if (!this->TestStatus(USERSTATUS_CRIME))
{
m_dwFlashCrimeTime = 0;
m_bFlashCrime = FALSE;
}
else if (::TimeGet () - m_dwFlashCrimeTime <= FLASHCRIME_TIME
&& m_bFlashCrime)
{
m_dwFlashCrimeTime = 0;
m_bFlashCrime = FALSE;
}
return m_bFlashCrime;
}
//-------------------------------------------------------------------------------
void CPlayer::ReplaceStatus (__int64 dwStatus)
{
// team leader
this->ProcessStatusEffect(dwStatus);
// XP FULL
if (this->TestStatus(USERSTATUS_XPFULL))
{
if ((dwStatus&USERSTATUS_XPFULL))
{
m_dwKoScale = 100;
m_infoPlayer.dwKoAmount = 0;
}
}
// tornado
/* if (dwStatus&USERSTATUS_TORNADO)
{
if (!this->TestStatus(USERSTATUS_TORNADO))
{
m_dwKoScale = 100;
}
}
else
{
if (this->TestStatus(USERSTATUS_TORNADO))
{
m_infoPlayer.dwKoAmount = 0;
}
}*/
// body shield
/* if (dwStatus&USERSTATUS_WEAPONDAMAGE)
{
if (!this->TestStatus(USERSTATUS_WEAPONDAMAGE))
{
this->ResetStepDir();
this->SetActionCmd(_ACTION_BODYSHIELD);
}
}*/
// god believe
if (dwStatus&USERSTATUS_MAGICDAMAGE)
{
if (!this->TestStatus(USERSTATUS_MAGICDAMAGE))
{
this->ResetStepDir();
// this->SetActionCmd(_ACTION_GODBELIEVE);
}
}
// die
if (dwStatus&USERSTATUS_DIE)
{
}
else
{
// reborn
if (TestStatus(USERSTATUS_DIE))
this->StandBy();
}
// disapear...
if (dwStatus&USERSTATUS_DISAPPEARING && !this->TestStatus(USERSTATUS_DISAPPEARING))
{
m_tmDisappear = ::TimeGet();
CMonsterInfo* pInfo = (CMonsterInfo*)g_obj3DRoleData.GetMonsterInfo(this->GetMonsterTypeId());
if(pInfo && strcmp(pInfo->szDisappearEffect, "NULL") != 0)
{
this->m_objEffect.Add(pInfo->szDisappearEffect,false,0,this->GetLook());
}
if(pInfo && strcmp(pInfo->szDisappearSound, "NULL") != 0)
{
CMyPos posWorld;
this->GetWorldPos(posWorld);
::DXPlaySound(pInfo->szDisappearSound, posWorld.x, posWorld.y, 1000);
}
}
// set status.
m_dwStatus = dwStatus;
}
//-------------------------------------------------------------------------------
OBJID CPlayer::GetSydicateID()
{
return m_infoPlayer.idSyndicate;
}
//-------------------------------------------------------------------------------
void CPlayer::SetSyndicateID(OBJID idSyndicate)
{
m_infoPlayer.idSyndicate = idSyndicate;
}
//-------------------------------------------------------------------------------
DWORD CPlayer::GetSyndicateRank()
{
return m_infoPlayer.dwSyndicateRank;
}
//-------------------------------------------------------------------------------
void CPlayer::SetSyndicateRank(DWORD dwRank)
{
m_infoPlayer.dwSyndicateRank = dwRank;
}
//-------------------------------------------------------------------------------
int CPlayer::GetSyndicateProffer()
{
return m_infoPlayer.nSyndicateProffer;
}
//-------------------------------------------------------------------------------
void CPlayer::SetSyndicateProffer(int nSyndicateProffer)
{
m_infoPlayer.nSyndicateProffer = nSyndicateProffer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -