The owner object isn't stored anymore. Instead we use the name of the player.
This means only players can now have a wolf, but it fixes the bug where when you log out the wolf isn't your wolf anymore.
This commit is contained in:
parent
0980567912
commit
4f11cd2f8a
@ -4,6 +4,7 @@
|
|||||||
#include "Wolf.h"
|
#include "Wolf.h"
|
||||||
#include "../World.h"
|
#include "../World.h"
|
||||||
#include "../Entities/Player.h"
|
#include "../Entities/Player.h"
|
||||||
|
#include "../Root.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ cWolf::cWolf(void) :
|
|||||||
m_bIsTame(false),
|
m_bIsTame(false),
|
||||||
m_bIsSitting(false),
|
m_bIsSitting(false),
|
||||||
m_bIsBegging(false),
|
m_bIsBegging(false),
|
||||||
m_bOwner(NULL)
|
m_bOwner("")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
|
|||||||
{
|
{
|
||||||
SetMaxHealth(20);
|
SetMaxHealth(20);
|
||||||
SetIsTame(true);
|
SetIsTame(true);
|
||||||
SetOwner(&a_Player);
|
SetOwner(a_Player.GetName());
|
||||||
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMED);
|
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -63,7 +64,7 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
|
|||||||
}
|
}
|
||||||
else if (IsTame())
|
else if (IsTame())
|
||||||
{
|
{
|
||||||
if (m_bOwner != NULL && a_Player.GetUniqueID() == m_bOwner->GetUniqueID()) // Is the player the owner of the dog?
|
if (a_Player.GetName() == m_bOwner) // Is the player the owner of the dog?
|
||||||
{
|
{
|
||||||
if (IsSitting())
|
if (IsSitting())
|
||||||
{
|
{
|
||||||
@ -130,22 +131,35 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class cCallback :
|
||||||
|
public cPlayerListCallback
|
||||||
|
{
|
||||||
|
virtual bool Item(cPlayer * Player) override
|
||||||
|
{
|
||||||
|
OwnerCoords = Player->GetPosition();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
Vector3f OwnerCoords;
|
||||||
|
} ;
|
||||||
|
cCallback Callback;
|
||||||
|
m_World->FindAndDoWithPlayer(m_bOwner, Callback);
|
||||||
|
Vector3f OwnerCoords = Callback.OwnerCoords;
|
||||||
|
|
||||||
if (IsTame())
|
if (IsTame())
|
||||||
{
|
{
|
||||||
if (m_bOwner != NULL)
|
if (m_bOwner != "")
|
||||||
{
|
{
|
||||||
Vector3f OwnerCoords = m_bOwner->GetPosition();
|
|
||||||
double Distance = (OwnerCoords - GetPosition()).Length();
|
double Distance = (OwnerCoords - GetPosition()).Length();
|
||||||
if (Distance < 3)
|
if (Distance < 3)
|
||||||
{
|
{
|
||||||
m_bMovingToDestination = false;
|
m_bMovingToDestination = false;
|
||||||
} else if((Distance > 30) && (!IsSitting())) {
|
} else if((Distance > 30) && (!IsSitting())) {
|
||||||
TeleportToEntity(*m_bOwner);
|
TeleportToCoords(OwnerCoords.x, OwnerCoords.y, OwnerCoords.z);
|
||||||
} else {
|
} else {
|
||||||
m_Destination = OwnerCoords;
|
m_Destination = OwnerCoords;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -27,14 +27,14 @@ public:
|
|||||||
bool IsTame(void) const { return m_bIsTame; }
|
bool IsTame(void) const { return m_bIsTame; }
|
||||||
bool IsBegging(void) const { return m_bIsBegging; }
|
bool IsBegging(void) const { return m_bIsBegging; }
|
||||||
bool IsAngry(void) const { return m_bIsAngry; }
|
bool IsAngry(void) const { return m_bIsAngry; }
|
||||||
cEntity * GetOwner(void) const { return m_bOwner; }
|
AString GetOwner(void) const { return m_bOwner; }
|
||||||
|
|
||||||
// Set functions
|
// Set functions
|
||||||
void SetIsSitting(bool a_IsSitting) { m_bIsSitting = a_IsSitting; }
|
void SetIsSitting(bool a_IsSitting) { m_bIsSitting = a_IsSitting; }
|
||||||
void SetIsTame(bool a_IsTame) { m_bIsTame = a_IsTame; }
|
void SetIsTame(bool a_IsTame) { m_bIsTame = a_IsTame; }
|
||||||
void SetIsBegging(bool a_IsBegging) { m_bIsBegging = a_IsBegging; }
|
void SetIsBegging(bool a_IsBegging) { m_bIsBegging = a_IsBegging; }
|
||||||
void SetIsAngry(bool a_IsAngry) { m_bIsAngry = a_IsAngry; }
|
void SetIsAngry(bool a_IsAngry) { m_bIsAngry = a_IsAngry; }
|
||||||
void SetOwner(cEntity * a_Entity) { m_bOwner = a_Entity; }
|
void SetOwner(AString a_NewOwner) { m_bOwner = a_NewOwner; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ private:
|
|||||||
bool m_bIsTame;
|
bool m_bIsTame;
|
||||||
bool m_bIsBegging;
|
bool m_bIsBegging;
|
||||||
bool m_bIsAngry;
|
bool m_bIsAngry;
|
||||||
cEntity * m_bOwner;
|
AString m_bOwner;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user