AI can now walk to where healing items are and pick them up to use.

This commit is contained in:
Zed A. Shaw 2025-09-05 23:20:45 -04:00
parent fe37aa11df
commit a2192e25eb
2 changed files with 31 additions and 8 deletions

View file

@ -3,7 +3,6 @@
#include "gui/ritual_ui.hpp"
#include "game_level.hpp"
#include "systems.hpp"
#define DEBUG 1
struct InventoryStats {
int healing = 0;
@ -347,8 +346,8 @@ bool Autowalker::found_item() {
return aimed_at != DinkyECS::NONE && world->has<components::InventoryItem>(aimed_at);
}
void Autowalker::send_event(gui::Event ev) {
fsm.event(ev);
void Autowalker::send_event(gui::Event ev, std::any data) {
fsm.event(ev, data);
fsm.render();
fsm.handle_world_events();
}
@ -393,6 +392,29 @@ bool Autowalker::face_enemy() {
return found;
}
void Autowalker::click_inventory(const std::string& name, guecs::Modifiers mods) {
auto& cell = fsm.$status_ui.$gui.cell_for(name);
fsm.$status_ui.mouse(cell.mid_x, cell.mid_y, mods);
fsm.handle_world_events();
}
void Autowalker::pocket_potion(GameDB::Level &level) {
auto& inventory = level.world->get<inventory::Model>(level.player);
if(inventory.has("pocket_r") && inventory.has("pocket_l")) {
auto gui_id = fsm.$status_ui.$gui.entity("pocket_r");
send_event(gui::Event::USE_ITEM, gui_id);
}
send_event(gui::Event::AIM_CLICK);
if(inventory.has("pocket_r")) {
click_inventory("pocket_l", {1 << guecs::ModBit::left});
} else {
click_inventory("pocket_r", {1 << guecs::ModBit::left});
}
}
void Autowalker::pickup_item() {
auto& level = GameDB::current_level();
auto& player_pos = GameDB::player_position();
@ -403,9 +425,8 @@ void Autowalker::pickup_item() {
fmt::println("AIMING AT entity {} @ {},{}",
entity, player_pos.aiming_at.x, player_pos.aiming_at.y);
if(auto curative = level.world->get_if<components::Curative>(entity)) {
send_event(gui::Event::AIM_CLICK);
(void)curative;
if(level.world->has<components::Curative>(entity)) {
pocket_potion(level);
status(L"A POTION");
} else {
send_event(gui::Event::AIM_CLICK);

View file

@ -1,7 +1,7 @@
#pragma once
#include "ai.hpp"
#include "gui/fsm.hpp"
#include <guecs/ui.hpp>
struct InventoryStats;
@ -29,7 +29,7 @@ struct Autowalker {
void handle_boss_fight();
void handle_player_walk(ai::State& start, ai::State& goal);
void send_event(gui::Event ev);
void send_event(gui::Event ev, std::any data={});
void process_combat();
bool process_move(Pathing& paths, std::function<bool(Point)> cb);
bool path_player(Pathing& paths, Point &target_out);
@ -49,4 +49,6 @@ struct Autowalker {
void face_target(Point target);
bool face_enemy();
void pickup_item();
void pocket_potion(GameDB::Level &level);
void click_inventory(const std::string& name, guecs::Modifiers mods);
};