Example #1
0
void Player::applyAction() {
  vector<Item*> items = chooseItem("Choose an item to apply:", [this](const Item* item) {
      return creature->applyItem(const_cast<Item*>(item));}, UserInput::APPLY_ITEM);
  if (items.size() == 0)
    return;
  applyItem(items);
}
Example #2
0
void Player::throwAction(Optional<Vec2> dir) {
  vector<Item*> items = chooseItem("Choose an item to throw:", [this](const Item* item) {
      return !creature->getEquipment().isEquiped(item);}, ActionId::THROW);
  if (items.size() == 0)
    return;
  throwItem(items, dir);
}
Example #3
0
void fList::doPotVal(int aVal) {

  int i;

  if (potTimer.ding()) {              // Ok, IF the timer is up.
    i = round(listMapper.Map(aVal));  // Map out an item index.
    chooseItem(i);                    // Set focus on that item.
    potTimer.start();
  }
}
Example #4
0
void Player::applyAction() {
  if (!creature->isHumanoid())
    return;
  if (creature->numGoodArms() == 0) {
    privateMessage("You don't have hands!");
    return;
  }
  vector<Item*> items = chooseItem("Choose an item to apply:", [this](const Item* item) {
      return creature->canApplyItem(item);}, ActionId::APPLY_ITEM);
  if (items.size() == 0)
    return;
  applyItem(items);
}
Example #5
0
void Player::equipmentAction() {
    if (!creature->isHumanoid()) {
        creature->privateMessage("You can't use any equipment.");
        return;
    }
    vector<EquipmentSlot> slots;
    for (auto slot : Equipment::slotTitles)
        slots.push_back(slot.first);
    int index = 0;
    creature->startEquipChain();
    while (1) {
        vector<View::ListElem> list;
        for (auto slot : slots) {
            list.push_back(View::ListElem(Equipment::slotTitles.at(slot), View::TITLE));
            Item* item = creature->getEquipment().getItem(slot);
            if (item)
                list.push_back(item->getNameAndModifiers());
            else
                list.push_back("[Nothing]");
        }
        model->getView()->updateView(creature);
        Optional<int> newIndex = model->getView()->chooseFromList("Equipment", list, index, View::NORMAL_MENU, nullptr,
                                 UserInput::Type::EQUIPMENT);
        if (!newIndex) {
            creature->finishEquipChain();
            return;
        }
        index = *newIndex;
        EquipmentSlot slot = slots[index];
        string reason;
        if (Item* item = creature->getEquipment().getItem(slot)) {
            if (creature->canUnequip(item, &reason))
                creature->unequip(item);
            else
                creature->privateMessage(reason);
        } else {
            vector<Item*> items = chooseItem("Choose an item to equip:", [=](const Item* item) {
                return item->canEquip()
                       && !creature->getEquipment().isEquiped(item)
                       && item->getEquipmentSlot() == slot;
            });
            if (items.size() == 0) {
                continue;
            }
            if (creature->canEquip(items[0], &reason)) {
                creature->equip(items[0]);
            } else
                creature->privateMessage(reason);
        }
    }
}
Example #6
0
void Player::displayInventory() {
  if (!creature->isHumanoid()) {
    model->getView()->presentText("", "You can't use inventory.");
    return;
  }
  if (creature->getEquipment().isEmpty()) {
    model->getView()->presentText("", "Your inventory is empty.");
    return;
  }
  vector<Item*> item = chooseItem("Inventory:", alwaysTrue<const Item*>(), ActionId::SHOW_INVENTORY);
  if (item.size() == 0) {
    return;
  }
  vector<View::ListElem> options;
  if (creature->canEquip(item[0], nullptr)) {
    options.push_back("equip");
  }
  if (creature->canApplyItem(item[0])) {
    options.push_back("apply");
  }
  if (creature->canUnequip(item[0], nullptr))
    options.push_back("remove");
  else {
    options.push_back("throw");
    options.push_back("drop");
  }
  auto index = model->getView()->chooseFromList("What to do with " + getPluralName(item[0], item.size()) + "?", options);
  if (!index) {
    displayInventory();
    return;
  }
  if (options[*index].getText() == "drop") {
    creature->privateMessage("You drop " + getPluralName(item[0], item.size()));
    creature->drop(item);
  }
  if (options[*index].getText() == "throw") {
    throwItem(item);
  }
  if (options[*index].getText() == "apply") {
    applyItem(item);
  }
  if (options[*index].getText() == "remove") {
    creature->privateMessage("You remove " + getPluralName(item[0], item.size()));
    creature->unequip(getOnlyElement(item));
  }
  if (options[*index].getText() == "equip") {
    creature->privateMessage("You equip " + getPluralName(item[0], item.size()));
    creature->equip(item[0]);
  }
}
Example #7
0
void Player::dropAction(bool extended) {
  vector<Item*> items = chooseItem("Choose an item to drop:", [this](const Item* item) {
      return !creature->getEquipment().isEquiped(item) || item->getType() == ItemType::WEAPON;}, UserInput::DROP);
  int num = items.size();
  if (num < 1)
    return;
  if (extended && num > 1) {
    Optional<int> res = model->getView()->getNumber("Drop how many " + items[0]->getName(true, creature->isBlind()) 
        + "?", 1, num);
    if (!res)
      return;
    num = *res;
  }
  tryToPerform(creature->drop(getPrefix(items, 0, num)));
}
Example #8
0
void Player::equipmentAction() {
  if (!creature->isHumanoid()) {
    privateMessage("You can't use any equipment.");
    return;
  }
  vector<EquipmentSlot> slots;
  for (auto slot : Equipment::slotTitles)
    slots.push_back(slot.first);
  int index = 0;
  creature->startEquipChain();
  while (1) {
    vector<View::ListElem> list;
    for (auto slot : slots) {
      list.push_back(View::ListElem(Equipment::slotTitles.at(slot), View::TITLE));
      Item* item = creature->getEquipment().getItem(slot);
      if (item)
        list.push_back(item->getNameAndModifiers());
      else
        list.push_back("[Nothing]");
    }
    model->getView()->updateView(creature);
    Optional<int> newIndex = model->getView()->chooseFromList("Equipment", list, index, View::NORMAL_MENU, nullptr,
        UserInput::Type::EQUIPMENT);
    if (!newIndex) {
      creature->finishEquipChain();
      return;
    }
    index = *newIndex;
    EquipmentSlot slot = slots[index];
    if (Item* item = creature->getEquipment().getItem(slot)) {
      tryToPerform(creature->unequip(item));
    } else {
      vector<Item*> items = chooseItem("Choose an item to equip:", [=](const Item* item) {
          return item->canEquip()
          && !creature->getEquipment().isEquiped(item)
          && item->getEquipmentSlot() == slot;});
      if (items.size() == 0) {
        continue;
      }
      if (slot == EquipmentSlot::WEAPON && creature->getAttr(AttrType::STRENGTH) < items[0]->getMinStrength()
          && !model->getView()->yesOrNoPrompt(items[0]->getTheName() + " is too heavy for you, and you will get an accuracy penaulty.\n Do you want to equip it?")) {
        creature->finishEquipChain();
        return;
      }
      tryToPerform(creature->equip(items[0]));
    }
  }
}
Example #9
0
void Player::grantIdentify(int numItems) {
  auto unidentFun = [this](const Item* item) { return item->canIdentify() && !item->isIdentified();};
  vector<Item*> unIded = creature->getEquipment().getItems(unidentFun);
  if (unIded.empty()) {
    privateMessage("All your posessions are already identified");
    return;
  }
  if (numItems > unIded.size()) {
    privateMessage("You identify all your posessions");
    for (Item* it : unIded)
      it->identify();
  } else
  for (int i : Range(numItems)) {
    vector<Item*> items = chooseItem("Choose an item to identify:", unidentFun);
    if (items.size() == 0)
      return; 
    items[0]->identify();
    privateMessage("You identify " + items[0]->getTheName());
  }
}
Example #10
0
//=========================
//背包的显示组件
//=========================
BackPackBarWidget::BackPackBarWidget()
    :QWidget(0)
{
    pocketThing.clear();

    for(int i=0;i<9;i++){                   //创建物品栏的9个映射格子
        ThingItemPanel *pi=new ThingItemPanel(16,this);
        pocketThing.append(pi);
        connect(pi,SIGNAL(mouseChoose()),this,SLOT(chooseItem()));
    }

    lastPageButton=new QPushButton("<",this);
    nextPageButton=new QPushButton(">",this);

    connect(lastPageButton,SIGNAL(clicked()),this,SLOT(lastPage()));
    connect(nextPageButton,SIGNAL(clicked()),this,SLOT(nextPage()));
    page=0;
    lastPageButton->setDisabled(true);

    this->setMouseTracking(true);
    this->setAttribute(Qt::WA_TranslucentBackground,true);          //背景透明
}
Example #11
0
void Menu::mouseClick()
{
  if( itemUnderMouse() )
    chooseItem();
}