|
|
@ -147,34 +147,49 @@ void System::motion(GameLevel &level) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void System::distribute_loot(World &world, Entity& ent, nlohmann::json& entity_data) { |
|
|
|
void System::distribute_loot(GameLevel &level, Entity& ent) { |
|
|
|
dbc::log("!!!!!!!!!!!!! THIS is where you update the dead body contents"); |
|
|
|
auto& world = *level.world; |
|
|
|
int inventory_count = entity_data["inventory_count"]; |
|
|
|
|
|
|
|
world.set<InventoryItem>(ent, {inventory_count, entity_data}); |
|
|
|
// BUG: I constantly open a config when I have GameConfig already
|
|
|
|
// use the inventory_level to fill the blanket with new items
|
|
|
|
auto& config = world.get_the<GameConfig>(); |
|
|
|
|
|
|
|
|
|
|
|
Config config("assets/rituals.json"); |
|
|
|
|
|
|
|
ritual::JunkPile pile; |
|
|
|
ritual::JunkPile pile; |
|
|
|
auto& junk = config["junk"]; |
|
|
|
auto& junk = config.rituals["junk"]; |
|
|
|
|
|
|
|
|
|
|
|
ritual::JunkPile select_from; |
|
|
|
ritual::JunkPile select_from; |
|
|
|
for(auto& el : junk.items()) { |
|
|
|
for(auto& el : junk.items()) { |
|
|
|
select_from.contents.push_back(el.key()); |
|
|
|
select_from.contents.push_back(el.key()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < inventory_count; i++) { |
|
|
|
int inventory_count = Random::uniform(0, 3); |
|
|
|
size_t max_junk = select_from.contents.size(); |
|
|
|
if(inventory_count > 0) { |
|
|
|
auto& item = select_from.contents.at(Random::uniform(size_t(0), max_junk-1)); |
|
|
|
for(int i = 0; i < inventory_count; i++) { |
|
|
|
pile.contents.push_back(item); |
|
|
|
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) { |
|
|
|
void System::death(GameLevel &level) { |
|
|
|
auto &world = *level.world; |
|
|
|
auto &world = *level.world; |
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
auto& config = world.get_the<GameConfig>(); |
|
|
|
|
|
|
|
std::vector<Entity> dead_things; |
|
|
|
std::vector<Entity> dead_things; |
|
|
|
|
|
|
|
|
|
|
|
world.query<Combat>([&](auto ent, auto &combat) { |
|
|
|
world.query<Combat>([&](auto ent, auto &combat) { |
|
|
@ -209,18 +224,14 @@ void System::death(GameLevel &level) { |
|
|
|
world.remove<ai::EntityAI>(ent); |
|
|
|
world.remove<ai::EntityAI>(ent); |
|
|
|
world.remove<Animation>(ent); |
|
|
|
world.remove<Animation>(ent); |
|
|
|
world.remove<SpriteEffect>(ent); |
|
|
|
world.remove<SpriteEffect>(ent); |
|
|
|
|
|
|
|
world.remove<Sprite>(ent); |
|
|
|
|
|
|
|
|
|
|
|
if(auto snd = world.get_if<Sound>(ent)) { |
|
|
|
if(auto snd = world.get_if<Sound>(ent)) { |
|
|
|
sound::stop(snd->attack); |
|
|
|
sound::stop(snd->attack); |
|
|
|
sound::play(snd->death); |
|
|
|
sound::play(snd->death); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
auto entity_data = config.devices["GRAVE_STONE"]; |
|
|
|
System::distribute_loot(level, ent); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -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) { |
|
|
|
void System::pickup(GameLevel &level, Entity entity) { |
|
|
|
auto &world = *level.world; |
|
|
|
auto &world = *level.world; |
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
auto player = world.get_the<Player>(); |
|
|
@ -329,12 +349,7 @@ void System::pickup(GameLevel &level, Entity entity) { |
|
|
|
if(world.has<InventoryItem>(entity)) { |
|
|
|
if(world.has<InventoryItem>(entity)) { |
|
|
|
// NOTE: this might need to be a separate system so that people can leave stuff alone
|
|
|
|
// NOTE: this might need to be a separate system so that people can leave stuff alone
|
|
|
|
auto item = world.get<InventoryItem>(entity); |
|
|
|
auto item = world.get<InventoryItem>(entity); |
|
|
|
auto& item_pos = world.get<Position>(entity); |
|
|
|
remove_from_world(level, 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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(world.has<ritual::JunkPile>(entity)) { |
|
|
|
if(world.has<ritual::JunkPile>(entity)) { |
|
|
|
auto& pile = world.get<ritual::JunkPile>(entity); |
|
|
|
auto& pile = world.get<ritual::JunkPile>(entity); |
|
|
|