本文整理汇总了C++中CNpc::GetDistance方法的典型用法代码示例。如果您正苦于以下问题:C++ CNpc::GetDistance方法的具体用法?C++ CNpc::GetDistance怎么用?C++ CNpc::GetDistance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNpc
的用法示例。
在下文中一共展示了CNpc::GetDistance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HealAreaCheck
void CUser::HealAreaCheck(int rx, int rz)
{
MAP* pMap = GetMap();
if (pMap == NULL) return;
// 자신의 region에 있는 NpcArray을 먼저 검색하여,, 가까운 거리에 Monster가 있는지를 판단..
if(rx < 0 || rz < 0 || rx > pMap->GetXRegionMax() || rz > pMap->GetZRegionMax()) {
TRACE("#### CUser-HealAreaCheck() Fail : [nid=%d, name=%s], nRX=%d, nRZ=%d #####\n", m_iUserId, m_strUserID, rx, rz);
return;
}
float fRadius = 10.0f; // 30m
__Vector3 vStart, vEnd;
CNpc* pNpc = NULL ; // Pointer initialization!
float fDis = 0.0f;
vStart.Set(m_curx, (float)0, m_curz);
int send_index=0, result = 1, count = 0;
EnterCriticalSection( &g_region_critical );
CRegion *pRegion = &pMap->m_ppRegion[rx][rz];
int total_mon = pRegion->m_RegionNpcArray.GetSize();
int *pNpcIDList = new int[total_mon];
foreach_stlmap (itr, pRegion->m_RegionNpcArray)
pNpcIDList[count++] = *itr->second;
LeaveCriticalSection( &g_region_critical );
for(int i = 0 ; i < total_mon; i++ ) {
int nid = pNpcIDList[i];
if( nid < NPC_BAND ) continue;
pNpc = (CNpc*)g_pMain->m_arNpc.GetData(nid - NPC_BAND);
if( pNpc != NULL && pNpc->m_NpcState != NPC_DEAD) {
if( m_bNation == pNpc->m_byGroup ) continue;
vEnd.Set(pNpc->m_fCurX, pNpc->m_fCurY, pNpc->m_fCurZ);
fDis = pNpc->GetDistance(vStart, vEnd);
if(fDis <= fRadius) { // NPC가 반경안에 있을 경우...
pNpc->ChangeTarget(1004, this);
}
}
}
if (pNpcIDList)
delete [] pNpcIDList;
}
示例2: AreaAttackDamage
void CMagicProcess::AreaAttackDamage(int magictype, int rx, int rz, int magicid, int moral, int data1, int data2, int data3, int dexpoint, int righthand_damage)
{
MAP* pMap = m_pSrcUser->GetMap();
if (pMap == NULL) return;
// 자신의 region에 있는 UserArray을 먼저 검색하여,, 가까운 거리에 유저가 있는지를 판단..
if(rx < 0 || rz < 0 || rx > pMap->GetXRegionMax() || rz > pMap->GetZRegionMax()) {
TRACE("#### CMagicProcess-AreaAttackDamage() Fail : [nid=%d, name=%s], nRX=%d, nRZ=%d #####\n", m_pSrcUser->m_iUserId, m_pSrcUser->m_strUserID, rx, rz);
return;
}
_MAGIC_TYPE3* pType3 = NULL;
_MAGIC_TYPE4* pType4 = NULL;
_MAGIC_TABLE* pMagic = NULL;
int damage = 0, tid = 0, target_damage = 0, attribute = 0;
float fRadius = 0;
pMagic = g_pMain->m_MagictableArray.GetData( magicid ); // Get main magic table.
if( !pMagic ) {
TRACE("#### CMagicProcess-AreaAttackDamage Fail : magic maintable error ,, magicid=%d\n", magicid);
return;
}
if(magictype == 3) {
pType3 = g_pMain->m_Magictype3Array.GetData( magicid ); // Get magic skill table type 3.
if( !pType3 ) {
TRACE("#### CMagicProcess-AreaAttackDamage Fail : magic table3 error ,, magicid=%d\n", magicid);
return;
}
target_damage = pType3->sFirstDamage;
attribute = pType3->bAttribute;
fRadius = (float)pType3->bRadius;
}
else if(magictype == 4) {
pType4 = g_pMain->m_Magictype4Array.GetData( magicid ); // Get magic skill table type 3.
if( !pType4 ) {
TRACE("#### CMagicProcess-AreaAttackDamage Fail : magic table4 error ,, magicid=%d\n", magicid);
return;
}
fRadius = (float)pType4->bRadius;
}
if( fRadius <= 0 ) {
TRACE("#### CMagicProcess-AreaAttackDamage Fail : magicid=%d, radius = %d\n", magicid, fRadius);
return;
}
__Vector3 vStart, vEnd;
CNpc* pNpc = NULL ; // Pointer initialization!
float fDis = 0.0f;
vStart.Set((float)data1, (float)0, (float)data3);
char send_buff[256];
int send_index=0, result = 1, count = 0, total_mon = 0, attack_type=0;;
int* pNpcIDList = NULL;
EnterCriticalSection( &g_region_critical );
CRegion *pRegion = &pMap->m_ppRegion[rx][rz];
total_mon = pRegion->m_RegionNpcArray.GetSize();
pNpcIDList = new int[total_mon];
foreach_stlmap (itr, pRegion->m_RegionNpcArray)
pNpcIDList[count++] = *itr->second;
LeaveCriticalSection(&g_region_critical);
for(int i = 0 ; i < total_mon; i++ ) {
int nid = pNpcIDList[i];
if( nid < NPC_BAND ) continue;
pNpc = (CNpc*)g_pMain->m_arNpc.GetData(nid - NPC_BAND);
if( pNpc != NULL && pNpc->m_NpcState != NPC_DEAD) {
if( m_pSrcUser->m_bNation == pNpc->m_byGroup ) continue;
vEnd.Set(pNpc->m_fCurX, pNpc->m_fCurY, pNpc->m_fCurZ);
fDis = pNpc->GetDistance(vStart, vEnd);
if(fDis <= fRadius) { // NPC가 반경안에 있을 경우...
if(magictype == 3) { // 타잎 3일 경우...
damage = GetMagicDamage(pNpc->m_sNid+NPC_BAND, target_damage, attribute, dexpoint, righthand_damage);
TRACE("Area magictype3 ,, magicid=%d, damage=%d\n", magicid, damage);
if(damage >= 0) {
result = pNpc->SetHMagicDamage(damage);
}
else {
damage = abs(damage);
if(pType3->bAttribute == 3) attack_type = 3; // 기절시키는 마법이라면.....
else attack_type = magicid;
if(pNpc->SetDamage(attack_type, damage, m_pSrcUser->m_strUserID, m_pSrcUser->m_iUserId + USER_BAND) == FALSE) {
// Npc가 죽은 경우,,
pNpc->SendExpToUserList(); // 경험치 분배!!
pNpc->SendDead();
m_pSrcUser->SendAttackSuccess(pNpc->m_sNid+NPC_BAND, MAGIC_ATTACK_TARGET_DEAD, damage, pNpc->m_iHP);
}
else {
m_pSrcUser->SendAttackSuccess(pNpc->m_sNid+NPC_BAND, ATTACK_SUCCESS, damage, pNpc->m_iHP);
}
}
//.........这里部分代码省略.........
示例3: AreaAttackDamage
void CMagicProcess::AreaAttackDamage(int magictype, int rx, int rz, int magicid, int moral, int data1, int data2, int data3, int dexpoint, int righthand_damage)
{
MAP* pMap = m_pSrcUser->GetMap();
if (pMap == nullptr) return;
// 자신의 region에 있는 UserArray을 먼저 검색하여,, 가까운 거리에 유저가 있는지를 판단..
if(rx < 0 || rz < 0 || rx > pMap->GetXRegionMax() || rz > pMap->GetZRegionMax()) {
TRACE("#### CMagicProcess-AreaAttackDamage() Fail : [nid=%d, name=%s], nRX=%d, nRZ=%d #####\n", m_pSrcUser->m_iUserId, m_pSrcUser->m_strUserID, rx, rz);
return;
}
_MAGIC_TYPE3* pType3 = nullptr;
_MAGIC_TYPE4* pType4 = nullptr;
_MAGIC_TABLE* pMagic = nullptr;
int damage = 0, tid = 0, target_damage = 0, attribute = 0;
float fRadius = 0;
pMagic = g_pMain->m_MagictableArray.GetData( magicid ); // Get main magic table.
if( !pMagic ) {
TRACE("#### CMagicProcess-AreaAttackDamage Fail : magic maintable error ,, magicid=%d\n", magicid);
return;
}
if(magictype == 3) {
pType3 = g_pMain->m_Magictype3Array.GetData( magicid ); // Get magic skill table type 3.
if( !pType3 ) {
TRACE("#### CMagicProcess-AreaAttackDamage Fail : magic table3 error ,, magicid=%d\n", magicid);
return;
}
target_damage = pType3->sFirstDamage;
attribute = pType3->bAttribute;
fRadius = (float)pType3->bRadius;
}
else if(magictype == 4) {
pType4 = g_pMain->m_Magictype4Array.GetData( magicid ); // Get magic skill table type 3.
if( !pType4 ) {
TRACE("#### CMagicProcess-AreaAttackDamage Fail : magic table4 error ,, magicid=%d\n", magicid);
return;
}
fRadius = (float)pType4->bRadius;
}
if( fRadius <= 0 ) {
TRACE("#### CMagicProcess-AreaAttackDamage Fail : magicid=%d, radius = %d\n", magicid, fRadius);
return;
}
__Vector3 vStart, vEnd;
CNpc* pNpc = nullptr ; // Pointer initialization!
float fDis = 0.0f;
vStart.Set((float)data1, (float)0, (float)data3);
int count = 0, total_mon = 0, attack_type=0;
int* pNpcIDList = nullptr;
bool bResult = true;
pMap->m_lock.Acquire();
CRegion *pRegion = &pMap->m_ppRegion[rx][rz];
total_mon = pRegion->m_RegionNpcArray.GetSize();
pNpcIDList = new int[total_mon];
foreach_stlmap (itr, pRegion->m_RegionNpcArray)
pNpcIDList[count++] = *itr->second;
pMap->m_lock.Release();
for(int i = 0; i < total_mon; i++)
{
int nid = pNpcIDList[i];
if( nid < NPC_BAND ) continue;
pNpc = g_pMain->m_arNpc.GetData(nid);
if (pNpc == nullptr || pNpc->m_NpcState == NPC_DEAD)
continue;
if( m_pSrcUser->m_bNation == pNpc->m_byGroup ) continue;
vEnd.Set(pNpc->GetX(), pNpc->GetY(), pNpc->GetZ());
fDis = pNpc->GetDistance(vStart, vEnd);
if(fDis > fRadius)
continue;
if (magictype == 3)
{
damage = GetMagicDamage(pNpc->GetID(), target_damage, attribute, dexpoint, righthand_damage);
TRACE("Area magictype3 ,, magicid=%d, damage=%d\n", magicid, damage);
if(damage >= 0) {
bResult = pNpc->SetHMagicDamage(damage);
}
else {
damage = abs(damage);
if(pType3->bAttribute == 3) attack_type = 3; // 기절시키는 마법이라면.....
else attack_type = magicid;
if(pNpc->SetDamage(attack_type, damage, m_pSrcUser->m_iUserId + USER_BAND) == false) {
m_pSrcUser->SendAttackSuccess(pNpc->GetID(), MAGIC_ATTACK_TARGET_DEAD, damage, pNpc->m_iHP);
}
else {
m_pSrcUser->SendAttackSuccess(pNpc->GetID(), ATTACK_SUCCESS, damage, pNpc->m_iHP);
}
}
//.........这里部分代码省略.........