2013-10-08 14:20:49 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "Wolf.h"
|
|
|
|
#include "../World.h"
|
|
|
|
#include "../Entities/Player.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cWolf::cWolf(void) :
|
2013-10-20 04:23:30 -04:00
|
|
|
super("Wolf", mtWolf, "mob.wolf.hurt", "mob.wolf.death", 0.6, 0.8),
|
2013-11-10 15:24:36 -05:00
|
|
|
m_IsAngry(false),
|
|
|
|
m_IsTame(false),
|
|
|
|
m_IsSitting(false),
|
|
|
|
m_IsBegging(false),
|
|
|
|
m_Owner(""),
|
2013-11-10 15:55:32 -05:00
|
|
|
m_CollarColor(14)
|
2013-10-08 14:20:49 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cWolf::DoTakeDamage(TakeDamageInfo & a_TDI)
|
|
|
|
{
|
|
|
|
super::DoTakeDamage(a_TDI);
|
2013-11-10 15:24:36 -05:00
|
|
|
if (!m_IsTame)
|
2013-10-08 14:20:49 -04:00
|
|
|
{
|
2013-11-10 15:24:36 -05:00
|
|
|
m_IsAngry = true;
|
2013-10-08 14:20:49 -04:00
|
|
|
}
|
|
|
|
m_World->BroadcastEntityMetadata(*this); // Broadcast health and possibly angry face
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cWolf::OnRightClicked(cPlayer & a_Player)
|
|
|
|
{
|
2013-11-10 15:55:32 -05:00
|
|
|
if (!IsTame() && !IsAngry())
|
2013-10-08 14:20:49 -04:00
|
|
|
{
|
|
|
|
if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_BONE)
|
|
|
|
{
|
|
|
|
if (!a_Player.IsGameModeCreative())
|
|
|
|
{
|
|
|
|
a_Player.GetInventory().RemoveOneEquippedItem();
|
|
|
|
}
|
|
|
|
|
2013-11-10 09:16:43 -05:00
|
|
|
if (m_World->GetTickRandomNumber(7) == 0)
|
2013-10-08 14:20:49 -04:00
|
|
|
{
|
|
|
|
SetMaxHealth(20);
|
2013-11-10 09:16:43 -05:00
|
|
|
SetIsTame(true);
|
2013-11-10 12:03:19 -05:00
|
|
|
SetOwner(a_Player.GetName());
|
2013-10-08 14:20:49 -04:00
|
|
|
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMED);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-10 09:16:43 -05:00
|
|
|
else if (IsTame())
|
2013-10-08 14:20:49 -04:00
|
|
|
{
|
2013-11-10 15:24:36 -05:00
|
|
|
if (a_Player.GetName() == m_Owner) // Is the player the owner of the dog?
|
2013-10-08 14:20:49 -04:00
|
|
|
{
|
2013-11-10 14:12:30 -05:00
|
|
|
if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_DYE)
|
|
|
|
{
|
2013-11-10 15:55:32 -05:00
|
|
|
m_CollarColor = 15 - a_Player.GetEquippedItem().m_ItemDamage;
|
2013-11-10 14:12:30 -05:00
|
|
|
if (!a_Player.IsGameModeCreative())
|
|
|
|
{
|
|
|
|
a_Player.GetInventory().RemoveOneEquippedItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (IsSitting())
|
2013-11-10 09:16:43 -05:00
|
|
|
{
|
|
|
|
SetIsSitting(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetIsSitting(true);
|
|
|
|
}
|
2013-10-08 14:20:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_World->BroadcastEntityMetadata(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-10 09:16:43 -05:00
|
|
|
|
|
|
|
void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
|
|
|
|
{
|
|
|
|
if (!IsAngry())
|
|
|
|
{
|
2013-11-10 09:51:32 -05:00
|
|
|
cMonster::Tick(a_Dt, a_Chunk);
|
2013-11-10 15:55:32 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-10 09:16:43 -05:00
|
|
|
super::Tick(a_Dt, a_Chunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsSitting())
|
|
|
|
{
|
|
|
|
m_bMovingToDestination = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cPlayer * a_Closest_Player = FindClosestPlayer();
|
|
|
|
if (a_Closest_Player != NULL)
|
|
|
|
{
|
|
|
|
switch (a_Closest_Player->GetEquippedItem().m_ItemType)
|
|
|
|
{
|
|
|
|
case E_ITEM_BONE:
|
|
|
|
case E_ITEM_RAW_BEEF:
|
|
|
|
case E_ITEM_STEAK:
|
|
|
|
case E_ITEM_RAW_CHICKEN:
|
|
|
|
case E_ITEM_COOKED_CHICKEN:
|
|
|
|
case E_ITEM_ROTTEN_FLESH:
|
|
|
|
{
|
|
|
|
if (!IsBegging())
|
|
|
|
{
|
|
|
|
SetIsBegging(true);
|
|
|
|
m_World->BroadcastEntityMetadata(*this);
|
|
|
|
}
|
|
|
|
Vector3f a_NewDestination = a_Closest_Player->GetPosition();
|
|
|
|
a_NewDestination.y = a_NewDestination.y + 1; // Look at the head of the player, not his feet.
|
|
|
|
m_Destination = Vector3f(a_NewDestination);
|
|
|
|
m_bMovingToDestination = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
if (IsBegging())
|
|
|
|
{
|
|
|
|
SetIsBegging(false);
|
|
|
|
m_World->BroadcastEntityMetadata(*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-10 12:03:19 -05:00
|
|
|
|
|
|
|
class cCallback :
|
|
|
|
public cPlayerListCallback
|
|
|
|
{
|
|
|
|
virtual bool Item(cPlayer * Player) override
|
|
|
|
{
|
|
|
|
OwnerCoords = Player->GetPosition();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
Vector3f OwnerCoords;
|
2013-11-10 15:55:32 -05:00
|
|
|
} Callback;
|
2013-11-10 15:24:36 -05:00
|
|
|
m_World->DoWithPlayer(m_Owner, Callback);
|
2013-11-10 12:03:19 -05:00
|
|
|
Vector3f OwnerCoords = Callback.OwnerCoords;
|
2013-11-10 09:16:43 -05:00
|
|
|
|
|
|
|
if (IsTame())
|
|
|
|
{
|
2013-11-10 15:24:36 -05:00
|
|
|
if (m_Owner != "")
|
2013-11-10 09:16:43 -05:00
|
|
|
{
|
|
|
|
double Distance = (OwnerCoords - GetPosition()).Length();
|
|
|
|
if (Distance < 3)
|
|
|
|
{
|
|
|
|
m_bMovingToDestination = false;
|
2013-11-10 15:55:32 -05:00
|
|
|
}
|
|
|
|
else if ((Distance > 30) && (!IsSitting()))
|
|
|
|
{
|
2013-11-10 12:03:19 -05:00
|
|
|
TeleportToCoords(OwnerCoords.x, OwnerCoords.y, OwnerCoords.z);
|
2013-11-10 15:55:32 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-10 09:16:43 -05:00
|
|
|
m_Destination = OwnerCoords;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-10 15:55:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|