std::vector<ColoredString> Engine::getActorsBenethPlayersFeet() { std::vector< ColoredString > items; MapPtr map = getWorld().getCurrentMap(); if ( map ) { std::function<bool(amarlon::ActorPtr)> filterFun = [&](ActorPtr a) -> bool { return a != Actor::Player; }; std::vector<ActorPtr> actorsOnTile = map->getActors(Actor::Player->getX(), Actor::Player->getY(), &filterFun); for ( ActorPtr actor : actorsOnTile ) { std::string msg = actor->getName(); PickablePtr pickable = actor->getFeature<Pickable>(); if ( pickable && pickable->getAmount() > 1 ) { msg = msg + " (" + std::to_string(pickable->getAmount()) + ")"; } items.push_back( ColoredString( msg, TCODColor::darkLime ) ); } } return items; }
void Wearer::assignItemsToSlots() { for ( ActorPtr a : _equippedItems->toVector() ) { PickablePtr pickable = a ? a->getFeature<Pickable>() : nullptr; if ( pickable && hasSlot( pickable->getItemSlot() )) { _itemSlots[ pickable->getItemSlot() ] = std::make_pair(a, false); } } }
void UseAction::removeUsedItemFromInventory() { PickablePtr pickable = _toUse->getFeature<Pickable>(); ContainerPtr container = _performer->getFeature<Container>(); if ( pickable && container ) { ActorPtr toRemove = pickable->spilt(1); container->remove( toRemove ); } }
ActorPtr createActor(const DropRule& rule) { ActorPtr toDrop = Actor::create(rule.dropActorId); PickablePtr pickable = toDrop->getFeature<Pickable>(); if ( pickable ) { pickable->setAmount( dices::roll( rule.amountMin, rule.amountMax ) ); } return toDrop; }
void BagManager::fillBag() { ContainerPtr inventory = Actor::Player->getFeature<Container>(); if ( inventory ) { std::function<std::string(ActorPtr)> category_function = [&](ActorPtr a) { PickablePtr p = a->getFeature<Pickable>(); return p ? PickableCategory2Str( p->getCategory() ) : ""; }; _bagMenu->fill<Actor>( inventory->content(), getItemNameAndAmount, category_function); } }
void CmdUse::execute() { ActorPtr item = acquireItemToUse(); Engine::instance().render(); if (item != nullptr) { PickablePtr pickable = item->getFeature<Pickable>(); TargetSelector* tSelector = TargetSelector::create(pickable->getTargetType()); if ( tSelector != nullptr ) { Actor::Player->performAction( std::make_shared<UseAction>( tSelector->select(), item) ); } } }
std::string Wearer::debug(const std::string &linebreak) { std::string d = " " + linebreak + "-----WEARER-----"+linebreak; for(auto slot : _itemSlots) { ActorPtr eq = equipped(slot.first); bool blocked = isBlocked(slot.first); PickablePtr p = eq ? eq->getFeature<Pickable>() : nullptr; d += ItemSlotType2Str(slot.first); d += ": " + (eq ? eq->getName() : "<none>") + (p ? " [" + toStr(p->getAmount()) + "]" : "" ) + ( blocked ? " [BLOCKED] " : "" ) + linebreak; } d.append("----------------"+linebreak); return d; }
int BagManager::getAmountToDrop(ActorPtr toDrop) { int amount = 1; PickablePtr pickable = toDrop->getFeature<Pickable>(); if ( pickable && pickable->isStackable() ) { amount = Engine::instance().windowManager() .getWindow<gui::AmountWindow>() .setMaxAmount( pickable->getAmount() ) .show() .downcast<gui::AmountWindow>() .getAmount(); } return amount; }
bool UseAction::perform(ActorPtr performer) { bool used = false; _performer = performer; PickablePtr pickable = _toUse->getFeature<Pickable>(); if ( pickable != nullptr && pickable->use( _performer, _target ) ) { if ( pickable->getUsesCount() == 0 ) { removeUsedItemFromInventory(); } used = true; } return used; }
bool Wearer::equip(ActorPtr item) { if ( !item ) return false; PickablePtr pickable = item->getFeature<Pickable>(); if ( !pickable ) return false; ItemSlotType slot = pickable->getItemSlot(); if ( hasSlot(slot) && !isEquipped(slot) ) { _equippedItems->push_back(item); _itemSlots[slot] = std::make_pair(item, false); return true; } return false; }
int Character::getArmorClass() { PickablePtr armor = getEquippedItem(ItemSlotType::Armor); return armor ? armor->getArmorClass() : _defaultArmorClass; }