System::distribute_loot now manages setting up loot junk and does a new entity instead of reusing old ones, that allows System::death to do a coorect world->destroy() on the dead thing. Closes #46.
This commit is contained in:
parent
6437bd3b54
commit
02c42eb042
2 changed files with 32 additions and 28 deletions
58
systems.cpp
58
systems.cpp
|
@ -146,22 +146,23 @@ void System::motion(GameLevel &level) {
|
|||
});
|
||||
}
|
||||
|
||||
void System::distribute_loot(GameLevel &level, Entity& ent) {
|
||||
void System::distribute_loot(GameLevel &level, Position target_pos) {
|
||||
auto& world = *level.world;
|
||||
|
||||
// BUG: I constantly open a config when I have GameConfig already
|
||||
auto& config = world.get_the<GameConfig>();
|
||||
|
||||
ritual::JunkPile pile;
|
||||
auto& junk = config.rituals["junk"];
|
||||
|
||||
ritual::JunkPile select_from;
|
||||
for(auto& el : junk.items()) {
|
||||
select_from.contents.push_back(el.key());
|
||||
}
|
||||
|
||||
int inventory_count = Random::uniform(0, 3);
|
||||
|
||||
if(inventory_count > 0) {
|
||||
// do a clone of the things we need, like Position
|
||||
auto junk_entity = world.entity();
|
||||
|
||||
ritual::JunkPile pile;
|
||||
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));
|
||||
|
@ -169,13 +170,16 @@ void System::distribute_loot(GameLevel &level, Entity& ent) {
|
|||
}
|
||||
|
||||
auto entity_data = config.devices["GRAVE_STONE"];
|
||||
components::configure_entity(world, ent, entity_data["components"]);
|
||||
world.set<ritual::JunkPile>(ent, pile);
|
||||
components::configure_entity(world, junk_entity, entity_data["components"]);
|
||||
world.set<ritual::JunkPile>(junk_entity, pile);
|
||||
// BUG: inventory_count here isn't really used to remove it
|
||||
world.set<InventoryItem>(ent, {inventory_count, entity_data});
|
||||
world.set<InventoryItem>(junk_entity, {inventory_count, entity_data});
|
||||
world.set<Position>(junk_entity, target_pos);
|
||||
level.collision->insert(target_pos.location, junk_entity);
|
||||
level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, junk_entity, {});
|
||||
} else {
|
||||
dbc::log("DEAD BODY NOT IMPLEMENTED, for now just removing enemy");
|
||||
remove_from_world(level, ent);
|
||||
level.collision->remove(target_pos.location);
|
||||
// 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:
|
||||
|
@ -215,22 +219,18 @@ void System::death(GameLevel &level) {
|
|||
// NOTE: this could be a separate system but also could be a function in
|
||||
// components::
|
||||
for(auto ent : dead_things) {
|
||||
// remove their enemy setting
|
||||
world.remove<Motion>(ent);
|
||||
world.remove<Combat>(ent);
|
||||
world.remove<EnemyConfig>(ent);
|
||||
world.remove<Personality>(ent);
|
||||
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);
|
||||
}
|
||||
|
||||
System::distribute_loot(level, ent);
|
||||
auto pos = world.get<Position>(ent);
|
||||
// NOTE: distribute loot is responsible for either removing or replacing
|
||||
// the collision for this entity. It has to do this since it's determining
|
||||
// if a junkpile goes there or nothing
|
||||
System::distribute_loot(level, pos);
|
||||
|
||||
world.destroy(ent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,6 +332,10 @@ void System::collision(GameLevel &level) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This isn't for destroying something, but just removing it
|
||||
* from the world for say, putting into a container or inventory.
|
||||
*/
|
||||
void System::remove_from_world(GameLevel &level, Entity entity) {
|
||||
auto& item_pos = level.world->get<Position>(entity);
|
||||
level.collision->remove(item_pos.location);
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace System {
|
|||
|
||||
std::shared_ptr<sf::Shader> sprite_effect(GameLevel &level, Entity entity);
|
||||
void player_status(GameLevel &level);
|
||||
void distribute_loot(GameLevel &level, Entity& ent);
|
||||
void distribute_loot(GameLevel &level, Position target_pos);
|
||||
|
||||
void pickup(GameLevel &level, Entity entity);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue