Enemies now turn into a lootable device witha grave_stone sprite so you know they died. Need to implement noclipping on items with collision.

This commit is contained in:
Zed A. Shaw 2025-02-19 23:18:33 -05:00
parent 0199248354
commit 3b9525cca4
8 changed files with 92 additions and 74 deletions

View file

@ -104,35 +104,37 @@ void System::motion(GameLevel &level) {
});
}
void System::death(GameLevel &level) {
void System::death(GameLevel &level, components::ComponentMap& components) {
auto &world = *level.world;
auto &collider = *level.collision;
auto player = world.get_the<Player>();
auto& config = world.get_the<GameConfig>();
std::vector<DinkyECS::Entity> dead_things;
// BUG: this is where entities can die on top of
// BUG: eachother and overlap their corpse
// BUG: maybe that can be allowed and looting just shows
// BUG: all dead things there?
world.query<Position, Combat>([&](auto ent, auto &position, auto &combat) {
world.query<Combat>([&](auto ent, auto &combat) {
// bring out yer dead
if(combat.hp <= 0 && !combat.dead) {
fmt::println("DIE! entity {} died", ent);
combat.dead = true;
// take them out of collision map
collider.remove(position.location);
if(ent == player.entity) {
world.send<Events::GUI>(Events::GUI::DEATH, ent, {});
} else {
// remove their motion so they're dead
// CHANGE: this needs to remove the enemies that are
// dead and then replace them at that position with
// a gave_stone device. And then that makes it so you
// can loot their dead bodies.
world.remove<Motion>(ent);
if(ent != player.entity) {
// we won't change out the player's components later
dead_things.push_back(ent);
}
// we need to send this event for everything that dies
world.send<Events::GUI>(Events::GUI::DEATH, ent, {});
}
});
// this goes through everything that died and changes them to a gravestone
// 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);
auto entity_data = config.devices["GRAVE_STONE"];
components::configure_entity(components, world, ent, entity_data["components"]);
}
}
void System::combat(GameLevel &level) {
@ -173,54 +175,60 @@ void System::collision(GameLevel &level) {
// this is guaranteed to not return the given position
auto [found, nearby] = collider.neighbors(player_position.location);
int combat_count = 0;
if(found) {
for(auto entity : nearby) {
if(world.has<Combat>(entity)) {
// BUG: this logic is garbage, needs a refactor
for(auto entity : nearby) {
if(world.has<Combat>(entity)) {
auto combat = world.get<Combat>(entity);
if(!combat.dead) {
combat_count++;
world.send<Events::GUI>(Events::GUI::COMBAT_START, entity, 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);
if(world.has<LightSource>(entity)) {
inventory.add(item);
auto &new_light = world.get<LightSource>(entity);
world.set<LightSource>(player.entity, new_light);
inventory.light = new_light;
world.remove<LightSource>(entity);
}
if(world.has<Weapon>(entity)) {
inventory.add(item);
auto &weapon = world.get<Weapon>(entity);
player_combat.damage = weapon.damage;
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)) {
auto& cure = world.get<Curative>(entity);
player_combat.hp = std::min(player_combat.hp + cure.hp, player_combat.max_hp);
world.remove<Curative>(entity);
}
collider.remove(item_pos.location);
world.remove<Tile>(entity);
world.remove<InventoryItem>(entity);
world.send<Events::GUI>(Events::GUI::LOOT, entity, item);
} else if(world.has<Device>(entity)) {
System::device(world, player.entity, entity);
} else {
println("UNKNOWN COLLISION TYPE {}", 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);
if(world.has<LightSource>(entity)) {
inventory.add(item);
auto &new_light = world.get<LightSource>(entity);
world.set<LightSource>(player.entity, new_light);
inventory.light = new_light;
world.remove<LightSource>(entity);
}
if(world.has<Weapon>(entity)) {
inventory.add(item);
auto &weapon = world.get<Weapon>(entity);
player_combat.damage = weapon.damage;
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)) {
auto& cure = world.get<Curative>(entity);
player_combat.hp = std::min(player_combat.hp + cure.hp, player_combat.max_hp);
world.remove<Curative>(entity);
}
collider.remove(item_pos.location);
world.remove<Tile>(entity);
world.remove<InventoryItem>(entity);
world.send<Events::GUI>(Events::GUI::LOOT, entity, item);
} else if(world.has<Device>(entity)) {
System::device(world, player.entity, entity);
} else {
println("UNKNOWN COLLISION TYPE {}", entity);
}
} else {
}
if(combat_count == 0) {
world.send<Events::GUI>(Events::GUI::NO_NEIGHBORS, player.entity, player.entity);
}
}