2013-10-17 15:28:45 -04:00
|
|
|
|
2013-09-18 17:17:43 -04:00
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "Horse.h"
|
2013-10-08 14:20:49 -04:00
|
|
|
#include "../World.h"
|
|
|
|
#include "../Entities/Player.h"
|
2013-09-18 17:17:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-08 14:20:49 -04:00
|
|
|
cHorse::cHorse(int Type, int Color, int Style, int TameTimes) :
|
2013-10-20 04:23:30 -04:00
|
|
|
super("Horse", mtHorse, "mob.horse.hit", "mob.horse.death", 1.4, 1.6),
|
2013-10-08 17:21:55 -04:00
|
|
|
m_bHasChest(false),
|
2013-10-08 14:20:49 -04:00
|
|
|
m_bIsEating(false),
|
|
|
|
m_bIsRearing(false),
|
|
|
|
m_bIsMouthOpen(false),
|
|
|
|
m_bIsTame(false),
|
2013-10-09 16:02:59 -04:00
|
|
|
m_bIsSaddled(false),
|
2013-10-08 14:20:49 -04:00
|
|
|
m_Type(Type),
|
|
|
|
m_Color(Color),
|
|
|
|
m_Style(Style),
|
|
|
|
m_Armour(0),
|
|
|
|
m_TimesToTame(TameTimes),
|
2013-10-11 16:33:56 -04:00
|
|
|
m_TameAttemptTimes(0),
|
|
|
|
m_RearTickCount(0)
|
2013-09-18 17:17:43 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-08 14:20:49 -04:00
|
|
|
void cHorse::Tick(float a_Dt, cChunk & a_Chunk)
|
|
|
|
{
|
|
|
|
super::Tick(a_Dt, a_Chunk);
|
|
|
|
|
|
|
|
if (!m_bIsMouthOpen)
|
|
|
|
{
|
|
|
|
if (m_World->GetTickRandomNumber(50) == 25)
|
|
|
|
{
|
|
|
|
m_bIsMouthOpen = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_World->GetTickRandomNumber(10) == 5)
|
|
|
|
{
|
|
|
|
m_bIsMouthOpen = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_Attachee != NULL) && (!m_bIsTame))
|
|
|
|
{
|
|
|
|
if (m_TameAttemptTimes < m_TimesToTame)
|
|
|
|
{
|
|
|
|
if (m_World->GetTickRandomNumber(50) == 25)
|
|
|
|
{
|
|
|
|
m_World->BroadcastSoundParticleEffect(2000, (int)(floor(GetPosX()) * 8), (int)(floor(GetPosY()) * 8), (int)(floor(GetPosZ()) * 8), 0);
|
|
|
|
m_World->BroadcastSoundParticleEffect(2000, (int)(floor(GetPosX()) * 8), (int)(floor(GetPosY()) * 8), (int)(floor(GetPosZ()) * 8), 2);
|
|
|
|
m_World->BroadcastSoundParticleEffect(2000, (int)(floor(GetPosX()) * 8), (int)(floor(GetPosY()) * 8), (int)(floor(GetPosZ()) * 8), 6);
|
|
|
|
m_World->BroadcastSoundParticleEffect(2000, (int)(floor(GetPosX()) * 8), (int)(floor(GetPosY()) * 8), (int)(floor(GetPosZ()) * 8), 8);
|
|
|
|
|
|
|
|
m_Attachee->Detach();
|
|
|
|
m_bIsRearing = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_bIsTame = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-11 16:33:56 -04:00
|
|
|
if (m_bIsRearing)
|
2013-10-08 14:20:49 -04:00
|
|
|
{
|
2013-10-11 16:33:56 -04:00
|
|
|
if (m_RearTickCount == 20)
|
|
|
|
{
|
|
|
|
m_bIsRearing = false;
|
2013-10-17 12:41:52 -04:00
|
|
|
m_RearTickCount = 0;
|
2013-10-11 16:33:56 -04:00
|
|
|
}
|
2013-10-18 10:34:01 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_RearTickCount++;
|
|
|
|
}
|
2013-10-08 14:20:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
m_World->BroadcastEntityMetadata(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cHorse::OnRightClicked(cPlayer & a_Player)
|
|
|
|
{
|
2013-10-18 10:34:01 -04:00
|
|
|
if (!m_bIsSaddled && m_bIsTame)
|
|
|
|
{
|
|
|
|
if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SADDLE)
|
|
|
|
{
|
|
|
|
// Saddle the horse:
|
|
|
|
if (!a_Player.IsGameModeCreative())
|
|
|
|
{
|
|
|
|
a_Player.GetInventory().RemoveOneEquippedItem();
|
|
|
|
}
|
|
|
|
m_bIsSaddled = true;
|
|
|
|
m_World->BroadcastEntityMetadata(*this);
|
|
|
|
}
|
|
|
|
else if (!a_Player.GetEquippedItem().IsEmpty())
|
|
|
|
{
|
|
|
|
// The horse doesn't like being hit, make it rear:
|
|
|
|
m_bIsRearing = true;
|
|
|
|
m_RearTickCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_Attachee != NULL)
|
|
|
|
{
|
|
|
|
if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID())
|
|
|
|
{
|
|
|
|
a_Player.Detach();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Attachee->IsPlayer())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Attachee->Detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_TameAttemptTimes++;
|
|
|
|
a_Player.AttachTo(this);
|
|
|
|
}
|
2013-10-08 14:20:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-18 17:17:43 -04:00
|
|
|
void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer)
|
|
|
|
{
|
|
|
|
AddRandomDropItem(a_Drops, 0, 2, E_ITEM_LEATHER);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|