Пример #1
0
const Tooltip &ClientObjectType::constructionTooltip() const {
  if (_constructionTooltip.hasValue()) return _constructionTooltip.value();

  const auto &client = *Client::_instance;

  _constructionTooltip = Tooltip{};
  auto &tooltip = _constructionTooltip.value();
  tooltip.setColor(Color::TOOLTIP_NAME);
  tooltip.addLine(_name);

  auto descriptionLines = std::vector<std::string>{};

  auto gapDrawn = false;

  if (isDebug()) descriptionLines.push_back(id());

  if (canGather()) {
    std::string text = "Gatherable";
    if (!gatherReq().empty())
      text += " (requires " + client.tagName(gatherReq()) + ")";
    descriptionLines.push_back(text);
  }

  if (canDeconstruct()) descriptionLines.push_back("Can pick up as item");

  if (containerSlots() > 0)
    descriptionLines.push_back("Container: " + toString(containerSlots()) +
                               " slots");

  if (merchantSlots() > 0)
    descriptionLines.push_back("Merchant: " + toString(merchantSlots()) +
                               " slots");

  if (!descriptionLines.empty()) tooltip.addGap();
  for (const auto &line : descriptionLines) tooltip.addLine(line);

  // Tags
  if (hasTags()) {
    tooltip.addGap();
    tooltip.setColor(Color::TOOLTIP_TAG);
    for (const std::string &tag : tags()) tooltip.addLine(client.tagName(tag));
  }

  tooltip.addGap();
  tooltip.setColor(Color::TOOLTIP_BODY);
  tooltip.addLine("Construction materials:");
  for (const auto &material : _materials) {
    const ClientItem &item = *dynamic_cast<const ClientItem *>(material.first);
    tooltip.addLine(makeArgs(material.second) + "x " + item.name());
  }

  if (!_constructionReq.empty()) {
    tooltip.addGap();
    tooltip.addLine("Requires tool: " + client.tagName(_constructionReq));
  }

  return tooltip;
}
Пример #2
0
	void GatherState::tick(float deltaTime)
	{
		string success;
		string start;

		if (canGather())
		{
			if (_actor->getBAC() > .4)
			{
				cout << _actor->getName()
						<< " drunkenly swings the tool, hits himself in the foot, and decides not to do that anymore."
						<< "\n";
				switchState("null");
			}
			else
			{
				bool canPickup = true;
				string typeName = _target->getName();
				Item* removedItem;
				if (typeName.find("gold") != string::npos)
				{
					Item gold("gold", _target->getColor(), true);
					removedItem = _target->getInventory().removeItem(gold);
					start = " lifts his pickaxe, and swings it at the rock.";
					success = " successfully mines some ";
				}
				else if (typeName.find("iron") != string::npos)
				{
					Item iron("iron", _target->getColor(), true);
					removedItem = _target->getInventory().removeItem(iron);
					start = " lifts his pickaxe, and swings it at the rock.";
					success = " successfully mines some ";
				}
				else if (typeName.find("coal") != string::npos)
				{
					Item coal("coal", _target->getColor(), true);
					removedItem = _target->getInventory().removeItem(coal);
					start = " lifts his pickaxe, and swings it at the rock.";
					success = " successfully mines some ";
				}
				else if (typeName.find("redwood") != string::npos
						|| typeName.find("oak") != string::npos
						|| typeName.find("birch") != string::npos
						|| typeName.find("cedar") != string::npos)
				{
					Item wood("wood", _target->getColor(), true);
					removedItem = _target->getInventory().removeItem(wood);
					start =
							" takes out his hatchet, and swings it at the tree.";
					success = " successfully chops some ";
				}
				else if (typeName.find("dock") != string::npos)
				{
					Item fish("fish", _target->getColor(), true);
					removedItem = _target->getInventory().removeItem(fish);
					start = " pulls out his harpoon, and jabs it at the water.";
					success = " successfully catches some ";
				}

				_actor->reduceStamina(1);

				string coloredName = Color::colorText(removedItem->getName(),
						removedItem->getColor());
				canPickup = _actor->getInventory().addItem(removedItem);
				cout << _actor->getName() << start << "\n";
				cout << _actor->getName() << success << coloredName << "\n";

				if (!canPickup)
				{
					delete removedItem;
					cout << _actor->getName()
							<< " has a full inventory, and drops "
							<< coloredName << " on the ground.\n";
					_amount = 0;
					switchState("null");
				}

				_amount--;
			}

		}

		else
		{
			_amount = 0;

			switchState("null");
		}
	}