Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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);
    }
  }
}
Ejemplo n.º 3
0
void UseAction::removeUsedItemFromInventory()
{
  PickablePtr pickable = _toUse->getFeature<Pickable>();
  ContainerPtr container = _performer->getFeature<Container>();

  if ( pickable && container )
  {
    ActorPtr toRemove = pickable->spilt(1);
    container->remove( toRemove );
  }
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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);
  }
}
Ejemplo n.º 6
0
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) );
    }
  }
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
int Character::getArmorClass()
{
  PickablePtr armor = getEquippedItem(ItemSlotType::Armor);
  return armor ? armor->getArmorClass() : _defaultArmorClass;
}