Improved Enderman code
This commit is contained in:
parent
806130a967
commit
5d4f70a7a5
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "Enderman.h"
|
#include "Enderman.h"
|
||||||
#include "../Entities/Player.h"
|
#include "../Entities/Player.h"
|
||||||
|
#include "../Tracer.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -51,13 +52,19 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Don't attack the player if there is a wall between the player and the enderman.
|
cTracer LineOfSight(a_Player->GetWorld());
|
||||||
|
if (LineOfSight.Trace(m_EndermanPos, Direction, (int)Direction.Length()))
|
||||||
|
{
|
||||||
|
// No direct line of sight
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
m_Player = a_Player;
|
m_Player = a_Player;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
cPlayer * GetPlayer(void) const {return m_Player;}
|
cPlayer * GetPlayer(void) const { return m_Player; }
|
||||||
bool HasFoundPlayer(void) const {return (m_Player != NULL);}
|
|
||||||
protected:
|
protected:
|
||||||
cPlayer * m_Player;
|
cPlayer * m_Player;
|
||||||
Vector3d m_EndermanPos;
|
Vector3d m_EndermanPos;
|
||||||
@ -92,33 +99,45 @@ void cEnderman::GetDrops(cItems & a_Drops, cEntity * a_Killer)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cEnderman::Tick(float a_Dt, cChunk & a_Chunk)
|
void cEnderman::CheckEventSeePlayer()
|
||||||
{
|
{
|
||||||
super::Tick(a_Dt, a_Chunk);
|
|
||||||
|
|
||||||
if (m_Target != NULL)
|
if (m_Target != NULL)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cPlayerLookCheck Callback(GetPosition());
|
cPlayerLookCheck Callback(GetPosition());
|
||||||
if (!m_World->ForEachPlayer(Callback))
|
if (m_World->ForEachPlayer(Callback))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASSERT(Callback.GetPlayer() != NULL);
|
||||||
|
|
||||||
if (!Callback.HasFoundPlayer())
|
int CX, CZ;
|
||||||
|
cChunkDef::BlockToChunk(POSX_TOINT, POSZ_TOINT, CX, CZ);
|
||||||
|
if (!GetWorld()->IsChunkLighted(CX, CZ))
|
||||||
{
|
{
|
||||||
|
GetWorld()->QueueLightChunk(CX, CZ);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bIsScreaming = true;
|
if ((GetWorld()->GetBlockSkyLight(POSX_TOINT, POSY_TOINT, POSZ_TOINT) - GetWorld()->GetSkyDarkness() < 15) && !Callback.GetPlayer()->IsGameModeCreative())
|
||||||
m_Target = Callback.GetPlayer();
|
{
|
||||||
|
super::EventSeePlayer(Callback.GetPlayer());
|
||||||
m_World->BroadcastEntityMetadata(*this);
|
m_EMState = CHASING;
|
||||||
|
m_bIsScreaming = true;
|
||||||
|
GetWorld()->BroadcastEntityMetadata(*this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cEnderman::EventLosePlayer()
|
||||||
|
{
|
||||||
|
super::EventLosePlayer();
|
||||||
|
m_bIsScreaming = false;
|
||||||
|
GetWorld()->BroadcastEntityMetadata(*this);
|
||||||
|
}
|
@ -18,7 +18,8 @@ public:
|
|||||||
CLASS_PROTODEF(cEnderman);
|
CLASS_PROTODEF(cEnderman);
|
||||||
|
|
||||||
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
|
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
|
||||||
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
|
virtual void CheckEventSeePlayer(void) override;
|
||||||
|
virtual void EventLosePlayer(void) override;
|
||||||
|
|
||||||
bool IsScreaming(void) const {return m_bIsScreaming; }
|
bool IsScreaming(void) const {return m_bIsScreaming; }
|
||||||
BLOCKTYPE GetCarriedBlock(void) const {return CarriedBlock; }
|
BLOCKTYPE GetCarriedBlock(void) const {return CarriedBlock; }
|
||||||
|
Loading…
Reference in New Issue
Block a user