예제 #1
0
//-----------------------------------------------
// updateActors :
// Update Actors.
//-----------------------------------------------
void CSceneParser::updateActors()
{
	// All actors in the scene.
	for(map<uint, CActor>::iterator itActor = _Actors.begin(); itActor != _Actors.end(); ++itActor)
	{
		// Get a reference on the actor.
		CActor &actor = (*itActor).second;

		// If there is no actor to follow -> next actor.
		if(actor.Actor < 0)
			continue;

		// Get the entity pointer.
		CEntityCL *entity = getEntity(Sid(Sid::npc, (uint64)actor.Id));
		if(!entity)
		{
			nlwarning("CSceneParser::updateActors : Cannot get the actor %d.", actor.Id);
			continue;
		}

		// Get the target entity pointer.
		CEntityCL *entityTarget = getEntity(Sid(Sid::npc, (uint64)actor.Actor));
		if(!entityTarget)
		{
			nlwarning("CSceneParser::updateActors : Cannot get the targeted actor %d.", actor.Actor);
			continue;
		}

		// Changes the entity position.
		entity->pacsPos(entityTarget->pos());
	}
}// updateActors //
	virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
	{
		CInterfaceManager *pIM = CInterfaceManager::getInstance();
		if(pIM == NULL) return;
		CEntityCL *selection = EntitiesMngr.entity(UserEntity->selection());

		// If mode Combat (no talk, no give, no mount)
		if(UserEntity->mode()==MBEHAV::COMBAT
		|| UserEntity->mode()==MBEHAV::COMBAT_FLOAT)
		{
			return; // Cant mount
		}
		// Mount
		else if(UserEntity->isRiding())
		{
			// We are currently mounted so unmount
			pIM->runActionHandler("context_unseat",NULL);
		}
		// Not in combat mode.
		else
		{
			// check if we can mount
			if ((selection) && (selection->properties().mountable()))
			{
				CVectorD vect1 = selection->pos();
				CVectorD vect2 = UserEntity->pos();
				double distanceSquare = pow(vect1.x-vect2.x,2) + pow(vect1.y-vect2.y,2);
				if(distanceSquare <= MaxTalkingDistSquare)
				{
					// Ok lets mount
					pIM->runActionHandler("context_mount",NULL);
				}
			}
		}
	}
예제 #3
0
//-----------------------------------------------
// resetActors :
// Reset all actors.
//-----------------------------------------------
void CSceneParser::resetActors()
{
	// Create new entities from actors
	map<uint, CActor>::iterator itActor;
	for(itActor = _Actors.begin(); itActor != _Actors.end(); ++itActor)
	{
		// Get a reference on the actor.
		CActor &actor = (*itActor).second;

		// Get the Sid.
		Sid entityId(Sid::npc, (uint64)actor.Id);

		// Find the actor.
		CEntityCL *entity = getEntity(entityId);
		if(entity)
		{
			// Position the entity.
			entity->pacsPos(actor.Pos);

			// Position the skeleton at the same position as the entity.
			if(entity->skeleton())
			{
				entity->skeleton()->setPos(actor.Pos);
				entity->skeleton()->setRotQuat(actor.Rot);
			}
		}

		// Reset entity animations.
		resetAnimatedSceneObject(entityId);
	}
}// resetActors //
	virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
	{
		CInterfaceManager *pIM = CInterfaceManager::getInstance();
		if(pIM == NULL) return;
		CEntityCL *selection = EntitiesMngr.entity(UserEntity->selection());

		if(UserEntity->mode()==MBEHAV::COMBAT
		|| UserEntity->mode()==MBEHAV::COMBAT_FLOAT)
		{
			return; // Cant exchange
		}
		// Mount
		else
		{
			if (selection && selection->properties().canExchangeItem())
				if (!UserEntity->isBusy())
					pIM->runActionHandler("context_exchange",NULL);
		}
	}
