本文整理汇总了C++中CNpc::OnDeath方法的典型用法代码示例。如果您正苦于以下问题:C++ CNpc::OnDeath方法的具体用法?C++ CNpc::OnDeath怎么用?C++ CNpc::OnDeath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CNpc
的用法示例。
在下文中一共展示了CNpc::OnDeath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RecvNpcDead
// TO-DO: Remove this. NPCs don't just randomly die, it would make sense to do this as a result of the cause, not just because.
void CAISocket::RecvNpcDead(Packet & pkt)
{
uint16 nid = pkt.read<uint16>();
CNpc* pNpc = g_pMain->m_arNpcArray.GetData(nid);
if (pNpc == NULL)
return;
C3DMap* pMap = pNpc->GetMap();
if (pMap == NULL)
return;
pNpc->OnDeath(NULL);
}
示例2: RecvNpcDead
// TO-DO: Remove this. NPCs don't just randomly die, it would make sense to do this as a result of the cause, not just because.
void CAISocket::RecvNpcDead(Packet & pkt)
{
CNpc * pNpc;
Unit * pAttacker;
uint16 nid, attackerID;
pkt >> nid >> attackerID;
pNpc = g_pMain->GetNpcPtr(nid);
if (pNpc == nullptr
|| pNpc->GetMap() == nullptr)
return;
pAttacker = g_pMain->GetUnitPtr(attackerID);
pNpc->OnDeath(pAttacker);
}
示例3: RecvNpcAttack
void CAISocket::RecvNpcAttack(Packet & pkt)
{
int nHP = 0, temp_damage = 0;
int16 sid, tid;
BYTE type, bResult, byAttackType = 0;
float fDir=0.0f;
short damage = 0;
CNpc* pNpc = NULL, *pMon = NULL;
CUser* pUser = NULL;
_OBJECT_EVENT* pEvent = NULL;
pkt >> type >> bResult >> sid >> tid >> damage >> nHP >> byAttackType;
//TRACE("CAISocket-RecvNpcAttack : sid=%s, tid=%d, zone_num=%d\n", sid, tid, m_iZoneNum);
if(type == 0x01) // user attack -> npc
{
pNpc = g_pMain->m_arNpcArray.GetData(tid);
if(!pNpc) return;
pNpc->m_iHP -= damage;
if( pNpc->m_iHP < 0 )
pNpc->m_iHP = 0;
pUser = g_pMain->GetUserPtr(sid);
// NPC died
if (bResult == 2 || bResult == 4)
pNpc->OnDeath(pUser);
else
{
Packet result(WIZ_ATTACK, byAttackType);
result << bResult << sid << tid;
pNpc->SendToRegion(&result);
}
if (pUser != NULL)
{
pUser->SendTargetHP( 0, tid, -damage );
if( byAttackType != MAGIC_ATTACK && byAttackType != DURATION_ATTACK) {
pUser->ItemWoreOut(ATTACK, damage);
temp_damage = damage * pUser->m_bMagicTypeLeftHand / 100 ;
switch (pUser->m_bMagicTypeLeftHand) { // LEFT HAND!!!
case ITEM_TYPE_HP_DRAIN : // HP Drain
pUser->HpChange(temp_damage);
break;
case ITEM_TYPE_MP_DRAIN : // MP Drain
pUser->MSpChange(temp_damage);
break;
}
temp_damage = 0; // reset data;
temp_damage = damage * pUser->m_bMagicTypeRightHand / 100 ;
switch (pUser->m_bMagicTypeRightHand) { // LEFT HAND!!!
case ITEM_TYPE_HP_DRAIN : // HP Drain
pUser->HpChange(temp_damage);
break;
case ITEM_TYPE_MP_DRAIN : // MP Drain
pUser->MSpChange(temp_damage);
break;
}
//
}
}
}
else if (type == 2) // npc attack -> user
{
pNpc = g_pMain->m_arNpcArray.GetData(sid);
if(!pNpc) return;
//TRACE("CAISocket-RecvNpcAttack 222 : sid=%s, tid=%d, zone_num=%d\n", sid, tid, m_iZoneNum);
if( tid >= USER_BAND && tid < NPC_BAND)
{
pUser = g_pMain->GetUserPtr(tid);
if(pUser == NULL)
return;
pUser->HpChange(-damage, pNpc, false);
pUser->ItemWoreOut(DEFENCE, damage);
Packet result(WIZ_ATTACK, byAttackType);
result << uint8(bResult == 3 ? 0 : bResult)
<< sid << tid;
pNpc->SendToRegion(&result);
//TRACE("RecvNpcAttack ==> sid = %d, tid = %d, result = %d\n", sid, tid, result);
}
else if (tid >= NPC_BAND) // npc attack -> monster
{
pMon = g_pMain->m_arNpcArray.GetData(tid);
if(!pMon) return;
pMon->m_iHP -= damage;
if( pMon->m_iHP < 0 )
pMon->m_iHP = 0;
Packet result(WIZ_ATTACK, byAttackType);
result << bResult << sid << tid;
//.........这里部分代码省略.........
示例4: RecvNpcAttack
void CAISocket::RecvNpcAttack(Packet & pkt)
{
int nHP = 0, temp_damage = 0;
int16 sid, tid;
BYTE type, bResult, byAttackType = 0;
float fDir=0.0f;
short damage = 0;
CNpc* pNpc = NULL, *pMon = NULL;
CUser* pUser = NULL;
_OBJECT_EVENT* pEvent = NULL;
pkt >> type >> bResult >> sid >> tid >> damage >> nHP >> byAttackType;
//TRACE("CAISocket-RecvNpcAttack : sid=%s, tid=%d, zone_num=%d\n", sid, tid, m_iZoneNum);
if(type == 0x01) // user attack -> npc
{
pNpc = g_pMain->m_arNpcArray.GetData(tid);
if(!pNpc) return;
pNpc->m_iHP -= damage;
if( pNpc->m_iHP < 0 )
pNpc->m_iHP = 0;
// NPC died
if (bResult == 4)
pNpc->OnDeath();
else
{
Packet result(WIZ_ATTACK, byAttackType);
result << bResult << sid << tid;
pNpc->SendToRegion(&result);
}
pUser = g_pMain->GetUserPtr(sid);
if (pUser != NULL)
{
pUser->SendTargetHP( 0, tid, -damage );
if( byAttackType != MAGIC_ATTACK && byAttackType != DURATION_ATTACK) {
pUser->ItemWoreOut(ATTACK, damage);
// LEFT HAND!!! by Yookozuna
temp_damage = damage * pUser->m_bMagicTypeLeftHand / 100 ;
switch (pUser->m_bMagicTypeLeftHand) { // LEFT HAND!!!
case ITEM_TYPE_HP_DRAIN : // HP Drain
pUser->HpChange(temp_damage, 0);
break;
case ITEM_TYPE_MP_DRAIN : // MP Drain
pUser->MSpChange(temp_damage);
break;
}
temp_damage = 0; // reset data;
// RIGHT HAND!!! by Yookozuna
temp_damage = damage * pUser->m_bMagicTypeRightHand / 100 ;
switch (pUser->m_bMagicTypeRightHand) { // LEFT HAND!!!
case ITEM_TYPE_HP_DRAIN : // HP Drain
pUser->HpChange(temp_damage, 0);
break;
case ITEM_TYPE_MP_DRAIN : // MP Drain
pUser->MSpChange(temp_damage);
break;
}
//
}
}
if (bResult == 2 || bResult== 4) // npc dead
{
pNpc->GetMap()->RegionNpcRemove(pNpc->m_sRegion_X, pNpc->m_sRegion_Z, tid);
// TRACE("--- Npc Dead : Npc�� Region���� ����ó��.. ,, region_x=%d, y=%d\n", pNpc->m_sRegion_X, pNpc->m_sRegion_Z);
pNpc->m_sRegion_X = 0; pNpc->m_sRegion_Z = 0;
pNpc->m_NpcState = NPC_DEAD;
if( pNpc->m_byObjectType == SPECIAL_OBJECT ) {
pEvent = pNpc->GetMap()->GetObjectEvent( pNpc->m_sSid );
if( pEvent ) pEvent->byLife = 0;
}
if (pNpc->m_tNpcType == 2 && pUser != NULL) // EXP
pUser->GiveItem(900001000, 1);
}
}
else if (type == 2) // npc attack -> user
{
pNpc = g_pMain->m_arNpcArray.GetData(sid);
if(!pNpc) return;
//TRACE("CAISocket-RecvNpcAttack 222 : sid=%s, tid=%d, zone_num=%d\n", sid, tid, m_iZoneNum);
if( tid >= USER_BAND && tid < NPC_BAND)
{
pUser = g_pMain->GetUserPtr(tid);
if(pUser == NULL)
return;
pUser->HpChange(-damage, 1, true);
pUser->ItemWoreOut(DEFENCE, damage);
Packet result(WIZ_ATTACK, byAttackType);
//.........这里部分代码省略.........