From 386d58b5862d8b76925c6523721594887606e82a Mon Sep 17 00:00:00 2001 From: faketruth Date: Mon, 3 Oct 2011 18:41:19 +0000 Subject: MCServer c++ source files git-svn-id: http://mc-server.googlecode.com/svn/trunk@3 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cPawn.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 source/cPawn.cpp (limited to 'source/cPawn.cpp') diff --git a/source/cPawn.cpp b/source/cPawn.cpp new file mode 100644 index 000000000..d9f2ec8b5 --- /dev/null +++ b/source/cPawn.cpp @@ -0,0 +1,96 @@ +#include "cPawn.h" +#include "cRoot.h" +#include "cServer.h" +#include "cWorld.h" +#include "cPlayer.h" +#include "cChunk.h" +#include "cMCLogger.h" +#include "cPluginManager.h" + +#include "packets/cPacket_TeleportEntity.h" +#include "packets/cPacket_EntityStatus.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_Health = 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; + cChunk* Chunk = cRoot::Get()->GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); + if( Chunk ) + Chunk->Broadcast( 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; + cChunk* Chunk = cRoot::Get()->GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); + if( Chunk ) + Chunk->Broadcast( Status ); // Die +} + +void cPawn::TeleportTo( 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 ); + cPacket_TeleportEntity TeleportEntity( this ); + if( IsA("cPlayer") ) + { + cPlayer* Player = (cPlayer*)this; + cRoot::Get()->GetServer()->Broadcast( TeleportEntity, Player->GetClientHandle() ); + } + else + { + cRoot::Get()->GetServer()->Broadcast( TeleportEntity ); + } +} -- cgit v1.2.3