예제 #5
0
// ***************************************************************************
// Used also in game_context_menu
void	outpostTestUserCanBan(CCDBNodeLeaf *dbBanRight, bool &okForBanPlayer, bool &okForBanGuild)
{
	okForBanPlayer= false;
	okForBanGuild= false;

	/** A player can ban a player in a PVP outpost if:
	 *	- The player has right to ban AND his guild attack/owns the outpost the player attacks (all this is in RIGHT_BANNISH)
	 *	- The player and the target are in the same war of the outpost, and in same alliance.
	 *	- The player and the target are not in same guild
	 */
	if(dbBanRight && dbBanRight->getValueBool() && UserEntity)
	{
		CEntityCL *selection = EntitiesMngr.entity(UserEntity->selection());
		if(selection && selection->isPlayer())
		{
			// in same outpost War and Side
			if( selection->getOutpostId() == UserEntity->getOutpostId() &&
				selection->getOutpostSide() == UserEntity->getOutpostSide() )
			{
				// not in same guild
				if( selection->getGuildNameID() != UserEntity->getGuildNameID() )
				{
					okForBanPlayer= true;
					okForBanGuild= selection->getGuildNameID()!=0;
				}
			}
		}
	}
}
예제 #6
0
void displayNetDebug ()
{
	CInterfaceManager	*pIM= CInterfaceManager::getInstance();
	float lineStep = ClientCfg.DebugLineStep;
	float line;

	// Initialize Pen //
	//----------------//
	// Create a shadow when displaying a text.
	TextContext->setShaded(true);
	// Set the font size.
	TextContext->setFontSize(ClientCfg.DebugFontSize);
	// Set the text color
	TextContext->setColor(ClientCfg.DebugFontColor);


	// BOTTOM RIGHT //
	//--------------//
	TextContext->setHotSpot(UTextContext::BottomRight);
	line = 0.f;
	// Database Synchronisation counter
	// Local Counter
	uint	val= pIM->getLocalSyncActionCounter() ;
	val&= pIM->getLocalSyncActionCounterMask();
	TextContext->printfAt(1.f, line, "Local Counter: %d", val);
	line += lineStep;
	// Inventory Counter
	val= pIM->getDbProp("SERVER:INVENTORY:COUNTER")->getValue32();
	val&= pIM->getLocalSyncActionCounterMask();
	TextContext->printfAt(1.f, line, "INVENTORY:COUNTER: %d", val);
	line += lineStep;
	// Exchange Counter
	val= pIM->getDbProp("SERVER:EXCHANGE:COUNTER")->getValue32();
	val&= pIM->getLocalSyncActionCounterMask();
	TextContext->printfAt(1.f, line, "EXCHANGE:COUNTER: %d", val);
	line += lineStep;
	// Programme Counter
	val= pIM->getDbProp("SERVER:TARGET:CONTEXT_MENU:COUNTER")->getValue32();
	val&= pIM->getLocalSyncActionCounterMask();
	TextContext->printfAt(1.f, line, "TARGET:CONTEXT_MENU:COUNTER: %d", val);
	line += lineStep;
	// User Counter
	val= pIM->getDbProp("SERVER:USER:COUNTER")->getValue32();
	val&= pIM->getLocalSyncActionCounterMask();
	TextContext->printfAt(1.f, line, "USER:COUNTER: %d", val);
	line += lineStep;
	line += lineStep;

	// SPhrase Execution Synchronisation Counter
	CSPhraseManager		*pPM= CSPhraseManager::getInstance();
	// Next action
	uint	srvVal= pIM->getDbProp(PHRASE_DB_COUNTER_NEXT)->getValue32();
	uint	locVal= pPM->getPhraseNextExecuteCounter() ;
	srvVal&= PHRASE_EXECUTE_COUNTER_MASK;
	locVal&= PHRASE_EXECUTE_COUNTER_MASK;
	TextContext->printfAt(1.f, line, "NextAction  (loc/srv): %d/%d", locVal, srvVal);
	line += lineStep;
	// CycleAction
	srvVal= pIM->getDbProp(PHRASE_DB_COUNTER_CYCLE)->getValue32();
	locVal= pPM->getPhraseCycleExecuteCounter();
	srvVal&= PHRASE_EXECUTE_COUNTER_MASK;
	locVal&= PHRASE_EXECUTE_COUNTER_MASK;
	TextContext->printfAt(1.f, line, "CycleAction (loc/srv): %d/%d", locVal, srvVal);
	line += lineStep;


	// BOTTOM MIDDLE //
	//--------------//
	TextContext->setHotSpot(UTextContext::BottomLeft);
	float	xUser= 0.3f;
	float	xWatched= 0.5f;
	// Display information about the debug entity slot.
	if(WatchedEntitySlot != CLFECOMMON::INVALID_SLOT)
	{
		line = 0.f;
		TextContext->printfAt(xWatched, line, "Watched");
		line += lineStep;
		// Get a pointer on the target.
		CEntityCL *watchedEntity = EntitiesMngr.entity(WatchedEntitySlot);
		if(watchedEntity)
			watchedEntity->displayDebugPropertyStages(xWatched, line, lineStep);
	}
	// Display information about the user
	if(UserEntity)
	{
		line = 0.f;
		TextContext->printfAt(xUser, line, "User");
		line += lineStep;
		UserEntity->displayDebugPropertyStages(xUser, line, lineStep);
	}

}
예제 #7
0
// ----------------------------------------------------------------------------
void CViewRadar::draw ()
{
	CInterfaceManager *pIM = CInterfaceManager::getInstance();
	CViewRenderer &rVR = pIM->getViewRenderer();

	CEntityCL *user = EntitiesMngr.entity(0);
	if (user == NULL) return;

	CVectorD xyzRef = user->pos();
	const CVector dir = user->front();

	float angle = (float)(atan2(dir.y, dir.x) - (Pi / 2.0));
	CMatrix mat;
	mat.identity();
	// Scale to transform from world to interface screen
	mat.scale( CVector((float)(_WReal / _WorldSize), (float)(_HReal / _WorldSize), 1) );
	// local to user
	mat.rotateZ(-angle);
	xyzRef.z = 0;
	mat.translate(-xyzRef);

	float	maxSqrRadius= (float)sqr(_WorldSize/2);

	for (sint32 i = 1; i < 256; ++i)
	{
		CEntityCL *entity = EntitiesMngr.entity(i);
		if (entity == NULL) continue;

		// if the entity must not be shown in radar
		if(!entity->getDisplayInRadar())
			continue;

		// get entity pos
		CVectorD xyz = entity->pos();

		xyz.z = 0;
		// if the distance is too big so do not display the entity
		if ((sqr(xyz.x - xyzRef.x)+sqr(xyz.y - xyzRef.y)) > maxSqrRadius) continue;

		// Transform the dot
		xyz = mat * xyz;

		// Convert to screen
		sint32 x = OptFastFloor((float)xyz.x);
		sint32 y = OptFastFloor((float)xyz.y);

		CRGBA col = entity->getColor();

		if(getModulateGlobalColor())
			col.modulateFromColor (col, pIM->getGlobalColorForContent());
		else
			col.A = (uint8)(((sint32)col.A*((sint32)pIM->getGlobalColorForContent().A+1))>>8);

		// Select the icon to display and draw it
		uint spotId = CNPCIconCache::getInstance().getNPCIcon(entity).getSpotId();
		CRadarSpotDesc spotDesc = _SpotDescriptions[spotId];

		if (!_MissionIconsObs._displayMissionSpots)
			spotDesc = _SpotDescriptions[0];

		if (spotDesc.isMissionSpot)
			col = CRGBA(255, 255, 255, 255);

		if (entity->isTarget())
			spotId = 4; // to make it over other spots

		// Draw it (and make sure mission icons are drawn over regular dot; caution: don't exceed the render layer range)
		if (spotDesc.isMissionSpot && _MiniMissionSpotsObs._displayMiniMissionSpots)
			rVR.drawRotFlipBitmap (_RenderLayer+spotId, _XReal+x-(spotDesc.MTxW/2)+(_WReal/2), _YReal+y-(spotDesc.MTxH/2)+(_HReal/2),
								spotDesc.MTxW, spotDesc.MTxH, 0, false, spotDesc.MiniTextureId, col );
		else
			rVR.drawRotFlipBitmap (_RenderLayer+spotId, _XReal+x-(spotDesc.TxW/2)+(_WReal/2), _YReal+y-(spotDesc.TxH/2)+(_HReal/2),
							spotDesc.TxW, spotDesc.TxH, 0, false, spotDesc.TextureId, col );
	}
}
예제 #8
0
// ****************************************************************************
ucstring CViewTextFormated::formatString(const ucstring &inputString, const ucstring &paramString)
{
	ucstring formatedResult;
	// Apply the format
	for(ucstring::const_iterator it = inputString.begin(); it != inputString.end();)
	{
		if (*it == '$')
		{
			++it;
			if (it == inputString.end()) break;
			switch(*it)
			{
				case 't': // add text ID
					formatedResult += paramString;
				break;

				case 'P':
				case 'p':  // add player name
					if (ClientCfg.Local)
					{
						formatedResult += ucstring("player");
					}
					else
					{
						if(UserEntity)
						{
							ucstring name = UserEntity->getEntityName();
							if (*it == 'P') setCase(name, CaseUpper);
							formatedResult += name;
						}
					}
				break;
				//
				case 's':
				case 'b': // add bot name
				{
					ucstring botName;
					bool womanTitle = false;
					if (ClientCfg.Local)
					{
						botName = ucstring("NPC");
					}
					else
					{
						CLFECOMMON::TCLEntityId trader = CLFECOMMON::INVALID_SLOT;
						if(UserEntity)
							trader = UserEntity->trader();
						if (trader != CLFECOMMON::INVALID_SLOT)
						{
							CEntityCL *entity = EntitiesMngr.entity(trader);
							if (entity != NULL)
							{
								uint32 nDBid = entity->getNameId();

								if (nDBid != 0)
								{
									CStringManagerClient *pSMC = CStringManagerClient::instance();
									pSMC->getString(nDBid, botName);
								}
								else
								{
									botName = entity->getDisplayName();
								}

								CCharacterCL *pChar = dynamic_cast<CCharacterCL*>(entity);
								if (pChar != NULL)
									womanTitle = pChar->getGender() == GSGENDER::female;
							}
						}
					}

					// get the title translated
					ucstring sTitleTranslated = botName;
					CStringPostProcessRemoveName spprn;
					spprn.Woman = womanTitle;
					spprn.cbIDStringReceived(sTitleTranslated);

					botName = CEntityCL::removeTitleAndShardFromName(botName);

					// short name (with no title such as 'guard', 'merchant' ...)
					if (*it == 's')
					{
						// But if there is no name, display only the title
						if (botName.empty())
							botName = sTitleTranslated;
					}
					else
					{
						// Else we want the title !
						if (!botName.empty())
							botName += " ";
						botName += sTitleTranslated;
					}

					formatedResult += botName;
				}
				break;
				default:
					formatedResult += (ucchar) '$';
				break;
			}
			++it;
		}
		else
		{
			formatedResult += (ucchar) *it;
			++it;
		}
	}

	return formatedResult;
}
예제 #9
0
// Constructor for moving object, it not create entity (mesh, skeleton) but build animation on pre-exist entity
CAnimatedSceneObject::CAnimatedSceneObject( const CEntityId& Id, const list < std::string >& Animations )
{
    _Id = Id;
    _ObjectName = "";
    _ClusterIG = "";
    _MeshName = "";
    _SkeletonName = "";
    _Distance = 0;

    _Skeleton = NULL;
    _Instance = NULL;

    CEntityCL *entity = getEntity(Id);
    if(entity)
    {
        _Skeleton = *entity->skeleton();
        _Transform = _Skeleton;

        _Position = _Skeleton->getPos();
        _Rotation = _Skeleton->getRotQuat();

        // create play list manager and animation set
        _PlayListManager = Scene->createPlayListManager();
        _AnimationSet = Driver->createAnimationSet();

        //fill animation set
        for( list< string >::const_iterator its = Animations.begin(); its != Animations.end(); ++its )
        {
            uint idAnim;
            try
            {
                idAnim = _AnimationSet->addAnimation( ( *its + string(".anim") ).c_str(), (*its).c_str() );
            }
            catch(Exception &)
            {
                idAnim = UAnimationSet::NotFound;
                if( idAnim == UAnimationSet::NotFound)
                {
                    nlwarning( "CAnimatedSceneObject::CAnimatedSceneObject Animation %s not found for entity CEntityId(%u,%f)", (*its).c_str(), Id.Type, (double)(sint64)Id.Id );
                    continue;
                }
            }
            _MapAnimation.insert( make_pair( *its, idAnim ) );
        }

        // build animation set
        _AnimationSet->build();

        // create playlist
        _PlayList = _PlayListManager->createPlayList( _AnimationSet );

        _Status = SAnimationStatus();
        _Status.SequenceAnim = 1;
        _Status.ApplyDisplacement = 1;

        // register skeleton in playlist
        _PlayList->registerTransform( *entity->skeleton() );

        // Snap to ground(the snap check if it's a flyer).
        entity->pacsPos(_Position);
        entity->snapToGround();
        _Position = entity->pos();

        CMatrix current;
        current.identity ();
        current.setRot (_Rotation);

        // Rotation 90 degrees
        CMatrix rot90;
        rot90.identity ();
        rot90.rotateZ (-(float)Pi/2);
        current *= rot90;

        _Transform->unfreezeHRC();

        _Transform->setPos(_Position);
        _Transform->setRotQuat(current.getRot());

        _Transform->freezeHRC();

        _IdAnimationPlayed = -1;

        if( _Id.Type == RYZOMID::npc )
        {
            sendEndSequenceMessage( _Id, 1 );
        }
    }
    else
    {
        _PlayList = NULL;
        _AnimationSet = NULL;
        _PlayListManager = NULL;
    }
}
예제 #10
0
//-----------------------------------------------
// updateParticlesActor :
//
//-----------------------------------------------
void CSceneParser::updateParticlesActor(float difTime, CParticle &particle, UAnimation &animation)
{
	// Get the entity pointer.
	CEntityCL *entity = getEntity(Sid(Sid::npc, (uint64)particle.Actor));
	if(!entity)
	{
		nlwarning("CSceneParser::updateParticlesActor : cannot get the actor %d.", (uint64)particle.Actor);
		return;
	}

	// If the entity has no skeleton -> Next particle.
	if(!entity->skeleton())
	{
		nlwarning("The particle follow an entity %d without a skeleton.", (uint64)particle.Actor);
		return;
	}

	// Matrix 90°
	CMatrix m90;
	m90.identity();
	m90.rotateZ((float)(Pi/2.0));

	// Matrix of the entity.
	CMatrix mChar = entity->skeleton()->getMatrix();
	mChar.setPos(entity->pos());

	// Animate all instances.
	for(uint i = 0; i < particle.IGPtr->getNumInstance(); ++i )
	{
		std::string iName = particle.IGPtr->getInstanceName(i);
		UInstance instance = particle.IGPtr->getByName(iName);

		if(!instance)
			continue;

		instance->setTransformMode(UTransformable::RotQuat);

		CMatrix mAnim;
		mAnim.identity();
		// If the animation has no track of position.
		UTrack* trackPos = animation.getTrackByName("PathPos");
		if(!trackPos)
			trackPos = animation.getTrackByName(string(iName + "." + "PathPos").c_str());
		if(trackPos)
		{
			CVector pos;
			trackPos->interpolate(difTime, pos);
			mAnim.setPos(pos);
		}

		// If the animation has no track of rotation.
		UTrack* trackRot = animation.getTrackByName("PathRotQuat");
		if(!trackRot)
			trackRot = animation.getTrackByName(string(iName + "." + "PathRotQuat").c_str());
		if(trackRot)
		{
			CQuat rot;
			trackPos->interpolate(difTime, rot);
			mAnim.setRot(rot);
		}

		CMatrix mFinal = mChar * m90 * mAnim;
		instance->setPos(mFinal.getPos());
		instance->setRotQuat(mFinal.getRot());
	}
}// updateParticlesActor //
예제 #11
0
void addWebIGParams (string &url, bool trustedDomain)
{
	if(!UserEntity || !NetMngr.getLoginCookie().isValid()) return;

	uint32 cid = NetMngr.getLoginCookie().getUserId() * 16 + PlayerSelectedSlot;
	url += ((url.find('?') != string::npos) ? "&" : "?") +
		string("shardid=") + toString(CharacterHomeSessionId) +
		string("&name=") + UserEntity->getLoginName().toUtf8() +
		string("&lang=") + CI18N::getCurrentLanguageCode() +
		string("&datasetid=") + toString(UserEntity->dataSetId()) +
		string("&ig=1");
	if (trustedDomain)
	{
		url += string("&cid=") + toString(cid) +
		string("&authkey=") + getWebAuthKey();
		
		if (url.find('$') != string::npos)
		{
			strFindReplace(url, "$gender$", GSGENDER::toString(UserEntity->getGender()));
			strFindReplace(url, "$displayName$", UserEntity->getDisplayName().toString());
			strFindReplace(url, "$posx$", toString(UserEntity->pos().x));
			strFindReplace(url, "$posy$", toString(UserEntity->pos().y));
			strFindReplace(url, "$posz$", toString(UserEntity->pos().z));
			strFindReplace(url, "$post$", toString(atan2(UserEntity->front().y, UserEntity->front().x)));
			
			// Target fields
			const char *dbPath = "UI:VARIABLES:TARGET:SLOT";
			CInterfaceManager *im = CInterfaceManager::getInstance();
			CCDBNodeLeaf *node = im->getDbProp(dbPath, false);
			if (node && (uint8)node->getValue32() != (uint8) CLFECOMMON::INVALID_SLOT)
			{
				CEntityCL *target = EntitiesMngr.entity((uint) node->getValue32());
				if (target)
				{
					strFindReplace(url, "$tdatasetid$", toString(target->dataSetId()));
					strFindReplace(url, "$tdisplayName$", target->getDisplayName().toString());
					strFindReplace(url, "$tposx$", toString(target->pos().x));
					strFindReplace(url, "$tposy$", toString(target->pos().y));
					strFindReplace(url, "$tposz$", toString(target->pos().z));
					strFindReplace(url, "$tpost$", toString(atan2(target->front().y, target->front().x)));
					strFindReplace(url, "$tsheet$", target->sheetId().toString());
					string type;
					if (target->isFauna())
						type = "fauna";
					else if (target->isNPC())
						type = "npc";
					else if (target->isPlayer())
						type = "player";
					else if (target->isUser())
						type = "user";
					strFindReplace(url, "$ttype$", target->sheetId().toString());
				}
				else
				{
					strFindReplace(url, "$tdatasetid$", "");
					strFindReplace(url, "$tdisplayName$", "");
					strFindReplace(url, "$tposx$", "");
					strFindReplace(url, "$tposy$", "");
					strFindReplace(url, "$tposz$", "");
					strFindReplace(url, "$tpost$", "");
					strFindReplace(url, "$tsheet$", "");
					strFindReplace(url, "$ttype$", "");
				}
			}
		}
	}
}