2013-09-18 21:17:43 +00:00
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "Horse.h"
|
2013-10-08 18:20:49 +00:00
|
|
|
#include "../World.h"
|
2015-11-23 23:39:19 +00:00
|
|
|
#include "../EffectID.h"
|
2013-10-08 18:20:49 +00:00
|
|
|
#include "../Entities/Player.h"
|
2013-09-18 21:17:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-08 18:20:49 +00:00
|
|
|
cHorse::cHorse(int Type, int Color, int Style, int TameTimes) :
|
2017-02-15 05:05:24 +00:00
|
|
|
super("Horse", mtHorse, "entity.horse.hurt", "entity.horse.death", 1.4, 1.6),
|
2013-10-08 21:21:55 +00:00
|
|
|
m_bHasChest(false),
|
2013-10-08 18:20:49 +00:00
|
|
|
m_bIsEating(false),
|
|
|
|
m_bIsRearing(false),
|
|
|
|
m_bIsMouthOpen(false),
|
|
|
|
m_bIsTame(false),
|
2013-10-09 20:02:59 +00:00
|
|
|
m_bIsSaddled(false),
|
2013-10-08 18:20:49 +00:00
|
|
|
m_Type(Type),
|
|
|
|
m_Color(Color),
|
|
|
|
m_Style(Style),
|
|
|
|
m_Armour(0),
|
|
|
|
m_TimesToTame(TameTimes),
|
2013-10-11 20:33:56 +00:00
|
|
|
m_TameAttemptTimes(0),
|
2015-12-15 20:11:58 +00:00
|
|
|
m_RearTickCount(0),
|
2017-05-20 06:16:28 +00:00
|
|
|
m_MaxSpeed(20.0)
|
2013-09-18 21:17:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-11 21:12:26 +00:00
|
|
|
void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2013-10-08 18:20:49 +00:00
|
|
|
{
|
|
|
|
super::Tick(a_Dt, a_Chunk);
|
2016-09-03 11:31:27 +00:00
|
|
|
if (!IsTicking())
|
|
|
|
{
|
|
|
|
// The base class tick destroyed us
|
|
|
|
return;
|
|
|
|
}
|
2013-10-08 18:20:49 +00:00
|
|
|
|
|
|
|
if (!m_bIsMouthOpen)
|
|
|
|
{
|
|
|
|
if (m_World->GetTickRandomNumber(50) == 25)
|
|
|
|
{
|
|
|
|
m_bIsMouthOpen = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_World->GetTickRandomNumber(10) == 5)
|
|
|
|
{
|
|
|
|
m_bIsMouthOpen = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-20 20:55:07 +00:00
|
|
|
if ((m_Attachee != nullptr) && (!m_bIsTame))
|
2013-10-08 18:20:49 +00:00
|
|
|
{
|
|
|
|
if (m_TameAttemptTimes < m_TimesToTame)
|
|
|
|
{
|
|
|
|
if (m_World->GetTickRandomNumber(50) == 25)
|
|
|
|
{
|
2015-11-23 23:39:19 +00:00
|
|
|
m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::SOUTH_EAST));
|
|
|
|
m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::SOUTH_WEST));
|
|
|
|
m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::NORTH_EAST));
|
|
|
|
m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::NORTH_WEST));
|
2013-10-08 18:20:49 +00:00
|
|
|
|
|
|
|
m_Attachee->Detach();
|
|
|
|
m_bIsRearing = true;
|
|
|
|
}
|
2014-07-17 20:59:02 +00:00
|
|
|
}
|
2013-10-08 18:20:49 +00:00
|
|
|
else
|
|
|
|
{
|
2015-12-15 20:11:58 +00:00
|
|
|
// TODO: emit hearts here
|
2013-10-08 18:20:49 +00:00
|
|
|
m_bIsTame = true;
|
|
|
|
}
|
|
|
|
}
|
2015-12-22 05:43:50 +00:00
|
|
|
|
2013-10-11 20:33:56 +00:00
|
|
|
if (m_bIsRearing)
|
2013-10-08 18:20:49 +00:00
|
|
|
{
|
2013-10-11 20:33:56 +00:00
|
|
|
if (m_RearTickCount == 20)
|
|
|
|
{
|
|
|
|
m_bIsRearing = false;
|
2013-10-17 16:41:52 +00:00
|
|
|
m_RearTickCount = 0;
|
2013-10-11 20:33:56 +00:00
|
|
|
}
|
2013-10-18 14:34:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_RearTickCount++;
|
|
|
|
}
|
2013-10-08 18:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_World->BroadcastEntityMetadata(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cHorse::OnRightClicked(cPlayer & a_Player)
|
|
|
|
{
|
2015-11-29 18:13:31 +00:00
|
|
|
super::OnRightClicked(a_Player);
|
|
|
|
|
2013-10-18 14:34:01 +00: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
|
|
|
|
{
|
2014-10-20 20:55:07 +00:00
|
|
|
if (m_Attachee != nullptr)
|
2013-10-18 14:34:01 +00:00
|
|
|
{
|
|
|
|
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 18:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-18 21:17:43 +00:00
|
|
|
void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer)
|
|
|
|
{
|
2015-05-19 18:32:10 +00:00
|
|
|
unsigned int LootingLevel = 0;
|
2014-10-20 20:55:07 +00:00
|
|
|
if (a_Killer != nullptr)
|
2014-02-23 18:44:58 +00:00
|
|
|
{
|
|
|
|
LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
|
|
|
|
}
|
|
|
|
AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER);
|
2013-10-28 19:28:16 +00:00
|
|
|
if (m_bIsSaddled)
|
|
|
|
{
|
|
|
|
a_Drops.push_back(cItem(E_ITEM_SADDLE, 1));
|
|
|
|
}
|
2013-09-18 21:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-15 20:11:58 +00:00
|
|
|
|
2015-12-22 05:43:50 +00:00
|
|
|
void cHorse::InStateIdle(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2015-12-15 20:11:58 +00:00
|
|
|
{
|
|
|
|
// If horse is tame and someone is sitting on it, don't walk around
|
|
|
|
if ((!m_bIsTame) || (m_Attachee == nullptr))
|
|
|
|
{
|
2015-12-22 05:43:50 +00:00
|
|
|
super::InStateIdle(a_Dt, a_Chunk);
|
2015-12-15 20:11:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cHorse::HandleSpeedFromAttachee(float a_Forward, float a_Sideways)
|
|
|
|
{
|
2016-03-01 11:58:02 +00:00
|
|
|
if ((m_bIsTame) && (m_bIsSaddled))
|
|
|
|
{
|
2017-05-20 06:16:28 +00:00
|
|
|
super::HandleSpeedFromAttachee(a_Forward * m_MaxSpeed, a_Sideways * m_MaxSpeed);
|
2016-03-01 11:58:02 +00:00
|
|
|
}
|
2015-12-15 20:11:58 +00:00
|
|
|
}
|