diff options
author | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2011-10-03 20:41:19 +0200 |
---|---|---|
committer | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2011-10-03 20:41:19 +0200 |
commit | 386d58b5862d8b76925c6523721594887606e82a (patch) | |
tree | ef073e7a843f4b75a4008d4b7383f7cdf08ceee5 /source/cPawn.cpp | |
parent | Visual Studio 2010 solution and project files (diff) | |
download | cuberite-386d58b5862d8b76925c6523721594887606e82a.tar cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.gz cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.bz2 cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.lz cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.xz cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.zst cuberite-386d58b5862d8b76925c6523721594887606e82a.zip |
Diffstat (limited to '')
-rw-r--r-- | source/cPawn.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
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 );
+ }
+}
|