Refactored inventory some so that the UI is not so knowing of the internals.
This commit is contained in:
parent
e0e7a1027c
commit
0878a9e978
8 changed files with 90 additions and 92 deletions
|
@ -40,4 +40,31 @@ namespace components {
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::pair<bool, std::string> Inventory::use(GameLevel &level, size_t at) {
|
||||
auto& player_combat = level.world->get<components::Combat>(level.player);
|
||||
auto& item = get(at);
|
||||
|
||||
if(item.count == 0) return {false, item.data["name"]};
|
||||
|
||||
if(item.data["id"] == "SWORD_RUSTY") {
|
||||
auto weapon = components::get<components::Weapon>(item.data);
|
||||
player_combat.damage = weapon.damage;
|
||||
} else if(item.data["id"] == "POTION_HEALING_SMALL") {
|
||||
auto cure = components::get<components::Curative>(item.data);
|
||||
player_combat.hp = std::min(player_combat.hp + cure.hp, player_combat.max_hp);
|
||||
} else if(item.data["id"] == "TORCH_BAD") {
|
||||
auto new_light = components::get<components::LightSource>(item.data);
|
||||
level.world->set<components::LightSource>(level.player, new_light);
|
||||
light = new_light;
|
||||
} else {
|
||||
return {false, fmt::format("UNKNOWN ITEM: {}", (std::string)item.data["id"])};
|
||||
}
|
||||
|
||||
decrease(at, 1);
|
||||
return {true, item.data["name"]};
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue