Improved endermen code a little
This commit is contained in:
parent
941a182d8a
commit
c865fc8ca5
@ -44,7 +44,7 @@ MaxHealth=10
|
|||||||
AttackRange=2.0
|
AttackRange=2.0
|
||||||
AttackRate=1
|
AttackRate=1
|
||||||
AttackDamage=4.0
|
AttackDamage=4.0
|
||||||
SightDistance=25.0
|
SightDistance=64.0
|
||||||
MaxHealth=40
|
MaxHealth=40
|
||||||
|
|
||||||
[ZombiePigman]
|
[ZombiePigman]
|
||||||
|
@ -14,9 +14,10 @@ class cPlayerLookCheck :
|
|||||||
public cPlayerListCallback
|
public cPlayerListCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cPlayerLookCheck(Vector3d a_EndermanPos) :
|
cPlayerLookCheck(Vector3d a_EndermanPos, int a_SightDistance) :
|
||||||
m_Player(NULL),
|
m_Player(NULL),
|
||||||
m_EndermanPos(a_EndermanPos)
|
m_EndermanPos(a_EndermanPos),
|
||||||
|
m_SightDistance(a_SightDistance)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,8 +31,8 @@ public:
|
|||||||
|
|
||||||
Vector3d Direction = m_EndermanPos - a_Player->GetPosition();
|
Vector3d Direction = m_EndermanPos - a_Player->GetPosition();
|
||||||
|
|
||||||
// Don't check players who are more then 64 blocks away
|
// Don't check players who are more then SightDistance (64) blocks away
|
||||||
if (Direction.SqrLength() > 64)
|
if (Direction.Length() > m_SightDistance)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -48,7 +49,7 @@ public:
|
|||||||
|
|
||||||
// 0.09 rad ~ 5 degrees
|
// 0.09 rad ~ 5 degrees
|
||||||
// If the player's crosshair is within 5 degrees of the enderman, it counts as looking
|
// If the player's crosshair is within 5 degrees of the enderman, it counts as looking
|
||||||
if (dot > cos(0.09))
|
if (dot <= cos(0.09))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -69,6 +70,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
cPlayer * m_Player;
|
cPlayer * m_Player;
|
||||||
Vector3d m_EndermanPos;
|
Vector3d m_EndermanPos;
|
||||||
|
int m_SightDistance;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
@ -107,7 +109,7 @@ void cEnderman::CheckEventSeePlayer()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cPlayerLookCheck Callback(GetPosition());
|
cPlayerLookCheck Callback(GetPosition(), m_SightDistance);
|
||||||
if (m_World->ForEachPlayer(Callback))
|
if (m_World->ForEachPlayer(Callback))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -115,20 +117,10 @@ void cEnderman::CheckEventSeePlayer()
|
|||||||
|
|
||||||
ASSERT(Callback.GetPlayer() != NULL);
|
ASSERT(Callback.GetPlayer() != NULL);
|
||||||
|
|
||||||
int ChunkX, ChunkZ;
|
if (!CheckLight())
|
||||||
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);
|
// Insufficient light for enderman to become aggravated
|
||||||
return;
|
// TODO: Teleport to a suitable location
|
||||||
}
|
|
||||||
|
|
||||||
// Enderman only attack if the skylight is higher than 7
|
|
||||||
if (m_World->GetBlockSkyLight(POSX_TOINT, POSY_TOINT, POSZ_TOINT) <= 7)
|
|
||||||
{
|
|
||||||
// TODO: Teleport the enderman to a random spot
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,6 +132,19 @@ void cEnderman::CheckEventSeePlayer()
|
|||||||
GetWorld()->BroadcastEntityMetadata(*this);
|
GetWorld()->BroadcastEntityMetadata(*this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cEnderman::CheckEventLostPlayer(void)
|
||||||
|
{
|
||||||
|
super::CheckEventLostPlayer();
|
||||||
|
if (!CheckLight())
|
||||||
|
{
|
||||||
|
EventLosePlayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -151,3 +156,28 @@ void cEnderman::EventLosePlayer()
|
|||||||
m_bIsScreaming = false;
|
m_bIsScreaming = false;
|
||||||
GetWorld()->BroadcastEntityMetadata(*this);
|
GetWorld()->BroadcastEntityMetadata(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
@ -19,12 +19,16 @@ public:
|
|||||||
|
|
||||||
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
|
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
|
||||||
virtual void CheckEventSeePlayer(void) override;
|
virtual void CheckEventSeePlayer(void) override;
|
||||||
|
virtual void CheckEventLostPlayer(void) override;
|
||||||
virtual void EventLosePlayer(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; }
|
||||||
NIBBLETYPE GetCarriedMeta(void) const {return CarriedMeta; }
|
NIBBLETYPE GetCarriedMeta(void) const {return CarriedMeta; }
|
||||||
|
|
||||||
|
/** Returns if the current sky light level is sufficient for the enderman to become aggravated */
|
||||||
|
bool CheckLight(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool m_bIsScreaming;
|
bool m_bIsScreaming;
|
||||||
|
@ -276,7 +276,9 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
if (DoesPosYRequireJump((int)floor(m_Destination.y)))
|
if (DoesPosYRequireJump((int)floor(m_Destination.y)))
|
||||||
{
|
{
|
||||||
m_bOnGround = false;
|
m_bOnGround = false;
|
||||||
AddSpeedY(5.2); // Jump!!
|
|
||||||
|
// TODO: Change to AddSpeedY once collision detection is fixed - currently, mobs will go into blocks attempting to jump without a teleport
|
||||||
|
AddPosY(1.2); // Jump!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user