[BREAKING] Battle system now runs the turn based combat better, and lots of interesting things like if you don't choose an action the host AI rebels and does it for you.
This commit is contained in:
parent
9739441a9c
commit
986b2612d4
9 changed files with 100 additions and 32 deletions
|
|
@ -1,4 +1,3 @@
|
|||
#define FSM_DEBUG 1
|
||||
#include "boss/fight.hpp"
|
||||
#include "boss/system.hpp"
|
||||
#include "animation.hpp"
|
||||
|
|
@ -9,7 +8,8 @@ namespace boss {
|
|||
$boss_id(boss_id),
|
||||
$battle(System::create_battle($world, $boss_id)),
|
||||
$ui(world, boss_id, player_id),
|
||||
$player_id(player_id)
|
||||
$host(player_id),
|
||||
$host_combat($world->get<components::Combat>(player_id))
|
||||
{
|
||||
$ui.init();
|
||||
}
|
||||
|
|
@ -31,8 +31,7 @@ namespace boss {
|
|||
return in_state(State::END);
|
||||
}
|
||||
|
||||
void Fight::START(gui::Event ev, std::any data) {
|
||||
(void)data;
|
||||
void Fight::START(gui::Event ev, std::any) {
|
||||
using enum gui::Event;
|
||||
|
||||
switch(ev) {
|
||||
|
|
@ -42,6 +41,7 @@ namespace boss {
|
|||
break;
|
||||
case TICK:
|
||||
$ui.status(L"PLAYER REQUESTS");
|
||||
$battle.ap_refresh();
|
||||
state(State::PLAYER_REQUESTS);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -58,8 +58,18 @@ namespace boss {
|
|||
state(State::END);
|
||||
break;
|
||||
case START_COMBAT:
|
||||
System::plan_battle($battle, $world, $boss_id);
|
||||
$ui.status(L"PLANNING BATTLE");
|
||||
state(State::PLAN_BATTLE);
|
||||
break;
|
||||
case ATTACK:
|
||||
if($battle.player_request("kill_enemy")) {
|
||||
fmt::println("player requests kill_enemy {} vs. {}",
|
||||
$host_combat.ap, $battle.player_pending_ap());
|
||||
} else {
|
||||
fmt::println("NO MORE ACTION!");
|
||||
}
|
||||
break;
|
||||
case TICK:
|
||||
break; // ignore tick
|
||||
default:
|
||||
|
|
@ -77,6 +87,10 @@ namespace boss {
|
|||
break;
|
||||
case START_COMBAT:
|
||||
$ui.status(L"EXEC PLAN");
|
||||
while(auto action = $battle.next()) {
|
||||
System::combat(*action, $world, $boss_id, 0);
|
||||
run_systems();
|
||||
}
|
||||
state(State::EXEC_PLAN);
|
||||
break;
|
||||
case TICK:
|
||||
|
|
@ -100,6 +114,8 @@ namespace boss {
|
|||
state(State::END);
|
||||
} else {
|
||||
$ui.status(L"PLAYER REQUESTS");
|
||||
$battle.ap_refresh();
|
||||
$battle.clear_requests();
|
||||
state(State::PLAYER_REQUESTS);
|
||||
}
|
||||
break; // ignore tick
|
||||
|
|
@ -113,7 +129,10 @@ namespace boss {
|
|||
}
|
||||
|
||||
void Fight::run_systems() {
|
||||
run++;
|
||||
$ui.update_stats();
|
||||
$battle.set($host, "tough_personality", false);
|
||||
$battle.set($host, "have_healing", false);
|
||||
$battle.set($host, "health_good", $host_combat.hp > 20);
|
||||
}
|
||||
|
||||
void Fight::render(sf::RenderWindow& window) {
|
||||
|
|
@ -150,7 +169,11 @@ namespace boss {
|
|||
}
|
||||
|
||||
bool Fight::player_dead() {
|
||||
auto& combat = $world->get<components::Combat>($player_id);
|
||||
return combat.hp <= 0;
|
||||
return $host_combat.hp <= 0;
|
||||
}
|
||||
|
||||
void Fight::init_fight() {
|
||||
System::initialize_actor_ai(*$world, $boss_id);
|
||||
run_systems();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ namespace boss {
|
|||
combat::BattleEngine $battle;
|
||||
boss::UI $ui;
|
||||
sf::Vector2f mouse_pos{0,0};
|
||||
Entity $player_id = NONE;
|
||||
int run = 0;
|
||||
Entity $host = NONE;
|
||||
components::Combat& $host_combat;
|
||||
|
||||
Fight(shared_ptr<World> world, Entity boss_id, Entity player_id);
|
||||
|
||||
|
|
@ -44,5 +44,6 @@ namespace boss {
|
|||
|
||||
void run_systems();
|
||||
bool player_dead();
|
||||
void init_fight();
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@ namespace boss {
|
|||
auto ai_goal = ai::load_state(config.ai_goal_name);
|
||||
|
||||
ai::EntityAI boss_ai(config.ai_script, ai_start, ai_goal);
|
||||
boss_ai.set_state("enemy_found", true);
|
||||
boss_ai.set_state("in_combat", true);
|
||||
boss_ai.set_state("tough_personality", true);
|
||||
boss_ai.set_state("detect_enemy", true);
|
||||
boss_ai.set_state("health_good", true);
|
||||
|
||||
world.set<ai::EntityAI>(entity_id, boss_ai);
|
||||
}
|
||||
|
|
@ -97,15 +99,17 @@ namespace boss {
|
|||
|
||||
switch(host_state) {
|
||||
case BattleHostState::agree:
|
||||
dbc::log("host_agrees");
|
||||
// BUG: this is hard coding only one boss, how to select targets?
|
||||
if(wants_to == "kill_enemy") {
|
||||
result.player_did = player_combat.attack(boss_combat);
|
||||
}
|
||||
break;
|
||||
case BattleHostState::disagree:
|
||||
dbc::log("host_DISagrees");
|
||||
fmt::println("HOST DISAGREES! {}", wants_to);
|
||||
|
||||
if(wants_to == "kill_enemy") {
|
||||
result.player_did = player_combat.attack(boss_combat);
|
||||
}
|
||||
break;
|
||||
case BattleHostState::not_host:
|
||||
dbc::log("kill_enemy");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue