Refactored boss fight to pull out the FSM code into boss::Fight.
This commit is contained in:
parent
3b11ed0a75
commit
61a40ae7cd
11 changed files with 127 additions and 94 deletions
55
boss/fight.cpp
Normal file
55
boss/fight.cpp
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include "boss/fight.hpp"
|
||||
|
||||
namespace boss {
|
||||
Fight::Fight(shared_ptr<World> world, Entity boss_id) :
|
||||
$world(world),
|
||||
$boss_id(boss_id),
|
||||
$ui(world, boss_id)
|
||||
{
|
||||
$ui.init();
|
||||
}
|
||||
|
||||
bool Fight::event(gui::Event ev, std::any data) {
|
||||
switch($state) {
|
||||
FSM_STATE(State, START, ev, data);
|
||||
FSM_STATE(State, END, ev, data);
|
||||
}
|
||||
|
||||
return in_state(State::END);
|
||||
}
|
||||
|
||||
void Fight::START(gui::Event ev, std::any data) {
|
||||
using enum gui::Event;
|
||||
|
||||
switch(ev) {
|
||||
// this is only if using the debug X key to skip it
|
||||
case BOSS_START:
|
||||
state(State::END);
|
||||
break;
|
||||
case MOUSE_CLICK: {
|
||||
$ui.mouse(mouse_pos.x, mouse_pos.y, guecs::NO_MODS);
|
||||
|
||||
if($ui.boss_dead()) {
|
||||
state(State::END);
|
||||
}
|
||||
} break;
|
||||
case ATTACK: {
|
||||
int attack_id = std::any_cast<int>(data);
|
||||
$ui.attack(attack_id);
|
||||
} break;
|
||||
case MOUSE_MOVE: {
|
||||
$ui.mouse(mouse_pos.x, mouse_pos.y, {1 << guecs::ModBit::hover});
|
||||
} break;
|
||||
case TICK:
|
||||
$ui.run_systems();
|
||||
break;
|
||||
default:
|
||||
fmt::println("BOSS_FIGHT unknown event {}", (int)ev);
|
||||
}
|
||||
}
|
||||
|
||||
void Fight::END(gui::Event ev, std::any data) {
|
||||
(void)ev;
|
||||
(void)data;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue