summaryrefslogtreecommitdiffstats
path: root/src/Entities/ExpOrb.cpp
blob: 1e5ee00ce84d55e26ce5729f893d5fc3be6e7ba7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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 );
	}
}