当前位置: 首页>>代码示例>>C++>>正文


C++ CNpc类代码示例

本文整理汇总了C++中CNpc的典型用法代码示例。如果您正苦于以下问题:C++ CNpc类的具体用法?C++ CNpc怎么用?C++ CNpc使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CNpc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: RecvNpcRegionUpdate

void CAISocket::RecvNpcRegionUpdate(Packet & pkt)
{
	uint16 sNpcID;
	float fX, fY, fZ;

	pkt >> sNpcID >> fX >> fY >> fZ;

	CNpc * pNpc = g_pMain->GetNpcPtr(sNpcID);
	if (pNpc == nullptr)
		return;

	pNpc->SetPosition(fX, fY, fZ);
	pNpc->RegisterRegion();
}
开发者ID:Damra,项目名称:koserver,代码行数:14,代码来源:AISocket.cpp

示例2: isDead

void CUser::ClientEvent(uint16 sNpcID)
{
	// Ensure AI's loaded
	if (!g_pMain->m_bPointCheckFlag
		|| isDead())
		return;

	int32 iEventID = 0;
	CNpc *pNpc = g_pMain->GetNpcPtr(sNpcID);
	if (pNpc == nullptr
		|| !isInRange(pNpc, MAX_NPC_RANGE))
		return;

	m_sEventNid = sNpcID;
	m_sEventSid = pNpc->GetProtoID(); // For convenience purposes with Lua scripts.

	// Aww.
	if (pNpc->GetType() == NPC_KISS)
	{
		KissUser();
		return;
	}

	FastGuard lock(g_pMain->m_questNpcLock);
	QuestNpcList::iterator itr = g_pMain->m_QuestNpcList.find(pNpc->GetProtoID());
	if (itr == g_pMain->m_QuestNpcList.end())
		return;

	// Copy it. We should really lock the list, but nevermind.
	QuestHelperList & pList = itr->second;
	_QUEST_HELPER * pHelper = nullptr;
	foreach(itr, pList)
	{
		if ((*itr) == nullptr
			|| (*itr)->sEventDataIndex
			|| (*itr)->bEventStatus
			|| ((*itr)->bNation != 3 && (*itr)->bNation != GetNation())
			|| ((*itr)->bClass != 5 && !JobGroupCheck((*itr)->bClass)))
			continue;

		pHelper = (*itr);
		break;
	}

	if (pHelper == nullptr)
		return;

	QuestV2RunEvent(pHelper, pHelper->nEventTriggerIndex);
}
开发者ID:BlackStaRinc,项目名称:snoxd-koserver,代码行数:49,代码来源:NPCHandler.cpp

示例3: SetFishingStartTime

void CFishingManager::Fishing_Ready_Ack(void* pMsg)
{
	MSG_DWORD4* pmsg = (MSG_DWORD4*)pMsg;

	CObject* pObject = OBJECTMGR->GetObject(pmsg->dwObjectID);
	if(!pObject)
		return;

	if(pObject == HERO)
	{
		if(0==pmsg->dwData1 || 0==pmsg->dwData3 || 0==pmsg->dwData4)
			return;

		SetFishingStartTime(gCurTime);
		SetFishingPlace(pmsg->dwData1);

		m_fGaugeStartPos = (float)pmsg->dwData2/100.0f;
		m_dwProcessTime = pmsg->dwData3;
		m_nRepeatCount = pmsg->dwData4;

		LONG maxValue = 0;
		cGuageBar* pGaugeBar = GAMEIN->GetFishingGaugeDlg()->GetFishingGB();
		if(pGaugeBar)
			maxValue = pGaugeBar->GetMaxValue();

		m_fGaugeBarSpeed = ((float)m_nRepeatCount * maxValue) / (float)m_dwProcessTime;
		m_dwUpdateTime = (m_dwProcessTime / m_nRepeatCount) / maxValue;

		m_bActive = TRUE;
	}
	else
	{
		CNpc* pNpc = (CNpc*)OBJECTMGR->GetObject(pmsg->dwData1);
		if(pNpc)
		{
			// 방향전환
			VECTOR3 pos;
			pNpc->GetPosition(&pos);
			MOVEMGR->SetLookatPos(pObject,&pos,0,gCurTime);
		}
	}


	OBJECTSTATEMGR->StartObjectState(pObject, eObjectState_Fishing);
	OBJECTEFFECTDESC desc( FindEffectNum("char_m_fishing_swing_A.beff") );

	pObject->RemoveObjectEffect( FISHING_START_EFFECT );
	pObject->AddObjectEffect( FISHING_START_EFFECT, &desc, 1 );
}
开发者ID:xianyinchen,项目名称:LUNAPlus,代码行数:49,代码来源:FishingManager.cpp

