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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "cPawn.h"
#include "cRoot.h"
#include "cServer.h"
#include "cWorld.h"
#include "cPlayer.h"
#include "cPluginManager.h"
#include "Vector3d.h"
#include "BlockID.h"
#include "Defines.h"
#include "packets/cPacket_TeleportEntity.h"
#include "packets/cPacket_EntityStatus.h"
#include "packets/cPacket_Metadata.h"
CLASS_DEFINITION( cPawn, cEntity )
cPawn::cPawn()
: cEntity( 0, 0, 0 )
, m_LastPosX( 0.0 )
, m_LastPosY( 0.0 )
, m_LastPosZ( 0.0 )
, m_TimeLastTeleportPacket( 0.f )
, m_bBurnable(true)
, m_MetaData(NORMAL)
, m_FireDamageInterval(0.f)
, m_BurnPeriod(0.f)
{
SetMaxHealth(20);
}
cPawn::~cPawn()
{
}
void cPawn::Heal( int a_Health )
{
(void)a_Health;
}
void cPawn::TakeDamage( int a_Damage, cEntity* a_Instigator )
{
TakeDamageInfo TDI;
TDI.Damage = a_Damage;
TDI.Instigator = a_Instigator;
cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_TAKE_DAMAGE, 2, this, &TDI );
if( TDI.Damage == 0 ) return;
if( m_Health <= 0 ) return; // Can't take damage if already dead
m_Health -= (short)TDI.Damage;
if( m_Health < 0 ) m_Health = 0;
cPacket_EntityStatus Status;
Status.m_UniqueID = GetUniqueID();
Status.m_Status = cPacket_EntityStatus::STATUS_TAKEDAMAGE;
m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, Status);
if (m_Health <= 0)
{
KilledBy( TDI.Instigator );
}
}
void cPawn::KilledBy( cEntity* a_Killer )
{
m_Health = 0;
if( cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_KILLED, 2, this, a_Killer ) )
{
return; // Give plugins a chance to 'unkill' the pawn.
}
cPacket_EntityStatus Status;
Status.m_UniqueID = GetUniqueID();
Status.m_Status = cPacket_EntityStatus::STATUS_DIE;
m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, Status);
}
void cPawn::TeleportToEntity( cEntity* a_Entity )
{
TeleportTo( a_Entity->GetPosX(), a_Entity->GetPosY(), a_Entity->GetPosZ() );
}
void cPawn::TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ )
{
SetPosition( a_PosX, a_PosY, a_PosZ );
GetWorld()->BroadcastTeleportEntity(*this);
}
void cPawn::Tick(float a_Dt)
{
CheckMetaDataBurn(); // Check to see if pawn should burn based on block they are on
if (GetMetaData() == BURNING)
{
InStateBurning(a_Dt);
}
}
void cPawn::SetMetaData(MetaData a_MetaData)
{
//Broadcast new status to clients in the chunk
m_MetaData = a_MetaData;
cPacket_Metadata md(a_MetaData, GetUniqueID());
m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, md);
}
//----Change Entity MetaData
void cPawn::CheckMetaDataBurn()
{
char Block = GetWorld()->GetBlock((int) m_Pos.x, (int) m_Pos.y, (int) m_Pos.z);
char BlockAbove = GetWorld()->GetBlock((int) m_Pos.x, (int) m_Pos.y + 1, (int) m_Pos.z);
char BlockBelow = GetWorld()->GetBlock((int) m_Pos.x, (int) m_Pos.y - 1, (int) m_Pos.z);
if (
(GetMetaData() == BURNING) &&
(IsBlockWater(Block) || IsBlockWater(BlockAbove) || IsBlockWater(BlockBelow))
)
{
SetMetaData(NORMAL);
}
else if (
m_bBurnable &&
(GetMetaData() != BURNING) &&
(
IsBlockLava(Block) || (Block == E_BLOCK_FIRE) ||
IsBlockLava(BlockAbove) || (BlockAbove == E_BLOCK_FIRE) ||
IsBlockLava(BlockBelow) || (BlockBelow == E_BLOCK_FIRE)
)
)
{
SetMetaData(BURNING);
}
}
//What to do if On fire
void cPawn::InStateBurning(float a_Dt)
{
m_FireDamageInterval += a_Dt;
char Block = GetWorld()->GetBlock( (int)m_Pos.x, (int)m_Pos.y, (int)m_Pos.z );
char BlockAbove = GetWorld()->GetBlock( (int)m_Pos.x, (int)m_Pos.y + 1, (int)m_Pos.z );
if (m_FireDamageInterval > 800)
{
m_FireDamageInterval = 0;
TakeDamage(1, this);
m_BurnPeriod++;
if (IsBlockLava(Block) || Block == E_BLOCK_FIRE
|| IsBlockLava(BlockAbove) || BlockAbove == E_BLOCK_FIRE)
{
m_BurnPeriod = 0;
TakeDamage(6, this);
}
else
{
TakeDamage(1, this);
}
if (m_BurnPeriod > 7)
{
SetMetaData(NORMAL);
m_BurnPeriod = 0;
}
}
}
void cPawn::SetMaxHealth(short a_MaxHealth)
{
this->m_MaxHealth = a_MaxHealth;
//Reset health
m_Health = a_MaxHealth;
}
|