summaryrefslogtreecommitdiffstats
path: root/source/cPawn.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/cPawn.cpp')
-rw-r--r--source/cPawn.cpp96
1 files changed, 89 insertions, 7 deletions
diff --git a/source/cPawn.cpp b/source/cPawn.cpp
index 2c1471156..e696ffc18 100644
--- a/source/cPawn.cpp
+++ b/source/cPawn.cpp
@@ -6,9 +6,14 @@
#include "cChunk.h"
#include "cMCLogger.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 )
@@ -18,8 +23,11 @@ cPawn::cPawn()
, m_LastPosY( 0.0 )
, m_LastPosZ( 0.0 )
, m_TimeLastTeleportPacket( 0.f )
+ , m_bBurnable(true)
+ , m_MetaData(NORMAL)
+ , m_FireDamageInterval(0.f)
{
- m_Health = 20;
+ SetMaxHealth(20);
}
cPawn::~cPawn()
@@ -83,14 +91,88 @@ void cPawn::TeleportTo( cEntity* a_Entity )
void cPawn::TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ )
{
SetPosition( a_PosX, a_PosY, a_PosZ );
+
cPacket_TeleportEntity TeleportEntity( this );
- if( IsA("cPlayer") )
- {
- cPlayer* Player = (cPlayer*)this;
- cRoot::Get()->GetServer()->Broadcast( TeleportEntity, Player->GetClientHandle() );
+
+ cRoot::Get()->GetServer()->Broadcast( TeleportEntity );
+
+}
+
+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)
+{
+ cChunk* InChunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ );
+
+ if(InChunk)
+ { //Broadcast new status to clients in the chunk
+ m_MetaData = a_MetaData;
+ cPacket_Metadata md(a_MetaData, GetUniqueID());
+ InChunk->Broadcast(md);
}
- else
+}
+
+//----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);
+ if(GetMetaData() == BURNING
+ && (IsBlockWater(Block)
+ || IsBlockWater(BlockAbove)))
{
- cRoot::Get()->GetServer()->Broadcast( TeleportEntity );
+ SetMetaData(NORMAL);
+ }else if(m_bBurnable && GetMetaData() != BURNING
+ && (IsBlockLava(Block) || Block == E_BLOCK_FIRE
+ || IsBlockLava(BlockAbove) || BlockAbove == 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;
+}
+
+