コード例 #1
0
ファイル: Entity.cpp プロジェクト: straemer/MCServer
void cEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
	if (m_AttachedTo != NULL)
	{
		if ((m_Pos - m_AttachedTo->GetPosition()).Length() > 0.5)
		{
			SetPosition(m_AttachedTo->GetPosition());
		}
	}
	else
	{
		if (a_Chunk.IsValid())
		{
			HandlePhysics(a_Dt, a_Chunk);
		}
	}
	if (a_Chunk.IsValid())
	{
		TickBurning(a_Chunk);
	}
	if ((a_Chunk.IsValid())  && (GetPosY() < -46))
	{
		TickInVoid(a_Chunk);
	}
	else { m_TicksSinceLastVoidDamage = 0; }
}
コード例 #2
0
ファイル: Entity.cpp プロジェクト: Kortak/MCServer
void cEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
	if (m_InvulnerableTicks > 0)
	{
		m_InvulnerableTicks--;
	}

	if (m_AttachedTo != NULL)
	{
		Vector3d DeltaPos = m_Pos - m_AttachedTo->GetPosition();
		if (DeltaPos.Length() > 0.5)
		{
			SetPosition(m_AttachedTo->GetPosition());

			if (IsPlayer())
			{
				cPlayer * Player = (cPlayer *)this;
				Player->UpdateMovementStats(DeltaPos);
			}
		}
	}
	else
	{
		if (!a_Chunk.IsValid())
		{
			return;
		}

		// Position changed -> super::Tick() called
		GET_AND_VERIFY_CURRENT_CHUNK(NextChunk, POSX_TOINT, POSZ_TOINT)

		TickBurning(*NextChunk);

		if (GetPosY() < VOID_BOUNDARY)
		{
			TickInVoid(*NextChunk);
		}
		else
		{
			m_TicksSinceLastVoidDamage = 0;
		}

		if (IsMob() || IsPlayer() || IsPickup() || IsExpOrb())
		{
			DetectCacti();
		}
		if (IsMob() || IsPlayer())
		{
			// Set swimming state
			SetSwimState(*NextChunk);

			// Handle drowning
			HandleAir();
		}

		// None of the above functions change position, we remain in the chunk of NextChunk
		HandlePhysics(a_Dt, *NextChunk);
	}
}
コード例 #3
0
ファイル: Entity.cpp プロジェクト: ravenscroftj/MCServer
void cEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
	if (m_AttachedTo != NULL)
	{
		if ((m_Pos - m_AttachedTo->GetPosition()).Length() > 0.5)
		{
			SetPosition(m_AttachedTo->GetPosition());
		}
	}
	else
	{
		if (a_Chunk.IsValid())
		{
			HandlePhysics(a_Dt, a_Chunk);
		}
	}
	if (a_Chunk.IsValid())
	{
		TickBurning(a_Chunk);
	}
}
コード例 #4
0
ファイル: Player.cpp プロジェクト: Kortak/MCServer
void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
{
	if (m_ClientHandle != NULL)
	{
		if (m_ClientHandle->IsDestroyed())
		{
			// This should not happen, because destroying a client will remove it from the world, but just in case
			m_ClientHandle = NULL;
			return;
		}
		
		if (!m_ClientHandle->IsPlaying())
		{
			// We're not yet in the game, ignore everything
			return;
		}
	}

	m_Stats.AddValue(statMinutesPlayed, 1);
	
	if (!a_Chunk.IsValid())
	{
		// This may happen if the cPlayer is created before the chunks have the chance of being loaded / generated (#83)
		return;
	}
	
	super::Tick(a_Dt, a_Chunk);
	
	// Handle charging the bow:
	if (m_IsChargingBow)
	{
		m_BowCharge += 1;
	}
	
	// Handle updating experience
	if (m_bDirtyExperience)
	{
		SendExperience();
	}

	if (GetPosition() != m_LastPos) // Change in position from last tick?
	{
		// Apply food exhaustion from movement:
		ApplyFoodExhaustionFromMovement();
		
		cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this);
		m_ClientHandle->StreamChunks();
	}

	BroadcastMovementUpdate(m_ClientHandle);

	if (m_Health > 0)  // make sure player is alive
	{
		m_World->CollectPickupsByPlayer(this);

		if ((m_EatingFinishTick >= 0) && (m_EatingFinishTick <= m_World->GetWorldAge()))
		{
			FinishEating();
		}
		
		HandleFood();
	}
	
	if (m_IsFishing)
	{
		HandleFloater();
	}

	// Update items (e.g. Maps)
	m_Inventory.UpdateItems();

	// Send Player List (Once per m_LastPlayerListTime/1000 ms)
	cTimer t1;
	if (m_LastPlayerListTime + cPlayer::PLAYER_LIST_TIME_MS <= t1.GetNowTime())
	{
		m_World->SendPlayerList(this);
		m_LastPlayerListTime = t1.GetNowTime();
	}

	if (IsFlying())
	{
		m_LastGroundHeight = (float)GetPosY();
	}
}
コード例 #5
0
ファイル: Player.cpp プロジェクト: Noraaron1/MCServer
void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
{
    if (m_ClientHandle != NULL)
    {
        if (m_ClientHandle->IsDestroyed())
        {
            // This should not happen, because destroying a client will remove it from the world, but just in case
            m_ClientHandle = NULL;
            return;
        }

        if (!m_ClientHandle->IsPlaying())
        {
            // We're not yet in the game, ignore everything
            return;
        }
    }

    if (!a_Chunk.IsValid())
    {
        // This may happen if the cPlayer is created before the chunks have the chance of being loaded / generated (#83)
        return;
    }

    super::Tick(a_Dt, a_Chunk);

    // Set player swimming state
    SetSwimState(a_Chunk);

    // Handle air drowning stuff
    HandleAir();

    // Handle charging the bow:
    if (m_IsChargingBow)
    {
        m_BowCharge += 1;
    }

    //handle updating experience
    if (m_bDirtyExperience)
    {
        SendExperience();
    }

    if (m_bDirtyPosition)
    {
        // Apply food exhaustion from movement:
        ApplyFoodExhaustionFromMovement();

        cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this);
        BroadcastMovementUpdate(m_ClientHandle);
        m_ClientHandle->StreamChunks();
    }
    else
    {
        BroadcastMovementUpdate(m_ClientHandle);
    }

    if (m_Health > 0)  // make sure player is alive
    {
        m_World->CollectPickupsByPlayer(this);

        if ((m_EatingFinishTick >= 0) && (m_EatingFinishTick <= m_World->GetWorldAge()))
        {
            FinishEating();
        }

        HandleFood();
    }

    // Send Player List (Once per m_LastPlayerListTime/1000 ms)
    cTimer t1;
    if (m_LastPlayerListTime + cPlayer::PLAYER_LIST_TIME_MS <= t1.GetNowTime())
    {
        m_World->SendPlayerList(this);
        m_LastPlayerListTime = t1.GetNowTime();
    }
}