Refactored the FSM so that it uses a generic registry of systems to do what it needs.
This commit is contained in:
parent
cbff127b40
commit
e742b8772d
7 changed files with 150 additions and 118 deletions
|
|
@ -474,14 +474,14 @@ bool System::inventory_occupied(Entity container_id, const std::string& name) {
|
|||
return inventory.has(name);
|
||||
}
|
||||
|
||||
bool System::use_item(const string& slot_name) {
|
||||
void System::use_item(const string& slot_name) {
|
||||
auto& level = GameDB::current_level();
|
||||
auto& world = *level.world;
|
||||
auto& inventory = world.get<inventory::Model>(level.player);
|
||||
auto& player_combat = world.get<Combat>(level.player);
|
||||
|
||||
if(player_combat.hp >= player_combat.max_hp) return false;
|
||||
if(!inventory.has(slot_name)) return false;
|
||||
if(player_combat.hp >= player_combat.max_hp) return;
|
||||
if(!inventory.has(slot_name)) return;
|
||||
|
||||
auto what = inventory.get(slot_name);
|
||||
|
||||
|
|
@ -498,10 +498,8 @@ bool System::use_item(const string& slot_name) {
|
|||
player_combat.hp));
|
||||
|
||||
world.remove<Curative>(what);
|
||||
return true;
|
||||
} else {
|
||||
dbc::log($F("no usable item at {}", what));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -541,3 +539,19 @@ void System::clear_attack() {
|
|||
|
||||
void System::spawn_attack(World& world, int attack_id, DinkyECS::Entity enemy) {
|
||||
}
|
||||
|
||||
|
||||
void System::init(Registry& reg) {
|
||||
reg.addRender(System::clear_attack);
|
||||
reg.addUseItem(System::use_item);
|
||||
reg.addMoving(System::move_player);
|
||||
reg.addCombat(System::combat);
|
||||
reg.addPickup(System::pickup);
|
||||
reg.addUpdate(System::generate_paths);
|
||||
reg.addUpdate(System::enemy_ai_initialize);
|
||||
reg.addUpdate(System::enemy_pathing);
|
||||
reg.addUpdate(System::motion);
|
||||
reg.addUpdate(System::collision);
|
||||
reg.addUpdate(System::lighting);
|
||||
reg.addUpdate(System::death);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue