From 008addf5d746b2d158f9116e4f6302861b42852f Mon Sep 17 00:00:00 2001 From: faketruth Date: Thu, 16 Feb 2012 17:20:28 +0000 Subject: Got rid of dangerous GetEntity(), not using DoWithEntity() git-svn-id: http://mc-server.googlecode.com/svn/trunk@278 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cClientHandle.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'source/cClientHandle.cpp') diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index a28d8a56c..c8f8e82ed 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -1532,13 +1532,27 @@ void cClientHandle::HandleUseEntity(cPacket_UseEntity * a_Packet) { return; } - cWorld * World = m_Player->GetWorld(); - cEntity * Entity = World->GetEntity(a_Packet->m_TargetID); - if ((Entity != NULL) && Entity->IsA("cPawn")) + + class cDamageEntity : public cEntityCallback { - cPawn * Pawn = (cPawn *)Entity; - Pawn->TakeDamage(1, m_Player); - } + virtual bool Item(cEntity * a_Entity) override + { + if( a_Entity->IsA("cPawn") ) + { + reinterpret_cast< cPawn* >( a_Entity )->TakeDamage(Damage, Instigator ); + } + return true; + } + public: + int Damage; + cEntity * Instigator; + } Callback; + + Callback.Damage = 1; // TODO: Find proper damage from current item equipped + Callback.Instigator = m_Player; + + cWorld * World = m_Player->GetWorld(); + World->DoWithEntity( a_Packet->m_TargetID, Callback ); } -- cgit v1.2.3