bool MinionEquipment::needs(const Creature* c, const Item* it, bool noLimit, bool replacement) const { if (Optional<EquipmentType> type = getEquipmentType(it)) { int limit = noLimit ? 10000 : getEquipmentLimit(*type); if (c->getEquipment().getItems([&](const Item* it) { return getEquipmentType(it) == *type;}).size() >= limit) return false; return ((c->canEquip(it) || (replacement && c->canEquipIfEmptySlot(it))) && (isItemAppropriate(c, it) || noLimit)) || (type == ARCHERY && (c->canEquip(it) || (it->getClass() == ItemClass::AMMO && !c->getEquipment().getItem(EquipmentSlot::RANGED_WEAPON).empty()))) || (type == HEALING && !c->isNotLiving()) || type == COMBAT_ITEM; } else return false; }
bool MinionEquipment::needs(const Creature* c, const Item* it) { if (Optional<EquipmentType> type = getEquipmentType(it)) return c->canEquip(it, nullptr) || (type == ARCHERY && c->hasSkill(Skill::archery) && (c->canEquip(it, nullptr) || (it->getType() == ItemType::AMMO && c->getEquipment().getItem(EquipmentSlot::RANGED_WEAPON)))) || (type == HEALING && !c->isNotLiving()) || type == COMBAT_ITEM; else return false; }
bool MinionEquipment::canTakeItem(const Creature* c, const Item* it) { if (const Creature* owner = getOwner(it)) { if (c == owner) { if (!needs(c, it)) { discard(it); return false; } return true; } if (owner->isDead()) discard(it); else return false; } if (!getEquipmentType(it) || !c->isHumanoid()) return false; return needs(c, it); }
bool MinionEquipment::isItemUseful(const Item* it) const { return getEquipmentType(it) || contains({ItemClass::GOLD, ItemClass::POTION, ItemClass::SCROLL}, it->getClass()); }
bool MinionEquipment::isItemUseful(const Item* it) { static EnumSet<ItemClass> usefulItems {ItemClass::FOOD, ItemClass::GOLD, ItemClass::POTION, ItemClass::SCROLL}; return getEquipmentType(it) || usefulItems[it->getClass()]; }