1
0
cuberite-2a/src/Entities/ExpOrb.cpp

64 lines
1.3 KiB
C++
Raw Normal View History

2013-11-25 14:05:52 -05:00
#include "Globals.h"
#include "ExpOrb.h"
#include "Player.h"
#include "../ClientHandle.h"
cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward) :
cEntity(etExpOrb, a_X, a_Y, a_Z, 0.98, 0.98),
m_Reward(a_Reward)
{
}
cExpOrb::cExpOrb(const Vector3d & a_Pos, int a_Reward) :
cEntity(etExpOrb, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98),
m_Reward(a_Reward)
{
}
void cExpOrb::SpawnOn(cClientHandle & a_Client)
{
a_Client.SendExperienceOrb(*this);
m_bDirtyPosition = false;
m_bDirtySpeed = false;
m_bDirtyOrientation = false;
m_bDirtyHead = false;
}
void cExpOrb::Tick(float a_Dt, cChunk & a_Chunk)
{
2013-12-11 10:14:08 -05:00
cPlayer * a_ClosestPlayer(m_World->FindClosestPlayer(Vector3f(GetPosition()), 5));
if (a_ClosestPlayer != NULL)
2013-11-25 14:05:52 -05:00
{
Vector3f a_PlayerPos(a_ClosestPlayer->GetPosition());
2013-12-11 10:14:08 -05:00
a_PlayerPos.y++;
2013-11-25 14:05:52 -05:00
Vector3f a_Distance(a_PlayerPos - GetPosition());
2013-12-11 10:14:08 -05:00
double Distance(a_Distance.Length());
if (Distance < 0.1f)
2013-11-25 14:05:52 -05:00
{
2013-12-14 06:50:08 -05:00
LOGD("Player %s picked up an ExpOrb. His reward is %i", a_ClosestPlayer->GetName().c_str(), m_Reward);
2013-11-25 14:05:52 -05:00
a_ClosestPlayer->DeltaExperience(m_Reward);
Destroy(true);
}
a_Distance.Normalize();
2013-12-15 09:57:38 -05:00
a_Distance *= ((float) (5.5 - Distance));
2013-11-25 14:05:52 -05:00
SetSpeedX( a_Distance.x );
2013-12-11 10:14:08 -05:00
SetSpeedY( a_Distance.y );
2013-11-25 14:05:52 -05:00
SetSpeedZ( a_Distance.z );
2013-12-11 10:14:08 -05:00
BroadcastMovementUpdate();
2013-11-25 14:05:52 -05:00
}
2013-12-11 10:14:08 -05:00
HandlePhysics(a_Dt, a_Chunk);
2013-11-25 14:05:52 -05:00
}