2012-01-29 14:28:19 -05:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
#include "cPawn.h"
|
|
|
|
#include "cRoot.h"
|
|
|
|
#include "cServer.h"
|
|
|
|
#include "cWorld.h"
|
|
|
|
#include "cPlayer.h"
|
|
|
|
#include "cPluginManager.h"
|
2011-12-27 21:10:05 -05:00
|
|
|
#include "Vector3d.h"
|
|
|
|
#include "BlockID.h"
|
|
|
|
|
|
|
|
#include "Defines.h"
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
#include "packets/cPacket_TeleportEntity.h"
|
|
|
|
#include "packets/cPacket_EntityStatus.h"
|
2011-12-27 21:10:05 -05:00
|
|
|
#include "packets/cPacket_Metadata.h"
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
CLASS_DEFINITION( cPawn, cEntity )
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
cPawn::cPawn()
|
|
|
|
: cEntity( 0, 0, 0 )
|
|
|
|
, m_LastPosX( 0.0 )
|
|
|
|
, m_LastPosY( 0.0 )
|
|
|
|
, m_LastPosZ( 0.0 )
|
|
|
|
, m_TimeLastTeleportPacket( 0.f )
|
2011-12-27 21:10:05 -05:00
|
|
|
, m_bBurnable(true)
|
|
|
|
, m_MetaData(NORMAL)
|
|
|
|
, m_FireDamageInterval(0.f)
|
2011-12-29 17:55:25 -05:00
|
|
|
, m_BurnPeriod(0.f)
|
2011-10-03 14:41:19 -04:00
|
|
|
{
|
2011-12-27 21:10:05 -05:00
|
|
|
SetMaxHealth(20);
|
2011-12-29 10:31:48 -05:00
|
|
|
SetMaxFoodLevel(125);
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
cPawn::~cPawn()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
void cPawn::Heal( int a_Health )
|
|
|
|
{
|
|
|
|
(void)a_Health;
|
|
|
|
}
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
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;
|
2012-02-20 11:39:00 -05:00
|
|
|
m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, Status);
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
if (m_Health <= 0)
|
|
|
|
{
|
2011-10-03 14:41:19 -04:00
|
|
|
KilledBy( TDI.Instigator );
|
2012-02-13 16:47:03 -05:00
|
|
|
}
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
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;
|
2012-02-20 11:39:00 -05:00
|
|
|
m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, Status);
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-22 10:46:38 -05:00
|
|
|
void cPawn::TeleportToEntity( cEntity* a_Entity )
|
2011-10-03 14:41:19 -04:00
|
|
|
{
|
|
|
|
TeleportTo( a_Entity->GetPosX(), a_Entity->GetPosY(), a_Entity->GetPosZ() );
|
|
|
|
}
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
void cPawn::TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ )
|
|
|
|
{
|
|
|
|
SetPosition( a_PosX, a_PosY, a_PosZ );
|
2011-12-27 21:10:05 -05:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
cPacket_TeleportEntity TeleportEntity( this );
|
2011-12-27 21:10:05 -05:00
|
|
|
|
|
|
|
cRoot::Get()->GetServer()->Broadcast( TeleportEntity );
|
|
|
|
}
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-27 21:10:05 -05:00
|
|
|
void cPawn::Tick(float a_Dt)
|
|
|
|
{
|
|
|
|
CheckMetaDataBurn(); //Check to see if pawn should burn based on block they are on
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
if (GetMetaData() == BURNING)
|
|
|
|
{
|
2011-12-27 21:10:05 -05:00
|
|
|
InStateBurning(a_Dt);
|
2012-02-13 16:47:03 -05:00
|
|
|
}
|
2011-12-27 21:10:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-27 21:10:05 -05:00
|
|
|
void cPawn::SetMetaData(MetaData a_MetaData)
|
|
|
|
{
|
2012-02-13 16:47:03 -05:00
|
|
|
//Broadcast new status to clients in the chunk
|
|
|
|
m_MetaData = a_MetaData;
|
|
|
|
cPacket_Metadata md(a_MetaData, GetUniqueID());
|
2012-02-20 11:39:00 -05:00
|
|
|
m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, md);
|
2011-12-27 21:10:05 -05:00
|
|
|
}
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-27 21:10:05 -05:00
|
|
|
//----Change Entity MetaData
|
|
|
|
void cPawn::CheckMetaDataBurn()
|
|
|
|
{
|
2012-02-15 17:50:00 -05:00
|
|
|
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);
|
2011-12-29 17:55:25 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
if (
|
|
|
|
(GetMetaData() == BURNING) &&
|
|
|
|
(IsBlockWater(Block) || IsBlockWater(BlockAbove) || IsBlockWater(BlockBelow))
|
|
|
|
)
|
2011-10-03 14:41:19 -04:00
|
|
|
{
|
2011-12-27 21:10:05 -05:00
|
|
|
SetMetaData(NORMAL);
|
2012-02-13 16:47:03 -05:00
|
|
|
}
|
|
|
|
else if (
|
|
|
|
m_bBurnable &&
|
|
|
|
(GetMetaData() != BURNING) &&
|
|
|
|
(
|
|
|
|
IsBlockLava(Block) || (Block == E_BLOCK_FIRE) ||
|
|
|
|
IsBlockLava(BlockAbove) || (BlockAbove == E_BLOCK_FIRE) ||
|
|
|
|
IsBlockLava(BlockBelow) || (BlockBelow == E_BLOCK_FIRE)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
2011-12-29 17:55:25 -05:00
|
|
|
SetMetaData(BURNING);
|
2011-12-27 21:10:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-27 21:10:05 -05:00
|
|
|
//What to do if On fire
|
|
|
|
void cPawn::InStateBurning(float a_Dt)
|
|
|
|
{
|
|
|
|
m_FireDamageInterval += a_Dt;
|
2012-02-15 17:50:00 -05:00
|
|
|
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 );
|
2012-02-13 16:47:03 -05:00
|
|
|
if (m_FireDamageInterval > 800)
|
|
|
|
{
|
2011-12-27 21:10:05 -05:00
|
|
|
|
|
|
|
m_FireDamageInterval = 0;
|
|
|
|
TakeDamage(1, this);
|
|
|
|
|
|
|
|
m_BurnPeriod++;
|
2012-02-13 16:47:03 -05:00
|
|
|
if (IsBlockLava(Block) || Block == E_BLOCK_FIRE
|
|
|
|
|| IsBlockLava(BlockAbove) || BlockAbove == E_BLOCK_FIRE)
|
|
|
|
{
|
2011-12-27 21:10:05 -05:00
|
|
|
m_BurnPeriod = 0;
|
|
|
|
TakeDamage(6, this);
|
2012-02-13 16:47:03 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-27 21:10:05 -05:00
|
|
|
TakeDamage(1, this);
|
|
|
|
}
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
if (m_BurnPeriod > 7)
|
|
|
|
{
|
2011-12-27 21:10:05 -05:00
|
|
|
SetMetaData(NORMAL);
|
|
|
|
m_BurnPeriod = 0;
|
|
|
|
}
|
2011-10-03 14:41:19 -04:00
|
|
|
}
|
|
|
|
}
|
2011-12-27 21:10:05 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-27 21:10:05 -05:00
|
|
|
void cPawn::SetMaxHealth(short a_MaxHealth)
|
|
|
|
{
|
|
|
|
this->m_MaxHealth = a_MaxHealth;
|
|
|
|
|
|
|
|
//Reset health
|
|
|
|
m_Health = a_MaxHealth;
|
|
|
|
}
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-29 10:31:48 -05:00
|
|
|
void cPawn::SetMaxFoodLevel(short a_MaxFoodLevel)
|
|
|
|
{
|
|
|
|
m_MaxFoodLevel = a_MaxFoodLevel;
|
2011-12-27 21:10:05 -05:00
|
|
|
|
2011-12-29 10:31:48 -05:00
|
|
|
//Reset food level
|
|
|
|
m_FoodLevel = a_MaxFoodLevel;
|
|
|
|
}
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|