//--------------------------------------------------------------
//				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);
	}
}