示例4: 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);
}
开发者ID:Damra,项目名称:koserver,代码行数:16,代码来源:AISocket.cpp

示例5: GetMap

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;
}
开发者ID:Ernosto,项目名称:snoxd-koserver,代码行数:46,代码来源:AIUser.cpp

示例6: TRACE

CNpc* CRoomEvent::GetNpcPtr( int sid )
{
	if (m_mapRoomNpcArray.IsEmpty())	
	{
		TRACE("### RoomEvent-GetNpcPtr() : monster empty ###\n");
		return nullptr;
	}

	foreach_stlmap (itr, m_mapRoomNpcArray)
	{
		CNpc *pNpc = g_pMain->GetNpcPtr(itr->first);
		if (pNpc == nullptr
			|| pNpc->GetProtoID() != sid)
			continue;

		return pNpc;
	}
开发者ID:BlackStaRinc,项目名称:snoxd-koserver,代码行数:17,代码来源:RoomEvent.cpp

示例7: GetByte

void CAISocket::RecvNpcInOut(char* pBuf)
{
	int index = 0, nid = 0, nType = 0;
	float fx = 0.0f, fz=0.0f, fy=0.0f;

	nType = GetByte( pBuf, index );
	nid = GetShort(pBuf, index);
	fx = Getfloat( pBuf, index );
	fz = Getfloat( pBuf, index );
	fy = Getfloat( pBuf, index );

	if(nid >= NPC_BAND)		{
		CNpc* pNpc = m_pMain->m_arNpcArray.GetData(nid);
		if(!pNpc)	return;
		pNpc->NpcInOut( nType, fx, fz, fy );
	}
}
开发者ID:tuku,项目名称:snoxd-koserver,代码行数:17,代码来源:AISocket.cpp

示例8: Attack

void CUser::Attack(int sid, int tid)
{
	CNpc* pNpc = m_pMain->m_arNpc.GetData(tid-NPC_BAND);
	if(pNpc == NULL)	return;
	if(pNpc->m_NpcState == NPC_DEAD) return;
	if(pNpc->m_iHP == 0) return;

/*	if(pNpc->m_tNpcType == NPCTYPE_GUARD)					// 경비병이면 타겟을 해당 유저로
	{
		pNpc->m_Target.id = m_iUserId + USER_BAND;
		pNpc->m_Target.x = m_curx;
		pNpc->m_Target.y = m_cury;
		pNpc->m_Target.failCount = 0;
		pNpc->Attack(m_pIocport);
	//	return;
	}	*/

	int nDefence = 0, nFinalDamage = 0;
	// NPC 방어값 
	nDefence = pNpc->GetDefense();

	// 명중이면 //Damage 처리 ----------------------------------------------------------------//
	nFinalDamage = GetDamage(tid);
	if( m_pMain->m_byTestMode )		nFinalDamage = 3000;	// sungyong test
		
	// Calculate Target HP	 -------------------------------------------------------//
	short sOldNpcHP = pNpc->m_iHP;

	if(pNpc->SetDamage(0, nFinalDamage, m_strUserID, m_iUserId + USER_BAND, m_pIocport) == FALSE)
	{
		// Npc가 죽은 경우,,
		pNpc->SendExpToUserList(); // 경험치 분배!!
		pNpc->SendDead(m_pIocport);
		SendAttackSuccess(tid, ATTACK_TARGET_DEAD, nFinalDamage, pNpc->m_iHP);

	//	CheckMaxValue(m_dwXP, 1);		// 몹이 죽을때만 1 증가!	
	//	SendXP();
	}
	else
	{
		// 공격 결과 전송
		SendAttackSuccess(tid, ATTACK_SUCCESS, nFinalDamage, pNpc->m_iHP);
	}
	//	m_dwLastAttackTime = GetTickCount();
}
开发者ID:Kageyoshi,项目名称:snoxd-koserver,代码行数:45,代码来源:User.cpp

示例9: result

uint8 CMagicProcess::ExecuteType2(int magicid, int tid, int data1, int data2, int data3)
{
	Packet result(AG_MAGIC_ATTACK_RESULT, uint8(MAGIC_EFFECTING));
	int damage = m_pSrcUser->GetDamage(tid, magicid);;
	uint8 bResult = 1;
	
	result << magicid << m_pSrcUser->m_iUserId << tid << data1;

	if (damage > 0){
		CNpc* pNpc = nullptr ;      // Pointer initialization!
		pNpc = g_pMain->m_arNpc.GetData(tid-NPC_BAND);
		if(pNpc == nullptr || pNpc->m_NpcState == NPC_DEAD || pNpc->m_iHP == 0)	{
			bResult = 0;
			goto packet_send;
		}

		if (!pNpc->SetDamage(magicid, damage, m_pSrcUser->m_strUserID, m_pSrcUser->m_iUserId + USER_BAND))
		{
			result	<< int16(bResult) << data3 << int16(0) << int16(0) << int16(0)
					<< int16(damage == 0 ? -104 : 0);
			g_pMain->Send(&result);

			pNpc->SendExpToUserList(); // 경험치 분배!!
			pNpc->SendDead();
			m_pSrcUser->SendAttackSuccess(tid, MAGIC_ATTACK_TARGET_DEAD, damage, pNpc->m_iHP);
			//m_pSrcUser->SendAttackSuccess(tid, ATTACK_TARGET_DEAD, damage, pNpc->m_iHP);

			return bResult;
		}
		else	{
			// 공격 결과 전송
			m_pSrcUser->SendAttackSuccess(tid, ATTACK_SUCCESS, damage, pNpc->m_iHP);
		}
	}
//	else
//		result = 0;

packet_send:
	// this is a little redundant but leaving it in just in case order is intended
	// this should all be removed eventually anyway...
	result	<< int16(bResult) << data3 << int16(0) << int16(0) << int16(0)
			<< int16(damage == 0 ? -104 : 0);
	g_pMain->Send(&result);
	return bResult;
}
开发者ID:Johnny11,项目名称:snoxd-koserver,代码行数:45,代码来源:MagicProcess.cpp

示例10: OnGS2C_LookInfoNpc

	bool OnGS2C_LookInfoNpc(struct pk::GS2C_LookInfoNpc *value)
	{
		if ( !gMap )
		{
			return false;
		}

		CNpc* pNPC = CNpc::create();
		if ( pNPC )
		{
			pNPC->SetId(value->id);
			//pNPC->SetDataID(value->npc_data_id);
			pNPC->SetDataID(1000000);

			pNPC->EnterMap(gMap,value->x,value->y);
		}

		return true;
	}
开发者ID:SmallRaindrop,项目名称:LocatorApp,代码行数:19,代码来源:NetDispatcherHandle_Map.cpp

示例11: LOAD_TABLE_ERROR_ONLY

BOOL CServerDlg::CreateNpcThread()
{
    m_TotalNPC = m_sMapEventNpc;
    m_CurrentNPC = 0;
    m_CurrentNPCError = 0;

    LOAD_TABLE_ERROR_ONLY(CNpcPosSet, &m_GameDB, NULL, false);

    int step = 0, nThreadNumber = 0;
    CNpcThread* pNpcThread = NULL;
    DWORD id;

    foreach_stlmap (itr, m_arNpc)
    {
        if (step == 0)
            pNpcThread = new CNpcThread;

        CNpc *pNpc = pNpcThread->m_pNpc[step] = itr->second;
        pNpc->m_sThreadNumber = nThreadNumber;
        pNpc->Init();

        ++step;

        if( step == NPC_NUM )
        {
            pNpcThread->m_sThreadNumber = nThreadNumber++;
            pNpcThread->m_hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&NpcThreadProc, &(pNpcThread->m_ThreadInfo), CREATE_SUSPENDED, &id);
            m_arNpcThread.push_back( pNpcThread );
            step = 0;
        }
    }
    if( step != 0 )
    {
        pNpcThread->m_sThreadNumber = nThreadNumber++;
        pNpcThread->m_hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&NpcThreadProc, &(pNpcThread->m_ThreadInfo), CREATE_SUSPENDED, &id);
        m_arNpcThread.push_back( pNpcThread );
    }

    m_hZoneEventThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&ZoneEventThreadProc, (LPVOID)(this), CREATE_SUSPENDED, &id);
    printf("[Monster Init - %d, threads=%d]\n", m_TotalNPC, m_arNpcThread.size());
    return TRUE;
}
开发者ID:heaheart,项目名称:snoxd-koserver,代码行数:42,代码来源:ServerDlg.cpp

