2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "Pawn.h"
|
|
|
|
#include "Root.h"
|
|
|
|
#include "Server.h"
|
|
|
|
#include "World.h"
|
|
|
|
#include "Player.h"
|
|
|
|
#include "PluginManager.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
#include "Vector3d.h"
|
|
|
|
#include "BlockID.h"
|
|
|
|
#include "Defines.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CLASS_DEFINITION( cPawn, cEntity )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cPawn::cPawn()
|
|
|
|
: cEntity( 0, 0, 0 )
|
|
|
|
, m_LastPosX( 0.0 )
|
|
|
|
, m_LastPosY( 0.0 )
|
|
|
|
, m_LastPosZ( 0.0 )
|
2012-11-01 17:38:20 -04:00
|
|
|
, m_TimeLastTeleportPacket(0)
|
2012-06-14 09:06:06 -04:00
|
|
|
, m_bBurnable(true)
|
|
|
|
, m_MetaData(NORMAL)
|
|
|
|
{
|
|
|
|
SetMaxHealth(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cPawn::~cPawn()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cPawn::Heal( int a_Health )
|
|
|
|
{
|
|
|
|
(void)a_Health;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 17:14:45 -04:00
|
|
|
void cPawn::TakeDamage(int a_Damage, cEntity * a_Instigator)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
TakeDamageInfo TDI;
|
|
|
|
TDI.Damage = a_Damage;
|
|
|
|
TDI.Instigator = a_Instigator;
|
2012-08-19 17:14:45 -04:00
|
|
|
cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_TAKE_DAMAGE, 2, this, &TDI);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-19 17:14:45 -04:00
|
|
|
if (TDI.Damage == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_Health <= 0)
|
|
|
|
{
|
|
|
|
// Can't take damage if already dead
|
|
|
|
return;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
m_Health -= (short)TDI.Damage;
|
2012-08-19 17:14:45 -04:00
|
|
|
if (m_Health < 0)
|
|
|
|
{
|
|
|
|
m_Health = 0;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-19 17:14:45 -04:00
|
|
|
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_HURT);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
if (m_Health <= 0)
|
|
|
|
{
|
2012-08-19 17:14:45 -04:00
|
|
|
KilledBy(TDI.Instigator);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 17:14:45 -04:00
|
|
|
void cPawn::KilledBy(cEntity * a_Killer)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
|
2012-08-19 17:14:45 -04:00
|
|
|
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_DEAD);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 17:14:45 -04:00
|
|
|
void cPawn::TeleportToEntity(cEntity * a_Entity)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-19 17:14:45 -04:00
|
|
|
TeleportTo(a_Entity->GetPosX(), a_Entity->GetPosY(), a_Entity->GetPosZ());
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cPawn::TeleportTo( const double & a_PosX, const double & a_PosY, const double & a_PosZ )
|
|
|
|
{
|
|
|
|
SetPosition( a_PosX, a_PosY, a_PosZ );
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
GetWorld()->BroadcastTeleportEntity(*this);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cPawn::Tick(float a_Dt)
|
|
|
|
{
|
2012-08-19 15:42:32 -04:00
|
|
|
CheckMetaDataBurn(); // Check to see if pawn should burn based on block they are on
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
if (GetMetaData() == BURNING)
|
|
|
|
{
|
|
|
|
InStateBurning(a_Dt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cPawn::SetMetaData(MetaData a_MetaData)
|
|
|
|
{
|
|
|
|
//Broadcast new status to clients in the chunk
|
|
|
|
m_MetaData = a_MetaData;
|
2012-08-19 17:14:45 -04:00
|
|
|
m_World->BroadcastMetadata(*this);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//----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;
|
|
|
|
}
|
|
|
|
|