示例#1
0
	uint processEvent( const TDataSetRow & userRow, const CMissionEvent & event,uint subStepIndex,const TDataSetRow & giverRow )
	{
		if ( event.Type == CMissionEvent::Kill )
		{
			CMissionEventKill & eventSpe = (CMissionEventKill&)event;
			CCreature * c = CreatureManager.getCreature( event.TargetEntity );
			if ( !c )
			{
				LOGMISSIONSTEPERROR("kill_fauna : invalid creature " + toString(event.TargetEntity.getIndex()));
			}
			else if ( _SubSteps[subStepIndex].Sheet == c->getType() )
			{
				if ( _Place != 0xFFFF )
				{
					float gooDistance;
					const CPlace * stable = NULL;
					std::vector<const CPlace *> places;
					const CRegion * region = NULL;
					const CContinent * continent = NULL;
					if ( !CZoneManager::getInstance().getPlace( c->getState().X, c->getState().Y, gooDistance, &stable, places, &region , &continent ) )
						return 0;

					if ( region && region->getId() == _Place )
					{
						LOGMISSIONSTEPSUCCESS("kill_fauna");
						return 1;
					}
					
					for ( uint i = 0; i < places.size(); i++ )
					{
						if ( places[i] && places[i]->getId() == _Place )
						{
							LOGMISSIONSTEPSUCCESS("kill_fauna");
							return 1;
						}
					}
					return 0;
				}
				else
				{
					LOGMISSIONSTEPSUCCESS("kill_fauna");
					return 1;
				}
			}
		}
		return 0;
	}
//--------------------------------------------------------------
//				CNpcBotDescription ::callback()  
//--------------------------------------------------------------
//void CNpcBotDescriptionImp::callback(const string &serviceName, uint8 sid)
void CGenNpcDescMsgImp::callback (const std::string &serviceName, NLNET::TServiceId sid)
{
	H_AUTO(CGenNpcDescMsgImp_callback );
	
	if ( ! Mirror.mirrorIsReady() )
	{
		nlwarning("<CNpcBotDescriptionImp::callback> Received from %s service but mirror not yet ready", serviceName.c_str() );
		return;
	}
	CEntityId	Eid= getEntityIdFromRow(_EntityIndex);
	if ( Eid.isUnknownId() )
	{
		nlwarning( "Received CNpcBotDescription with E%u that has no entity id, skipping it", _EntityIndex.getIndex() );
		nldebug( "Reason: %s", TheDataset.explainIsAccessible(_EntityIndex).c_str() );
#ifdef NL_DEBUG
//		nlstop;
#endif
		return;
	}
	CCreature *creature = CreatureManager.getCreature( Eid );
	if( creature == 0 )
	{
		creature = new CCreature();
		if ( creature )
		{
			creature->setAIGroupAlias( _GrpAlias );
			creature->setUserModelId(_UserModelId);
			creature->setCustomLootTableId(_CustomLootTableId);
			creature->setPrimAlias(_PrimAlias);
			if ( _GrpAlias != CAIAliasTranslator::Invalid )
			{
				CreatureManager.addNpcToGroup( _GrpAlias, _Alias ); // called every time the callback is received
			}
			creature->setId(Eid);
			creature->mirrorizeEntityState( false,	_EntityIndex ); // import the position
			creature->addPropertiesToMirror( _EntityIndex, false ); // init properties + import the sheetid from the mirror
			creature->setServerSheet();

			if( creature->getType() == CSheetId::Unknown )
			{
				nlwarning("<CNpcBotDescriptionImp::callback> Npc Eid %s GrpAlias %s Alias %s have invalide sheet, not spawned in EGS", 
					Eid.toString().c_str(), 
					CPrimitivesParser::aliasToString(_GrpAlias).c_str(), 
					CPrimitivesParser::aliasToString(_Alias).c_str() );
				delete creature;
				return;
			}
			else
			{
				creature->loadSheetCreature( _EntityIndex );
				
				//if the creature has a user model and if the user model's script contains parse errors, change
				//the creature's name to <usermodelId:ERROR> 
				if (_UserModelId != "" && CDynamicSheetManager::getInstance()->scriptErrors(_PrimAlias, _UserModelId) == true)
				{
					TDataSetRow row = creature->getEntityRowId();
					ucstring name;
					name.fromUtf8("<"+ _UserModelId + ":ERROR>");
					NLNET::CMessage	msgout("CHARACTER_NAME");
					msgout.serial(row);
					msgout.serial(name);
					sendMessageViaMirror("IOS", msgout);
				}
				CreatureManager.addCreature( Eid, creature );

				// set the items
				creature->setItems( _RightHandItem, _RightHandItemQuality, _LeftHandItem, _LeftHandItemQuality );
			}
		}
	}
//	else
//		CreatureManager.addUnaffectedDescription( *this );

	if (creature != NULL)
	{
		if (!creature->getCustomLootTableId().empty())
		{
			creature->getContextualProperty().directAccessForStructMembers().lootable(true);
		}
		creature->setBotDescription( *this );
		CAIAliasTranslator::getInstance()->updateAssociation(_Alias,Eid);

		if (_BuildingBot)
			COutpostManager::getInstance().onBuildingSpawned(creature);
	}
}