Exemple #1
0
void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
	// Iterate through this entity's applied effects
	for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
	{
		// Copies values to prevent pesky wrong accesses and erasures
		cEntityEffect::eType EffectType = iter->first;
		cEntityEffect * Effect = iter->second;
		
		Effect->OnTick(*this);
		
		// Iterates (must be called before any possible erasure)
		++iter;
		
		// Remove effect if duration has elapsed
		if (Effect->GetDuration() - Effect->GetTicks() <= 0)
		{
			RemoveEntityEffect(EffectType);
		}
		
		// TODO: Check for discrepancies between client and server effect values
	}
	
	super::Tick(a_Dt, a_Chunk);
}
Exemple #2
0
void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
    // Iterate through this entity's applied effects
    for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
    {
        // Copies values to prevent pesky wrong accesses and erasures
        cEntityEffect::eType EffectType = iter->first;
        cEntityEffect * Effect = iter->second;

        Effect->OnTick(*this);

        // Iterates (must be called before any possible erasure)
        ++iter;

        // Remove effect if duration has elapsed
        if (Effect->GetDuration() - Effect->GetTicks() <= 0)
        {
            RemoveEntityEffect(EffectType);
        }

        // TODO: Check for discrepancies between client and server effect values
    }

    class Pusher : public cEntityCallback
    {
    public:
        cEntity * m_Pusher;

        Pusher(cEntity * a_Pusher) :
            m_Pusher(a_Pusher)
        {
        }

        virtual bool Item(cEntity * a_Entity) override
        {
            if (a_Entity->GetUniqueID() == m_Pusher->GetUniqueID())
            {
                return false;
            }

            // we only push other mobs, boats and minecarts
            if ((a_Entity->GetEntityType() != etMonster) && (a_Entity->GetEntityType() != etMinecart) && (a_Entity->GetEntityType() != etBoat))
            {
                return false;
            }

            Vector3d v3Delta = a_Entity->GetPosition() - m_Pusher->GetPosition();
            v3Delta.y = 0.0;  // we only push sideways
            v3Delta *= 1.0 / (v3Delta.Length() + 0.01);  // we push harder if we're close
            // QUESTION: is there an additional multiplier for this? current shoving seems a bit weak

            a_Entity->AddSpeed(v3Delta);
            return false;
        }
    } Callback(this);

    m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), GetWidth(), GetHeight()), Callback);

    super::Tick(a_Dt, a_Chunk);
}
Exemple #3
0
void cPawn::ClearEntityEffects()
{
	// Iterate through this entity's applied effects
	for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
	{
		// Copy values to prevent pesky wrong erasures
		cEntityEffect::eType EffectType = iter->first;

		// Iterates (must be called before any possible erasure)
		++iter;

		// Remove effect
		RemoveEntityEffect(EffectType);
	}
}
Exemple #4
0
void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
	std::vector<cEntityEffect *> EffectsToTick;

	// Iterate through this entity's applied effects
	for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();)
	{
		// Copies values to prevent pesky wrong accesses and erasures
		cEntityEffect::eType EffectType = iter->first;
		cEntityEffect * Effect = iter->second.get();

		// Iterates (must be called before any possible erasure)
		++iter;

		// Remove effect if duration has elapsed
		if (Effect->GetDuration() - Effect->GetTicks() <= 0)
		{
			RemoveEntityEffect(EffectType);
		}
		// Call OnTick later to make sure the iterator won't be invalid
		else
		{
			EffectsToTick.push_back(Effect);
		}

		// TODO: Check for discrepancies between client and server effect values
	}


	for (auto * Effect : EffectsToTick)
	{
		Effect->OnTick(*this);
	}

	// Spectators cannot push entities around
	if ((!IsPlayer()) || (!static_cast<cPlayer *>(this)->IsGameModeSpectator()))
	{
		m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), GetWidth(), GetHeight()), [=](cEntity & a_Entity)
			{
				if (a_Entity.GetUniqueID() == GetUniqueID())
				{
					return false;
				}

				// we only push other mobs, boats and minecarts
				if ((a_Entity.GetEntityType() != etMonster) && (a_Entity.GetEntityType() != etMinecart) && (a_Entity.GetEntityType() != etBoat))
				{
					return false;
				}

				// do not push a boat / minecart you're sitting in
				if (IsAttachedTo(&a_Entity))
				{
					return false;
				}

				Vector3d v3Delta = a_Entity.GetPosition() - GetPosition();
				v3Delta.y = 0.0;  // we only push sideways
				v3Delta *= 1.0 / (v3Delta.Length() + 0.01);  // we push harder if we're close
				// QUESTION: is there an additional multiplier for this? current shoving seems a bit weak

				a_Entity.AddSpeed(v3Delta);
				return false;
			}
		);
	}

	super::Tick(a_Dt, a_Chunk);
	if (!IsTicking())
	{
		// The base class tick destroyed us
		return;
	}
	HandleFalling();
}