Peoplemon  0.1.0
Peoplemon 3 game source documentation
Trainers.hpp
Go to the documentation of this file.
1 #ifndef CORE_SYSTEMS_TRAINERS_HPP
2 #define CORE_SYSTEMS_TRAINERS_HPP
3 
4 #include <BLIB/Audio/AudioSystem.hpp>
5 #include <BLIB/ECS.hpp>
6 #include <BLIB/Engine/System.hpp>
7 #include <BLIB/Events.hpp>
8 #include <BLIB/Resources.hpp>
9 #include <BLIB/Tilemap/Position.hpp>
12 #include <Core/Events/Battle.hpp>
14 #include <Core/Events/GameSave.hpp>
15 #include <SFML/Graphics.hpp>
16 
17 namespace core
18 {
19 namespace system
20 {
21 class Systems;
22 
28 class Trainers
29 : public bl::engine::System
30 , bl::event::Listener<event::GameSaveInitializing,
31  bl::ecs::event::ComponentAdded<component::Trainer>, event::BattleCompleted,
32  event::EntityMoveFinished, event::EntityRotated> {
33 public:
39  Trainers(Systems& owner);
40 
44  virtual ~Trainers() = default;
45 
51  bl::ecs::Entity approachingTrainer() const;
52 
56  void resetDefeated();
57 
64  bool trainerDefeated(const component::Trainer& trainer) const;
65 
71  void setDefeated(component::Trainer& trainer);
72 
73 private:
74  enum struct State { Searching, PoppingUp, Holding, Rising, Walking, Battling };
75 
76  Systems& owner;
77  bl::ecs::ComponentPool<component::Trainer>& trainerPool;
78  bl::rc::res::TextureRef exclaimTxtr;
79  bl::gfx::Sprite exclaim;
80  bl::audio::AudioSystem::Handle exclaimSound;
81  float height;
82 
83  State state;
84  bl::ecs::Entity walkingTrainer;
85  component::Trainer* trainerComponent;
86  const bl::tmap::Position* trainerPos;
87  component::Movable* trainerMove;
88 
89  std::unordered_set<std::string> defeated;
90 
91  virtual void update(std::mutex& stageMutex, float dt, float realDt, float residual,
92  float realResidual) override;
93  virtual void init(bl::engine::Engine&) override;
94 
95  virtual void observe(const event::GameSaveInitializing& save) override;
96  virtual void observe(const bl::ecs::event::ComponentAdded<component::Trainer>& tc) override;
97  virtual void observe(const event::BattleCompleted& event) override;
98  virtual void observe(const event::EntityMoveFinished& moved) override;
99  virtual void observe(const event::EntityRotated& rotated) override;
100 
101  void checkTrainer(bl::ecs::Entity ent, component::Trainer& trainer);
102  void cleanup();
103 };
104 
105 } // namespace system
106 } // namespace core
107 
108 #endif
Core classes and functionality for both the editor and game.
Adding this component to an entity will allow it to move.
Definition: Movable.hpp:26
Adding this to an entity will make it a trainer that can battle.
Definition: Trainer.hpp:18
Fired when a battle finishes.
Definition: Battle.hpp:36
Fired when an entity completes a move from one tile to another.
Definition: EntityMoved.hpp:52
Fired when an entity rotates without moving.
Definition: EntityMoved.hpp:76
Fired when the game is saving or loading. Allows systems to hook in their data.
Definition: GameSave.hpp:22
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47
This system manages trainers. It handles their vision and makes them walk up to the player.
Definition: Trainers.hpp:32
virtual ~Trainers()=default
Destroys the system.
void resetDefeated()
Resets the list of defeated trainers.
Definition: Trainers.cpp:200
bl::ecs::Entity approachingTrainer() const
Returns the trainer currently approaching the player.
Definition: Trainers.cpp:105
bool trainerDefeated(const component::Trainer &trainer) const
Checks whether or not the given trainer has been defeated.
Definition: Trainers.cpp:107
void setDefeated(component::Trainer &trainer)
Sets the given trainer as having been defeated and updates the game save data.
Definition: Trainers.cpp:111
Trainers(Systems &owner)
Construct a new Trainers system.
Definition: Trainers.cpp:21