2013-12-20 11:11:51 -05:00
|
|
|
|
2013-12-19 11:32:06 -05:00
|
|
|
#include "Globals.h"
|
|
|
|
|
|
|
|
#include "Floater.h"
|
|
|
|
#include "Player.h"
|
2013-12-19 16:44:10 -05:00
|
|
|
#include "../ClientHandle.h"
|
2013-12-19 11:32:06 -05:00
|
|
|
|
2013-12-20 11:11:51 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-22 08:48:22 -05:00
|
|
|
cFloater::cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID, int a_CountDownTime) :
|
2013-12-19 11:32:06 -05:00
|
|
|
cEntity(etFloater, a_X, a_Y, a_Z, 0.98, 0.98),
|
2013-12-20 11:11:51 -05:00
|
|
|
m_PickupCountDown(0),
|
2013-12-19 11:32:06 -05:00
|
|
|
m_PlayerID(a_PlayerID),
|
2013-12-22 08:48:22 -05:00
|
|
|
m_CanPickupItem(false),
|
|
|
|
m_CountDownTime(a_CountDownTime)
|
2013-12-19 11:32:06 -05:00
|
|
|
{
|
|
|
|
SetSpeed(a_Speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cFloater::SpawnOn(cClientHandle & a_Client)
|
|
|
|
{
|
|
|
|
a_Client.SendSpawnObject(*this, 90, m_PlayerID, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cFloater::Tick(float a_Dt, cChunk & a_Chunk)
|
|
|
|
{
|
|
|
|
HandlePhysics(a_Dt, a_Chunk);
|
2013-12-21 08:11:21 -05:00
|
|
|
if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ())) && m_World->GetBlockMeta((int) GetPosX(), (int) GetPosY(), (int) GetPosZ()) == 0)
|
2013-12-19 11:32:06 -05:00
|
|
|
{
|
2013-12-22 08:48:22 -05:00
|
|
|
if (!m_CanPickupItem)
|
2013-12-19 11:32:06 -05:00
|
|
|
{
|
2013-12-22 08:48:22 -05:00
|
|
|
if (m_CountDownTime <= 0)
|
|
|
|
{
|
|
|
|
m_World->BroadcastSoundEffect("random.splash", (int) floor(GetPosX() * 8), (int) floor(GetPosY() * 8), (int) floor(GetPosZ() * 8), 1, 1);
|
|
|
|
SetPosY(GetPosY() - 1);
|
|
|
|
m_CanPickupItem = true;
|
|
|
|
m_PickupCountDown = 20;
|
|
|
|
m_CountDownTime = 100 + m_World->GetTickRandomNumber(800);
|
|
|
|
LOGD("Floater %i can be picked up", GetUniqueID());
|
|
|
|
}
|
|
|
|
else if (m_CountDownTime == 20) // Calculate the position where the particles should spawn and start producing them.
|
|
|
|
{
|
|
|
|
LOGD("Started producing particles for floater %i", GetUniqueID());
|
|
|
|
m_ParticlePos.Set(GetPosX() + (-4 + m_World->GetTickRandomNumber(8)), GetPosY(), GetPosZ() + (-4 + m_World->GetTickRandomNumber(8)));
|
|
|
|
m_World->BroadcastParticleEffect("splash", m_ParticlePos.x, m_ParticlePos.y, m_ParticlePos.z, 0, 0, 0, 0, 15);
|
|
|
|
}
|
|
|
|
else if (m_CountDownTime < 20)
|
|
|
|
{
|
|
|
|
m_ParticlePos = (m_ParticlePos + (GetPosition() - m_ParticlePos) / 6);
|
|
|
|
m_World->BroadcastParticleEffect("splash", m_ParticlePos.x, m_ParticlePos.y, m_ParticlePos.z, 0, 0, 0, 0, 15);
|
|
|
|
}
|
|
|
|
m_CountDownTime--;
|
2013-12-19 11:32:06 -05:00
|
|
|
}
|
2013-12-22 08:48:22 -05:00
|
|
|
SetSpeedY(0.7);
|
2013-12-19 11:32:06 -05:00
|
|
|
}
|
|
|
|
SetSpeedX(GetSpeedX() * 0.95);
|
|
|
|
SetSpeedZ(GetSpeedZ() * 0.95);
|
|
|
|
if (CanPickup())
|
|
|
|
{
|
|
|
|
m_PickupCountDown--;
|
|
|
|
if (m_PickupCountDown == 0)
|
|
|
|
{
|
|
|
|
m_CanPickupItem = false;
|
|
|
|
LOGD("The fish is gone. Floater %i can not pick an item up.", GetUniqueID());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BroadcastMovementUpdate();
|
2013-12-20 11:11:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|