|
|
@ -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 &world = *level.world; |
|
|
|
auto &collider = *level.collision; |
|
|
|
|
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
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
|
|
|
|
world.query<Combat>([&](auto ent, auto &combat) { |
|
|
|
// 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) { |
|
|
|
|
|
|
|
// bring out yer dead
|
|
|
|
// bring out yer dead
|
|
|
|
if(combat.hp <= 0 && !combat.dead) { |
|
|
|
if(combat.hp <= 0 && !combat.dead) { |
|
|
|
fmt::println("DIE! entity {} died", ent); |
|
|
|
|
|
|
|
combat.dead = true; |
|
|
|
combat.dead = true; |
|
|
|
// take them out of collision map
|
|
|
|
if(ent != player.entity) { |
|
|
|
collider.remove(position.location); |
|
|
|
// we won't change out the player's components later
|
|
|
|
|
|
|
|
dead_things.push_back(ent); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 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) { |
|
|
|
void System::combat(GameLevel &level) { |
|
|
@ -173,54 +175,60 @@ void System::collision(GameLevel &level) { |
|
|
|
|
|
|
|
|
|
|
|
// this is guaranteed to not return the given position
|
|
|
|
// this is guaranteed to not return the given position
|
|
|
|
auto [found, nearby] = collider.neighbors(player_position.location); |
|
|
|
auto [found, nearby] = collider.neighbors(player_position.location); |
|
|
|
|
|
|
|
int combat_count = 0; |
|
|
|
if(found) { |
|
|
|
|
|
|
|
for(auto entity : nearby) { |
|
|
|
// BUG: this logic is garbage, needs a refactor
|
|
|
|
if(world.has<Combat>(entity)) { |
|
|
|
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); |
|
|
|
world.send<Events::GUI>(Events::GUI::COMBAT_START, entity, entity); |
|
|
|
} else if(world.has<InventoryItem>(entity)) { |
|
|
|
} |
|
|
|
auto item = world.get<InventoryItem>(entity); |
|
|
|
} else if(world.has<InventoryItem>(entity)) { |
|
|
|
auto& item_pos = world.get<Position>(entity); |
|
|
|
auto item = world.get<InventoryItem>(entity); |
|
|
|
auto& inventory = world.get<Inventory>(player.entity); |
|
|
|
auto& item_pos = world.get<Position>(entity); |
|
|
|
|
|
|
|
auto& inventory = world.get<Inventory>(player.entity); |
|
|
|
if(world.has<LightSource>(entity)) { |
|
|
|
|
|
|
|
inventory.add(item); |
|
|
|
if(world.has<LightSource>(entity)) { |
|
|
|
auto &new_light = world.get<LightSource>(entity); |
|
|
|
inventory.add(item); |
|
|
|
world.set<LightSource>(player.entity, new_light); |
|
|
|
auto &new_light = world.get<LightSource>(entity); |
|
|
|
inventory.light = new_light; |
|
|
|
world.set<LightSource>(player.entity, new_light); |
|
|
|
world.remove<LightSource>(entity); |
|
|
|
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)) { |
|
|
|
if(world.has<Weapon>(entity)) { |
|
|
|
auto &loot = world.get<Loot>(entity); |
|
|
|
inventory.add(item); |
|
|
|
inventory.gold += loot.amount; |
|
|
|
auto &weapon = world.get<Weapon>(entity); |
|
|
|
world.remove<Loot>(entity); |
|
|
|
player_combat.damage = weapon.damage; |
|
|
|
} |
|
|
|
world.remove<Weapon>(entity); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(world.has<Curative>(entity)) { |
|
|
|
if(world.has<Loot>(entity)) { |
|
|
|
auto& cure = world.get<Curative>(entity); |
|
|
|
auto &loot = world.get<Loot>(entity); |
|
|
|
player_combat.hp = std::min(player_combat.hp + cure.hp, player_combat.max_hp); |
|
|
|
inventory.gold += loot.amount; |
|
|
|
world.remove<Curative>(entity); |
|
|
|
world.remove<Loot>(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
collider.remove(item_pos.location); |
|
|
|
if(world.has<Curative>(entity)) { |
|
|
|
world.remove<Tile>(entity); |
|
|
|
auto& cure = world.get<Curative>(entity); |
|
|
|
world.remove<InventoryItem>(entity); |
|
|
|
player_combat.hp = std::min(player_combat.hp + cure.hp, player_combat.max_hp); |
|
|
|
world.send<Events::GUI>(Events::GUI::LOOT, entity, item); |
|
|
|
world.remove<Curative>(entity); |
|
|
|
} else if(world.has<Device>(entity)) { |
|
|
|
|
|
|
|
System::device(world, player.entity, entity); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
println("UNKNOWN COLLISION TYPE {}", 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); |
|
|
|
world.send<Events::GUI>(Events::GUI::NO_NEIGHBORS, player.entity, player.entity); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|