11 const protocol::Inventory& bag,
12 int health,
int max_health,
14 const bool hurt = health > 0 && health * 2 < max_health;
15 for (uint32_t slot = 0; slot <
kBagSlots; ++slot) {
16 const auto stack = bag.bag().find(slot);
17 const auto item = stack != bag.bag().end()
18 ? items.
by_id.find(stack->second.item())
20 if (item == items.
by_id.end()) {
23 protocol::ItemAction action;
24 if (hurt && can_drink && item->second.use().heal() > 0) {
28 const items::Slot worn = item->second.equip().slot();
29 if (!hurt && item->second.has_equip() && !bag.worn().contains(worn)) {
30 *action.mutable_move()->mutable_from() =
InBag(slot);
31 *action.mutable_move()->mutable_to() =
Worn(worn);
std::optional< protocol::ItemAction > Tend(const ItemTable &items, const protocol::Inventory &bag, int health, int max_health, bool can_drink)