示例12: length

void CAISocket::RecvMagicAttackResult(Packet & pkt)
{
	uint32 magicid;
	uint16 sid, tid;
	uint8 byCommand; 

	/* 
		This is all so redundant...
		When everything's switched over to pass in Packets
		we can just pass it through directly!
		As it is now.. we still need a length (which we can hardcode, but meh)
	*/
	pkt >> byCommand >> magicid >> sid >> tid;

	pkt.SetOpcode(WIZ_MAGIC_PROCESS);
	if (byCommand == MAGIC_CASTING
		|| (byCommand == MAGIC_EFFECTING && sid >= NPC_BAND && tid >= NPC_BAND))
	{
		CNpc *pNpc = g_pMain->m_arNpcArray.GetData(sid);
		if (!pNpc)
			return;

		pNpc->SendToRegion(&pkt);
	}
	else if (byCommand == MAGIC_EFFECTING)
	{
		if (sid >= USER_BAND && sid < NPC_BAND)
		{
			CUser *pUser = g_pMain->GetUserPtr(sid);
			if (pUser == NULL || pUser->isDead())
				return;

			pUser->SendToRegion(&pkt);
			return;
		}

		// If we're an NPC, casting a skill (rather, it's finished casting) on a player...
		pkt.rpos(0);
		m_MagicProcess.MagicPacket(pkt);
	}
	
}
开发者ID:BrokenWings,项目名称:snoxd-koserver,代码行数:42,代码来源:AISocket.cpp

