Peoplemon  0.1.0
Peoplemon 3 game source documentation
WildPeoplemon.cpp
Go to the documentation of this file.
2 
3 #include <BLIB/Util/Random.hpp>
8 #include <Core/Maps/Map.hpp>
9 #include <Core/Properties.hpp>
10 #include <Core/Systems/Systems.hpp>
11 
12 namespace core
13 {
14 namespace system
15 {
16 namespace
17 {
18 const pplmn::WildPeoplemon DebugWild{
19  .id = pplmn::Id::BenToo, .minLevel = 5, .maxLevel = 25, .frequency = 0};
20 }
21 
23 : owner(o) {}
24 
25 void WildPeoplemon::init() { bl::event::Dispatcher::subscribe(this); }
26 
28  currentWild = DebugWild.generate();
29  startBattle();
30 }
31 
32 void WildPeoplemon::observe(const event::EntityMoveFinished& m) {
33  if (m.entity == owner.player().player() && owner.player().state().repelSteps == 0) {
34  const map::CatchRegion* region = owner.world().activeMap().getCatchRegion(m.position);
35  if (region &&
36  bl::util::Random::get<unsigned int>(0, 100) < Properties::WildPeoplemonChance()) {
37  BL_LOG_INFO << "Starting wild battle";
38  currentWild = region->selectWild().generate();
39 
40  startBattle();
41  }
42  }
43 }
44 
45 void WildPeoplemon::startBattle() {
46  std::unique_ptr<battle::Battle> battle =
48  owner.world().activeMap().getLocationName(owner.player().position()),
49  owner.player(),
51  std::vector<pplmn::BattlePeoplemon> team;
52  team.emplace_back(&currentWild);
53 
54  battle->state.enemy().init(
55  std::move(team),
56  std::make_unique<battle::AIController>(currentWild.name(), std::vector<item::Id>{}));
57  battle->setController(std::make_unique<battle::LocalBattleController>());
58 
59  bl::event::Dispatcher::dispatch<event::BattleStarted>({std::move(battle)});
60 }
61 
62 } // namespace system
63 } // namespace core
Core classes and functionality for both the editor and game.
static std::unique_ptr< Battle > create(bl::engine::Engine &engine, const std::string &location, system::Player &player, Type type)
Creates the battle struct and initializes the player battler.
Definition: Battle.cpp:42
Fired when an entity completes a move from one tile to another.
Definition: EntityMoved.hpp:52
const bl::ecs::Entity entity
The entity that moved.
Definition: EntityMoved.hpp:54
const bl::tmap::Position & position
The current position of the entity.
Definition: EntityMoved.hpp:57
Represents a class of catchable peoplemon.
Definition: CatchRegion.hpp:18
const pplmn::WildPeoplemon & selectWild() const
Selects a wild peoplemon from the set based on frequency, or returns a level 100 Ben if the set is em...
Definition: CatchRegion.cpp:16
const CatchRegion * getCatchRegion(const bl::tmap::Position &position) const
Returns the catch region at the given position if the position is on a catch tile.
Definition: Map.cpp:567
const std::string & getLocationName(const bl::tmap::Position &pos) const
Returns the name of the town or route at the given position.
Definition: Map.cpp:610
const std::string & name() const
Returns the name of this peoplemon, custom or defualt.
OwnedPeoplemon generate() const
Generate an OwnedPeoplemon from the template.
unsigned int repelSteps
Definition: State.hpp:54
static unsigned int WildPeoplemonChance()
Definition: Properties.cpp:678
player::State & state()
Returns the state of the player.
Definition: Player.cpp:154
const bl::tmap::Position & position() const
Returns the current position of the player.
Definition: Player.cpp:57
bl::ecs::Entity player() const
Returns the id of the player entity.
Definition: Player.cpp:55
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47
const bl::engine::Engine & engine() const
Const accessor for the Engine.
Definition: Systems.cpp:35
Player & player()
Returns the player system.
Definition: Systems.cpp:59
World & world()
Modifiable accessor for the world system.
Definition: Systems.cpp:43
void init()
Subscribes to the game event bus.
void startDebugBattle()
Starts a wild Peoplemon battle for debugging.
WildPeoplemon(Systems &owner)
Construct a new Wild Peoplemon system.
map::Map & activeMap()
Returns a reference to the active map.
Definition: World.cpp:84