From c0711407e96353e14bfa41f17db4e45c43f8ebb9 Mon Sep 17 00:00:00 2001 From: 12xx12 <44411062+12xx12@users.noreply.github.com> Date: Sat, 10 Oct 2020 21:31:44 +0200 Subject: Adding more customize options to mob spawners and improving the way to look for surrounding entities (#4955) * added nearly any customize option * fixed unnecessary diff added comments * removed unnecessary const qualifier * fixed build * changed to ForEachEntityInBox * added docs * updated lua api description * checkstyle * added changes suggested by @peterbell10 And now the player may break the server by setting ridiculous ranges * updated docs changed cast to static cast * fixed clang * fixed clang on WSSAnvil.cpp Co-authored-by: 12xx12 <12xx12100@gmail.com> --- src/BlockEntities/MobSpawnerEntity.h | 60 ++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 19 deletions(-) (limited to 'src/BlockEntities/MobSpawnerEntity.h') diff --git a/src/BlockEntities/MobSpawnerEntity.h b/src/BlockEntities/MobSpawnerEntity.h index 0d1991e87..a037343f4 100644 --- a/src/BlockEntities/MobSpawnerEntity.h +++ b/src/BlockEntities/MobSpawnerEntity.h @@ -33,46 +33,68 @@ public: // tolua_export virtual bool UsedBy(cPlayer * a_Player) override; virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + static const char * GetClassStatic(void) { return "cMobSpawnerEntity"; } // tolua_begin - /** Upate the active flag from the mob spawner. This function will called every 5 seconds from the Tick() function. */ + /** Update the active flag from the mob spawner. This function will called every 5 seconds from the Tick() function. */ void UpdateActiveState(void); /** Sets the spawn delay to a new random value. */ void ResetTimer(void); - /** Spawns the entity. This function automaticly change the spawn delay! */ + /** Spawns the entity. This function automatically change the spawn delay! */ void SpawnEntity(void); - /** Returns the entity type that will be spawn by this mob spawner. */ - eMonsterType GetEntity(void) const { return m_Entity; } - - /** Sets the entity type who will be spawn by this mob spawner. */ - void SetEntity(eMonsterType a_EntityType) { m_Entity = a_EntityType; } - - /** Returns the spawn delay. This is the tick delay that is needed to spawn new monsters. */ - short GetSpawnDelay(void) const { return m_SpawnDelay; } - - /** Sets the spawn delay. */ - void SetSpawnDelay(short a_Delay) { m_SpawnDelay = a_Delay; } - - /** Returns the amount of the nearby players in a 16-block radius. */ + // Getters + int GetNearbyMonsterNum(eMonsterType a_EntityType); int GetNearbyPlayersNum(void); - /** Returns the amount of this monster type in a 8-block radius (Y: 4-block radius). */ - int GetNearbyMonsterNum(eMonsterType a_EntityType); + 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; } // tolua_end - static const char * GetClassStatic(void) { return "cMobSpawnerEntity"; } - private: /** The entity to spawn. */ eMonsterType m_Entity; + /** Time in ticks until the next entity spawns */ short m_SpawnDelay; 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; + } ; // tolua_end -- cgit v1.2.3