📄 gameplayerset.cpp
字号:
// GamePlayerSet.cpp: implementation of the CGamePlayerSet class.
//
//////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786)
#include "player.h"
#include "GamePlayerSet.h"
#include "3DGameMap.h"
#include "Hero.h"
#include "AllMsg.h"
#include "GameDataSet.h"
#include "BoothNpc.h"
// globle...
CGamePlayerSet g_objPlayerSet;
const DWORD CREATE_3DROLE_INTERVAL = 300;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CGamePlayerSet::CGamePlayerSet()
{
this->Init();
m_dwTimeFor3DRole = ::TimeGet();
m_idWhiteSyn = m_idBlackSyn = ID_NONE;
}
CGamePlayerSet::~CGamePlayerSet()
{
this->Destroy();
this->DestroySyndicateInfo();
}
//////////////////////////////////////////////////////////////////////
void CGamePlayerSet::DestroySyndicateInfo()
{
int nAmount = m_setSyndicateInfo.size();
for(int i = nAmount-1; i >= 0; i --)
{
InfoSyndicate* pInfo = m_setSyndicateInfo[i];
SAFE_DELETE(pInfo);
}
m_setSyndicateInfo.clear();
}
//////////////////////////////////////////////////////////////////////
void CGamePlayerSet::Init(void)
{
m_dequePlayer.clear();
m_pFocusPlayer =NULL;
}
//////////////////////////////////////////////////////////////////////
void CGamePlayerSet::Destroy(void)
{
this->DelAllPlayer();
m_pFocusPlayer =NULL;
}
//////////////////////////////////////////////////////////////////////
BOOL CGamePlayerSet::AddPlayer(CPlayer* pPlayer)
{
if (!CPlayer::IsValidPt(pPlayer))
return false;
if (this->GetPlayer(pPlayer->GetID()))
return false;
switch(pPlayer->GetRoleType())
{
case _ROLE_BOOTH_NPC:
{
CMyPos posNpc;
pPlayer->GetPos(posNpc);
int nDir = pPlayer->GetDir()%8;
for(int i = 0; i < 5; i ++)
{
CMyPos posMask;
posMask.x = posNpc.x + BoothMaskOffset[nDir][i][0];
posMask.y = posNpc.y + BoothMaskOffset[nDir][i][1];
CellInfo* pInfo = g_objGameMap.GetCell(posMask.x, posMask.y);
if(pInfo)
{
LayerInfo* pLayerInfo = g_objGameMap.GetLastLayerInfo(pInfo);
pLayerInfo->usMask = 1;
}
}
}
break;
/* case _ROLE_SHOPKEEPER_NPC:
case _ROLE_TASK_NPC:
case _ROLE_STORAGE_NPC:
case _ROLE_TRUNCK_NPC:
case _ROLE_FACE_NPC:
case _ROLE_FORGE_NPC:
case _ROLE_EMBED_NPC:
case _ROLE_STATUARY_NPC:
case _SYNTRANS_NPC:
case _ROLE_BOOTH_FLAG_NPC:
case _ROLE_WEAPONGOAL_NPC:
case _ROLE_MAGICGOAL_NPC:
case _ROLE_BOWGOAL_NPC:
{
CMyPos posNpc;
pPlayer->GetPos(posNpc);
CMyPos posMask;
posMask.x = posNpc.x;
posMask.y = posNpc.y;
CellInfo* pInfo = g_objGameMap.GetCell(posMask.x, posMask.y);
if(pInfo)
{
LayerInfo* pLayerInfo = g_objGameMap.GetLastLayerInfo(pInfo);
pLayerInfo->usMask = 1;
}
}
break;*/
default:
{
if(pPlayer->IsNpc())
{
NpcTypeInfo* pInfo = g_obj3DRoleData.GetNpcTypeInfo(pPlayer->GetLook()/10);
if(pInfo)
{
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};
int nDirFront = (pPlayer->GetDir()+8)%8;
int nDirBack = (nDirFront+4+8)%8;
int nDirLeft = (nDirFront-2+8)%8;
int nDirRight = (nDirFront+2+8)%8;
CMyPos posOrg, posFront, posBack, posLeft, posRight;
pPlayer->GetPos(posOrg);
posFront.x = posOrg.x + _DELTA_X[nDirFront] * pInfo->nFront;
posFront.y = posOrg.y + _DELTA_Y[nDirFront] * pInfo->nFront;
posBack.x = posOrg.x + _DELTA_X[nDirBack] * pInfo->nBack;
posBack.y = posOrg.y + _DELTA_Y[nDirBack] * pInfo->nBack;
posLeft.x = posOrg.x + _DELTA_X[nDirLeft] * pInfo->nLeft;
posLeft.y = posOrg.y + _DELTA_Y[nDirLeft] * pInfo->nLeft;
posRight.x = posOrg.x + _DELTA_X[nDirRight] * pInfo->nRight;
posRight.y = posOrg.y + _DELTA_Y[nDirRight] * pInfo->nRight;
int nMinX = __min(__min(posFront.x, posBack.x), __min(posLeft.x, posRight.x));
int nMinY = __min(__min(posFront.y, posBack.y), __min(posLeft.y, posRight.y));
int nMaxX = __max(__max(posFront.x, posBack.x), __max(posLeft.x, posRight.x));
int nMaxY = __max(__max(posFront.y, posBack.y), __max(posLeft.y, posRight.y));
for(int i = nMinY; i <= nMaxY; i ++)
{
for(int j = nMinX; j <= nMaxX; j ++)
{
CellInfo* pInfo = g_objGameMap.GetCell(j, i);
if(pInfo)
{
LayerInfo* pLayerInfo = g_objGameMap.GetLastLayerInfo(pInfo);
if(pLayerInfo)
pLayerInfo->usMask = 1;
}
}
}
}
}
}
break;
}
m_dequePlayer.push_back(pPlayer);
g_objGameMap.AddInteractiveObj(pPlayer);
return true;
}
//////////////////////////////////////////////////////////////////////
BOOL CGamePlayerSet::DelPlayer(OBJID id, BOOL bDelObj)
{
int nPlayerAmount =m_dequePlayer.size();
CPlayer* pMyPlayer = this->GetPlayer(id);
if(pMyPlayer && pMyPlayer->IsMyPet())
{
g_objHero.DelPet(id);
}
for (int i=nPlayerAmount-1; i>=0; i--)
{
CPlayer* pPlayer = m_dequePlayer[i];
if(id == pPlayer->GetID())
{
if (m_pFocusPlayer == pPlayer)
m_pFocusPlayer = NULL;
if(pPlayer->GetRoleType() == _ROLE_BOOTH_NPC)
{
// 1*1 ...
CMyPos posNpc;
pPlayer->GetPos(posNpc);
for(int i = 0; i < 5; i ++)
{
CMyPos posMask;
int nDir = pPlayer->GetDir()%8;
posMask.x = posNpc.x + BoothMaskOffset[nDir][i][0];
posMask.y = posNpc.y + BoothMaskOffset[nDir][i][1];
CellInfo* pInfo = g_objGameMap.GetCell(posMask.x, posMask.y);
if(pInfo)
{
LayerInfo* pLayerInfo = g_objGameMap.GetLastLayerInfo(pInfo);
pLayerInfo->usMask = 0;
}
}
// reset cry out
{
CPlayer* pOwner = this->GetPlayer(pPlayer->GetName());
if (pOwner)
{
pOwner->SetCryOut("");
}
else
{
if (0 == strcmp(pPlayer->GetName(), g_objHero.GetName()))
g_objHero.SetCryOut("");
}
}
}
else
{
if(pPlayer->IsNpc())
{
NpcTypeInfo* pInfo = g_obj3DRoleData.GetNpcTypeInfo(pPlayer->GetLook()/10);
if(pInfo)
{
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};
int nDirFront = (pPlayer->GetDir()+8)%8;
int nDirBack = (nDirFront+4+8)%8;
int nDirLeft = (nDirFront-2+8)%8;
int nDirRight = (nDirFront+2+8)%8;
CMyPos posOrg, posFront, posBack, posLeft, posRight;
pPlayer->GetPos(posOrg);
posFront.x = posOrg.x + _DELTA_X[nDirFront] * pInfo->nFront;
posFront.y = posOrg.y + _DELTA_Y[nDirFront] * pInfo->nFront;
posBack.x = posOrg.x + _DELTA_X[nDirBack] * pInfo->nBack;
posBack.y = posOrg.y + _DELTA_Y[nDirBack] * pInfo->nBack;
posLeft.x = posOrg.x + _DELTA_X[nDirLeft] * pInfo->nLeft;
posLeft.y = posOrg.y + _DELTA_Y[nDirLeft] * pInfo->nLeft;
posRight.x = posOrg.x + _DELTA_X[nDirRight] * pInfo->nRight;
posRight.y = posOrg.y + _DELTA_Y[nDirRight] * pInfo->nRight;
int nMinX = __min(__min(posFront.x, posBack.x), __min(posLeft.x, posRight.x));
int nMinY = __min(__min(posFront.y, posBack.y), __min(posLeft.y, posRight.y));
int nMaxX = __max(__max(posFront.x, posBack.x), __max(posLeft.x, posRight.x));
int nMaxY = __max(__max(posFront.y, posBack.y), __max(posLeft.y, posRight.y));
for(int i = nMinY; i <= nMaxY; i ++)
{
for(int j = nMinX; j <= nMaxX; j ++)
{
CellInfo* pInfo = g_objGameMap.GetCell(j, i);
if(pInfo)
{
LayerInfo* pLayerInfo = g_objGameMap.GetLastLayerInfo(pInfo);
if(pLayerInfo)
pLayerInfo->usMask = 0;
}
}
}
}
}
}
if (bDelObj)
{
g_objGameMap.DelInteractiveObj(pPlayer);
SAFE_DELETE (pPlayer);
}
m_dequePlayer.erase(m_dequePlayer.begin()+i);
return true;
}
}
return false;
}
//////////////////////////////////////////////////////////////////////
/*
BOOL CGamePlayerSet::DelPlayer (const char* pszName, BOOL bDelObj)
{
CPlayer* pPlayer =this->GetPlayer(pszName);
if (!pPlayer)
return false;
return this->DelPlayer(pPlayer->GetID(), bDelObj);
}
*/
//////////////////////////////////////////////////////////////////////
void CGamePlayerSet::DelAllPlayer(BOOL bExcludeMyPet)
{
if(bExcludeMyPet)
{
int nPlayerAmount =m_dequePlayer.size();
for (int i=nPlayerAmount-1; i>=0; i--)
{
CPlayer* pPlayer = m_dequePlayer[i];
if(!pPlayer->IsMyPet())
{
if (CPlayer::IsValidPt(pPlayer))
{
g_objGameMap.DelInteractiveObj(pPlayer);
SAFE_DELETE (pPlayer);
m_dequePlayer.erase(m_dequePlayer.begin()+i);
}
else
{
g_objGameMap.DelInteractiveObj(pPlayer);
m_dequePlayer.erase(m_dequePlayer.begin()+i);
}
}
}
}
else
{
int nPlayerAmount =m_dequePlayer.size();
for (int i=nPlayerAmount-1; i>=0; i--)
{
CPlayer* pPlayer = m_dequePlayer[i];
if (CPlayer::IsValidPt(pPlayer))
{
g_objGameMap.DelInteractiveObj(pPlayer);
SAFE_DELETE (pPlayer);
}
else
{
g_objGameMap.DelInteractiveObj(pPlayer);
m_dequePlayer.erase(m_dequePlayer.begin()+i);
}
}
m_dequePlayer.clear();
}
m_pFocusPlayer = NULL;
}
//////////////////////////////////////////////////////////////////////
CPlayer* CGamePlayerSet::GetPlayerByIndex(DWORD dwIndex) const
{
if(dwIndex >= m_dequePlayer.size())
return NULL;
return m_dequePlayer[dwIndex];
}
//////////////////////////////////////////////////////////////////////
CPlayer* CGamePlayerSet::GetPlayer (const char* pszName) const
{
if (!pszName)
return NULL;
int nPlayerAmount =m_dequePlayer.size();
for (int i=nPlayerAmount-1; i>=0; i--)
{
CPlayer* pPlayer = m_dequePlayer[i];
if (!pPlayer)
continue;
if (pPlayer->IsPlayer() &&
0 == strcmp(pPlayer->GetName(), pszName))
{
return pPlayer;
}
}
return NULL;
}
//////////////////////////////////////////////////////////////////////
CPlayer* CGamePlayerSet::GetPlayer (OBJID id, BOOL bIncludeSelf) const
{
if(bIncludeSelf && g_objHero.GetID() == id)
return &g_objHero;
int nPlayerAmount =m_dequePlayer.size();
for (int i=nPlayerAmount-1; i>=0; i--)
{
CPlayer* pPlayer =m_dequePlayer[i];
if (!pPlayer)
continue;
if(id == pPlayer->GetID())
return pPlayer;
}
return NULL;
}
//////////////////////////////////////////////////////////////////////
CPlayer* CGamePlayerSet::GetPlayer (int nMapX, int nMapY, int nRoleType) const
{
int nPlayerAmount =m_dequePlayer.size();
for (int i=nPlayerAmount-1; i>=0; i--)
{
CPlayer* pPlayer =m_dequePlayer[i];
if (!pPlayer)
continue;
CMyPos posPlayer;
pPlayer->GetPos(posPlayer);
if(nMapX == posPlayer.x && nMapY == posPlayer.y)
{
if(nRoleType == _ROLE_NPC_NONE)
return pPlayer;
else if(pPlayer->GetRoleType() == nRoleType)
return pPlayer;
}
}
return NULL;
}
//////////////////////////////////////////////////////////////////////
CPlayer* CGamePlayerSet::GetFocusPlayer(DWORD dwFlag/*=PLAYER_NORMAL*/)
{
if (PLAYER_NORMAL == dwFlag)
{
if (CPlayer::IsValidPt(m_pFocusPlayer))
return m_pFocusPlayer;
else
{
m_pFocusPlayer = NULL;
return NULL;
}
}
CPlayer* pFocusPlayer = NULL;
if ((dwFlag&PLAYER_INCLUDESELF) && g_objHero.IsMouseFocus())
pFocusPlayer = &g_objHero;
int iPlayerAmount = this->GetPlayerAmount();
for(int i=iPlayerAmount-1; i>=0; i--)
{
CPlayer* pPlayer = m_dequePlayer[i];
if (!CPlayer::IsValidPt(pPlayer))
continue;
if (pPlayer->GetID() == MOUSE_PLAYER_ID)
continue;
/*
if (pPlayer->IsDead() && !(((dwFlag&PLAYER_INCLUDEDEAD) == 0)||
((dwFlag&PLAYER_INCLUDEDEADMONSTER)==0) ||
((dwFlag&PLAYER_DEADONLY)==0)))
continue;
*/
if (pPlayer->IsDead())
{
BOOL bCanDead = false;
if (dwFlag&PLAYER_INCLUDEDEAD)
bCanDead = true;
if (dwFlag&PLAYER_INCLUDEDEADMONSTER)
bCanDead = true;
if (!bCanDead)
continue;
}
if(dwFlag&PLAYER_DEADONLY)
if(!pPlayer->IsDead())
continue;
if (pPlayer->IsMouseFocus())
{
if(pPlayer->IsHypersensitive())
{
m_pFocusPlayer = pPlayer;
return pPlayer;
}
if (pFocusPlayer) // got one already
{
CMyPos posFocusPlayer;
pFocusPlayer->GetPos(posFocusPlayer);
CMyPos posPlayer;
pPlayer->GetPos(posPlayer);
if ((posPlayer.x+posPlayer.y >= posFocusPlayer.x+posFocusPlayer.y) ||
(g_objHero.GetPkMode() == PKMODE_ARRESTMENT && !pFocusPlayer->IsBaddy() && pPlayer->IsBaddy()))
{
if (dwFlag&PLAYER_MONSTERPRI)
{
if (pFocusPlayer->IsNpc())
{
if (pPlayer->IsNpc())
pFocusPlayer = pPlayer;
}
else
{
if (pPlayer->IsNpc())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -