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

99 lines
2.0 KiB
C++
Raw Normal View History

2013-11-25 19:05:52 +00:00
#include "Globals.h"
#include "ExpOrb.h"
#include "Player.h"
#include "../ClientHandle.h"
2014-03-14 23:32:49 +00:00
cExpOrb::cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward)
2014-07-17 21:15:53 +00:00
: cEntity(etExpOrb, a_X, a_Y, a_Z, 0.98, 0.98)
2014-03-14 23:32:49 +00:00
, m_Reward(a_Reward)
2015-01-16 13:27:10 +00:00
, m_Timer(0)
2013-11-25 19:05:52 +00:00
{
2014-03-14 23:32:49 +00:00
SetMaxHealth(5);
SetHealth(5);
SetGravity(0);
2013-11-25 19:05:52 +00:00
}
2014-03-14 23:32:49 +00:00
cExpOrb::cExpOrb(const Vector3d & a_Pos, int a_Reward)
2014-07-17 21:15:53 +00:00
: cEntity(etExpOrb, a_Pos.x, a_Pos.y, a_Pos.z, 0.98, 0.98)
2014-03-14 23:32:49 +00:00
, m_Reward(a_Reward)
2015-01-16 13:27:10 +00:00
, m_Timer(0)
2013-11-25 19:05:52 +00:00
{
2014-03-14 23:32:49 +00:00
SetMaxHealth(5);
SetHealth(5);
SetGravity(0);
2013-11-25 19:05:52 +00:00
}
void cExpOrb::SpawnOn(cClientHandle & a_Client)
{
a_Client.SendExperienceOrb(*this);
m_bDirtyOrientation = false;
m_bDirtyHead = false;
}
void cExpOrb::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
2013-11-25 19:05:52 +00:00
{
DetectCacti();
// Check player proximity no more than twice per second
if ((m_TicksAlive % 10) == 0)
2013-11-25 19:05:52 +00:00
{
cPlayer * a_ClosestPlayer(m_World->FindClosestPlayer(Vector3f(GetPosition()), 5, false));
if ((a_ClosestPlayer != nullptr) && (!a_ClosestPlayer->IsGameModeSpectator()))
2013-11-25 19:05:52 +00:00
{
Vector3f a_PlayerPos(a_ClosestPlayer->GetPosition());
a_PlayerPos.y++;
Vector3f a_Distance(a_PlayerPos - GetPosition());
double Distance(a_Distance.Length());
if (Distance < 0.5f)
{
LOGD("Player %s picked up an ExpOrb. His reward is %i", a_ClosestPlayer->GetName().c_str(), m_Reward);
a_ClosestPlayer->DeltaExperience(m_Reward);
m_World->BroadcastSoundEffect("entity.experience_orb.pickup", GetPosition(), 0.5f, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
Destroy(true);
return;
}
SetSpeedX((a_PlayerPos.x - GetPosition().x) * 2.0);
SetSpeedY((a_PlayerPos.y - GetPosition().y) * 2.0);
SetSpeedZ((a_PlayerPos.z - GetPosition().z) * 2.0);
2013-11-25 19:05:52 +00:00
}
}
2013-12-11 15:14:08 +00:00
HandlePhysics(a_Dt, a_Chunk);
2016-02-05 21:45:45 +00:00
2015-01-16 13:27:10 +00:00
m_Timer += a_Dt;
if (m_Timer >= std::chrono::minutes(5))
2014-03-14 23:32:49 +00:00
{
Destroy(true);
}
2014-02-14 21:49:23 +00:00
}
bool cExpOrb::DoTakeDamage(TakeDamageInfo & a_TDI)
{
if (a_TDI.DamageType == dtCactusContact)
{
Destroy(true);
return true;
}
return super::DoTakeDamage(a_TDI);
}