107 lines
3.8 KiB
C++
107 lines
3.8 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;
|
|
|
|
void System::load_config() {
|
|
fmt::println("load it");
|
|
}
|
|
|
|
void System::initialize_boss_ai(DinkyECS::World& world, DinkyECS::Entity boss_id) {
|
|
dbc::check(world.has<EnemyConfig>(boss_id), "boss doesn't have an AI EnemyConfig");
|
|
auto& config = world.get<EnemyConfig>(boss_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>(boss_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_boss_ai(*world, boss_id);
|
|
|
|
dbc::check(world->has<ai::EntityAI>(boss_id), "boss doesn't have an AI");
|
|
|
|
return make_shared<boss::Fight>(world, boss_id, level.player);
|
|
}
|
|
|
|
void System::combat(std::shared_ptr<DinkyECS::World> world, DinkyECS::Entity boss_id, int attack_id) {
|
|
// get the player from the previous level, but should I just make the boss fights a level?
|
|
auto& level = GameDB::current_level();
|
|
dbc::check(world->has<ai::EntityAI>(boss_id), "boss doesn't have an AI");
|
|
|
|
auto host_start = ai::load_state("Host::initial_state");
|
|
auto host_goal = ai::load_state("Host::final_state");
|
|
ai::EntityAI host_ai("Host::actions", host_start, host_goal);
|
|
|
|
auto& player_combat = world->get<Combat>(level.player);
|
|
auto& boss_combat = world->get<Combat>(boss_id);
|
|
auto& boss_ai = world->get<ai::EntityAI>(boss_id);
|
|
|
|
combat::BattleEngine battle;
|
|
battle.add_enemy({boss_id, &boss_ai, &boss_combat});
|
|
battle.add_enemy({level.player, &host_ai, &player_combat});
|
|
|
|
battle.set_all("enemy_found", true);
|
|
battle.set_all("in_combat", true);
|
|
battle.set(boss_id, "tough_personality", true);
|
|
battle.set(level.player, "tough_personality", false);
|
|
battle.set(level.player, "have_healing", false);
|
|
battle.set(level.player, "health_good", player_combat.hp > 20);
|
|
|
|
battle.player_request("kill_enemy");
|
|
|
|
battle.plan();
|
|
|
|
while(auto act = battle.next()) {
|
|
auto [enemy, wants_to, cost, host_state] = *act;
|
|
Events::Combat result{};
|
|
|
|
switch(host_state) {
|
|
case combat::BattleHostState::agree:
|
|
result.player_did = player_combat.attack(*enemy.combat);
|
|
break;
|
|
case combat::BattleHostState::disagree:
|
|
fmt::println("HOST DISAGREES! {}", wants_to);
|
|
break;
|
|
case combat::BattleHostState::not_host:
|
|
if(wants_to == "kill_enemy") {
|
|
result.enemy_did = enemy.combat->attack(player_combat);
|
|
}
|
|
break;
|
|
case combat::BattleHostState::out_of_ap:
|
|
fmt::println("OUT OF AP {}", wants_to);
|
|
break;
|
|
}
|
|
|
|
if(result.player_did > 0) {
|
|
auto& the_belt = world->get_the<ritual::Belt>();
|
|
dbc::check(the_belt.has(attack_id), "STOP passing invalid attack IDs to the system.");
|
|
}
|
|
|
|
// need to replicate this in the boss UI
|
|
world->send<Events::GUI>(Events::GUI::COMBAT, enemy.entity, result);
|
|
}
|
|
}
|
|
}
|