Loot boxes now have ritual items and you can click on them, or the enemy just dies.

This commit is contained in:
Zed A. Shaw 2025-06-23 01:33:09 -04:00
parent 3c5021e4c9
commit fb064ffbf1
6 changed files with 53 additions and 34 deletions

View file

@ -147,34 +147,49 @@ void System::motion(GameLevel &level) {
});
}
void System::distribute_loot(World &world, Entity& ent, nlohmann::json& entity_data) {
dbc::log("!!!!!!!!!!!!! THIS is where you update the dead body contents");
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
void System::distribute_loot(GameLevel &level, Entity& ent) {
auto& world = *level.world;
// BUG: I constantly open a config when I have GameConfig already
auto& config = world.get_the<GameConfig>();
Config config("assets/rituals.json");
ritual::JunkPile pile;
auto& junk = config["junk"];
auto& junk = config.rituals["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);
}
int inventory_count = Random::uniform(0, 3);
if(inventory_count > 0) {
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);
auto entity_data = config.devices["GRAVE_STONE"];
components::configure_entity(world, ent, entity_data["components"]);
world.set<ritual::JunkPile>(ent, pile);
// BUG: inventory_count here isn't really used to remove it
world.set<InventoryItem>(ent, {inventory_count, entity_data});
} else {
dbc::log("DEAD BODY NOT IMPLEMENTED, for now just removing enemy");
remove_from_world(level, ent);
// BUG: should maybe add a component to the world for "dead thing no loot" that
// has no collision or goes away after some kind of animation
// Something like:
// auto entity_data = config.devices["DEAD_BODY"];
// components::configure_entity(world, ent, entity_data["components"]);
// then give it a collision device that makes it go away and make a sound
// or maybe you can walk over dead bodies and they make a noise
}
}
void System::death(GameLevel &level) {
auto &world = *level.world;
auto player = world.get_the<Player>();
auto& config = world.get_the<GameConfig>();
std::vector<Entity> dead_things;
world.query<Combat>([&](auto ent, auto &combat) {
@ -209,18 +224,14 @@ void System::death(GameLevel &level) {
world.remove<ai::EntityAI>(ent);
world.remove<Animation>(ent);
world.remove<SpriteEffect>(ent);
world.remove<Sprite>(ent);
if(auto snd = world.get_if<Sound>(ent)) {
sound::stop(snd->attack);
sound::play(snd->death);
}
auto entity_data = config.devices["GRAVE_STONE"];
components::configure_entity(world, ent, entity_data["components"]);
if(entity_data["inventory_count"] > 0) {
dbc::sentinel("BOOM! this is where you fill in the dead bodies.");
System::distribute_loot(world, ent, entity_data);
}
System::distribute_loot(level, ent);
}
}
@ -322,6 +333,15 @@ void System::collision(GameLevel &level) {
}
}
void System::remove_from_world(GameLevel &level, Entity entity) {
auto& item_pos = level.world->get<Position>(entity);
level.collision->remove(item_pos.location);
level.world->remove<Tile>(entity);
// if you don't do this you get the bug that you can pickup
// an item and it'll also be in your inventory
level.world->remove<Position>(entity);
}
void System::pickup(GameLevel &level, Entity entity) {
auto &world = *level.world;
auto player = world.get_the<Player>();
@ -329,12 +349,7 @@ void System::pickup(GameLevel &level, Entity entity) {
if(world.has<InventoryItem>(entity)) {
// NOTE: this might need to be a separate system so that people can leave stuff alone
auto item = world.get<InventoryItem>(entity);
auto& item_pos = world.get<Position>(entity);
level.collision->remove(item_pos.location);
world.remove<Tile>(entity);
// if you don't do this you get the bug that you can pickup
// an item and it'll also be in your inventory
world.remove<Position>(entity);
remove_from_world(level, entity);
if(world.has<ritual::JunkPile>(entity)) {
auto& pile = world.get<ritual::JunkPile>(entity);