コード例 #1
0
ファイル: ExpOrb.cpp プロジェクト: JABirchall/MCServer
void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk)
{
	cPlayer * a_ClosestPlayer(m_World->FindClosestPlayer(Vector3f(GetPosition()), 5));
	if (a_ClosestPlayer != nullptr)
	{
		Vector3f a_PlayerPos(a_ClosestPlayer->GetPosition());
		a_PlayerPos.y++;
		Vector3f a_Distance(a_PlayerPos - GetPosition());
		double Distance(a_Distance.Length());
		if (Distance < 0.1f)
		{
			LOGD("Player %s picked up an ExpOrb. His reward is %i", a_ClosestPlayer->GetName().c_str(), m_Reward);
			a_ClosestPlayer->DeltaExperience(m_Reward);
			
			m_World->BroadcastSoundEffect("random.orb", GetPosX(), GetPosY(), GetPosZ(), 0.5f, (float)(0.75 + ((float)((GetUniqueID() * 23) % 32)) / 64));
			
			Destroy();
		}
		a_Distance.Normalize();
		a_Distance *= ((float) (5.5 - Distance));
		SetSpeedX( a_Distance.x);
		SetSpeedY( a_Distance.y);
		SetSpeedZ( a_Distance.z);
		BroadcastMovementUpdate();
	}
	HandlePhysics(a_Dt, a_Chunk);
	
	m_Timer += a_Dt;
	if (m_Timer >= 1000 * 60 * 5)  // 5 minutes
	{
		Destroy(true);
	}
}
コード例 #2
0
ファイル: ExpOrb.cpp プロジェクト: UltraCoderRU/MCServer
void cExpOrb::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
	// Check player proximity no more than twice per second
	if ((m_TicksAlive % 10) == 0)
	{
		cPlayer * a_ClosestPlayer(m_World->FindClosestPlayer(Vector3f(GetPosition()), 5, false));
		if ((a_ClosestPlayer != nullptr) && (!a_ClosestPlayer->IsGameModeSpectator()))
		{
			Vector3f a_PlayerPos(a_ClosestPlayer->GetPosition());
			a_PlayerPos.y++;
			Vector3f a_Distance(a_PlayerPos - GetPosition());
			double Distance(a_Distance.Length());
			if (Distance < 0.5f)
			{
				LOGD("Player %s picked up an ExpOrb. His reward is %i", a_ClosestPlayer->GetName().c_str(), m_Reward);
				a_ClosestPlayer->DeltaExperience(m_Reward);

				m_World->BroadcastSoundEffect("entity.experience_orb.pickup", GetPosition(), 0.5f, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));

				Destroy(true);
				return;
			}
			SetSpeedX((a_PlayerPos.x - GetPosition().x) * 2.0);
			SetSpeedY((a_PlayerPos.y - GetPosition().y) * 2.0);
			SetSpeedZ((a_PlayerPos.z - GetPosition().z) * 2.0);
		}
	}
	HandlePhysics(a_Dt, a_Chunk);

	m_Timer += a_Dt;
	if (m_Timer >= std::chrono::minutes(5))
	{
		Destroy(true);
	}
}
コード例 #3
0
ファイル: ExpOrb.cpp プロジェクト: Noraaron1/MCServer
void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk)
{
	cPlayer * a_ClosestPlayer(m_World->FindClosestPlayer(Vector3f(GetPosition()), 4));
	if (a_ClosestPlayer)
	{
		Vector3f a_PlayerPos(a_ClosestPlayer->GetPosition());
		Vector3f a_Distance(a_PlayerPos - GetPosition());
		if (a_Distance.Length() < 0.1f)
		{
			a_ClosestPlayer->DeltaExperience(m_Reward);
			a_ClosestPlayer->SendExperience();
			Destroy(true);
		}
		a_Distance.y = 0;
		a_Distance.Normalize();
		a_Distance *= 3;
		SetSpeedX( a_Distance.x );
		SetSpeedZ( a_Distance.z );
	}
}