refactor: separate mob ans world listener

This commit is contained in:
2021-12-11 18:43:49 +01:00
parent a802b5cef5
commit 1474220a77
7 changed files with 38 additions and 21 deletions

View File

@@ -4,6 +4,8 @@
#include "Types.h"
#include "Team.h"
#include "misc/ObjectNotifier.h"
#include <vector>
#include <memory>
@@ -218,6 +220,18 @@ MobPtr createMob(MobID id, MobType type, std::uint8_t level, PlayerID sender);
std::string getMobName(MobType type);
}
class MobListener {
public:
virtual void OnMobSpawn(MobPtr mob) {}
virtual void OnMobDie(MobPtr mob) {}
virtual void OnMobDamage(MobPtr target, float damage, Tower* damager) {}
virtual void OnMobTouchCastle(MobPtr damager, TeamCastle* enemyCastle) {}
virtual void OnMobCastleDamage(MobPtr damager, TeamCastle* enemyCastle) {}
};
typedef utils::ObjectNotifier<MobListener> MobNotifier;
} // namespace game
} // namespace td

View File

@@ -10,8 +10,6 @@
#include "Mobs.h"
#include "Team.h"
#include "misc/ObjectNotifier.h"
namespace td {
namespace game {
typedef std::pair<std::int16_t, std::int16_t> ChunkCoord;
@@ -127,15 +125,11 @@ public:
virtual void OnArrowShot(MobPtr target, bool fire, Tower* shooter) {}
virtual void OnExplosion(utils::shape::Circle explosion, float centerDamage, Tower* shooter) {}
virtual void OnMobDamage(MobPtr target, float damage, Tower* damager) {}
virtual void OnMobDead(MobPtr mob) {}
};
typedef utils::ObjectNotifier<WorldListener> WorldNotifier;
class World : public WorldNotifier, public WorldListener {
class World : public WorldListener, public MobListener {
protected:
TowerTileColorPalette m_TowerPlacePalette;
Color m_WalkablePalette;
@@ -152,6 +146,9 @@ protected:
TowerList m_Towers;
Game* m_Game;
WorldNotifier m_WorldNotifier;
MobNotifier m_MobNotifier;
public:
World(Game* game);
@@ -211,6 +208,9 @@ public:
const TowerList& getTowers() const { return m_Towers; };
TowerPtr getTowerById(TowerID tower);
WorldNotifier& getWorldNotifier() { return m_WorldNotifier; }
MobNotifier& getMobNotifier() { return m_MobNotifier; }
// WorldListener
virtual void OnArcherTowerShot(MobPtr target, ArcherTower* shooter);
@@ -218,6 +218,8 @@ public:
virtual void OnArrowShot(MobPtr target, bool fire, Tower* shooter);
virtual void OnExplosion(utils::shape::Circle explosion, float centerDamage, Tower* shooter);
// MobListener
virtual void OnMobDamage(MobPtr target, float damage, Tower* source);
private:
void moveMobs(std::uint64_t delta);