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;
|
||||
}
|
||||
|
||||
if(host_state == out_of_ap) {
|
||||
break;
|
||||
} else {
|
||||
if(host_state != out_of_ap) {
|
||||
enemy.combat->ap -= action.cost;
|
||||
}
|
||||
|
||||
$pending_actions.emplace_back(enemy, action.name, action.cost, host_state);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,19 +116,29 @@ namespace boss {
|
|||
}
|
||||
|
||||
void Fight::do_combat(std::any data) {
|
||||
using combat::BattleHostState;
|
||||
|
||||
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);
|
||||
|
||||
$ui.zoom("", 1.0);
|
||||
std::string boss_move = Random::uniform(0, 1) == 0 ? "boss5" : "boss6";
|
||||
std::string player_move = Random::uniform(0, 1) == 0 ? "player1" : "player3";
|
||||
$ui.move_actor("player", player_move);
|
||||
$ui.move_actor("boss", boss_move);
|
||||
switch(result.host_state) {
|
||||
case BattleHostState::agree:
|
||||
case BattleHostState::disagree: {
|
||||
std::string player_move = Random::uniform(0, 1) == 0 ? "player1" : "player3";
|
||||
$ui.move_actor("player", player_move);
|
||||
$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;
|
||||
}
|
||||
|
||||
$ui.damage("player", result.enemy_did);
|
||||
$ui.damage("boss", result.player_did);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
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{};
|
||||
components::CombatResult result {
|
||||
.attacker=enemy.entity,
|
||||
.host_state=host_state,
|
||||
.player_did=0,
|
||||
.enemy_did=0
|
||||
};
|
||||
|
||||
switch(host_state) {
|
||||
case BattleHostState::agree:
|
||||
|
|
|
|||
|
|
@ -105,11 +105,16 @@ namespace boss {
|
|||
}
|
||||
|
||||
void UI::damage(const std::string& actor, int amount) {
|
||||
auto& config = $arena.actor_config(actor);
|
||||
|
||||
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 {
|
||||
$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) {
|
||||
|
|
|
|||
|
|
@ -14,11 +14,17 @@
|
|||
#include "json_mods.hpp"
|
||||
#include "goap.hpp"
|
||||
|
||||
namespace combat {
|
||||
enum class BattleHostState;
|
||||
}
|
||||
|
||||
namespace components {
|
||||
using std::string;
|
||||
using namespace nlohmann;
|
||||
|
||||
struct CombatResult {
|
||||
DinkyECS::Entity attacker;
|
||||
combat::BattleHostState host_state;
|
||||
int player_did = 0;
|
||||
int enemy_did = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ if build_machine.system() == 'windows'
|
|||
'-static-libgcc',
|
||||
'-static-libstdc++',
|
||||
'-static',
|
||||
'-flto',
|
||||
language: 'cpp',
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -86,8 +86,12 @@ namespace scene {
|
|||
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) {
|
||||
auto& config = $actors.at($actor_name_ids.at(actor));
|
||||
auto& config = actor_config(actor);
|
||||
config.cell = cell_name;
|
||||
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 animate_actor(const std::string& actor);
|
||||
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()) {
|
||||
auto [enemy, enemy_action, cost, host_state] = *act;
|
||||
|
||||
// player shouldn't hit theirself
|
||||
if(host_state != BattleHostState::not_host) continue;
|
||||
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue