86 lines
2.9 KiB
C++
86 lines
2.9 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& 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.set_all("enemy_found", true);
|
|
battle.set_all("in_combat", true);
|
|
battle.plan();
|
|
|
|
while(auto act = battle.next()) {
|
|
auto [enemy, ai_action, enemy_action] = *act;
|
|
|
|
Events::Combat result {
|
|
player_combat.attack(*enemy.combat), 0
|
|
};
|
|
|
|
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.");
|
|
}
|
|
|
|
if(enemy_action == combat::BattleAction::ATTACK) {
|
|
result.enemy_did = enemy.combat->attack(player_combat);
|
|
}
|
|
|
|
// need to replicate this in the boss UI
|
|
world->send<Events::GUI>(Events::GUI::COMBAT, enemy.entity, result);
|
|
}
|
|
}
|
|
}
|