示例13: RecvNpcMoveResult

void CAISocket::RecvNpcMoveResult(Packet & pkt)
{
	uint8 flag;			// 01(INFO_MODIFY), 02(INFO_DELETE)	
	uint16 sNid;
	float fX, fY, fZ, fSecForMetor;
	pkt >> flag >> sNid >> fX >> fZ >> fY >> fSecForMetor;

	CNpc * pNpc = g_pMain->GetNpcPtr(sNid);
	if (pNpc == nullptr)
		return;

	if (pNpc->isDead())
	{
		Packet result(AG_NPC_HP_REQ);
		result << sNid << pNpc->m_iHP;
		Send(&result);
	}

	pNpc->MoveResult(fX, fY, fZ, fSecForMetor);
}
开发者ID:Damra,项目名称:koserver,代码行数:20,代码来源:AISocket.cpp

示例14: RecvNpcHpChange

void CGameSocket::RecvNpcHpChange(Packet & pkt)
{
	int16 nid, sAttackerID;
	int32 nHP, nAmount;
	pkt >> nid >> sAttackerID >> nHP >> nAmount;
	CNpc * pNpc = g_pMain->m_arNpc.GetData(nid);
	if (pNpc == nullptr)
		return;

	if (nAmount < 0)
	{
		pNpc->SetDamage(0, -nAmount, sAttackerID, 1);
	}
	else
	{		
		pNpc->m_iHP += nAmount;
		if (pNpc->m_iHP > pNpc->m_iMaxHP)
			pNpc->m_iHP = pNpc->m_iMaxHP;
	}
}
开发者ID:TheNewbGuy,项目名称:snoxd-koserver,代码行数:20,代码来源:GameSocket.cpp

示例15: RecvBattleEvent

void CGameSocket::RecvBattleEvent(char* pBuf)
{
	int index = 0, i=0;
	int nType = 0, nEvent = 0;
	CNpc* pNpc = NULL;

	nType = GetByte(pBuf,index);
	nEvent = GetByte(pBuf,index);

	if( nEvent == BATTLEZONE_OPEN )	{
		m_pMain->m_sKillKarusNpc = 0;
		m_pMain->m_sKillElmoNpc = 0;
		m_pMain->m_byBattleEvent = BATTLEZONE_OPEN;
		TRACE("----> RecvBattleEvent : Battle zone Open \n");
	}
	else if( nEvent == BATTLEZONE_CLOSE )	{
		m_pMain->m_sKillKarusNpc = 0;
		m_pMain->m_sKillElmoNpc = 0;
		m_pMain->m_byBattleEvent = BATTLEZONE_CLOSE;
		TRACE("<---- RecvBattleEvent : Battle zone Close \n");
		m_pMain->ResetBattleZone();
	}

	int nSize = m_pMain->m_arNpc.GetSize();

	for( i = 0; i < nSize; i++)	{
		pNpc = m_pMain->m_arNpc.GetData( i );
		if( !pNpc ) continue;
		if( pNpc->m_tNpcType > 10 && (pNpc->m_byGroup == KARUS_ZONE || pNpc->m_byGroup == ELMORAD_ZONE) )	{	// npc에만 적용되고, 국가에 소속된 npc
			if( nEvent == BATTLEZONE_OPEN )	{		// 전쟁 이벤트 시작 (npc의 능력치 다운)
				pNpc->ChangeAbility( BATTLEZONE_OPEN );
			}
			else if( nEvent == BATTLEZONE_CLOSE )	{	// 전쟁 이벤트 끝 (npc의 능력치 회복)	
				pNpc->ChangeAbility( BATTLEZONE_CLOSE );
			}
		}
	}

	
}
开发者ID:DeathsEffigy,项目名称:snoxd-koserver-1,代码行数:40,代码来源:GameSocket.cpp


注:本文中的CNpc类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。