Now have enough state to show what's going on in the fight, next is to use graphics and stuff to make it better.
This commit is contained in:
parent
a8863cf687
commit
f50e713179
9 changed files with 55 additions and 16 deletions
|
|
@ -74,11 +74,10 @@ namespace combat {
|
||||||
host_state = $player_requests.contains(action.name) ? agree : disagree;
|
host_state = $player_requests.contains(action.name) ? agree : disagree;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(host_state == out_of_ap) {
|
if(host_state != out_of_ap) {
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
enemy.combat->ap -= action.cost;
|
enemy.combat->ap -= action.cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pending_actions.emplace_back(enemy, action.name, action.cost, host_state);
|
$pending_actions.emplace_back(enemy, action.name, action.cost, host_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,19 +116,29 @@ namespace boss {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fight::do_combat(std::any data) {
|
void Fight::do_combat(std::any data) {
|
||||||
|
using combat::BattleHostState;
|
||||||
|
|
||||||
dbc::check(data.type() == typeid(components::CombatResult),
|
dbc::check(data.type() == typeid(components::CombatResult),
|
||||||
fmt::format("Boss Fight received any data={}", data.type().name()));
|
fmt::format("Boss Fight wrong any data={}", data.type().name()));
|
||||||
|
|
||||||
auto result = std::any_cast<components::CombatResult>(data);
|
auto result = std::any_cast<components::CombatResult>(data);
|
||||||
|
|
||||||
$ui.zoom("", 1.0);
|
switch(result.host_state) {
|
||||||
std::string boss_move = Random::uniform(0, 1) == 0 ? "boss5" : "boss6";
|
case BattleHostState::agree:
|
||||||
|
case BattleHostState::disagree: {
|
||||||
std::string player_move = Random::uniform(0, 1) == 0 ? "player1" : "player3";
|
std::string player_move = Random::uniform(0, 1) == 0 ? "player1" : "player3";
|
||||||
$ui.move_actor("player", player_move);
|
$ui.move_actor("player", player_move);
|
||||||
$ui.move_actor("boss", boss_move);
|
|
||||||
|
|
||||||
$ui.damage("player", result.enemy_did);
|
|
||||||
$ui.damage("boss", result.player_did);
|
$ui.damage("boss", result.player_did);
|
||||||
|
} break;
|
||||||
|
case BattleHostState::not_host: {
|
||||||
|
std::string boss_move = Random::uniform(0, 1) == 0 ? "boss5" : "boss6";
|
||||||
|
$ui.move_actor("boss", boss_move);
|
||||||
|
$ui.damage("player", result.enemy_did);
|
||||||
|
} break;
|
||||||
|
case BattleHostState::out_of_ap:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fight::END(game::Event ev, std::any) {
|
void Fight::END(game::Event ev, std::any) {
|
||||||
|
|
|
||||||
|
|
@ -94,13 +94,21 @@ namespace boss {
|
||||||
|
|
||||||
void System::combat(BattleResult& action, std::shared_ptr<DinkyECS::World> world, DinkyECS::Entity boss_id, int attack_id) {
|
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& level = GameDB::current_level();
|
||||||
auto& player_combat = world->get<Combat>(level.player);
|
auto& player_combat = world->get<Combat>(level.player);
|
||||||
auto& boss_combat = world->get<Combat>(boss_id);
|
auto& boss_combat = world->get<Combat>(boss_id);
|
||||||
|
|
||||||
auto& [enemy, wants_to, cost, host_state] = action;
|
auto& [enemy, wants_to, cost, host_state] = action;
|
||||||
|
|
||||||
components::CombatResult result{};
|
components::CombatResult result {
|
||||||
|
.attacker=enemy.entity,
|
||||||
|
.host_state=host_state,
|
||||||
|
.player_did=0,
|
||||||
|
.enemy_did=0
|
||||||
|
};
|
||||||
|
|
||||||
switch(host_state) {
|
switch(host_state) {
|
||||||
case BattleHostState::agree:
|
case BattleHostState::agree:
|
||||||
|
|
|
||||||
|
|
@ -105,11 +105,16 @@ namespace boss {
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::damage(const std::string& actor, int amount) {
|
void UI::damage(const std::string& actor, int amount) {
|
||||||
|
auto& config = $arena.actor_config(actor);
|
||||||
|
|
||||||
if(amount == 0) {
|
if(amount == 0) {
|
||||||
$arena.$ui.show_text("boss7", fmt::format(L"{} MISSED!", guecs::to_wstring(actor)));
|
$arena.$ui.show_text(config.cell,
|
||||||
|
fmt::format(L"{} MISSED!", guecs::to_wstring(actor)));
|
||||||
} else {
|
} else {
|
||||||
$arena.$ui.show_text("boss7", fmt::format(L"{} HIT {}!", guecs::to_wstring(actor), amount));
|
$arena.$ui.show_text(config.cell,
|
||||||
|
fmt::format(L"{} HIT {}!", guecs::to_wstring(actor), amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::zoom(const std::string &cell_name, double ratio) {
|
void UI::zoom(const std::string &cell_name, double ratio) {
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,17 @@
|
||||||
#include "json_mods.hpp"
|
#include "json_mods.hpp"
|
||||||
#include "goap.hpp"
|
#include "goap.hpp"
|
||||||
|
|
||||||
|
namespace combat {
|
||||||
|
enum class BattleHostState;
|
||||||
|
}
|
||||||
|
|
||||||
namespace components {
|
namespace components {
|
||||||
using std::string;
|
using std::string;
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
|
|
||||||
struct CombatResult {
|
struct CombatResult {
|
||||||
|
DinkyECS::Entity attacker;
|
||||||
|
combat::BattleHostState host_state;
|
||||||
int player_did = 0;
|
int player_did = 0;
|
||||||
int enemy_did = 0;
|
int enemy_did = 0;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ if build_machine.system() == 'windows'
|
||||||
'-static-libgcc',
|
'-static-libgcc',
|
||||||
'-static-libstdc++',
|
'-static-libstdc++',
|
||||||
'-static',
|
'-static',
|
||||||
|
'-flto',
|
||||||
language: 'cpp',
|
language: 'cpp',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,12 @@ namespace scene {
|
||||||
if(DEBUG) $ui.debug_layout(window);
|
if(DEBUG) $ui.debug_layout(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Element& Engine::actor_config(const std::string& actor) {
|
||||||
|
return $actors.at($actor_name_ids.at(actor));
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::move_actor(const std::string& actor, const std::string& cell_name) {
|
void Engine::move_actor(const std::string& actor, const std::string& cell_name) {
|
||||||
auto& config = $actors.at($actor_name_ids.at(actor));
|
auto& config = actor_config(actor);
|
||||||
config.cell = cell_name;
|
config.cell = cell_name;
|
||||||
config.pos = position_sprite(config.st, config.cell, config.scale_x, config.scale_y, config.at_mid);
|
config.pos = position_sprite(config.st, config.cell, config.scale_x, config.scale_y, config.at_mid);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,5 +43,6 @@ namespace scene {
|
||||||
void move_actor(const std::string& actor, const std::string& cell_name);
|
void move_actor(const std::string& actor, const std::string& cell_name);
|
||||||
void animate_actor(const std::string& actor);
|
void animate_actor(const std::string& actor);
|
||||||
void play_animations();
|
void play_animations();
|
||||||
|
Element& actor_config(const std::string& actor);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -262,10 +262,15 @@ void System::combat(int attack_id) {
|
||||||
|
|
||||||
while(auto act = battle.next()) {
|
while(auto act = battle.next()) {
|
||||||
auto [enemy, enemy_action, cost, host_state] = *act;
|
auto [enemy, enemy_action, cost, host_state] = *act;
|
||||||
|
|
||||||
|
// player shouldn't hit theirself
|
||||||
if(host_state != BattleHostState::not_host) continue;
|
if(host_state != BattleHostState::not_host) continue;
|
||||||
|
|
||||||
components::CombatResult result {
|
components::CombatResult result {
|
||||||
player_combat.attack(*enemy.combat), 0
|
.attacker=enemy.entity,
|
||||||
|
.host_state=host_state,
|
||||||
|
.player_did=player_combat.attack(*enemy.combat),
|
||||||
|
.enemy_did=0
|
||||||
};
|
};
|
||||||
|
|
||||||
if(result.player_did > 0) {
|
if(result.player_did > 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue