2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 16:53:08 -04:00
|
|
|
#include "Enderman.h"
|
2014-05-29 07:34:38 -04:00
|
|
|
#include "../Entities/Player.h"
|
2014-06-04 04:19:55 -04:00
|
|
|
#include "../Tracer.h"
|
2014-05-29 07:34:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-04 06:03:37 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-05-29 07:34:38 -04:00
|
|
|
// cPlayerLookCheck
|
|
|
|
class cPlayerLookCheck :
|
|
|
|
public cPlayerListCallback
|
|
|
|
{
|
|
|
|
public:
|
2014-08-01 17:05:40 -04:00
|
|
|
cPlayerLookCheck(Vector3d a_EndermanPos, int a_SightDistance) :
|
2014-10-20 16:55:07 -04:00
|
|
|
m_Player(nullptr),
|
2014-08-01 17:05:40 -04:00
|
|
|
m_EndermanPos(a_EndermanPos),
|
|
|
|
m_SightDistance(a_SightDistance)
|
2014-05-29 07:34:38 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Item(cPlayer * a_Player) override
|
|
|
|
{
|
2014-07-31 13:17:21 -04:00
|
|
|
// Don't check players who are in creative gamemode
|
2014-05-29 07:34:38 -04:00
|
|
|
if (a_Player->IsGameModeCreative())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3d Direction = m_EndermanPos - a_Player->GetPosition();
|
|
|
|
|
2014-08-01 17:05:40 -04:00
|
|
|
// Don't check players who are more then SightDistance (64) blocks away
|
|
|
|
if (Direction.Length() > m_SightDistance)
|
2014-05-29 07:34:38 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-31 13:17:21 -04:00
|
|
|
// Don't check if the player has a pumpkin on his head
|
2014-05-29 07:34:38 -04:00
|
|
|
if (a_Player->GetEquippedHelmet().m_ItemType == E_BLOCK_PUMPKIN)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Vector3d LookVector = a_Player->GetLookVector();
|
2014-06-04 09:16:24 -04:00
|
|
|
double dot = Direction.Dot(LookVector);
|
2014-05-29 07:34:38 -04:00
|
|
|
|
2014-07-31 13:17:21 -04:00
|
|
|
// 0.09 rad ~ 5 degrees
|
|
|
|
// If the player's crosshair is within 5 degrees of the enderman, it counts as looking
|
2014-08-01 17:05:40 -04:00
|
|
|
if (dot <= cos(0.09))
|
2014-05-29 07:34:38 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-04 04:19:55 -04:00
|
|
|
cTracer LineOfSight(a_Player->GetWorld());
|
|
|
|
if (LineOfSight.Trace(m_EndermanPos, Direction, (int)Direction.Length()))
|
|
|
|
{
|
|
|
|
// No direct line of sight
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-29 07:34:38 -04:00
|
|
|
m_Player = a_Player;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-04 04:19:55 -04:00
|
|
|
cPlayer * GetPlayer(void) const { return m_Player; }
|
|
|
|
|
2014-05-29 07:34:38 -04:00
|
|
|
protected:
|
|
|
|
cPlayer * m_Player;
|
|
|
|
Vector3d m_EndermanPos;
|
2014-08-01 17:05:40 -04:00
|
|
|
int m_SightDistance;
|
2014-05-29 07:34:38 -04:00
|
|
|
} ;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-22 04:39:13 -05:00
|
|
|
cEnderman::cEnderman(void) :
|
2013-10-20 04:23:30 -04:00
|
|
|
super("Enderman", mtEnderman, "mob.endermen.hit", "mob.endermen.death", 0.5, 2.9),
|
2013-10-09 16:02:59 -04:00
|
|
|
m_bIsScreaming(false),
|
|
|
|
CarriedBlock(E_BLOCK_AIR),
|
|
|
|
CarriedMeta(0)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-01 06:39:56 -04:00
|
|
|
void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-02-23 13:44:58 -05:00
|
|
|
int LootingLevel = 0;
|
2014-10-20 16:55:07 -04:00
|
|
|
if (a_Killer != nullptr)
|
2014-02-23 13:44:58 -05:00
|
|
|
{
|
|
|
|
LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
|
|
|
|
}
|
|
|
|
AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_ENDER_PEARL);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-04 04:19:55 -04:00
|
|
|
void cEnderman::CheckEventSeePlayer()
|
2014-08-03 15:31:04 -04:00
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_Target != nullptr)
|
2014-05-29 07:34:38 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-01 17:05:40 -04:00
|
|
|
cPlayerLookCheck Callback(GetPosition(), m_SightDistance);
|
2014-06-04 04:19:55 -04:00
|
|
|
if (m_World->ForEachPlayer(Callback))
|
2014-05-29 07:34:38 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-06-04 04:19:55 -04:00
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(Callback.GetPlayer() != nullptr);
|
2014-05-29 07:34:38 -04:00
|
|
|
|
2014-08-01 17:05:40 -04:00
|
|
|
if (!CheckLight())
|
2014-07-30 13:18:11 -04:00
|
|
|
{
|
2014-08-01 17:05:40 -04:00
|
|
|
// Insufficient light for enderman to become aggravated
|
|
|
|
// TODO: Teleport to a suitable location
|
2014-07-30 13:18:11 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-30 07:59:47 -04:00
|
|
|
if (!Callback.GetPlayer()->IsGameModeCreative())
|
2014-06-04 04:19:55 -04:00
|
|
|
{
|
|
|
|
super::EventSeePlayer(Callback.GetPlayer());
|
|
|
|
m_EMState = CHASING;
|
|
|
|
m_bIsScreaming = true;
|
|
|
|
GetWorld()->BroadcastEntityMetadata(*this);
|
|
|
|
}
|
2014-05-29 07:34:38 -04:00
|
|
|
}
|
2014-08-01 17:05:40 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cEnderman::CheckEventLostPlayer(void)
|
|
|
|
{
|
|
|
|
super::CheckEventLostPlayer();
|
|
|
|
if (!CheckLight())
|
|
|
|
{
|
|
|
|
EventLosePlayer();
|
|
|
|
}
|
|
|
|
}
|
2014-05-29 07:34:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-04 04:19:55 -04:00
|
|
|
void cEnderman::EventLosePlayer()
|
|
|
|
{
|
|
|
|
super::EventLosePlayer();
|
|
|
|
m_bIsScreaming = false;
|
|
|
|
GetWorld()->BroadcastEntityMetadata(*this);
|
2014-06-04 09:16:24 -04:00
|
|
|
}
|
2014-08-01 17:05:40 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cEnderman::CheckLight()
|
|
|
|
{
|
|
|
|
int ChunkX, ChunkZ;
|
|
|
|
cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, ChunkX, ChunkZ);
|
|
|
|
|
|
|
|
// Check if the chunk the enderman is in is lit
|
|
|
|
if (!m_World->IsChunkLighted(ChunkX, ChunkZ))
|
|
|
|
{
|
|
|
|
m_World->QueueLightChunk(ChunkX, ChunkZ);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enderman only attack if the skylight is lower or equal to 8
|
|
|
|
if (m_World->GetBlockSkyLight(POSX_TOINT, POSY_TOINT, POSZ_TOINT) - GetWorld()->GetSkyDarkness() > 8)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-28 16:56:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-11 16:12:26 -05:00
|
|
|
void cEnderman::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
2014-09-28 16:56:41 -04:00
|
|
|
{
|
|
|
|
super::Tick(a_Dt, a_Chunk);
|
|
|
|
|
2014-09-28 22:24:47 -04:00
|
|
|
// TODO take damage in rain
|
2014-09-28 16:56:41 -04:00
|
|
|
|
2014-09-28 22:24:47 -04:00
|
|
|
// Take damage when touching water, drowning damage seems to be most appropriate
|
2014-09-28 16:56:41 -04:00
|
|
|
if (IsSwimming())
|
|
|
|
{
|
|
|
|
EventLosePlayer();
|
2014-10-20 16:55:07 -04:00
|
|
|
TakeDamage(dtDrowning, nullptr, 1, 0);
|
2014-09-28 22:27:53 -04:00
|
|
|
// TODO teleport to a safe location
|
2014-09-28 16:56:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|