Junk items are now transfered to your blanket so you can use them in crafting. No UI for that though.
This commit is contained in:
parent
bc557652ba
commit
1a9e068d02
10 changed files with 86 additions and 53 deletions
41
systems.cpp
41
systems.cpp
|
@ -140,6 +140,29 @@ void System::motion(GameLevel &level) {
|
|||
});
|
||||
}
|
||||
|
||||
void System::distribute_loot(DinkyECS::World &world, DinkyECS::Entity& ent, nlohmann::json& entity_data) {
|
||||
int inventory_count = entity_data["inventory_count"];
|
||||
world.set<InventoryItem>(ent, {inventory_count, entity_data});
|
||||
// use the inventory_level to fill the blanket with new items
|
||||
|
||||
Config config("assets/rituals.json");
|
||||
ritual::JunkPile pile;
|
||||
auto& junk = config["junk"];
|
||||
|
||||
ritual::JunkPile select_from;
|
||||
for(auto& el : junk.items()) {
|
||||
select_from.contents.push_back(el.key());
|
||||
}
|
||||
|
||||
for(int i = 0; i < inventory_count; i++) {
|
||||
size_t max_junk = select_from.contents.size();
|
||||
auto& item = select_from.contents.at(Random::uniform(size_t(0), max_junk-1));
|
||||
pile.contents.push_back(item);
|
||||
}
|
||||
|
||||
world.set<ritual::JunkPile>(ent, pile);
|
||||
}
|
||||
|
||||
void System::death(GameLevel &level, components::ComponentMap& components) {
|
||||
auto &world = *level.world;
|
||||
auto player = world.get_the<Player>();
|
||||
|
@ -187,8 +210,7 @@ void System::death(GameLevel &level, components::ComponentMap& components) {
|
|||
auto entity_data = config.items["GRAVE_STONE"];
|
||||
components::configure_entity(components, world, ent, entity_data["components"]);
|
||||
if(entity_data["inventory_count"] > 0) {
|
||||
// right here use a std::any that's already converted instead?
|
||||
world.set<InventoryItem>(ent, {entity_data["inventory_count"], entity_data});
|
||||
System::distribute_loot(world, ent, entity_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -293,17 +315,20 @@ void System::collision(GameLevel &level) {
|
|||
world.remove<LightSource>(entity);
|
||||
}
|
||||
|
||||
if(world.has<ritual::JunkPile>(entity)) {
|
||||
auto& pile = world.get<ritual::JunkPile>(entity);
|
||||
auto& blanket = world.get_the<ritual::Blanket>();
|
||||
for(auto& junk : pile.contents) {
|
||||
fmt::println("adding {} to blanket", junk);
|
||||
blanket.add(junk);
|
||||
}
|
||||
}
|
||||
|
||||
if(world.has<Weapon>(entity)) {
|
||||
inventory.add(item);
|
||||
world.remove<Weapon>(entity);
|
||||
}
|
||||
|
||||
if(world.has<Loot>(entity)) {
|
||||
auto &loot = world.get<Loot>(entity);
|
||||
inventory.gold += loot.amount;
|
||||
world.remove<Loot>(entity);
|
||||
}
|
||||
|
||||
if(world.has<Curative>(entity)) {
|
||||
inventory.add(item);
|
||||
world.remove<Curative>(entity);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue