2013-11-25 14:05:52 -05:00
|
|
|
#include "Globals.h"
|
|
|
|
|
|
|
|
#include "ExpOrb.h"
|
|
|
|
#include "Player.h"
|
|
|
|
#include "../ClientHandle.h"
|
|
|
|
|
|
|
|
|
2019-09-29 08:59:24 -04:00
|
|
|
cExpOrb::cExpOrb(Vector3d a_Pos, int a_Reward):
|
2021-04-06 11:09:16 -04:00
|
|
|
Super(etExpOrb, a_Pos, 0.5f, 0.5f),
|
2019-09-29 08:59:24 -04:00
|
|
|
m_Reward(a_Reward),
|
|
|
|
m_Timer(0)
|
2013-11-25 14:05:52 -05:00
|
|
|
{
|
2014-03-14 19:32:49 -04:00
|
|
|
SetMaxHealth(5);
|
|
|
|
SetHealth(5);
|
2018-08-02 10:59:10 -04:00
|
|
|
SetGravity(-16);
|
|
|
|
SetAirDrag(0.02f);
|
2013-11-25 14:05:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cExpOrb::SpawnOn(cClientHandle & a_Client)
|
|
|
|
{
|
|
|
|
a_Client.SendExperienceOrb(*this);
|
|
|
|
m_bDirtyOrientation = false;
|
|
|
|
m_bDirtyHead = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-11 16:12:26 -05:00
|
|
|
void cExpOrb::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2013-11-25 14:05:52 -05:00
|
|
|
{
|
2018-01-16 14:13:17 -05:00
|
|
|
DetectCacti();
|
2018-08-02 10:59:10 -04:00
|
|
|
m_TicksAlive++;
|
2018-01-16 14:13:17 -05:00
|
|
|
|
2018-08-02 10:59:10 -04:00
|
|
|
// Find closest player within 6.5 meter (slightly increase detect range to have same effect in client)
|
|
|
|
bool FoundPlayer = m_World->DoWithNearestPlayer(GetPosition(), 6.5, [&](cPlayer & a_Player) -> bool
|
2013-11-25 14:05:52 -05:00
|
|
|
{
|
2018-08-02 10:59:10 -04:00
|
|
|
Vector3f a_PlayerPos(a_Player.GetPosition());
|
|
|
|
a_PlayerPos.y += 0.8f;
|
|
|
|
Vector3f a_Distance = a_PlayerPos - GetPosition();
|
|
|
|
double Distance = a_Distance.Length();
|
|
|
|
|
|
|
|
if (Distance < 0.7f)
|
|
|
|
{
|
|
|
|
a_Player.DeltaExperience(m_Reward);
|
|
|
|
|
|
|
|
m_World->BroadcastSoundEffect("entity.experience_orb.pickup", GetPosition(), 0.5f, (0.75f + (static_cast<float>((GetUniqueID() * 23) % 32)) / 64));
|
2020-03-05 05:52:34 -05:00
|
|
|
Destroy();
|
2018-08-02 10:59:10 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Experience orb will "float" or glide toward the player up to a distance of 6 blocks.
|
|
|
|
// speeding up as they get nearer to the player, Speed range 6 - 12 m per second, accelerate 60 m per second^2
|
|
|
|
Vector3d SpeedDelta(a_Distance);
|
|
|
|
SpeedDelta.Normalize();
|
|
|
|
SpeedDelta *= 3;
|
|
|
|
|
|
|
|
Vector3d CurrentSpeed = GetSpeed();
|
|
|
|
CurrentSpeed += SpeedDelta;
|
|
|
|
if (CurrentSpeed.Length() > 12)
|
2013-11-25 14:05:52 -05:00
|
|
|
{
|
2018-08-02 10:59:10 -04:00
|
|
|
CurrentSpeed.Normalize();
|
|
|
|
CurrentSpeed *= 12;
|
2013-11-25 14:05:52 -05:00
|
|
|
}
|
2018-08-02 10:59:10 -04:00
|
|
|
|
|
|
|
SetSpeed(CurrentSpeed);
|
|
|
|
m_Gravity = 0;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}, false, true); // Don't check line of sight, ignore spectator mode player
|
|
|
|
|
|
|
|
if (!FoundPlayer)
|
|
|
|
{
|
|
|
|
m_Gravity = -16;
|
2013-11-25 14:05:52 -05:00
|
|
|
}
|
2018-08-02 10:59:10 -04:00
|
|
|
|
2013-12-11 10:14:08 -05:00
|
|
|
HandlePhysics(a_Dt, a_Chunk);
|
2018-08-02 10:59:10 -04:00
|
|
|
BroadcastMovementUpdate();
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-01-16 08:27:10 -05:00
|
|
|
m_Timer += a_Dt;
|
|
|
|
if (m_Timer >= std::chrono::minutes(5))
|
2014-03-14 19:32:49 -04:00
|
|
|
{
|
2020-03-05 05:52:34 -05:00
|
|
|
Destroy();
|
2014-03-14 19:32:49 -04:00
|
|
|
}
|
2014-02-14 16:49:23 -05:00
|
|
|
}
|
2018-01-16 14:13:17 -05:00
|
|
|
|
2018-07-26 17:24:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-16 14:13:17 -05:00
|
|
|
bool cExpOrb::DoTakeDamage(TakeDamageInfo & a_TDI)
|
|
|
|
{
|
|
|
|
if (a_TDI.DamageType == dtCactusContact)
|
|
|
|
{
|
2020-03-05 05:52:34 -05:00
|
|
|
Destroy();
|
2018-01-16 14:13:17 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
return Super::DoTakeDamage(a_TDI);
|
2018-01-16 14:13:17 -05:00
|
|
|
}
|
2018-08-02 10:59:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<int> cExpOrb::Split(int a_Reward)
|
|
|
|
{
|
|
|
|
const static std::array<int, 11> BaseValue = {{1, 3, 7, 17, 37, 73, 149, 307, 617, 1237, 2477}};
|
|
|
|
|
|
|
|
std::vector<int> Rewards;
|
|
|
|
size_t Index = BaseValue.size() - 1; // Last one
|
|
|
|
|
|
|
|
while (a_Reward > 0)
|
|
|
|
{
|
|
|
|
while (a_Reward < BaseValue[Index])
|
|
|
|
{
|
|
|
|
Index--;
|
|
|
|
}
|
|
|
|
|
|
|
|
a_Reward -= BaseValue[Index];
|
|
|
|
Rewards.push_back(BaseValue[Index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Rewards;
|
|
|
|
}
|
|
|
|
|
|
|
|
|