📄 player.cpp
字号:
// Player.cpp: implementation of the CPlayer class.
//
//////////////////////////////////////////////////////////////////////
#include "basefunc.h"
#include "Player.h"
#include "Hero.h"
#include "gamedataset.h"
#include "GamePlayerSet.h"
#include "../NdSound/NdSound.h"
#include "3DGameMap.h"
#include "3DRoleData.h"
#include "pet.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
// static...
BOOL CPlayer::s_bShowName =false;
HANDLE CPlayer::s_hHeap =NULL;
UINT CPlayer::s_uNumAllocsInHeap =0;
//////////////////////////////////////////////////////////////////////
void * CPlayer::operator new(size_t size)
{
// got heap?
if (!s_hHeap)
{
s_hHeap =::HeapCreate(0, 0, 0);
if (!s_hHeap)
return NULL;
}
// alloc mem for new obj
void* p =::HeapAlloc(s_hHeap, HEAP_ZERO_MEMORY, size);
if (p)
{
s_uNumAllocsInHeap++;
}
return p;
}
//////////////////////////////////////////////////////////////////////
void CPlayer::operator delete(void* p)
{
// check param
if (!s_hHeap || s_uNumAllocsInHeap <= 0)
return;
// free it...
if (::HeapFree(s_hHeap, 0, p))
{
s_uNumAllocsInHeap--;
}
// time to destroy heap?
if (s_uNumAllocsInHeap <= 0)
{
if (::HeapDestroy(s_hHeap))
s_hHeap =NULL;
}
}
//////////////////////////////////////////////////////////////////////
BOOL CPlayer::IsValidPt(void* p)
{
if (!s_hHeap || !p)
return false;
if ((DWORD)p < 0x00010000 || (DWORD)p >= 0x7FFEFFFF) // user address range from 1M--2G-64k
return false;
if (::IsBadCodePtr((FARPROC)p))
return false;
BOOL bOk = ::HeapValidate(s_hHeap, 0, p);
if(bOk == false)
int kkk = 1;
return bOk;
}
//////////////////////////////////////////////////////////////////////
CPlayer::CPlayer()
{
memset(&m_infoPlayer, 0L, sizeof(m_infoPlayer));
m_nType = MAP_PLAYER;
const DWORD MaxPhysicalForce = 100;
m_infoPlayer.dwMaxPhysicalForce = MaxPhysicalForce;
strcpy(m_szCryOut, "");
m_infoPlayer.dwKoAmount = 0;
m_dwKoScale = 0;
m_pFD = CFDword::CreateNew(::GetDate(), 16);
strcpy(m_szNpcTitle, "");
m_bFlashCrime = FALSE;
m_dwFlashCrimeTime = 0;
m_nAttackTimes = 0;
}
CPlayer::~CPlayer()
{
SAFE_DELETE(m_pFD);
}
//////////////////////////////////////////////////////////////////////
void CPlayer::Show(void* pInfo)
{
// if(this->TestStatus(USERSTATUS_LURKER))
// this->SetARGB(0x55000000 | (this->GetARGB() & 0x00ffffff));
CRole::Show();
//show teammember life
if (this->GetID() != g_objHero.GetID() && g_objHero.GetTeamMemberAmount()>0
&& g_objHero.GetTeamMemberInfoByID(this->GetID())!=NULL)
this->ShowLife();
// show info
if (this->IsMouseFocus())
{
this->ShowInfo();
//show hero life
// if (this->GetID () == g_objHero.GetID ())
// this->ShowLife ();
}
else
{
if (CPlayer::s_bShowName || g_objGameMap.GetShowMapObjInfoFlag())
{
if((this->GetID() >= MONSTERID_FIRST && this->GetID() <= MONSTERID_LAST)
&& (this->TestStatus(USERSTATUS_DISAPPEARING) || this->TestStatus(USERSTATUS_DIE)))
{
// idle
}
else
{
if (this->GetID () == g_objHero.GetID ())
this->ShowLife ();
this->ShowName();
this->ShowSyndicate();
this->ShowKoAmount(false);
}
}
}
// show zoom number
CMyPos posNum;
posNum.x = m_Info.posScr.x;
posNum.y = m_Info.posScr.y-100;
m_objZoomNum.Show(posNum);
}
//////////////////////////////////////////////////////////////////////
void CPlayer::ShowLife()
{
CMySize sizeFont;
sizeFont.iHeight =CMyBitmap::GetFontSize();
sizeFont.iWidth =sizeFont.iHeight/2;
if(this->GetRoleType() == _ROLE_SYNFLAG_NPC &&
this->GetData(CPlayer::_PLAYER_LIFE)>0 && this->GetMaxLife()>0)
{
DWORD dwBloodColor;
DWORD dwLife = this->GetData(CPlayer::_PLAYER_LIFE);
DWORD dwMaxLife = this->GetMaxLife();
if(dwLife > 20000000)
dwBloodColor = _COLOR_GREEN;
else if(dwLife > 10000000)
dwBloodColor = _COLOR_YELLOW;
else
dwBloodColor = _COLOR_RED;
int nBarAmount = dwMaxLife/2000000;
if(nBarAmount * 2000000 < dwMaxLife)
nBarAmount ++;
if(nBarAmount > 5)
nBarAmount = 5;
int nBarWidth = 50, nBarHeight = 4;
int nNameShowOffset = this->GetZoomPercent()*OFFSET_NAMESHOW/100;
int nShowX =m_Info.posScr.x-nBarWidth/2;
int nShowY =m_Info.posScr.y-nNameShowOffset-sizeFont.iHeight*2;
dwLife = dwLife%(10000000+1);
for(int i = 0; i < nBarAmount; i ++)
{
CMyPos posBegin, posEnd;
posBegin.x = nShowX;
posBegin.y = nShowY-nBarHeight*i*2;
posEnd.x = nShowX+nBarWidth;
posEnd.y = nShowY+nBarHeight-nBarHeight*i*2;
g_objGameMap.MapScaleShowPos(posBegin.x, posBegin.y);
g_objGameMap.MapScaleShowPos(posEnd.x, posEnd.y);
CMyBitmap::ShowBlock(posBegin.x, posBegin.y, posEnd.x, posEnd.y, 0x55000000+_COLOR_GRAY);
DWORD dwCurrentMaxLife = 2000000;
DWORD dwCurrentLife;
if(dwLife > dwCurrentMaxLife*i)
dwCurrentLife = dwLife - dwCurrentMaxLife*i;
else
dwCurrentLife = 0;
if(dwCurrentLife > dwCurrentMaxLife)
dwCurrentLife = dwCurrentMaxLife;
int nLifeBarLen;
if(dwCurrentMaxLife == 0)
nLifeBarLen = 0;
else
nLifeBarLen = nBarWidth*dwCurrentLife/dwCurrentMaxLife;
posBegin.x = nShowX;
posBegin.y = nShowY-nBarHeight*i*2;
posEnd.x = nShowX+nLifeBarLen;
posEnd.y = nShowY+nBarHeight-nBarHeight*i*2;
g_objGameMap.MapScaleShowPos(posBegin.x, posBegin.y);
g_objGameMap.MapScaleShowPos(posEnd.x, posEnd.y);
CMyBitmap::ShowBlock(posBegin.x, posBegin.y, posEnd.x, posEnd.y, 0xff000000+dwBloodColor);
}
}
else if(this->IsMyPet() && this->GetData(CPlayer::_PLAYER_LIFE) >0 && this->GetMaxLife()>0)
{
g_objGameMap.World2Screen(m_Info.posWorld.x, m_Info.posWorld.y, m_Info.posScr.x, m_Info.posScr.y);
int nBarWidth = 50, nBarHeight = 6;
int nNameShowOffset = this->GetZoomPercent()*OFFSET_NAMESHOW/100;
int nShowX =m_Info.posScr.x-nBarWidth/2;
int nShowY =m_Info.posScr.y-nNameShowOffset - sizeFont.iHeight*3;
CMyPos posBegin, posEnd;
posBegin.x = nShowX;
posBegin.y = nShowY;
posEnd.x = nShowX+nBarWidth;
posEnd.y = nShowY+nBarHeight;
g_objGameMap.MapScaleShowPos(posBegin.x, posBegin.y);
g_objGameMap.MapScaleShowPos(posEnd.x, posEnd.y);
CMyBitmap::ShowBlock(posBegin.x-1, posBegin.y-1, posEnd.x+1, posEnd.y+1, 0x77000000+_COLOR_GRAY);
CMyBitmap::ShowRect(posBegin.x-1, posBegin.y-1, posEnd.x, posEnd.y, 0x77000000+_COLOR_RED);
int nLifeBarLen = nBarWidth*this->GetData(CPlayer::_PLAYER_LIFE)/this->GetMaxLife();
posBegin.x = nShowX;
posBegin.y = nShowY;
posEnd.x = nShowX+nLifeBarLen;
posEnd.y = nShowY+nBarHeight;
g_objGameMap.MapScaleShowPos(posBegin.x, posBegin.y);
g_objGameMap.MapScaleShowPos(posEnd.x, posEnd.y);
CMyBitmap::ShowBlock(posBegin.x, posBegin.y, posEnd.x, posEnd.y, 0xffffff00);
}
else if (g_objHero.GetID() == this->GetID()
&& this->GetData(CPlayer::_PLAYER_LIFE) >0 && this->GetMaxLife()>0)
{
g_objGameMap.World2Screen(m_Info.posWorld.x, m_Info.posWorld.y, m_Info.posScr.x, m_Info.posScr.y);
int nBarWidth = 50, nBarHeight = 6;
int nNameShowOffset = this->GetZoomPercent()*OFFSET_NAMESHOW/100;
CCommand* pCommand = this->GetCommand();
if (pCommand
&& pCommand->nData == _ACTION_SITDOWN
&& pCommand->iType == _COMMAND_EMOTION
&& pCommand->iStatus == _CMDSTATUS_CONTINUE)
{
nNameShowOffset = this->GetZoomPercent()*OFFSET_NAMESHOW/200;
}
int nShowX =m_Info.posScr.x-nBarWidth/2;
int nShowY =m_Info.posScr.y-nNameShowOffset - sizeFont.iHeight*3;
CMyPos posBegin, posEnd;
posBegin.x = nShowX;
posBegin.y = nShowY;
posEnd.x = nShowX+nBarWidth;
posEnd.y = nShowY+nBarHeight;
g_objGameMap.MapScaleShowPos(posBegin.x, posBegin.y);
g_objGameMap.MapScaleShowPos(posEnd.x, posEnd.y);
CMyBitmap::ShowBlock(posBegin.x-1, posBegin.y-1, posEnd.x+1, posEnd.y+1, 0x77000000+_COLOR_GRAY);
CMyBitmap::ShowRect(posBegin.x-1, posBegin.y-1, posEnd.x, posEnd.y, 0x77000000+_COLOR_RED);
int nLifeBarLen = nBarWidth*this->GetData(CPlayer::_PLAYER_LIFE)/this->GetMaxLife();
posBegin.x = nShowX;
posBegin.y = nShowY;
posEnd.x = nShowX+nLifeBarLen;
posEnd.y = nShowY+nBarHeight;
g_objGameMap.MapScaleShowPos(posBegin.x, posBegin.y);
g_objGameMap.MapScaleShowPos(posEnd.x, posEnd.y);
CMyBitmap::ShowBlock(posBegin.x, posBegin.y, posEnd.x, posEnd.y, 0xffffff00);
}
else if (g_objHero.GetID() != this->GetID()
&& g_objHero.GetTeamMemberInfoByID(this->GetID())!=NULL)
{
TeamMemberInfo* pTeamMemberInfo = g_objHero.GetTeamMemberInfoByID(this->GetID());
if (pTeamMemberInfo == NULL)
return;
else if (pTeamMemberInfo->dwHp >=0 && pTeamMemberInfo->dwMaxHp >0)
{
g_objGameMap.World2Screen(m_Info.posWorld.x, m_Info.posWorld.y, m_Info.posScr.x, m_Info.posScr.y);
int nBarWidth = 50, nBarHeight = 6;
int nNameShowOffset = this->GetZoomPercent()*OFFSET_NAMESHOW/100;
CCommand* pCommand = this->GetCommand();
if (pCommand
&& pCommand->nData == _ACTION_SITDOWN
&& pCommand->iType == _COMMAND_EMOTION
&& pCommand->iStatus == _CMDSTATUS_CONTINUE)
{
nNameShowOffset = this->GetZoomPercent()*OFFSET_NAMESHOW/200;
}
int nShowX =m_Info.posScr.x-nBarWidth/2;
int nShowY =m_Info.posScr.y-nNameShowOffset - sizeFont.iHeight*3;
CMyPos posBegin, posEnd;
posBegin.x = nShowX;
posBegin.y = nShowY;
posEnd.x = nShowX+nBarWidth;
posEnd.y = nShowY+nBarHeight;
g_objGameMap.MapScaleShowPos(posBegin.x, posBegin.y);
g_objGameMap.MapScaleShowPos(posEnd.x, posEnd.y);
CMyBitmap::ShowBlock(posBegin.x-1, posBegin.y-1, posEnd.x+1, posEnd.y+1, 0x77000000+_COLOR_GRAY);
CMyBitmap::ShowRect(posBegin.x-1, posBegin.y-1, posEnd.x, posEnd.y, 0x77000000+_COLOR_RED);
int nLifeBarLen = nBarWidth*pTeamMemberInfo->dwHp/pTeamMemberInfo->dwMaxHp;
posBegin.x = nShowX;
posBegin.y = nShowY;
posEnd.x = nShowX+nLifeBarLen;
posEnd.y = nShowY+nBarHeight;
g_objGameMap.MapScaleShowPos(posBegin.x, posBegin.y);
g_objGameMap.MapScaleShowPos(posEnd.x, posEnd.y);
CMyBitmap::ShowBlock(posBegin.x, posBegin.y, posEnd.x, posEnd.y, 0xffffff00);
}
}
else if (this->IsNpc() &&
this->GetData(CPlayer::_PLAYER_LIFE)>0 && this->GetMaxLife()>0)
{ // npc will show life bar
int nBarWidth = 50, nBarHeight = 4;
int nNameShowOffset = this->GetZoomPercent()*OFFSET_NAMESHOW/100;
int nShowX =m_Info.posScr.x-nBarWidth/2;
int nShowY =m_Info.posScr.y-nNameShowOffset-12;
CMyPos posBegin, posEnd;
posBegin.x = nShowX;
posBegin.y = nShowY;
posEnd.x = nShowX+nBarWidth;
posEnd.y = nShowY+nBarHeight;
g_objGameMap.MapScaleShowPos(posBegin.x, posBegin.y);
g_objGameMap.MapScaleShowPos(posEnd.x, posEnd.y);
CMyBitmap::ShowBlock(posBegin.x, posBegin.y, posEnd.x, posEnd.y, 0x55000000+_COLOR_GRAY);
int nLifeBarLen = nBarWidth*this->GetData(CPlayer::_PLAYER_LIFE)/this->GetMaxLife();
posBegin.x = nShowX;
posBegin.y = nShowY;
posEnd.x = nShowX+nLifeBarLen;
posEnd.y = nShowY+nBarHeight;
g_objGameMap.MapScaleShowPos(posBegin.x, posBegin.y);
g_objGameMap.MapScaleShowPos(posEnd.x, posEnd.y);
CMyBitmap::ShowBlock(posBegin.x, posBegin.y, posEnd.x, posEnd.y, 0xffB80303);
}
}
//////////////////////////////////////////////////////////////////////
void CPlayer::ShowName(void)
{
if(this->GetRoleType() == _ROLE_STONE_MINE)
return;
if(this->GetID() != g_objHero.GetID()
&& g_objHero.GetTeamMemberInfoByID(this->GetID()) == NULL)
this->ShowLife();
CMySize sizeFont;
sizeFont.iHeight =CMyBitmap::GetFontSize();
sizeFont.iWidth =sizeFont.iHeight/2;
g_objGameMap.World2Screen(m_Info.posWorld.x, m_Info.posWorld.y, m_Info.posScr.x, m_Info.posScr.y);
const char* pszString =this->GetName();
#ifdef _DEBUG
char szID[256] = "";
if (this->IsNpc())
{
sprintf(szID, "%s[%u]", pszString, this->GetID());
pszString = szID;
}
if (this->IsMyPet())
{
CPet* pPet = (CPet*)this;
CMyPos posC;
pPet->GetPos(posC);
//pPet->GetAlignPos(posA);
//sprintf(szID, "%s[%d,%d][%d,%d]", pszString, posC.x, posC.y, posA.x, posA.y);
pszString = szID;
}
#endif
int iInfoLen =strlen(pszString);
if (iInfoLen <= 0)
return;
static dwNameFlashTimer = ::TimeGet();
DWORD dwColor = _COLOR_WHITE;
if (this->IsNpc())
{
dwColor = g_objHero.GetMonsterNameColor(this->GetLev());
}
else
{
if (this->TestStatus(USERSTATUS_RED))
dwColor = _COLOR_RED;
if(this->TestStatus(USERSTATUS_DARKRED))
dwColor = _COLOR_BLACK;
if(this->TestStatus(USERSTATUS_CRIME))
{
int nFrame = (::TimeGet() - dwNameFlashTimer)/200;
if(nFrame > nFrame/2*2)
dwColor = _COLOR_BLUE;
else
dwColor = _COLOR_WHITE;
}
/* if(this->TestStatus(KEEPEFFECT_SELFDEFENCE))
{
int nFrame = (::TimeGet() - dwNameFlashTimer)/200;
if(nFrame > nFrame/2*2)
dwColor = _COLOR_BLUE;
else
dwColor = _COLOR_WHITE;
}*/
}
int nNameShowOffset = this->GetZoomPercent()*OFFSET_NAMESHOW/100;
CCommand* pCommand = this->GetCommand();
if (pCommand
&& pCommand->nData == _ACTION_SITDOWN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -