Пример #1
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]);
  }
}
Пример #2
0
void XmlSchema::addSimpleVector(const XmlNode* child, String& structDefinition, size_t typeWidth,
								 String& readingFunction, String& writingFunction) const
{
	assert(child != NULL);
	XmlAttribute* type = child->findAttribute(ATTR_TYPE);
	if (type == NULL)
	{
		return;
	}
	
	String typeString = T("std::vector<");
	typeString += getSimpleTypeString(type);
	typeString += T(">");

	size_t thisWidth = typeString.size();
	assert(thisWidth < typeWidth + 1);
	for (size_t i = 0; i < typeWidth + 1 - thisWidth; ++i)
	{
		typeString += T(" ");
	}
	structDefinition += T("	");
	structDefinition += typeString;
	structDefinition += getPluralName(child->getName());
	structDefinition += T(";\r\n");	

	readingFunction += T("\r\n	childNode = node->findFirstChild(");
	readingFunction += LEFT_QUOTE;
	readingFunction += child->getName();
	readingFunction += T("\", iter);\r\n	while (childNode != NULL)\r\n	{\r\n		");
	readingFunction += getPluralName(child->getName());
	readingFunction += T(".resize(");
	readingFunction += getPluralName(child->getName());
	readingFunction += T(".size() + 1);\r\n		");
	readingFunction += getPluralName(child->getName());
	readingFunction += T(".back() = childNode->get");
	String typeName = type->getString();
	typeName[0] -= 32;
	readingFunction += typeName;
	readingFunction += T("();\r\n		childNode = node->findNextChild(");
	readingFunction += LEFT_QUOTE;
	readingFunction += child->getName();
	readingFunction += T("\", iter);\r\n	}\r\n");

	writingFunction += T("\r\n	for (std::vector<");
	writingFunction += getSimpleTypeString(type);
	writingFunction += T(">::const_iterator iter = ");
	writingFunction += getPluralName(child->getName());
	writingFunction += T(".begin();\r\n		  iter != ");
	writingFunction += getPluralName(child->getName());
	writingFunction += T(".end();\r\n		  ++iter)\r\n	{\r\n		const ");
	writingFunction += getSimpleTypeString(type);
	writingFunction += T("& value = *iter;\r\n");
	writingFunction += T("		childNode = node->addChild(");
	writingFunction += LEFT_QUOTE;
	writingFunction += child->getName();
	writingFunction += T("\");\r\n		childNode->set");
	writingFunction += typeName;
	writingFunction += T("(value);\r\n	}\r\n");
}
Пример #3
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;}, ActionId::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;
  }
  creature->privateMessage("You drop " + getPluralName(items[0], num));
  creature->drop(getPrefix(items, 0, num));
}
Пример #4
0
void Player::onItemsAppeared(vector<Item*> items, const Creature* from) {
  if (!creature->canPickUp(items))
    return;
  vector<View::ListElem> names;
  vector<vector<Item*> > groups;
  getItemNames(items, names, groups);
  CHECK(!names.empty());
  Optional<int> index = model->getView()->chooseFromList("Do you want to take it?", names);
  if (!index) {
    return;
  }
  int num = groups[*index].size(); //groups[index].size() == 1 ? 1 : howMany(model->getView(), groups[index].size());
  if (num < 1)
    return;
  creature->privateMessage("You take " + getPluralName(groups[*index][0], num));
  creature->pickUp(getPrefix(groups[*index], 0, num), false);
}
Пример #5
0
void Player::pickUpAction(bool extended) {
    auto items = creature->getPickUpOptions();
    const Square* square = creature->getConstSquare();
    if (square->getApplyType(creature)) {
        string question = getSquareQuestion(*square->getApplyType(creature), square->getName());
        if (!question.empty() && (items.empty() || model->getView()->yesOrNoPrompt(question))) {
            creature->applySquare();
            return;
        }
    }
    vector<View::ListElem> names;
    vector<vector<Item*> > groups;
    getItemNames(creature->getPickUpOptions(), names, groups);
    if (names.empty())
        return;
    int index = 0;
    if (names.size() > 1) {
        Optional<int> res = model->getView()->chooseFromList("Choose an item to pick up:", names);
        if (!res)
            return;
        else
            index = *res;
    }
    int num = groups[index].size();
    if (num < 1)
        return;
    if (extended && num > 1) {
        Optional<int> res = model->getView()->getNumber("Pick up how many " + groups[index][0]->getName(true) + "?",
                            1, num);
        if (!res)
            return;
        num = *res;
    }
    vector<Item*> pickUpItems = getPrefix(groups[index], 0, num);
    if (creature->canPickUp(pickUpItems)) {
        creature->privateMessage("You pick up " + getPluralName(groups[index][0], num));
        creature->pickUp(pickUpItems);
    }
}
Пример #6
0
void XmlSchema::addStructVector(const XmlNode* child, String& structDefinition, size_t typeWidth,
								 String& readingFunction, String& writingFunction) const
{
	assert(child != NULL);

	structDefinition += T("	std::vector<");
	structDefinition += child->getName();
	structDefinition += T(">");
	size_t thisWidth = Strlen(child->getName()) + Strlen(T("std::vector<>"));
	assert(thisWidth < typeWidth + 1);
	for (size_t i = 0;	i < typeWidth + 1 - thisWidth; ++i)
	{
		structDefinition += T(" ");
	}
	structDefinition += getPluralName(child->getName());
	structDefinition += T(";\r\n");

	readingFunction += T("\r\n	childNode = node->findFirstChild(");
	readingFunction += LEFT_QUOTE;
	readingFunction += child->getName();
	readingFunction += T("\", iter);\r\n	while (childNode != NULL)\r\n	{\r\n		");
	readingFunction += getPluralName(child->getName());
	readingFunction += T(".resize(");
	readingFunction += getPluralName(child->getName());
	readingFunction += T(".size() + 1);\r\n		");
	readingFunction += getPluralName(child->getName());
	readingFunction += T(".back().read(childNode);\r\n		childNode = node->findNextChild(");
	readingFunction += LEFT_QUOTE;
	readingFunction += child->getName();
	readingFunction += T("\", iter);\r\n	}\r\n");

	writingFunction += T("\r\n	for (std::vector<");
	writingFunction += child->getName();
	writingFunction += T(">::const_iterator iter = ");
	writingFunction += getPluralName(child->getName());
	writingFunction += T(".begin();\r\n		  iter != ");
	writingFunction += getPluralName(child->getName());
	writingFunction += T(".end();\r\n		  ++iter)\r\n	{\r\n		const ");
	writingFunction += child->getName();
	writingFunction += T("& obj = *iter;\r\n");
	writingFunction += T("		childNode = node->addChild(");
	writingFunction += LEFT_QUOTE;
	writingFunction += child->getName();
	writingFunction += T("\");\r\n		obj.write(childNode);\r\n	}\r\n");
}