More on the boss fight sytem, just a basic FSM going.

This commit is contained in:
Zed A. Shaw 2025-10-07 12:47:47 -04:00
parent a0861a8f57
commit f33e14f2cf
7 changed files with 91 additions and 32 deletions

View file

@ -1,4 +1,5 @@
#include "boss/fight.hpp"
#include "boss/system.hpp"
namespace boss {
Fight::Fight(shared_ptr<World> world, Entity boss_id) :
@ -10,33 +11,26 @@ namespace boss {
}
bool Fight::event(gui::Event ev, std::any data) {
// if the mouse event is handled the done, this may be wrong later
if(handle_mouse(ev)) return in_state(State::END);
switch($state) {
FSM_STATE(State, START, ev, data);
FSM_STATE(State, BOSS_TURN, ev, data);
FSM_STATE(State, PLAYER_TURN, ev, data);
FSM_STATE(State, END, ev, data);
}
return in_state(State::END);
}
void Fight::START(gui::Event ev, std::any data) {
bool Fight::handle_mouse(gui::Event ev) {
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});
}
@ -50,17 +44,79 @@ namespace boss {
case MOUSE_DROP:
dbc::log("mouse DROP");
break;
default:
return false;
}
// switch/default didn't happen so handled it.
return true;
}
void Fight::START(gui::Event ev, std::any data) {
(void)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 TICK:
$ui.run_systems();
run_systems();
break;
case ATTACK:
state(State::PLAYER_TURN);
break;
default:
fmt::println("BOSS_FIGHT unknown event {}", (int)ev);
}
}
void Fight::BOSS_TURN(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 ATTACK: {
int attack_id = std::any_cast<int>(data);
boss::System::combat(attack_id);
state(State::PLAYER_TURN);
} break;
default:
break;
// skip it
}
}
void Fight::PLAYER_TURN(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 ATTACK: {
int attack_id = std::any_cast<int>(data);
boss::System::combat(attack_id);
state(State::BOSS_TURN);
} break;
default:
// skip it
break;
}
}
void Fight::END(gui::Event ev, std::any data) {
// We need to clean up that world I think, but not sure how
(void)ev;
(void)data;
}
void Fight::run_systems() {
}
}