Basic inventory system working and can pick up items but needs to be reflected in the UI next.
This commit is contained in:
parent
d7353a02df
commit
135d9a128b
14 changed files with 212 additions and 48 deletions
28
systems.cpp
28
systems.cpp
|
@ -62,7 +62,7 @@ void System::init_positions(DinkyECS::World &world) {
|
|||
}
|
||||
});
|
||||
|
||||
world.query<Position, Loot>([&](const auto &ent, auto &pos, auto &loot) {
|
||||
world.query<Position, InventoryItem>([&](const auto &ent, auto &pos, auto &item) {
|
||||
collider.insert(pos.location, ent);
|
||||
});
|
||||
}
|
||||
|
@ -134,10 +134,12 @@ void System::collision(DinkyECS::World &world, Player &player) {
|
|||
};
|
||||
|
||||
world.send<Events::GUI>(Events::GUI::COMBAT, entity, result);
|
||||
} else if(world.has<Loot>(entity)) {
|
||||
auto loot = world.get<Loot>(entity);
|
||||
auto &loot_pos = world.get<Position>(entity);
|
||||
auto &inventory = world.get<Inventory>(player.entity);
|
||||
} else if(world.has<InventoryItem>(entity)) {
|
||||
auto& item = world.get<InventoryItem>(entity);
|
||||
auto& item_pos = world.get<Position>(entity);
|
||||
auto& inventory = world.get<Inventory>(player.entity);
|
||||
|
||||
inventory.add(item);
|
||||
|
||||
if(world.has<LightSource>(entity)) {
|
||||
auto &new_light = world.get<LightSource>(entity);
|
||||
|
@ -148,15 +150,12 @@ void System::collision(DinkyECS::World &world, Player &player) {
|
|||
auto &weapon = world.get<Weapon>(entity);
|
||||
player_combat.damage = weapon.damage;
|
||||
world.remove<Weapon>(entity);
|
||||
} else {
|
||||
// it's just gold
|
||||
inventory.gold += loot.amount;
|
||||
}
|
||||
|
||||
collider.remove(loot_pos.location);
|
||||
collider.remove(item_pos.location);
|
||||
world.remove<Tile>(entity);
|
||||
world.remove<Loot>(entity);
|
||||
world.send<Events::GUI>(Events::GUI::LOOT, entity, loot);
|
||||
world.remove<InventoryItem>(entity);
|
||||
world.send<Events::GUI>(Events::GUI::LOOT, entity, item);
|
||||
} else {
|
||||
println("UNKNOWN COLLISION TYPE {}", entity);
|
||||
}
|
||||
|
@ -183,3 +182,10 @@ void System::draw_entities(DinkyECS::World &world, Map &game_map, const Matrix &
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
void System::pickup(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item) {
|
||||
auto& inventory = world.get<Inventory>(actor);
|
||||
auto& invitem = world.get<InventoryItem>(item);
|
||||
|
||||
inventory.add(invitem);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue