Example #1
0
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();
	}
}
Example #2
0
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();
    }
}