2014-04-10 10:52:00 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2013-10-20 07:25:56 -04:00
|
|
|
#include "IncludeAllMonsters.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "../Root.h"
|
|
|
|
#include "../Server.h"
|
|
|
|
#include "../ClientHandle.h"
|
2017-08-18 06:23:08 -04:00
|
|
|
#include "../Items/ItemHandler.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "../World.h"
|
2015-11-23 18:39:19 -05:00
|
|
|
#include "../EffectID.h"
|
2013-08-19 05:39:13 -04:00
|
|
|
#include "../Entities/Player.h"
|
2013-11-25 14:04:39 -05:00
|
|
|
#include "../Entities/ExpOrb.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "../MonsterConfig.h"
|
2017-08-21 04:46:41 -04:00
|
|
|
#include "BoundingBox.h"
|
2012-09-23 16:53:08 -04:00
|
|
|
|
2013-09-05 16:40:08 -04:00
|
|
|
#include "../Chunk.h"
|
2013-10-20 07:25:56 -04:00
|
|
|
#include "../FastRandom.h"
|
2013-04-22 03:18:03 -04:00
|
|
|
|
2015-11-20 03:03:20 -05:00
|
|
|
#include "PathFinder.h"
|
2017-08-21 04:46:41 -04:00
|
|
|
#include "../Entities/LeashKnot.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ticks to wait to do leash calculations
|
|
|
|
#define LEASH_ACTIONS_TICK_STEP 10
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-20 07:25:56 -04:00
|
|
|
/** Map for eType <-> string
|
|
|
|
Needs to be alpha-sorted by the strings, because binary search is used in StringToMobType()
|
|
|
|
The strings need to be lowercase (for more efficient comparisons in StringToMobType())
|
2014-12-01 08:58:13 -05:00
|
|
|
m_VanillaName is the name that vanilla use for this mob.
|
2013-10-20 07:25:56 -04:00
|
|
|
*/
|
|
|
|
static const struct
|
|
|
|
{
|
2014-09-17 13:40:10 -04:00
|
|
|
eMonsterType m_Type;
|
2013-10-20 07:25:56 -04:00
|
|
|
const char * m_lcName;
|
2014-11-29 09:20:44 -05:00
|
|
|
const char * m_VanillaName;
|
2017-05-22 11:41:41 -04:00
|
|
|
const char * m_VanillaNameNBT;
|
2013-10-20 07:25:56 -04:00
|
|
|
} g_MobTypeNames[] =
|
|
|
|
{
|
2017-05-22 11:41:41 -04:00
|
|
|
{mtBat, "bat", "Bat", "bat"},
|
|
|
|
{mtBlaze, "blaze", "Blaze", "blaze"},
|
|
|
|
{mtCaveSpider, "cavespider", "CaveSpider", "cave_spider"},
|
|
|
|
{mtChicken, "chicken", "Chicken", "chicken"},
|
|
|
|
{mtCow, "cow", "Cow", "cow"},
|
|
|
|
{mtCreeper, "creeper", "Creeper", "creeper"},
|
|
|
|
{mtEnderman, "enderman", "Enderman", "enderman"},
|
|
|
|
{mtEnderDragon, "enderdragon", "EnderDragon", "ender_dragon"},
|
|
|
|
{mtGhast, "ghast", "Ghast", "ghast"},
|
|
|
|
{mtGiant, "giant", "Giant", "giant"},
|
|
|
|
{mtGuardian, "guardian", "Guardian", "guardian"},
|
|
|
|
{mtHorse, "horse", "EntityHorse", "horse"},
|
|
|
|
{mtIronGolem, "irongolem", "VillagerGolem", "iron_golem"},
|
|
|
|
{mtMagmaCube, "magmacube", "LavaSlime", "magma_cube"},
|
|
|
|
{mtMooshroom, "mooshroom", "MushroomCow", "mooshroom"},
|
|
|
|
{mtOcelot, "ocelot", "Ozelot", "ocelot"},
|
|
|
|
{mtPig, "pig", "Pig", "pig"},
|
|
|
|
{mtRabbit, "rabbit", "Rabbit", "rabbit"},
|
|
|
|
{mtSheep, "sheep", "Sheep", "sheep"},
|
|
|
|
{mtSilverfish, "silverfish", "Silverfish", "silverfish"},
|
|
|
|
{mtSkeleton, "skeleton", "Skeleton", "skeleton"},
|
|
|
|
{mtSlime, "slime", "Slime", "slime"},
|
|
|
|
{mtSnowGolem, "snowgolem", "SnowMan", "snow_golem"},
|
|
|
|
{mtSpider, "spider", "Spider", "spider"},
|
|
|
|
{mtSquid, "squid", "Squid", "squid"},
|
|
|
|
{mtVillager, "villager", "Villager", "villager"},
|
|
|
|
{mtWitch, "witch", "Witch", "witch"},
|
|
|
|
{mtWither, "wither", "WitherBoss", "wither"},
|
|
|
|
{mtWolf, "wolf", "Wolf", "wolf"},
|
|
|
|
{mtZombie, "zombie", "Zombie", "zombie"},
|
|
|
|
{mtZombiePigman, "zombiepigman", "PigZombie", "zombie_pigman"},
|
2013-10-20 07:25:56 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-10-20 07:25:56 -04:00
|
|
|
// cMonster:
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-09-17 13:40:10 -04:00
|
|
|
cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height)
|
2013-10-13 07:47:55 -04:00
|
|
|
: super(etMonster, a_Width, a_Height)
|
2013-12-20 10:39:20 -05:00
|
|
|
, m_EMState(IDLE)
|
|
|
|
, m_EMPersonality(AGGRESSIVE)
|
2015-11-20 03:03:20 -05:00
|
|
|
, m_PathFinder(a_Width, a_Height)
|
2015-07-11 15:40:03 -04:00
|
|
|
, m_PathfinderActivated(false)
|
2015-05-02 14:22:28 -04:00
|
|
|
, m_JumpCoolDown(0)
|
2014-02-05 12:43:49 -05:00
|
|
|
, m_IdleInterval(0)
|
2014-01-24 16:55:04 -05:00
|
|
|
, m_DestroyTimer(0)
|
2013-10-20 04:23:30 -04:00
|
|
|
, m_MobType(a_MobType)
|
2014-09-01 14:12:56 -04:00
|
|
|
, m_CustomName("")
|
|
|
|
, m_CustomNameAlwaysVisible(false)
|
2012-12-22 04:39:13 -05:00
|
|
|
, m_SoundHurt(a_SoundHurt)
|
|
|
|
, m_SoundDeath(a_SoundDeath)
|
2014-02-05 12:43:49 -05:00
|
|
|
, m_AttackRate(3)
|
2014-01-24 16:55:04 -05:00
|
|
|
, m_AttackDamage(1)
|
2015-05-16 07:05:33 -04:00
|
|
|
, m_AttackRange(1)
|
2016-01-12 05:11:10 -05:00
|
|
|
, m_AttackCoolDownTicksLeft(0)
|
2014-02-24 09:38:38 -05:00
|
|
|
, m_SightDistance(25)
|
2014-03-16 17:00:28 -04:00
|
|
|
, m_DropChanceWeapon(0.085f)
|
|
|
|
, m_DropChanceHelmet(0.085f)
|
|
|
|
, m_DropChanceChestplate(0.085f)
|
|
|
|
, m_DropChanceLeggings(0.085f)
|
|
|
|
, m_DropChanceBoots(0.085f)
|
2014-02-23 13:44:58 -05:00
|
|
|
, m_CanPickUpLoot(true)
|
2015-04-29 12:24:14 -04:00
|
|
|
, m_TicksSinceLastDamaged(100)
|
2013-09-07 10:42:34 -04:00
|
|
|
, m_BurnsInDaylight(false)
|
2015-04-29 12:24:14 -04:00
|
|
|
, m_RelativeWalkSpeed(1)
|
2015-07-12 12:00:56 -04:00
|
|
|
, m_Age(1)
|
2015-11-29 13:13:31 -05:00
|
|
|
, m_AgingTimer(20 * 60 * 20) // about 20 minutes
|
2017-05-21 04:29:06 -04:00
|
|
|
, m_WasLastTargetAPlayer(false)
|
2017-08-21 04:46:41 -04:00
|
|
|
, m_LeashedTo(nullptr)
|
|
|
|
, m_LeashToPos(nullptr)
|
|
|
|
, m_IsLeashActionJustDone(false)
|
|
|
|
, m_CanBeLeashed(GetMobFamily() == eFamily::mfPassive)
|
2016-02-01 15:49:34 -05:00
|
|
|
, m_Target(nullptr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-22 04:39:13 -05:00
|
|
|
if (!a_ConfigName.empty())
|
|
|
|
{
|
|
|
|
GetMonsterConfig(a_ConfigName);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-01 15:49:34 -05:00
|
|
|
cMonster::~cMonster()
|
|
|
|
{
|
|
|
|
ASSERT(GetTarget() == nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-21 04:46:41 -04:00
|
|
|
void cMonster::Destroy(bool a_ShouldBroadcast)
|
|
|
|
{
|
|
|
|
if (IsLeashed())
|
|
|
|
{
|
|
|
|
cEntity * LeashedTo = GetLeashedTo();
|
|
|
|
Unleash(false, a_ShouldBroadcast);
|
|
|
|
|
|
|
|
// Remove leash knot if there are no more mobs leashed to
|
|
|
|
if (!LeashedTo->HasAnyMobLeashed() && LeashedTo->IsLeashKnot())
|
|
|
|
{
|
|
|
|
LeashedTo->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
super::Destroy(a_ShouldBroadcast);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-01 15:49:34 -05:00
|
|
|
void cMonster::Destroyed()
|
|
|
|
{
|
|
|
|
SetTarget(nullptr); // Tell them we're no longer targeting them.
|
|
|
|
super::Destroyed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-24 03:58:26 -04:00
|
|
|
void cMonster::SpawnOn(cClientHandle & a_Client)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-24 03:58:26 -04:00
|
|
|
a_Client.SendSpawnMob(*this);
|
2017-08-21 04:46:41 -04:00
|
|
|
|
|
|
|
if (IsLeashed())
|
|
|
|
{
|
|
|
|
a_Client.SendLeashEntity(*this, *this->GetLeashedTo());
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-20 03:03:20 -05:00
|
|
|
void cMonster::MoveToWayPoint(cChunk & a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2015-11-20 03:03:20 -05:00
|
|
|
if ((m_NextWayPointPosition - GetPosition()).SqrLength() < WAYPOINT_RADIUS * WAYPOINT_RADIUS)
|
2015-05-03 13:56:37 -04:00
|
|
|
{
|
2015-11-20 03:03:20 -05:00
|
|
|
return;
|
2014-01-24 14:57:32 -05:00
|
|
|
}
|
|
|
|
|
2017-05-28 14:56:17 -04:00
|
|
|
if (m_JumpCoolDown <= 0)
|
2015-05-03 13:56:37 -04:00
|
|
|
{
|
2015-05-06 10:23:07 -04:00
|
|
|
if (DoesPosYRequireJump(FloorC(m_NextWayPointPosition.y)))
|
2015-05-03 13:56:37 -04:00
|
|
|
{
|
2017-05-28 14:56:17 -04:00
|
|
|
if (
|
|
|
|
(IsOnGround() && (GetSpeed().SqrLength() <= 0.5)) || // If walking on the ground, we need to slow down first, otherwise we miss the jump
|
|
|
|
IsSwimming()
|
|
|
|
)
|
2015-05-03 13:56:37 -04:00
|
|
|
{
|
|
|
|
m_bOnGround = false;
|
|
|
|
m_JumpCoolDown = 20;
|
|
|
|
AddPosY(1.6); // Jump!!
|
2017-05-28 14:56:17 -04:00
|
|
|
SetSpeedY(1);
|
2015-05-05 03:04:41 -04:00
|
|
|
SetSpeedX(3.2 * (m_NextWayPointPosition.x - GetPosition().x)); // Move forward in a preset speed.
|
2017-05-28 14:56:17 -04:00
|
|
|
SetSpeedZ(3.2 * (m_NextWayPointPosition.z - GetPosition().z)); // The numbers were picked based on trial and error
|
2015-05-03 13:56:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
--m_JumpCoolDown;
|
|
|
|
}
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2015-05-05 03:04:41 -04:00
|
|
|
Vector3d Distance = m_NextWayPointPosition - GetPosition();
|
2017-05-28 14:56:17 -04:00
|
|
|
if ((std::abs(Distance.x) > 0.05) || (std::abs(Distance.z) > 0.05))
|
2015-05-03 13:56:37 -04:00
|
|
|
{
|
|
|
|
Distance.y = 0;
|
|
|
|
Distance.Normalize();
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2015-05-03 13:56:37 -04:00
|
|
|
if (m_bOnGround)
|
|
|
|
{
|
|
|
|
Distance *= 2.5f;
|
|
|
|
}
|
|
|
|
else if (IsSwimming())
|
|
|
|
{
|
|
|
|
Distance *= 1.3f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Don't let the mob move too much if he's falling.
|
|
|
|
Distance *= 0.25f;
|
|
|
|
}
|
|
|
|
// Apply walk speed:
|
|
|
|
Distance *= m_RelativeWalkSpeed;
|
|
|
|
/* Reduced default speed.
|
2015-05-05 03:04:41 -04:00
|
|
|
Close to Vanilla, easier for mobs to follow m_NextWayPointPositions, hence
|
2015-05-03 13:56:37 -04:00
|
|
|
better pathfinding. */
|
|
|
|
Distance *= 0.5;
|
|
|
|
AddSpeedX(Distance.x);
|
|
|
|
AddSpeedZ(Distance.z);
|
|
|
|
}
|
2017-08-21 04:46:41 -04:00
|
|
|
|
|
|
|
// Speed up leashed mobs getting far from player
|
|
|
|
if (IsLeashed() && GetLeashedTo()->IsPlayer())
|
|
|
|
{
|
|
|
|
Distance = GetLeashedTo()->GetPosition() - GetPosition();
|
|
|
|
Distance.Normalize();
|
|
|
|
AddSpeedX(Distance.x);
|
|
|
|
AddSpeedZ(Distance.z);
|
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-08 18:20:22 -04:00
|
|
|
|
2015-05-06 10:23:07 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-03 13:56:37 -04:00
|
|
|
void cMonster::MoveToPosition(const Vector3d & a_Position)
|
2015-04-29 12:24:14 -04:00
|
|
|
{
|
2015-07-11 15:40:03 -04:00
|
|
|
m_FinalDestination = a_Position;
|
|
|
|
m_PathfinderActivated = true;
|
2015-04-29 12:24:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-03 13:56:37 -04:00
|
|
|
void cMonster::StopMovingToPosition()
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2015-07-11 15:40:03 -04:00
|
|
|
m_PathfinderActivated = false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-11 16:12:26 -05:00
|
|
|
void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-04-13 17:02:10 -04:00
|
|
|
super::Tick(a_Dt, a_Chunk);
|
2016-09-03 07:31:27 -04:00
|
|
|
if (!IsTicking())
|
|
|
|
{
|
|
|
|
// The base class tick destroyed us
|
|
|
|
return;
|
|
|
|
}
|
2015-05-01 13:34:24 -04:00
|
|
|
GET_AND_VERIFY_CURRENT_CHUNK(Chunk, POSX_TOINT, POSZ_TOINT);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2016-02-01 15:49:34 -05:00
|
|
|
ASSERT((GetTarget() == nullptr) || (GetTarget()->IsPawn() && (GetTarget()->GetWorld() == GetWorld())));
|
2016-01-12 05:11:10 -05:00
|
|
|
if (m_AttackCoolDownTicksLeft > 0)
|
|
|
|
{
|
|
|
|
m_AttackCoolDownTicksLeft -= 1;
|
|
|
|
}
|
|
|
|
|
2012-12-22 05:15:53 -05:00
|
|
|
if (m_Health <= 0)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2015-11-20 03:03:20 -05:00
|
|
|
// The mob is dead, but we're still animating the "puff" they leave when they die
|
2015-01-16 09:38:21 -05:00
|
|
|
m_DestroyTimer += a_Dt;
|
|
|
|
if (m_DestroyTimer > std::chrono::seconds(1))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-06-25 02:36:59 -04:00
|
|
|
Destroy(true);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-29 12:24:14 -04:00
|
|
|
if (m_TicksSinceLastDamaged < 100)
|
|
|
|
{
|
|
|
|
++m_TicksSinceLastDamaged;
|
|
|
|
}
|
2016-02-01 15:49:34 -05:00
|
|
|
if ((GetTarget() != nullptr))
|
2014-12-05 10:59:11 -05:00
|
|
|
{
|
2016-02-07 12:07:14 -05:00
|
|
|
ASSERT(GetTarget()->IsTicking());
|
2016-02-01 15:49:34 -05:00
|
|
|
|
|
|
|
if (GetTarget()->IsPlayer())
|
2015-12-13 00:51:13 -05:00
|
|
|
{
|
2016-10-12 08:38:45 -04:00
|
|
|
if (!static_cast<cPlayer *>(GetTarget())->CanMobsTarget())
|
2015-12-13 00:51:13 -05:00
|
|
|
{
|
2016-02-01 15:49:34 -05:00
|
|
|
SetTarget(nullptr);
|
2015-12-13 00:51:13 -05:00
|
|
|
m_EMState = IDLE;
|
|
|
|
}
|
|
|
|
}
|
2014-12-05 10:59:11 -05:00
|
|
|
}
|
2014-01-24 18:56:19 -05:00
|
|
|
|
2015-11-20 03:03:20 -05:00
|
|
|
// Process the undead burning in daylight.
|
|
|
|
HandleDaylightBurning(*Chunk, WouldBurnAt(GetPosition(), *Chunk));
|
|
|
|
|
|
|
|
bool a_IsFollowingPath = false;
|
|
|
|
if (m_PathfinderActivated)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2017-08-21 04:46:41 -04:00
|
|
|
if (ReachedFinalDestination() || (m_LeashToPos != nullptr))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2015-11-20 03:03:20 -05:00
|
|
|
StopMovingToPosition(); // Simply sets m_PathfinderActivated to false.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Note that m_NextWayPointPosition is actually returned by GetNextWayPoint)
|
|
|
|
switch (m_PathFinder.GetNextWayPoint(*Chunk, GetPosition(), &m_FinalDestination, &m_NextWayPointPosition, m_EMState == IDLE ? true : false))
|
2015-09-05 16:02:15 -04:00
|
|
|
{
|
2015-11-20 03:03:20 -05:00
|
|
|
case ePathFinderStatus::PATH_FOUND:
|
|
|
|
{
|
|
|
|
/* If I burn in daylight, and I won't burn where I'm standing, and I'll burn in my next position, and at least one of those is true:
|
|
|
|
1. I am idle
|
|
|
|
2. I was not hurt by a player recently.
|
|
|
|
Then STOP. */
|
|
|
|
if (
|
|
|
|
m_BurnsInDaylight && ((m_TicksSinceLastDamaged >= 100) || (m_EMState == IDLE)) &&
|
|
|
|
WouldBurnAt(m_NextWayPointPosition, *Chunk) &&
|
|
|
|
!WouldBurnAt(GetPosition(), *Chunk)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// If we burn in daylight, and we would burn at the next step, and we won't burn where we are right now, and we weren't provoked recently:
|
|
|
|
StopMovingToPosition();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a_IsFollowingPath = true; // Used for proper body / head orientation only.
|
|
|
|
MoveToWayPoint(*Chunk);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ePathFinderStatus::PATH_NOT_FOUND:
|
|
|
|
{
|
|
|
|
StopMovingToPosition();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2015-09-05 16:02:15 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
2013-03-23 00:33:47 -04:00
|
|
|
|
2015-11-20 03:03:20 -05:00
|
|
|
SetPitchAndYawFromDestination(a_IsFollowingPath);
|
2013-03-22 02:33:10 -04:00
|
|
|
|
2012-12-22 05:15:53 -05:00
|
|
|
switch (m_EMState)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2012-12-22 05:15:53 -05:00
|
|
|
case IDLE:
|
|
|
|
{
|
2015-04-29 12:24:14 -04:00
|
|
|
// If enemy passive we ignore checks for player visibility.
|
2015-12-22 00:43:50 -05:00
|
|
|
InStateIdle(a_Dt, a_Chunk);
|
2012-12-22 05:15:53 -05:00
|
|
|
break;
|
2014-07-17 16:50:58 -04:00
|
|
|
}
|
2012-12-22 05:15:53 -05:00
|
|
|
case CHASING:
|
|
|
|
{
|
2015-04-29 12:24:14 -04:00
|
|
|
// If we do not see a player anymore skip chasing action.
|
2015-12-22 00:43:50 -05:00
|
|
|
InStateChasing(a_Dt, a_Chunk);
|
2012-12-22 05:15:53 -05:00
|
|
|
break;
|
2014-07-17 16:50:58 -04:00
|
|
|
}
|
2012-12-22 05:15:53 -05:00
|
|
|
case ESCAPING:
|
|
|
|
{
|
2015-12-22 00:43:50 -05:00
|
|
|
InStateEscaping(a_Dt, a_Chunk);
|
2012-12-22 05:15:53 -05:00
|
|
|
break;
|
|
|
|
}
|
2014-05-11 19:25:21 -04:00
|
|
|
case ATTACKING: break;
|
2012-12-22 05:15:53 -05:00
|
|
|
} // switch (m_EMState)
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2017-08-21 04:46:41 -04:00
|
|
|
// Leash calculations
|
|
|
|
if ((m_TicksAlive % LEASH_ACTIONS_TICK_STEP) == 0)
|
|
|
|
{
|
|
|
|
CalcLeashActions();
|
|
|
|
}
|
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
BroadcastMovementUpdate();
|
2015-11-29 13:13:31 -05:00
|
|
|
|
|
|
|
if (m_AgingTimer > 0)
|
|
|
|
{
|
|
|
|
m_AgingTimer--;
|
|
|
|
if ((m_AgingTimer <= 0) && IsBaby())
|
|
|
|
{
|
|
|
|
SetAge(1);
|
|
|
|
m_World->BroadcastEntityMetadata(*this);
|
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:56:37 -04:00
|
|
|
}
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-21 04:46:41 -04:00
|
|
|
void cMonster::CalcLeashActions()
|
|
|
|
{
|
|
|
|
// This mob just spotted in the world and [m_LeashToPos not null] shows that should be leashed to a leash knot at m_LeashToPos.
|
|
|
|
// This keeps trying until knot is found. Leash knot may be in a different chunk that needn't or can't be loaded yet.
|
|
|
|
if (!IsLeashed() && (m_LeashToPos != nullptr))
|
|
|
|
{
|
|
|
|
auto LeashKnot = cLeashKnot::FindKnotAtPos(*m_World, { FloorC(m_LeashToPos->x), FloorC(m_LeashToPos->y), FloorC(m_LeashToPos->z) });
|
|
|
|
if (LeashKnot != nullptr)
|
|
|
|
{
|
2017-08-24 07:26:23 -04:00
|
|
|
LeashTo(*LeashKnot);
|
2017-08-21 04:46:41 -04:00
|
|
|
SetLeashToPos(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (IsLeashed()) // Mob is already leashed to an entity: follow it.
|
|
|
|
{
|
|
|
|
// TODO: leashed mobs in vanilla can move around up to 5 blocks distance from leash origin
|
|
|
|
MoveToPosition(m_LeashedTo->GetPosition());
|
|
|
|
|
|
|
|
// If distance to target > 10 break leash
|
|
|
|
Vector3f a_Distance(m_LeashedTo->GetPosition() - GetPosition());
|
|
|
|
double Distance(a_Distance.Length());
|
|
|
|
if (Distance > 10.0)
|
|
|
|
{
|
|
|
|
LOGD("Leash broken (distance)");
|
|
|
|
Unleash(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-20 03:03:20 -05:00
|
|
|
void cMonster::SetPitchAndYawFromDestination(bool a_IsFollowingPath)
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
2015-05-28 10:45:47 -04:00
|
|
|
Vector3d BodyDistance;
|
2016-02-01 15:49:34 -05:00
|
|
|
if (!a_IsFollowingPath && (GetTarget() != nullptr))
|
2015-05-28 10:45:47 -04:00
|
|
|
{
|
2016-02-01 15:49:34 -05:00
|
|
|
BodyDistance = GetTarget()->GetPosition() - GetPosition();
|
2015-05-28 10:45:47 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BodyDistance = m_NextWayPointPosition - GetPosition();
|
|
|
|
}
|
2015-05-16 07:05:33 -04:00
|
|
|
double BodyRotation, BodyPitch;
|
|
|
|
BodyDistance.Normalize();
|
|
|
|
VectorToEuler(BodyDistance.x, BodyDistance.y, BodyDistance.z, BodyRotation, BodyPitch);
|
|
|
|
SetYaw(BodyRotation);
|
|
|
|
|
2015-11-20 03:03:20 -05:00
|
|
|
Vector3d HeadDistance;
|
2016-02-01 15:49:34 -05:00
|
|
|
if (GetTarget() != nullptr)
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
2016-02-01 15:49:34 -05:00
|
|
|
if (GetTarget()->IsPlayer()) // Look at a player
|
2015-05-16 07:05:33 -04:00
|
|
|
{
|
2016-02-01 15:49:34 -05:00
|
|
|
HeadDistance = GetTarget()->GetPosition() - GetPosition();
|
2015-05-16 07:05:33 -04:00
|
|
|
}
|
2015-11-20 03:03:20 -05:00
|
|
|
else // Look at some other entity
|
2015-05-16 07:05:33 -04:00
|
|
|
{
|
2016-02-01 15:49:34 -05:00
|
|
|
HeadDistance = GetTarget()->GetPosition() - GetPosition();
|
|
|
|
// HeadDistance.y = GetTarget()->GetPosY() + GetHeight();
|
2015-05-16 07:05:33 -04:00
|
|
|
}
|
2014-01-24 14:57:32 -05:00
|
|
|
}
|
2015-11-20 03:03:20 -05:00
|
|
|
else // Look straight
|
|
|
|
{
|
|
|
|
HeadDistance = BodyDistance;
|
|
|
|
HeadDistance.y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double HeadRotation, HeadPitch;
|
|
|
|
HeadDistance.Normalize();
|
|
|
|
VectorToEuler(HeadDistance.x, HeadDistance.y, HeadDistance.z, HeadRotation, HeadPitch);
|
2015-12-22 00:43:50 -05:00
|
|
|
if ((std::abs(BodyRotation - HeadRotation) < 70) && (std::abs(HeadPitch) < 60))
|
2015-11-20 03:03:20 -05:00
|
|
|
{
|
|
|
|
SetHeadYaw(HeadRotation);
|
|
|
|
SetPitch(-HeadPitch);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetHeadYaw(BodyRotation);
|
2015-12-22 00:43:50 -05:00
|
|
|
SetPitch(0);
|
2015-11-20 03:03:20 -05:00
|
|
|
}
|
2014-01-24 14:57:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2014-01-25 14:02:13 -05:00
|
|
|
void cMonster::HandleFalling()
|
|
|
|
{
|
2015-11-10 08:02:07 -05:00
|
|
|
m_bTouchGround = IsOnGround();
|
|
|
|
super::HandleFalling();
|
2014-01-25 14:02:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-08 21:44:20 -04:00
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ)
|
|
|
|
{
|
2014-04-17 13:50:25 -04:00
|
|
|
int PosY = POSY_TOINT;
|
2014-07-19 04:40:29 -04:00
|
|
|
PosY = Clamp(PosY, 0, cChunkDef::Height);
|
2014-01-25 09:42:26 -05:00
|
|
|
|
2015-07-29 11:04:03 -04:00
|
|
|
if (!cBlockInfo::IsSolid(m_World->GetBlock(FloorC(a_PosX), PosY, FloorC(a_PosZ))))
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
2015-07-29 11:04:03 -04:00
|
|
|
while (!cBlockInfo::IsSolid(m_World->GetBlock(FloorC(a_PosX), PosY, FloorC(a_PosZ))) && (PosY > 0))
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
|
|
|
PosY--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PosY + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-29 11:04:03 -04:00
|
|
|
while ((PosY < cChunkDef::Height) && cBlockInfo::IsSolid(m_World->GetBlock(static_cast<int>(floor(a_PosX)), PosY, static_cast<int>(floor(a_PosZ)))))
|
2014-01-24 14:57:32 -05:00
|
|
|
{
|
|
|
|
PosY++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PosY;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
2014-04-25 18:32:30 -04:00
|
|
|
bool cMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-04-25 18:32:30 -04:00
|
|
|
if (!super::DoTakeDamage(a_TDI))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2014-05-13 07:53:15 -04:00
|
|
|
if (!m_SoundHurt.empty() && (m_Health > 0))
|
2014-05-12 14:38:52 -04:00
|
|
|
{
|
2014-07-12 20:08:02 -04:00
|
|
|
m_World->BroadcastSoundEffect(m_SoundHurt, GetPosX(), GetPosY(), GetPosZ(), 1.0f, 0.8f);
|
2014-05-12 14:38:52 -04:00
|
|
|
}
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2016-02-01 15:49:34 -05:00
|
|
|
if ((a_TDI.Attacker != nullptr) && a_TDI.Attacker->IsPawn())
|
2012-12-21 06:04:08 -05:00
|
|
|
{
|
2016-10-12 08:38:45 -04:00
|
|
|
if (
|
|
|
|
(!a_TDI.Attacker->IsPlayer()) ||
|
|
|
|
(static_cast<cPlayer *>(a_TDI.Attacker)->CanMobsTarget())
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SetTarget(static_cast<cPawn*>(a_TDI.Attacker));
|
|
|
|
}
|
2015-04-29 12:24:14 -04:00
|
|
|
m_TicksSinceLastDamaged = 0;
|
2012-12-21 06:04:08 -05:00
|
|
|
}
|
2014-04-25 18:32:30 -04:00
|
|
|
return true;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-04 05:55:09 -04:00
|
|
|
void cMonster::KilledBy(TakeDamageInfo & a_TDI)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-07-04 05:55:09 -04:00
|
|
|
super::KilledBy(a_TDI);
|
2013-07-01 06:39:56 -04:00
|
|
|
if (m_SoundHurt != "")
|
|
|
|
{
|
2014-07-12 20:08:02 -04:00
|
|
|
m_World->BroadcastSoundEffect(m_SoundDeath, GetPosX(), GetPosY(), GetPosZ(), 1.0f, 0.8f);
|
2013-07-01 06:39:56 -04:00
|
|
|
}
|
2013-11-25 15:43:43 -05:00
|
|
|
int Reward;
|
2013-11-25 15:03:26 -05:00
|
|
|
switch (m_MobType)
|
|
|
|
{
|
|
|
|
// Animals
|
2014-09-17 13:40:10 -04:00
|
|
|
case mtChicken:
|
|
|
|
case mtCow:
|
|
|
|
case mtHorse:
|
|
|
|
case mtPig:
|
2014-12-20 04:31:34 -05:00
|
|
|
case mtRabbit:
|
2014-09-17 13:40:10 -04:00
|
|
|
case mtSheep:
|
|
|
|
case mtSquid:
|
|
|
|
case mtMooshroom:
|
|
|
|
case mtOcelot:
|
|
|
|
case mtWolf:
|
2013-11-25 15:03:26 -05:00
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
Reward = GetRandomProvider().RandInt(1, 3);
|
2013-12-14 06:50:08 -05:00
|
|
|
break;
|
2013-11-25 15:03:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Monsters
|
2014-09-17 13:40:10 -04:00
|
|
|
case mtCaveSpider:
|
|
|
|
case mtCreeper:
|
|
|
|
case mtEnderman:
|
|
|
|
case mtGhast:
|
2014-12-18 13:30:32 -05:00
|
|
|
case mtGuardian:
|
2014-09-17 13:40:10 -04:00
|
|
|
case mtSilverfish:
|
|
|
|
case mtSkeleton:
|
|
|
|
case mtSpider:
|
|
|
|
case mtWitch:
|
|
|
|
case mtZombie:
|
|
|
|
case mtZombiePigman:
|
|
|
|
case mtSlime:
|
|
|
|
case mtMagmaCube:
|
2013-11-25 15:03:26 -05:00
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
Reward = GetRandomProvider().RandInt(6, 8);
|
2013-12-14 06:50:08 -05:00
|
|
|
break;
|
2013-11-25 15:43:43 -05:00
|
|
|
}
|
2014-09-17 13:40:10 -04:00
|
|
|
case mtBlaze:
|
2013-11-25 15:43:43 -05:00
|
|
|
{
|
|
|
|
Reward = 10;
|
2013-12-14 06:50:08 -05:00
|
|
|
break;
|
2013-11-25 15:03:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bosses
|
2014-09-17 13:40:10 -04:00
|
|
|
case mtEnderDragon:
|
2013-11-25 15:03:26 -05:00
|
|
|
{
|
2013-11-25 15:43:43 -05:00
|
|
|
Reward = 12000;
|
2013-12-14 06:50:08 -05:00
|
|
|
break;
|
2013-11-25 15:03:26 -05:00
|
|
|
}
|
2014-09-17 13:40:10 -04:00
|
|
|
case mtWither:
|
2013-11-25 15:03:26 -05:00
|
|
|
{
|
2013-11-25 15:43:43 -05:00
|
|
|
Reward = 50;
|
2013-12-14 06:50:08 -05:00
|
|
|
break;
|
2013-11-25 15:03:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2013-11-25 15:43:43 -05:00
|
|
|
Reward = 0;
|
2013-12-14 06:50:08 -05:00
|
|
|
break;
|
2013-11-25 15:03:26 -05:00
|
|
|
}
|
|
|
|
}
|
2014-10-20 16:55:07 -04:00
|
|
|
if ((a_TDI.Attacker != nullptr) && (!IsBaby()))
|
2014-04-10 10:50:43 -04:00
|
|
|
{
|
|
|
|
m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), Reward);
|
|
|
|
}
|
2015-01-16 09:38:21 -05:00
|
|
|
m_DestroyTimer = std::chrono::milliseconds(0);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-01 15:05:45 -04:00
|
|
|
void cMonster::OnRightClicked(cPlayer & a_Player)
|
|
|
|
{
|
|
|
|
super::OnRightClicked(a_Player);
|
|
|
|
|
|
|
|
const cItem & EquippedItem = a_Player.GetEquippedItem();
|
|
|
|
if ((EquippedItem.m_ItemType == E_ITEM_NAME_TAG) && !EquippedItem.m_CustomName.empty())
|
|
|
|
{
|
|
|
|
SetCustomName(EquippedItem.m_CustomName);
|
|
|
|
if (!a_Player.IsGameModeCreative())
|
|
|
|
{
|
|
|
|
a_Player.GetInventory().RemoveOneEquippedItem();
|
|
|
|
}
|
|
|
|
}
|
2017-08-21 04:46:41 -04:00
|
|
|
|
|
|
|
// Using leashes
|
|
|
|
m_IsLeashActionJustDone = false;
|
|
|
|
if (IsLeashed() && (GetLeashedTo() == &a_Player)) // a player can only unleash a mob leashed to him
|
|
|
|
{
|
|
|
|
Unleash(!a_Player.IsGameModeCreative());
|
|
|
|
}
|
|
|
|
else if (IsLeashed())
|
|
|
|
{
|
|
|
|
// Mob is already leashed but client anticipates the server action and draws a leash link, so we need to send current leash to cancel it
|
|
|
|
m_World->BroadcastLeashEntity(*this, *this->GetLeashedTo());
|
|
|
|
}
|
|
|
|
else if (CanBeLeashed() && (EquippedItem.m_ItemType == E_ITEM_LEASH))
|
|
|
|
{
|
|
|
|
if (!a_Player.IsGameModeCreative())
|
|
|
|
{
|
|
|
|
a_Player.GetInventory().RemoveOneEquippedItem();
|
|
|
|
}
|
2017-08-24 07:26:23 -04:00
|
|
|
LeashTo(a_Player);
|
2017-08-21 04:46:41 -04:00
|
|
|
}
|
2014-09-01 15:05:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
// Checks to see if EventSeePlayer should be fired
|
|
|
|
// monster sez: Do I see the player
|
2016-01-17 09:09:25 -05:00
|
|
|
void cMonster::CheckEventSeePlayer(cChunk & a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-22 05:15:53 -05:00
|
|
|
// TODO: Rewrite this to use cWorld's DoWithPlayers()
|
2015-07-29 11:04:03 -04:00
|
|
|
cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), static_cast<float>(m_SightDistance), false);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if (Closest != nullptr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2016-01-17 09:09:25 -05:00
|
|
|
EventSeePlayer(Closest, a_Chunk);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-13 17:02:10 -04:00
|
|
|
void cMonster::CheckEventLostPlayer(void)
|
2014-07-17 16:50:58 -04:00
|
|
|
{
|
2016-02-01 15:49:34 -05:00
|
|
|
if (GetTarget() != nullptr)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2016-02-01 15:49:34 -05:00
|
|
|
if ((GetTarget()->GetPosition() - GetPosition()).Length() > m_SightDistance)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
EventLosePlayer();
|
|
|
|
}
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
EventLosePlayer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// What to do if player is seen
|
|
|
|
// default to change state to chasing
|
2016-10-12 08:38:45 -04:00
|
|
|
void cMonster::EventSeePlayer(cPlayer * a_SeenPlayer, cChunk & a_Chunk)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2016-02-01 15:49:34 -05:00
|
|
|
UNUSED(a_Chunk);
|
2016-10-12 08:38:45 -04:00
|
|
|
SetTarget(a_SeenPlayer);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-22 05:15:53 -05:00
|
|
|
void cMonster::EventLosePlayer(void)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2016-02-01 15:49:34 -05:00
|
|
|
SetTarget(nullptr);
|
2012-06-14 09:06:06 -04:00
|
|
|
m_EMState = IDLE;
|
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-22 00:43:50 -05:00
|
|
|
void cMonster::InStateIdle(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2015-11-20 03:03:20 -05:00
|
|
|
if (m_PathfinderActivated)
|
2014-01-25 09:42:26 -05:00
|
|
|
{
|
2014-07-17 16:15:34 -04:00
|
|
|
return; // Still getting there
|
2014-01-25 09:42:26 -05:00
|
|
|
}
|
|
|
|
|
2013-12-20 10:39:20 -05:00
|
|
|
m_IdleInterval += a_Dt;
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2015-01-16 09:38:21 -05:00
|
|
|
if (m_IdleInterval > std::chrono::seconds(1))
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
auto & Random = GetRandomProvider();
|
|
|
|
|
2014-01-24 14:57:32 -05:00
|
|
|
// At this interval the results are predictable
|
2017-06-13 15:35:30 -04:00
|
|
|
int rem = Random.RandInt(1, 7);
|
2015-01-16 09:38:21 -05:00
|
|
|
m_IdleInterval -= std::chrono::seconds(1); // So nothing gets dropped when the server hangs for a few seconds
|
2014-01-24 14:57:32 -05:00
|
|
|
|
|
|
|
Vector3d Dist;
|
2017-06-13 15:35:30 -04:00
|
|
|
Dist.x = static_cast<double>(Random.RandInt(-5, 5));
|
|
|
|
Dist.z = static_cast<double>(Random.RandInt(-5, 5));
|
2014-01-24 14:57:32 -05:00
|
|
|
|
2012-12-22 05:15:53 -05:00
|
|
|
if ((Dist.SqrLength() > 2) && (rem >= 3))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2015-12-22 00:43:50 -05:00
|
|
|
|
|
|
|
Vector3d Destination(GetPosX() + Dist.x, GetPosition().y, GetPosZ() + Dist.z);
|
|
|
|
|
|
|
|
cChunk * Chunk = a_Chunk.GetNeighborChunk(static_cast<int>(Destination.x), static_cast<int>(Destination.z));
|
|
|
|
if ((Chunk == nullptr) || !Chunk->IsValid())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
NIBBLETYPE BlockMeta;
|
|
|
|
int RelX = static_cast<int>(Destination.x) - Chunk->GetPosX() * cChunkDef::Width;
|
|
|
|
int RelZ = static_cast<int>(Destination.z) - Chunk->GetPosZ() * cChunkDef::Width;
|
2016-04-18 14:58:57 -04:00
|
|
|
int YBelowUs = static_cast<int>(Destination.y) - 1;
|
|
|
|
if (YBelowUs >= 0)
|
2015-12-22 00:43:50 -05:00
|
|
|
{
|
2016-04-18 14:58:57 -04:00
|
|
|
Chunk->GetBlockTypeMeta(RelX, YBelowUs, RelZ, BlockType, BlockMeta);
|
|
|
|
if (BlockType != E_BLOCK_STATIONARY_WATER) // Idle mobs shouldn't enter water on purpose
|
|
|
|
{
|
|
|
|
MoveToPosition(Destination);
|
|
|
|
}
|
2015-12-22 00:43:50 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// What to do if in Chasing State
|
|
|
|
// This state should always be defined in each child class
|
2015-12-22 00:43:50 -05:00
|
|
|
void cMonster::InStateChasing(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
|
|
|
UNUSED(a_Dt);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// What to do if in Escaping State
|
2015-12-22 00:43:50 -05:00
|
|
|
void cMonster::InStateEscaping(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2012-12-22 05:15:53 -05:00
|
|
|
UNUSED(a_Dt);
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2016-02-01 15:49:34 -05:00
|
|
|
if (GetTarget() != nullptr)
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2013-03-22 02:33:10 -04:00
|
|
|
Vector3d newloc = GetPosition();
|
2016-02-01 15:49:34 -05:00
|
|
|
newloc.x = (GetTarget()->GetPosition().x < newloc.x)? (newloc.x + m_SightDistance): (newloc.x - m_SightDistance);
|
|
|
|
newloc.z = (GetTarget()->GetPosition().z < newloc.z)? (newloc.z + m_SightDistance): (newloc.z - m_SightDistance);
|
2012-06-14 09:06:06 -04:00
|
|
|
MoveToPosition(newloc);
|
|
|
|
}
|
2012-08-19 15:42:32 -04:00
|
|
|
else
|
|
|
|
{
|
2012-12-22 05:15:53 -05:00
|
|
|
m_EMState = IDLE; // This shouldnt be required but just to be safe
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-01-12 05:11:10 -05:00
|
|
|
void cMonster::ResetAttackCooldown()
|
|
|
|
{
|
|
|
|
m_AttackCoolDownTicksLeft = static_cast<int>(3 * 20 * m_AttackRate); // A second has 20 ticks, an attack rate of 1 means 1 hit every 3 seconds
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-01 14:12:56 -04:00
|
|
|
void cMonster::SetCustomName(const AString & a_CustomName)
|
|
|
|
{
|
|
|
|
m_CustomName = a_CustomName;
|
|
|
|
|
|
|
|
// The maximal length is 64
|
|
|
|
if (a_CustomName.length() > 64)
|
|
|
|
{
|
|
|
|
m_CustomName = a_CustomName.substr(0, 64);
|
|
|
|
}
|
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_World != nullptr)
|
2014-09-02 13:34:58 -04:00
|
|
|
{
|
|
|
|
m_World->BroadcastEntityMetadata(*this);
|
|
|
|
}
|
2014-09-01 14:12:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cMonster::SetCustomNameAlwaysVisible(bool a_CustomNameAlwaysVisible)
|
|
|
|
{
|
|
|
|
m_CustomNameAlwaysVisible = a_CustomNameAlwaysVisible;
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_World != nullptr)
|
2014-09-02 13:34:58 -04:00
|
|
|
{
|
|
|
|
m_World->BroadcastEntityMetadata(*this);
|
|
|
|
}
|
2014-09-01 14:12:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-22 04:39:13 -05:00
|
|
|
void cMonster::GetMonsterConfig(const AString & a_Name)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-22 04:39:13 -05:00
|
|
|
cRoot::Get()->GetMonsterConfig()->AssignAttributes(this, a_Name);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-08 21:44:20 -04:00
|
|
|
bool cMonster::IsUndead(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-17 13:40:10 -04:00
|
|
|
AString cMonster::MobTypeToString(eMonsterType a_MobType)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
|
|
|
// Mob types aren't sorted, so we need to search linearly:
|
2013-12-20 10:01:34 -05:00
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
|
|
|
if (g_MobTypeNames[i].m_Type == a_MobType)
|
|
|
|
{
|
|
|
|
return g_MobTypeNames[i].m_lcName;
|
|
|
|
}
|
|
|
|
}
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2013-10-20 07:25:56 -04:00
|
|
|
// Not found:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-29 09:20:44 -05:00
|
|
|
AString cMonster::MobTypeToVanillaName(eMonsterType a_MobType)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2014-11-29 09:20:44 -05:00
|
|
|
// Mob types aren't sorted, so we need to search linearly:
|
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2014-11-29 09:20:44 -05:00
|
|
|
if (g_MobTypeNames[i].m_Type == a_MobType)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2014-11-29 09:20:44 -05:00
|
|
|
return g_MobTypeNames[i].m_VanillaName;
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
|
|
|
}
|
2014-11-29 09:20:44 -05:00
|
|
|
|
|
|
|
// Not found:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-22 11:41:41 -04:00
|
|
|
AString cMonster::MobTypeToVanillaNBT(eMonsterType a_MobType)
|
|
|
|
{
|
|
|
|
// Mob types aren't sorted, so we need to search linearly:
|
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++)
|
|
|
|
{
|
|
|
|
if (g_MobTypeNames[i].m_Type == a_MobType)
|
|
|
|
{
|
|
|
|
return g_MobTypeNames[i].m_VanillaNameNBT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not found:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-29 09:20:44 -05:00
|
|
|
eMonsterType cMonster::StringToMobType(const AString & a_Name)
|
|
|
|
{
|
|
|
|
AString lcName = StrToLower(a_Name);
|
|
|
|
|
2015-09-25 04:14:17 -04:00
|
|
|
// Search Cuberite name:
|
2014-11-29 09:20:44 -05:00
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2014-11-29 09:20:44 -05:00
|
|
|
if (strcmp(g_MobTypeNames[i].m_lcName, lcName.c_str()) == 0)
|
|
|
|
{
|
|
|
|
return g_MobTypeNames[i].m_Type;
|
|
|
|
}
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
2014-11-29 09:20:44 -05:00
|
|
|
|
|
|
|
// Not found. Search Vanilla name:
|
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2014-11-29 09:20:44 -05:00
|
|
|
if (strcmp(StrToLower(g_MobTypeNames[i].m_VanillaName).c_str(), lcName.c_str()) == 0)
|
|
|
|
{
|
|
|
|
return g_MobTypeNames[i].m_Type;
|
|
|
|
}
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
2014-11-29 09:20:44 -05:00
|
|
|
|
2017-05-22 11:41:41 -04:00
|
|
|
// Search in NBT name
|
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++)
|
|
|
|
{
|
|
|
|
if (strcmp(StrToLower(g_MobTypeNames[i].m_VanillaNameNBT).c_str(), lcName.c_str()) == 0)
|
|
|
|
{
|
|
|
|
return g_MobTypeNames[i].m_Type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-20 07:25:56 -04:00
|
|
|
// Not found:
|
|
|
|
return mtInvalidType;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-17 13:40:10 -04:00
|
|
|
cMonster::eFamily cMonster::FamilyFromType(eMonsterType a_Type)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2014-01-24 14:57:32 -05:00
|
|
|
// Passive-agressive mobs are counted in mob spawning code as passive
|
|
|
|
|
2013-10-20 08:15:55 -04:00
|
|
|
switch (a_Type)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2013-10-20 08:15:55 -04:00
|
|
|
case mtBat: return mfAmbient;
|
|
|
|
case mtBlaze: return mfHostile;
|
|
|
|
case mtCaveSpider: return mfHostile;
|
|
|
|
case mtChicken: return mfPassive;
|
|
|
|
case mtCow: return mfPassive;
|
|
|
|
case mtCreeper: return mfHostile;
|
2014-04-25 23:49:55 -04:00
|
|
|
case mtEnderDragon: return mfNoSpawn;
|
2013-10-20 08:15:55 -04:00
|
|
|
case mtEnderman: return mfHostile;
|
|
|
|
case mtGhast: return mfHostile;
|
2014-04-25 23:49:55 -04:00
|
|
|
case mtGiant: return mfNoSpawn;
|
2014-12-24 18:44:09 -05:00
|
|
|
case mtGuardian: return mfWater; // Just because they have special spawning conditions. If Watertemples have been added, this needs to be edited!
|
2013-10-20 08:15:55 -04:00
|
|
|
case mtHorse: return mfPassive;
|
2013-12-25 11:07:52 -05:00
|
|
|
case mtIronGolem: return mfPassive;
|
2013-10-20 08:15:55 -04:00
|
|
|
case mtMagmaCube: return mfHostile;
|
|
|
|
case mtMooshroom: return mfHostile;
|
2013-12-25 11:07:52 -05:00
|
|
|
case mtOcelot: return mfPassive;
|
2013-10-20 08:15:55 -04:00
|
|
|
case mtPig: return mfPassive;
|
2014-12-20 04:31:34 -05:00
|
|
|
case mtRabbit: return mfPassive;
|
2013-10-20 08:15:55 -04:00
|
|
|
case mtSheep: return mfPassive;
|
|
|
|
case mtSilverfish: return mfHostile;
|
|
|
|
case mtSkeleton: return mfHostile;
|
|
|
|
case mtSlime: return mfHostile;
|
2014-04-25 23:49:55 -04:00
|
|
|
case mtSnowGolem: return mfNoSpawn;
|
2013-10-20 08:15:55 -04:00
|
|
|
case mtSpider: return mfHostile;
|
|
|
|
case mtSquid: return mfWater;
|
|
|
|
case mtVillager: return mfPassive;
|
|
|
|
case mtWitch: return mfHostile;
|
2014-04-25 23:49:55 -04:00
|
|
|
case mtWither: return mfNoSpawn;
|
2013-10-20 08:15:55 -04:00
|
|
|
case mtWolf: return mfHostile;
|
|
|
|
case mtZombie: return mfHostile;
|
|
|
|
case mtZombiePigman: return mfHostile;
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2014-04-24 21:11:11 -04:00
|
|
|
case mtInvalidType: break;
|
|
|
|
}
|
2013-10-20 08:15:55 -04:00
|
|
|
ASSERT(!"Unhandled mob type");
|
2014-04-24 21:11:11 -04:00
|
|
|
return mfUnhandled;
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 10:45:13 -04:00
|
|
|
int cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily)
|
2013-10-20 08:00:45 -04:00
|
|
|
{
|
|
|
|
switch (a_MobFamily)
|
|
|
|
{
|
2014-04-24 21:11:11 -04:00
|
|
|
case mfHostile: return 40;
|
|
|
|
case mfPassive: return 40;
|
|
|
|
case mfAmbient: return 40;
|
|
|
|
case mfWater: return 400;
|
2014-04-25 23:49:55 -04:00
|
|
|
case mfNoSpawn: return -1;
|
2014-04-24 21:11:11 -04:00
|
|
|
case mfUnhandled: break;
|
2013-10-20 08:00:45 -04:00
|
|
|
}
|
|
|
|
ASSERT(!"Unhandled mob family");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-01 15:49:34 -05:00
|
|
|
|
|
|
|
/** Sets the target. */
|
|
|
|
void cMonster::SetTarget (cPawn * a_NewTarget)
|
|
|
|
{
|
2016-02-07 12:07:14 -05:00
|
|
|
ASSERT((a_NewTarget == nullptr) || (IsTicking()));
|
2016-02-01 15:49:34 -05:00
|
|
|
if (m_Target == a_NewTarget)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cPawn * OldTarget = m_Target;
|
|
|
|
m_Target = a_NewTarget;
|
|
|
|
|
|
|
|
if (OldTarget != nullptr)
|
|
|
|
{
|
|
|
|
// Notify the old target that we are no longer targeting it.
|
|
|
|
OldTarget->NoLongerTargetingMe(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a_NewTarget != nullptr)
|
|
|
|
{
|
2016-02-07 12:07:14 -05:00
|
|
|
ASSERT(a_NewTarget->IsTicking());
|
2016-02-01 15:49:34 -05:00
|
|
|
// Notify the new target that we are now targeting it.
|
|
|
|
m_Target->TargetingMe(this);
|
2017-05-21 04:29:06 -04:00
|
|
|
m_WasLastTargetAPlayer = m_Target->IsPlayer();
|
2016-02-01 15:49:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cMonster::UnsafeUnsetTarget()
|
|
|
|
{
|
|
|
|
m_Target = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-12-19 15:12:23 -05:00
|
|
|
cPawn * cMonster::GetTarget()
|
2016-02-01 15:49:34 -05:00
|
|
|
{
|
|
|
|
return m_Target;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-12-19 15:12:23 -05:00
|
|
|
std::unique_ptr<cMonster> cMonster::NewMonsterFromType(eMonsterType a_MobType)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
auto & Random = GetRandomProvider();
|
2013-10-20 07:25:56 -04:00
|
|
|
|
2013-11-10 15:48:12 -05:00
|
|
|
// Create the mob entity
|
2013-10-20 07:25:56 -04:00
|
|
|
switch (a_MobType)
|
|
|
|
{
|
|
|
|
case mtMagmaCube:
|
2014-05-02 13:17:22 -04:00
|
|
|
{
|
2016-12-19 15:12:23 -05:00
|
|
|
return cpp14::make_unique<cMagmaCube>(1 << Random.RandInt(2)); // Size 1, 2 or 4
|
2014-05-02 13:17:22 -04:00
|
|
|
}
|
2013-10-20 07:25:56 -04:00
|
|
|
case mtSlime:
|
|
|
|
{
|
2016-12-19 15:12:23 -05:00
|
|
|
return cpp14::make_unique<cSlime>(1 << Random.RandInt(2)); // Size 1, 2 or 4
|
2013-11-13 05:08:51 -05:00
|
|
|
}
|
2013-11-10 17:20:25 -05:00
|
|
|
case mtSkeleton:
|
|
|
|
{
|
|
|
|
// TODO: Actual detection of spawning in Nether
|
2016-12-19 15:12:23 -05:00
|
|
|
return cpp14::make_unique<cSkeleton>(false);
|
2013-11-10 17:20:25 -05:00
|
|
|
}
|
2013-11-10 15:48:12 -05:00
|
|
|
case mtVillager:
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
int VillagerType = Random.RandInt(6);
|
2013-11-13 05:08:51 -05:00
|
|
|
if (VillagerType == 6)
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2013-11-13 05:08:51 -05:00
|
|
|
// Give farmers a better chance of spawning
|
|
|
|
VillagerType = 0;
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
2013-11-10 15:48:12 -05:00
|
|
|
|
2016-12-19 15:12:23 -05:00
|
|
|
return cpp14::make_unique<cVillager>(static_cast<cVillager::eVillagerType>(VillagerType));
|
2013-11-10 15:48:12 -05:00
|
|
|
}
|
|
|
|
case mtHorse:
|
|
|
|
{
|
|
|
|
// Horses take a type (species), a colour, and a style (dots, stripes, etc.)
|
2017-06-13 15:35:30 -04:00
|
|
|
int HorseType = Random.RandInt(7);
|
|
|
|
int HorseColor = Random.RandInt(6);
|
|
|
|
int HorseStyle = Random.RandInt(4);
|
|
|
|
int HorseTameTimes = Random.RandInt(1, 6);
|
2013-11-10 15:48:12 -05:00
|
|
|
|
2013-11-13 05:08:51 -05:00
|
|
|
if ((HorseType == 5) || (HorseType == 6) || (HorseType == 7))
|
2013-10-20 07:25:56 -04:00
|
|
|
{
|
2013-11-13 05:08:51 -05:00
|
|
|
// Increase chances of normal horse (zero)
|
|
|
|
HorseType = 0;
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
2013-11-10 15:48:12 -05:00
|
|
|
|
2016-12-19 15:12:23 -05:00
|
|
|
return cpp14::make_unique<cHorse>(HorseType, HorseColor, HorseStyle, HorseTameTimes);
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
|
|
|
|
2016-12-19 15:12:23 -05:00
|
|
|
case mtBat: return cpp14::make_unique<cBat>();
|
|
|
|
case mtBlaze: return cpp14::make_unique<cBlaze>();
|
|
|
|
case mtCaveSpider: return cpp14::make_unique<cCaveSpider>();
|
|
|
|
case mtChicken: return cpp14::make_unique<cChicken>();
|
|
|
|
case mtCow: return cpp14::make_unique<cCow>();
|
|
|
|
case mtCreeper: return cpp14::make_unique < cCreeper>();
|
|
|
|
case mtEnderDragon: return cpp14::make_unique<cEnderDragon>();
|
|
|
|
case mtEnderman: return cpp14::make_unique<cEnderman>();
|
|
|
|
case mtGhast: return cpp14::make_unique<cGhast>();
|
|
|
|
case mtGiant: return cpp14::make_unique<cGiant>();
|
|
|
|
case mtGuardian: return cpp14::make_unique<cGuardian>();
|
|
|
|
case mtIronGolem: return cpp14::make_unique<cIronGolem>();
|
|
|
|
case mtMooshroom: return cpp14::make_unique<cMooshroom>();
|
|
|
|
case mtOcelot: return cpp14::make_unique<cOcelot>();
|
|
|
|
case mtPig: return cpp14::make_unique<cPig>();
|
|
|
|
case mtRabbit: return cpp14::make_unique<cRabbit>();
|
|
|
|
case mtSheep: return cpp14::make_unique<cSheep>();
|
|
|
|
case mtSilverfish: return cpp14::make_unique<cSilverfish>();
|
|
|
|
case mtSnowGolem: return cpp14::make_unique<cSnowGolem>();
|
|
|
|
case mtSpider: return cpp14::make_unique<cSpider>();
|
|
|
|
case mtSquid: return cpp14::make_unique<cSquid>();
|
|
|
|
case mtWitch: return cpp14::make_unique<cWitch>();
|
|
|
|
case mtWither: return cpp14::make_unique<cWither>();
|
|
|
|
case mtWolf: return cpp14::make_unique<cWolf>();
|
|
|
|
case mtZombie: return cpp14::make_unique<cZombie>(false); // TODO: Infected zombie parameter
|
|
|
|
case mtZombiePigman: return cpp14::make_unique<cZombiePigman>();
|
2013-10-20 07:25:56 -04:00
|
|
|
default:
|
|
|
|
{
|
2013-11-10 15:48:12 -05:00
|
|
|
ASSERT(!"Unhandled mob type whilst trying to spawn mob!");
|
2016-12-19 15:12:23 -05:00
|
|
|
return nullptr;
|
2013-10-20 07:25:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
void cMonster::AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2017-08-18 06:23:08 -04:00
|
|
|
auto Count = GetRandomProvider().RandInt<unsigned int>(a_Min, a_Max);
|
|
|
|
auto MaxStackSize = static_cast<unsigned char>(ItemHandler(a_Item)->GetMaxStackSize());
|
|
|
|
while (Count > MaxStackSize)
|
|
|
|
{
|
|
|
|
a_Drops.emplace_back(a_Item, MaxStackSize, a_ItemHealth);
|
|
|
|
Count -= MaxStackSize;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
if (Count > 0)
|
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
a_Drops.emplace_back(a_Item, Count, a_ItemHealth);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-05 16:40:08 -04:00
|
|
|
|
2014-02-23 13:44:58 -05:00
|
|
|
void cMonster::AddRandomUncommonDropItem(cItems & a_Drops, float a_Chance, short a_Item, short a_ItemHealth)
|
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
if (GetRandomProvider().RandBool(a_Chance / 100.0))
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
|
|
|
a_Drops.push_back(cItem(a_Item, 1, a_ItemHealth));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-19 14:32:10 -04:00
|
|
|
void cMonster::AddRandomRareDropItem(cItems & a_Drops, cItems & a_Items, unsigned int a_LootingLevel)
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
auto & r1 = GetRandomProvider();
|
|
|
|
if (r1.RandBool((5 + a_LootingLevel) / 200.0))
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
size_t Rare = r1.RandInt<size_t>(a_Items.Size() - 1);
|
2014-02-23 13:44:58 -05:00
|
|
|
a_Drops.push_back(a_Items.at(Rare));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-19 14:32:10 -04:00
|
|
|
void cMonster::AddRandomArmorDropItem(cItems & a_Drops, unsigned int a_LootingLevel)
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
auto & r1 = GetRandomProvider();
|
|
|
|
|
|
|
|
double LootingBonus = a_LootingLevel / 100.0;
|
|
|
|
|
|
|
|
if (r1.RandBool(m_DropChanceHelmet + LootingBonus))
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
2014-12-05 10:59:11 -05:00
|
|
|
if (!GetEquippedHelmet().IsEmpty())
|
|
|
|
{
|
|
|
|
a_Drops.push_back(GetEquippedHelmet());
|
|
|
|
}
|
2014-02-23 13:44:58 -05:00
|
|
|
}
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2017-06-13 15:35:30 -04:00
|
|
|
if (r1.RandBool(m_DropChanceChestplate + LootingBonus))
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
2014-12-05 10:59:11 -05:00
|
|
|
if (!GetEquippedChestplate().IsEmpty())
|
|
|
|
{
|
|
|
|
a_Drops.push_back(GetEquippedChestplate());
|
|
|
|
}
|
2014-02-23 13:44:58 -05:00
|
|
|
}
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2017-06-13 15:35:30 -04:00
|
|
|
if (r1.RandBool(m_DropChanceLeggings + LootingBonus))
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
2014-12-05 10:59:11 -05:00
|
|
|
if (!GetEquippedLeggings().IsEmpty())
|
|
|
|
{
|
|
|
|
a_Drops.push_back(GetEquippedLeggings());
|
|
|
|
}
|
2014-02-23 13:44:58 -05:00
|
|
|
}
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2017-06-13 15:35:30 -04:00
|
|
|
if (r1.RandBool(m_DropChanceBoots + LootingBonus))
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
2014-12-05 10:59:11 -05:00
|
|
|
if (!GetEquippedBoots().IsEmpty())
|
|
|
|
{
|
|
|
|
a_Drops.push_back(GetEquippedBoots());
|
|
|
|
}
|
2014-02-23 13:44:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-19 14:32:10 -04:00
|
|
|
void cMonster::AddRandomWeaponDropItem(cItems & a_Drops, unsigned int a_LootingLevel)
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
2017-06-13 15:35:30 -04:00
|
|
|
if (GetRandomProvider().RandBool(m_DropChanceWeapon + (a_LootingLevel / 100.0)))
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
2014-12-05 10:59:11 -05:00
|
|
|
if (!GetEquippedWeapon().IsEmpty())
|
|
|
|
{
|
|
|
|
a_Drops.push_back(GetEquippedWeapon());
|
|
|
|
}
|
2014-02-23 13:44:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-01 13:34:24 -04:00
|
|
|
void cMonster::HandleDaylightBurning(cChunk & a_Chunk, bool WouldBurn)
|
2013-09-05 16:40:08 -04:00
|
|
|
{
|
|
|
|
if (!m_BurnsInDaylight)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2014-04-17 13:50:25 -04:00
|
|
|
int RelY = POSY_TOINT;
|
2013-09-05 16:40:08 -04:00
|
|
|
if ((RelY < 0) || (RelY >= cChunkDef::Height))
|
|
|
|
{
|
|
|
|
// Outside the world
|
|
|
|
return;
|
|
|
|
}
|
2014-01-24 14:57:32 -05:00
|
|
|
if (!a_Chunk.IsLightValid())
|
|
|
|
{
|
|
|
|
m_World->QueueLightChunk(GetChunkX(), GetChunkZ());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-01 13:34:24 -04:00
|
|
|
if (!IsOnFire() && WouldBurn)
|
2015-04-29 12:24:14 -04:00
|
|
|
{
|
|
|
|
// Burn for 100 ticks, then decide again
|
|
|
|
StartBurning(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cMonster::WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk)
|
|
|
|
{
|
2015-12-29 19:15:13 -05:00
|
|
|
// If the Y coord is out of range, return the most logical result without considering anything else:
|
|
|
|
int RelY = FloorC(a_Location.y);
|
|
|
|
if (RelY < 0)
|
|
|
|
{
|
|
|
|
// Never burn under the world
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (RelY >= cChunkDef::Height)
|
|
|
|
{
|
|
|
|
// Always burn above the world
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-29 09:34:41 -04:00
|
|
|
if (RelY <= 0)
|
2015-05-06 10:02:50 -04:00
|
|
|
{
|
2016-03-29 09:34:41 -04:00
|
|
|
// The mob is about to die, no point in burning
|
2015-05-06 10:02:50 -04:00
|
|
|
return false;
|
|
|
|
}
|
2015-05-08 20:51:25 -04:00
|
|
|
|
2016-03-29 09:34:41 -04:00
|
|
|
PREPARE_REL_AND_CHUNK(a_Location, a_Chunk);
|
|
|
|
if (!RelSuccess)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-08 20:51:25 -04:00
|
|
|
|
2013-09-05 16:40:08 -04:00
|
|
|
if (
|
2016-03-29 09:34:41 -04:00
|
|
|
(Chunk->GetBlock(Rel.x, Rel.y, Rel.z) != E_BLOCK_SOULSAND) && // Not on soulsand
|
2015-12-29 19:15:13 -05:00
|
|
|
(GetWorld()->GetTimeOfDay() < 12000 + 1000) && // Daytime
|
|
|
|
GetWorld()->IsWeatherSunnyAt(POSX_TOINT, POSZ_TOINT) // Not raining
|
2013-09-05 16:40:08 -04:00
|
|
|
)
|
|
|
|
{
|
2016-08-19 08:09:10 -04:00
|
|
|
int MobHeight = FloorC(a_Location.y + GetHeight()) - 1; // The block Y coord of the mob's head
|
2016-03-29 09:34:41 -04:00
|
|
|
if (MobHeight >= cChunkDef::Height)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Start with the highest block and scan down to the mob's head.
|
|
|
|
// If a non transparent is found, return false (do not burn). Otherwise return true.
|
|
|
|
// Note that this loop is not a performance concern as transparent blocks are rare and the loop almost always bailes out
|
|
|
|
// instantly.(An exception is e.g. standing under a long column of glass).
|
|
|
|
int CurrentBlock = Chunk->GetHeight(Rel.x, Rel.z);
|
|
|
|
while (CurrentBlock >= MobHeight)
|
|
|
|
{
|
|
|
|
BLOCKTYPE Block = Chunk->GetBlock(Rel.x, CurrentBlock, Rel.z);
|
|
|
|
if (
|
|
|
|
// Do not burn if a block above us meets one of the following conditions:
|
|
|
|
(!cBlockInfo::IsTransparent(Block)) ||
|
|
|
|
(Block == E_BLOCK_LEAVES) ||
|
|
|
|
(Block == E_BLOCK_NEW_LEAVES) ||
|
|
|
|
(IsBlockWater(Block))
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
--CurrentBlock;
|
|
|
|
}
|
2015-04-29 12:24:14 -04:00
|
|
|
return true;
|
2016-03-29 09:34:41 -04:00
|
|
|
|
2013-09-05 16:40:08 -04:00
|
|
|
}
|
2015-04-29 12:24:14 -04:00
|
|
|
return false;
|
2013-09-05 16:40:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-29 12:24:14 -04:00
|
|
|
|
2013-09-10 09:09:45 -04:00
|
|
|
cMonster::eFamily cMonster::GetMobFamily(void) const
|
|
|
|
{
|
2013-10-20 07:25:56 -04:00
|
|
|
return FamilyFromType(m_MobType);
|
2013-09-10 09:09:45 -04:00
|
|
|
}
|
2017-08-21 04:46:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-24 07:26:23 -04:00
|
|
|
void cMonster::LeashTo(cEntity & a_Entity, bool a_ShouldBroadcast)
|
2017-08-21 04:46:41 -04:00
|
|
|
{
|
|
|
|
// Do nothing if already leashed
|
|
|
|
if (m_LeashedTo != nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-24 07:26:23 -04:00
|
|
|
m_LeashedTo = &a_Entity;
|
2017-08-21 04:46:41 -04:00
|
|
|
|
2017-08-24 07:26:23 -04:00
|
|
|
a_Entity.AddLeashedMob(this);
|
2017-08-21 04:46:41 -04:00
|
|
|
|
|
|
|
if (a_ShouldBroadcast)
|
|
|
|
{
|
2017-08-24 07:26:23 -04:00
|
|
|
m_World->BroadcastLeashEntity(*this, a_Entity);
|
2017-08-21 04:46:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
m_IsLeashActionJustDone = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cMonster::Unleash(bool a_ShouldDropLeashPickup, bool a_ShouldBroadcast)
|
|
|
|
{
|
|
|
|
// Do nothing if not leashed
|
|
|
|
if (m_LeashedTo == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_LeashedTo->RemoveLeashedMob(this);
|
|
|
|
|
|
|
|
m_LeashedTo = nullptr;
|
|
|
|
|
|
|
|
if (a_ShouldDropLeashPickup)
|
|
|
|
{
|
|
|
|
cItems Pickups;
|
|
|
|
Pickups.Add(cItem(E_ITEM_LEASH, 1, 0));
|
|
|
|
GetWorld()->SpawnItemPickups(Pickups, GetPosX() + 0.5, GetPosY() + 0.5, GetPosZ() + 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a_ShouldBroadcast)
|
|
|
|
{
|
|
|
|
m_World->BroadcastUnleashEntity(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_IsLeashActionJustDone = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cMonster::Unleash(bool a_ShouldDropLeashPickup)
|
|
|
|
{
|
|
|
|
Unleash(a_ShouldDropLeashPickup, true);
|
|
|
|
}
|