Files are now in a src directory and I'm using a src/meson.build and tests/meson.build to specify what to build.
This commit is contained in:
parent
4778677647
commit
1d4ae911b9
108 changed files with 94 additions and 83 deletions
140
src/boss/system.cpp
Normal file
140
src/boss/system.cpp
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
#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("enemy_found", true);
|
||||
boss_ai.set_state("in_combat", true);
|
||||
boss_ai.set_state("tough_personality", true);
|
||||
boss_ai.set_state("health_good", true);
|
||||
|
||||
world.set<ai::EntityAI>(entity_id, boss_ai);
|
||||
}
|
||||
|
||||
shared_ptr<boss::Fight> System::create_bossfight() {
|
||||
// need to copy so we can clone it and keep things working, even
|
||||
// if we don't use things like map and lighting
|
||||
auto level = GameDB::current_level();
|
||||
dbc::check(level.world != nullptr, "Starter world for boss fights can't be null.");
|
||||
|
||||
level.world = GameDB::clone_load_world(level.world);
|
||||
|
||||
auto& config = level.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 = level.world->entity();
|
||||
components::configure_entity(*level.world, boss_id, boss_data["components"]);
|
||||
|
||||
initialize_actor_ai(*level.world, boss_id);
|
||||
dbc::check(level.world->has<ai::EntityAI>(boss_id), "boss doesn't have an AI");
|
||||
|
||||
initialize_actor_ai(*level.world, level.player);
|
||||
dbc::check(level.world->has<ai::EntityAI>(level.player), "player/host doesn't have an AI");
|
||||
|
||||
GameDB::register_level(level);
|
||||
|
||||
return make_shared<boss::Fight>(level.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) {
|
||||
// BUG: 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) {
|
||||
|
||||
fmt::println("COMBAT >>> enemy={}, wants_to={}, cost={}, host_state={}",
|
||||
int(action.enemy.entity), action.wants_to, action.cost, int(action.host_state));
|
||||
|
||||
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;
|
||||
|
||||
components::CombatResult result {
|
||||
.attacker=enemy.entity,
|
||||
.host_state=host_state,
|
||||
.player_did=0,
|
||||
.enemy_did=0
|
||||
};
|
||||
|
||||
switch(host_state) {
|
||||
case BattleHostState::agree:
|
||||
// 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:
|
||||
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");
|
||||
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<game::Event>(game::Event::COMBAT, enemy.entity, result);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue