#include "boss/fight.hpp" #include "boss/system.hpp" #include "animation.hpp" namespace boss { Fight::Fight(shared_ptr world, Entity boss_id, Entity player_id) : $world(world), $boss_id(boss_id), $battle(System::create_battle($world, $boss_id)), $ui(world, boss_id, player_id) { $ui.init(); } 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); } run_systems(); return in_state(State::END); } bool Fight::handle_mouse(gui::Event ev) { using enum gui::Event; switch(ev) { case MOUSE_CLICK: { $ui.mouse(mouse_pos.x, mouse_pos.y, guecs::NO_MODS); } break; case MOUSE_MOVE: { $ui.mouse(mouse_pos.x, mouse_pos.y, {1 << guecs::ModBit::hover}); } break; case MOUSE_DRAG: dbc::log("mouse drag"); break; case MOUSE_DRAG_START: dbc::log("mouse START drag"); break; 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 KEY_PRESS: fmt::println("KEY_PRESS"); break; case ATTACK: $ui.status(L"PLAYER TURN"); state(State::PLAYER_TURN); break; case TICK: break; // ignore tick default: fmt::println("BOSS_FIGHT:START unknown event {}", (int)ev); break; } } 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 KEY_PRESS: fmt::println("KEY_PRESS"); break; case ATTACK: { int attack_id = std::any_cast(data); fmt::println("Player attack: {}", attack_id); $ui.status(L"PLAYER TURN"); const std::string& player_pos = run % 10 < 5 ? "player1" : "player2"; $ui.move_actor("player", player_pos); boss::System::plan_battle($battle, $world, $boss_id); while(auto action = $battle.next()) { fmt::println("*** combat turn run: eid={}", action->enemy.entity); boss::System::combat(*action, $world, $boss_id, attack_id); } $ui.update_stats(); state(State::PLAYER_TURN); } break; case TICK: break; // ignore tick default: fmt::println("BOSS_FIGHT:BOSS_TURN unknown event {}", (int)ev); break; } } 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 KEY_PRESS: fmt::println("KEY_PRESS"); break; case ATTACK: { $ui.status(L"BOSS TURN"); const std::string &boss_at = run % 10 < 5 ? "boss5" : "boss6"; $ui.move_actor("boss", boss_at); $ui.animate_actor("boss"); int attack_id = std::any_cast(data); state(State::BOSS_TURN); } break; case TICK: break; // ignore tick default: fmt::println("BOSS_FIGHT:PLAYER_TURN unknown event {}", (int)ev); break; } } void Fight::END(gui::Event ev, std::any) { fmt::println("BOSS_FIGHT:END event {}", (int)ev); } void Fight::run_systems() { run++; } void Fight::render(sf::RenderWindow& window) { window.clear(); $ui.play_animations(); $ui.render(window); } }