1
0
cuberite-2a/src/BlockEntities/MobSpawnerEntity.h

99 lines
3.0 KiB
C
Raw Normal View History

2014-12-01 08:58:13 -05:00
// MobSpawnerEntity.h
// Declares the cMobSpawnerEntity class representing a single mob spawner in the world
2014-09-17 11:45:13 -04:00
#pragma once
#include "BlockEntity.h"
#include "../Entities/Player.h"
// tolua_begin
class cMobSpawnerEntity :
public cBlockEntity
{
// tolua_end
2016-02-05 16:45:45 -05:00
2020-04-13 12:38:06 -04:00
using Super = cBlockEntity;
public: // tolua_export
cMobSpawnerEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World);
2014-09-17 11:45:13 -04:00
2017-06-15 09:32:33 -04:00
// cBlockEntity overrides:
virtual void CopyFrom(const cBlockEntity & a_Src) override;
2014-09-19 17:00:54 -04:00
virtual void SendTo(cClientHandle & a_Client) override;
virtual bool UsedBy(cPlayer * a_Player) override;
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
2014-09-17 11:45:13 -04:00
// tolua_begin
/** Update the active flag from the mob spawner. This function will called every 5 seconds from the Tick() function. */
2014-09-19 17:00:54 -04:00
void UpdateActiveState(void);
/** Sets the spawn delay to a new random value. */
void ResetTimer(void);
/** Spawns the entity. This function automatically change the spawn delay! */
2014-09-19 17:00:54 -04:00
void SpawnEntity(void);
// Getters
int GetNearbyMonsterNum(eMonsterType a_EntityType);
2014-09-19 17:00:54 -04:00
int GetNearbyPlayersNum(void);
eMonsterType GetEntity(void) const { return m_Entity; }
short GetSpawnCount(void) const { return m_SpawnCount; }
short GetSpawnRange(void) const { return m_SpawnRange; }
short GetSpawnDelay(void) const { return m_SpawnDelay; }
short GetMinSpawnDelay(void) const { return m_MinSpawnDelay; }
short GetMaxSpawnDelay(void) const { return m_MaxSpawnDelay; }
short GetMaxNearbyEntities(void) const { return m_MaxNearbyEntities; }
short GetRequiredPlayerRange(void) const { return m_RequiredPlayerRange; }
// Setters
void SetEntity(eMonsterType a_EntityType) { m_Entity = a_EntityType; }
void SetSpawnDelay(short a_Delay) { m_SpawnDelay = a_Delay; }
void SetSpawnCount(short a_SpawnCount) { m_SpawnCount = a_SpawnCount; }
void SetSpawnRange(short a_SpawnRange) { m_SpawnRange = a_SpawnRange; }
void SetMinSpawnDelay(short a_Min) { m_MinSpawnDelay = a_Min; }
void SetMaxSpawnDelay(short a_Max) { m_MaxSpawnDelay = a_Max; }
void SetMaxNearbyEntities(short a_MaxNearbyEntities) { m_MaxNearbyEntities = a_MaxNearbyEntities; }
void SetRequiredPlayerRange(short a_RequiredPlayerRange) { m_RequiredPlayerRange = a_RequiredPlayerRange; }
2014-09-17 11:45:13 -04:00
// tolua_end
private:
2020-10-20 07:28:45 -04:00
2014-09-17 11:45:13 -04:00
/** The entity to spawn. */
2014-09-26 18:07:17 -04:00
eMonsterType m_Entity;
2014-09-17 11:45:13 -04:00
/** Time in ticks until the next entity spawns */
2014-11-18 09:33:41 -05:00
short m_SpawnDelay;
2014-09-17 11:45:13 -04:00
2014-09-19 17:00:54 -04:00
bool m_IsActive;
/** Number of entities the spawner tries to spawn each activation. */
short m_SpawnCount = 4;
/** Diameter of the square the new monsters are spawned in */
short m_SpawnRange = 8;
short m_MinSpawnDelay = 200;
short m_MaxSpawnDelay = 800;
/** Maximum amount of the same entity type in proximity. */
short m_MaxNearbyEntities = 6;
/** Maximum distance to player for activation */
short m_RequiredPlayerRange = 16;
2014-09-17 11:45:13 -04:00
} ; // tolua_end