123 lines
4.2 KiB
C++
123 lines
4.2 KiB
C++
#include "boss/system.hpp"
|
|
#include <fmt/core.h>
|
|
#include "components.hpp"
|
|
#include "game_level.hpp"
|
|
#include "ai.hpp"
|
|
#include "battle.hpp"
|
|
|
|
namespace boss {
|
|
using namespace components;
|
|
using namespace combat;
|
|
|
|
void System::load_config() {
|
|
fmt::println("load it");
|
|
}
|
|
|
|
void System::initialize_actor_ai(DinkyECS::World& world, DinkyECS::Entity entity_id) {
|
|
dbc::check(world.has<EnemyConfig>(entity_id), "boss doesn't have an AI EnemyConfig");
|
|
auto& config = world.get<EnemyConfig>(entity_id);
|
|
auto ai_start = ai::load_state(config.ai_start_name);
|
|
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("tough_personality", true);
|
|
boss_ai.set_state("detect_enemy", true);
|
|
|
|
world.set<ai::EntityAI>(entity_id, boss_ai);
|
|
}
|
|
|
|
shared_ptr<boss::Fight> System::create_bossfight() {
|
|
auto& level = GameDB::current_level();
|
|
auto prev_world = GameDB::current_world();
|
|
dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null.");
|
|
auto world = GameDB::clone_load_world(prev_world);
|
|
auto& config = prev_world->get_the<GameConfig>();
|
|
|
|
auto boss_names = config.bosses.keys();
|
|
auto& level_name = boss_names[level.index % boss_names.size()];
|
|
auto& boss_data = config.bosses[level_name];
|
|
|
|
auto boss_id = world->entity();
|
|
components::configure_entity(*world, boss_id, boss_data["components"]);
|
|
|
|
initialize_actor_ai(*world, boss_id);
|
|
dbc::check(world->has<ai::EntityAI>(boss_id), "boss doesn't have an AI");
|
|
|
|
initialize_actor_ai(*world, level.player);
|
|
dbc::check(world->has<ai::EntityAI>(level.player), "player/host doesn't have an AI");
|
|
|
|
return make_shared<boss::Fight>(world, boss_id, level.player);
|
|
}
|
|
|
|
BattleEngine System::create_battle(std::shared_ptr<DinkyECS::World> world, DinkyECS::Entity boss_id) {
|
|
auto& level = GameDB::current_level();
|
|
|
|
auto player_combat = world->get_if<Combat>(level.player);
|
|
dbc::check(player_combat != nullptr, "No Combat for player.");
|
|
|
|
auto boss_combat = world->get_if<Combat>(boss_id);
|
|
dbc::check(boss_combat != nullptr, "No Combat for Boss.");
|
|
|
|
// BUG: should I reset AP here?
|
|
player_combat->ap = player_combat->max_ap;
|
|
boss_combat->ap = boss_combat->max_ap;
|
|
|
|
auto boss_ai = world->get_if<ai::EntityAI>(boss_id);
|
|
dbc::check(boss_ai != nullptr, "boss doesn't have an AI");
|
|
|
|
auto host_ai = world->get_if<ai::EntityAI>(boss_id);
|
|
dbc::check(host_ai != nullptr, "host doesn't have an AI");
|
|
|
|
BattleEngine battle;
|
|
battle.add_enemy({boss_id, boss_ai, boss_combat, false});
|
|
battle.add_enemy({level.player, host_ai, player_combat, true});
|
|
|
|
battle.set_all("enemy_found", true);
|
|
battle.set_all("in_combat", true);
|
|
battle.set(boss_id, "tough_personality", true);
|
|
|
|
return battle;
|
|
}
|
|
|
|
void System::plan_battle(BattleEngine& battle, std::shared_ptr<DinkyECS::World> world, DinkyECS::Entity boss_id) {
|
|
// REFACTOR: make this loop the list of entities in the battle then
|
|
// use their world state to configure the plan
|
|
battle.plan();
|
|
}
|
|
|
|
void System::combat(BattleResult& action, std::shared_ptr<DinkyECS::World> world, DinkyECS::Entity boss_id, int attack_id) {
|
|
|
|
auto& level = GameDB::current_level();
|
|
auto& player_combat = world->get<Combat>(level.player);
|
|
auto& boss_combat = world->get<Combat>(boss_id);
|
|
|
|
auto& [enemy, wants_to, cost, host_state] = action;
|
|
|
|
Events::Combat result{};
|
|
|
|
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);
|
|
break;
|
|
case BattleHostState::not_host:
|
|
dbc::log("kill_enemy");
|
|
if(wants_to == "kill_enemy") {
|
|
result.enemy_did = enemy.combat->attack(player_combat);
|
|
}
|
|
break;
|
|
case BattleHostState::out_of_ap:
|
|
fmt::println("OUT OF AP {}", wants_to);
|
|
break;
|
|
}
|
|
|
|
world->send<Events::GUI>(Events::GUI::COMBAT, enemy.entity, result);
|
|
}
|
|
}
|