diff options
author | Mattes D <github@xoft.cz> | 2013-11-26 10:48:46 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2013-11-26 10:48:46 +0100 |
commit | 6041fa1e62cc490c4595e6cd267eb96ac5b6e041 (patch) | |
tree | 00e3c895d8e0143275ba6d1a9a1ff0361714b53e /source/Entities | |
parent | Fixed cFile compilation on Linux. (diff) | |
parent | Added ExpOrb.cpp and ExpOrb.h to MCServer.vcproj. (diff) | |
download | cuberite-6041fa1e62cc490c4595e6cd267eb96ac5b6e041.tar cuberite-6041fa1e62cc490c4595e6cd267eb96ac5b6e041.tar.gz cuberite-6041fa1e62cc490c4595e6cd267eb96ac5b6e041.tar.bz2 cuberite-6041fa1e62cc490c4595e6cd267eb96ac5b6e041.tar.lz cuberite-6041fa1e62cc490c4595e6cd267eb96ac5b6e041.tar.xz cuberite-6041fa1e62cc490c4595e6cd267eb96ac5b6e041.tar.zst cuberite-6041fa1e62cc490c4595e6cd267eb96ac5b6e041.zip |
Diffstat (limited to '')
-rw-r--r-- | source/Entities/Entity.h | 1 | ||||
-rw-r--r-- | source/Entities/ExpOrb.cpp | 60 | ||||
-rw-r--r-- | source/Entities/ExpOrb.h | 29 |
3 files changed, 90 insertions, 0 deletions
diff --git a/source/Entities/Entity.h b/source/Entities/Entity.h index dafda7826..de5f176ae 100644 --- a/source/Entities/Entity.h +++ b/source/Entities/Entity.h @@ -74,6 +74,7 @@ public: etBoat, etTNT, etProjectile, + etExpOrb, // Common variations etMob = etMonster, // DEPRECATED, use etMonster instead! diff --git a/source/Entities/ExpOrb.cpp b/source/Entities/ExpOrb.cpp new file mode 100644 index 000000000..1e5ee00ce --- /dev/null +++ b/source/Entities/ExpOrb.cpp @@ -0,0 +1,60 @@ +#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) +{ + cPlayer * a_ClosestPlayer(m_World->FindClosestPlayer(Vector3f(GetPosition()), 4)); + if (a_ClosestPlayer) + { + Vector3f a_PlayerPos(a_ClosestPlayer->GetPosition()); + Vector3f a_Distance(a_PlayerPos - GetPosition()); + if (a_Distance.Length() < 0.1f) + { + a_ClosestPlayer->DeltaExperience(m_Reward); + a_ClosestPlayer->SendExperience(); + Destroy(true); + } + a_Distance.y = 0; + a_Distance.Normalize(); + a_Distance *= 3; + SetSpeedX( a_Distance.x ); + SetSpeedZ( a_Distance.z ); + } +}
\ No newline at end of file diff --git a/source/Entities/ExpOrb.h b/source/Entities/ExpOrb.h new file mode 100644 index 000000000..a062eedd3 --- /dev/null +++ b/source/Entities/ExpOrb.h @@ -0,0 +1,29 @@ + +#pragma once + +#include "Entity.h" + + + + + +class cExpOrb : + public cEntity +{ + typedef cExpOrb super; + +public: + + cExpOrb(double a_X, double a_Y, double a_Z, int a_Reward); + cExpOrb(const Vector3d & a_Pos, int a_Reward); + + // Override functions + virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void SpawnOn(cClientHandle & a_Client) override; + + // cExpOrb functions + int GetReward(void) const { return m_Reward; } + +protected: + int m_Reward; +} ;
\ No newline at end of file |