|
|
@@ -2,6 +2,10 @@
|
|
|
|
|
|
#include <Fenster.h>
|
|
|
|
|
|
+#include "BlockType.h"
|
|
|
+#include "Game.h"
|
|
|
+#include "ItemFilter.h"
|
|
|
+#include "ItemType.h"
|
|
|
#include "Quest.h"
|
|
|
|
|
|
QuestRequirement::QuestRequirement()
|
|
|
@@ -137,4 +141,632 @@ JSONObjectValidationBuilder* QuestRequirementOpenDialogType::addToValidator(
|
|
|
const char* QuestRequirementOpenDialogType::getTypeToken() const
|
|
|
{
|
|
|
return "open_dialog";
|
|
|
+}
|
|
|
+
|
|
|
+QuestRequirementBlockBreak::QuestRequirementBlockBreak()
|
|
|
+ : QuestRequirement(),
|
|
|
+ blockTypeId(0),
|
|
|
+ amount(1),
|
|
|
+ usedItemTypeId(-1)
|
|
|
+{}
|
|
|
+
|
|
|
+void QuestRequirementBlockBreak::processEvent(
|
|
|
+ QuestEvent* zEvent, QuestStorage* zStorage)
|
|
|
+{
|
|
|
+ QuestEventBlockBreak* event = dynamic_cast<QuestEventBlockBreak*>(zEvent);
|
|
|
+ if (event)
|
|
|
+ {
|
|
|
+ if (event->getBlockTypeId() == blockTypeId)
|
|
|
+ {
|
|
|
+ if (usedItemTypeId != -1
|
|
|
+ && event->getUsedItemTypeId() != usedItemTypeId)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int currentAmount = zStorage->containsKey(getRequirementId())
|
|
|
+ ? (int)zStorage->zValue(getRequirementId())
|
|
|
+ ->asNumber()
|
|
|
+ ->getNumber()
|
|
|
+ : 0;
|
|
|
+ currentAmount += 1;
|
|
|
+ zStorage->putValue(getRequirementId(),
|
|
|
+ new Framework::JSON::JSONNumber(currentAmount));
|
|
|
+ if (currentAmount >= amount)
|
|
|
+ {
|
|
|
+ zStorage->zStorage(getRequirementId())->setFullfilled(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementBlockBreak::addRequirementUIML(QuestStorage* zStorage,
|
|
|
+ Framework::XML::Element* zParent,
|
|
|
+ Framework::Text onClickPrefix)
|
|
|
+{
|
|
|
+ Framework::XML::Element* container = new Framework::XML::Element(
|
|
|
+ "<frame width=\"100%\" height=\"50\" display=\"row\" gap=\"10\"/>");
|
|
|
+ container->setAttribute("style",
|
|
|
+ Framework::Text() += (Framework::Fenster::Style::Sichtbar
|
|
|
+ | Framework::Fenster::Style::Erlaubt));
|
|
|
+ container->setAttribute(
|
|
|
+ "id", Framework::Text("requirement_") += getRequirementId());
|
|
|
+ // TODO: add icon of block
|
|
|
+ auto text
|
|
|
+ = new Framework::XML::Element("<text width=\"auto\" height=\"auto\"/>");
|
|
|
+ text->setAttribute("id",
|
|
|
+ Framework::Text("requirement_description_") += getRequirementId());
|
|
|
+ text->setText(description);
|
|
|
+ container->addChild(text);
|
|
|
+ auto status = new Framework::XML::Element(
|
|
|
+ "<text margin-top=\"10\" width=\"auto\" height=\"auto\"/>");
|
|
|
+ status->setAttribute("align-top", text->getAttributeValue("id"));
|
|
|
+ status->setAttribute("align-x", text->getAttributeValue("id"));
|
|
|
+ if (zStorage->zStorage(getRequirementId())->isFullfilled())
|
|
|
+ {
|
|
|
+ Framework::Text completedText = "Completed (";
|
|
|
+ completedText.append() << amount << "/" << amount << ")";
|
|
|
+ status->setText(completedText.getText());
|
|
|
+ status->setAttribute("text-color", "0xFF00FF00");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int currentAmount = zStorage->containsKey(getRequirementId())
|
|
|
+ ? (int)zStorage->zValue(getRequirementId())
|
|
|
+ ->asNumber()
|
|
|
+ ->getNumber()
|
|
|
+ : 0;
|
|
|
+ Framework::Text completedText = "Not completed (";
|
|
|
+ completedText.append() << currentAmount << "/" << amount << ")";
|
|
|
+ status->setAttribute("text-color", "0xFFFF0000");
|
|
|
+ }
|
|
|
+ container->addChild(status);
|
|
|
+ zParent->addChild(container);
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementBlockBreak::setBlockTypeId(int blockTypeId)
|
|
|
+{
|
|
|
+ this->blockTypeId = blockTypeId;
|
|
|
+}
|
|
|
+
|
|
|
+int QuestRequirementBlockBreak::getBlockTypeId() const
|
|
|
+{
|
|
|
+ return blockTypeId;
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementBlockBreak::setAmount(int amount)
|
|
|
+{
|
|
|
+ this->amount = amount;
|
|
|
+}
|
|
|
+
|
|
|
+int QuestRequirementBlockBreak::getAmount() const
|
|
|
+{
|
|
|
+ return amount;
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementBlockBreak::setUsedItemTypeId(int usedItemTypeId)
|
|
|
+{
|
|
|
+ this->usedItemTypeId = usedItemTypeId;
|
|
|
+}
|
|
|
+
|
|
|
+int QuestRequirementBlockBreak::getUsedItemTypeId() const
|
|
|
+{
|
|
|
+ return usedItemTypeId;
|
|
|
+}
|
|
|
+
|
|
|
+QuestRequirementBlockBreakType::QuestRequirementBlockBreakType()
|
|
|
+ : QuestRequirementFactoryBase()
|
|
|
+{}
|
|
|
+
|
|
|
+QuestRequirementBlockBreak* QuestRequirementBlockBreakType::createValue(
|
|
|
+ Framework::JSON::JSONObject* zJson) const
|
|
|
+{
|
|
|
+ return new QuestRequirementBlockBreak();
|
|
|
+}
|
|
|
+
|
|
|
+QuestRequirementBlockBreak* QuestRequirementBlockBreakType::fromJson(
|
|
|
+ Framework::JSON::JSONObject* zJson) const
|
|
|
+{
|
|
|
+ QuestRequirementBlockBreak* result
|
|
|
+ = QuestRequirementFactoryBase::fromJson(zJson);
|
|
|
+ result->setBlockTypeId(Game::INSTANCE->getBlockTypeId(
|
|
|
+ zJson->zValue("blockType")->asString()->getString()));
|
|
|
+ result->setAmount((int)zJson->zValue("amount")->asNumber()->getNumber());
|
|
|
+ if (zJson->hasValue("usedItemTypeId"))
|
|
|
+ {
|
|
|
+ result->setUsedItemTypeId(Game::INSTANCE->getItemTypeId(
|
|
|
+ zJson->zValue("usedItemType")->asString()->getString()));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result->setUsedItemTypeId(-1);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+Framework::JSON::JSONObject* QuestRequirementBlockBreakType::toJsonObject(
|
|
|
+ QuestRequirementBlockBreak* zObject) const
|
|
|
+{
|
|
|
+ Framework::JSON::JSONObject* result
|
|
|
+ = QuestRequirementFactoryBase::toJsonObject(zObject);
|
|
|
+ result->addValue("blockType",
|
|
|
+ new Framework::JSON::JSONString(
|
|
|
+ Game::INSTANCE->zBlockType(zObject->getBlockTypeId())->getName()));
|
|
|
+ result->addValue("amount",
|
|
|
+ new Framework::JSON::JSONNumber((double)zObject->getAmount()));
|
|
|
+ if (zObject->getUsedItemTypeId() != -1)
|
|
|
+ {
|
|
|
+ result->addValue("usedItemType",
|
|
|
+ new Framework::JSON::JSONString(
|
|
|
+ Game::INSTANCE->zItemType(zObject->getUsedItemTypeId())
|
|
|
+ ->getName()));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+JSONObjectValidationBuilder* QuestRequirementBlockBreakType::addToValidator(
|
|
|
+ JSONObjectValidationBuilder* builder) const
|
|
|
+{
|
|
|
+ return QuestRequirementFactoryBase::addToValidator(builder
|
|
|
+ ->withRequiredAttribute("blockType",
|
|
|
+ Game::INSTANCE->zTypeRegistry()->getValidator<Framework::Text>(
|
|
|
+ BlockTypeNameFactory::TYPE_ID))
|
|
|
+ ->withRequiredNumber("amount")
|
|
|
+ ->whichIsGreaterOrEqual(1.0)
|
|
|
+ ->withDefault(1.0)
|
|
|
+ ->finishNumber()
|
|
|
+ ->withOptionalAttribute("usedItemType",
|
|
|
+ Game::INSTANCE->zTypeRegistry()->getValidator<Framework::Text>(
|
|
|
+ ItemTypeNameFactory::TYPE_ID)));
|
|
|
+}
|
|
|
+
|
|
|
+const char* QuestRequirementBlockBreakType::getTypeToken() const
|
|
|
+{
|
|
|
+ return "block_break";
|
|
|
+}
|
|
|
+
|
|
|
+QuestRequirementBlockPlace::QuestRequirementBlockPlace()
|
|
|
+ : QuestRequirement(),
|
|
|
+ blockTypeId(0),
|
|
|
+ amount(1)
|
|
|
+{}
|
|
|
+
|
|
|
+void QuestRequirementBlockPlace::processEvent(
|
|
|
+ QuestEvent* zEvent, QuestStorage* zStorage)
|
|
|
+{
|
|
|
+ QuestEventBlockPlace* event = dynamic_cast<QuestEventBlockPlace*>(zEvent);
|
|
|
+ if (event)
|
|
|
+ {
|
|
|
+ if (event->getBlockTypeId() == blockTypeId)
|
|
|
+ {
|
|
|
+ int currentAmount = zStorage->containsKey(getRequirementId())
|
|
|
+ ? (int)zStorage->zValue(getRequirementId())
|
|
|
+ ->asNumber()
|
|
|
+ ->getNumber()
|
|
|
+ : 0;
|
|
|
+ currentAmount += 1;
|
|
|
+ zStorage->putValue(getRequirementId(),
|
|
|
+ new Framework::JSON::JSONNumber(currentAmount));
|
|
|
+ if (currentAmount >= amount)
|
|
|
+ {
|
|
|
+ zStorage->zStorage(getRequirementId())->setFullfilled(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementBlockPlace::addRequirementUIML(QuestStorage* zStorage,
|
|
|
+ Framework::XML::Element* zParent,
|
|
|
+ Framework::Text onClickPrefix)
|
|
|
+{
|
|
|
+ Framework::XML::Element* container = new Framework::XML::Element(
|
|
|
+ "<frame width=\"100%\" height=\"50\" display=\"row\" gap=\"10\"/>");
|
|
|
+ container->setAttribute("style",
|
|
|
+ Framework::Text() += (Framework::Fenster::Style::Sichtbar
|
|
|
+ | Framework::Fenster::Style::Erlaubt));
|
|
|
+ container->setAttribute(
|
|
|
+ "id", Framework::Text("requirement_") += getRequirementId());
|
|
|
+ // TODO: add icon of block
|
|
|
+ auto text
|
|
|
+ = new Framework::XML::Element("<text width=\"auto\" height=\"auto\"/>");
|
|
|
+ text->setAttribute("id",
|
|
|
+ Framework::Text("requirement_description_") += getRequirementId());
|
|
|
+ text->setText(description);
|
|
|
+ container->addChild(text);
|
|
|
+ auto status = new Framework::XML::Element(
|
|
|
+ "<text margin-top=\"10\" width=\"auto\" height=\"auto\"/>");
|
|
|
+ status->setAttribute("align-top", text->getAttributeValue("id"));
|
|
|
+ status->setAttribute("align-x", text->getAttributeValue("id"));
|
|
|
+ if (zStorage->zStorage(getRequirementId())->isFullfilled())
|
|
|
+ {
|
|
|
+ Framework::Text completedText = "Completed (";
|
|
|
+ completedText.append() << amount << "/" << amount << ")";
|
|
|
+ status->setText(completedText.getText());
|
|
|
+ status->setAttribute("text-color", "0xFF00FF00");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int currentAmount = zStorage->containsKey(getRequirementId())
|
|
|
+ ? (int)zStorage->zValue(getRequirementId())
|
|
|
+ ->asNumber()
|
|
|
+ ->getNumber()
|
|
|
+ : 0;
|
|
|
+ Framework::Text completedText = "Not completed (";
|
|
|
+ completedText.append() << currentAmount << "/" << amount << ")";
|
|
|
+ status->setAttribute("text-color", "0xFFFF0000");
|
|
|
+ }
|
|
|
+ container->addChild(status);
|
|
|
+ zParent->addChild(container);
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementBlockPlace::setBlockTypeId(int blockTypeId)
|
|
|
+{
|
|
|
+ this->blockTypeId = blockTypeId;
|
|
|
+}
|
|
|
+
|
|
|
+int QuestRequirementBlockPlace::getBlockTypeId() const
|
|
|
+{
|
|
|
+ return blockTypeId;
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementBlockPlace::setAmount(int amount)
|
|
|
+{
|
|
|
+ this->amount = amount;
|
|
|
+}
|
|
|
+
|
|
|
+int QuestRequirementBlockPlace::getAmount() const
|
|
|
+{
|
|
|
+ return amount;
|
|
|
+}
|
|
|
+
|
|
|
+QuestRequirementBlockPlaceType::QuestRequirementBlockPlaceType()
|
|
|
+ : QuestRequirementFactoryBase()
|
|
|
+{}
|
|
|
+
|
|
|
+QuestRequirementBlockPlace* QuestRequirementBlockPlaceType::createValue(
|
|
|
+ Framework::JSON::JSONObject* zJson) const
|
|
|
+{
|
|
|
+ return new QuestRequirementBlockPlace();
|
|
|
+}
|
|
|
+
|
|
|
+QuestRequirementBlockPlace* QuestRequirementBlockPlaceType::fromJson(
|
|
|
+ Framework::JSON::JSONObject* zJson) const
|
|
|
+{
|
|
|
+ QuestRequirementBlockPlace* result
|
|
|
+ = QuestRequirementFactoryBase::fromJson(zJson);
|
|
|
+ result->setBlockTypeId(Game::INSTANCE->getBlockTypeId(
|
|
|
+ zJson->zValue("blockType")->asString()->getString()));
|
|
|
+ result->setAmount((int)zJson->zValue("amount")->asNumber()->getNumber());
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+Framework::JSON::JSONObject* QuestRequirementBlockPlaceType::toJsonObject(
|
|
|
+ QuestRequirementBlockPlace* zObject) const
|
|
|
+{
|
|
|
+ Framework::JSON::JSONObject* result
|
|
|
+ = QuestRequirementFactoryBase::toJsonObject(zObject);
|
|
|
+ result->addValue("blockType",
|
|
|
+ new Framework::JSON::JSONString(
|
|
|
+ Game::INSTANCE->zBlockType(zObject->getBlockTypeId())->getName()));
|
|
|
+ result->addValue("amount",
|
|
|
+ new Framework::JSON::JSONNumber((double)zObject->getAmount()));
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+JSONObjectValidationBuilder* QuestRequirementBlockPlaceType::addToValidator(
|
|
|
+ JSONObjectValidationBuilder* builder) const
|
|
|
+{
|
|
|
+ return QuestRequirementFactoryBase::addToValidator(builder
|
|
|
+ ->withRequiredAttribute("blockType",
|
|
|
+ Game::INSTANCE->zTypeRegistry()->getValidator<Framework::Text>(
|
|
|
+ BlockTypeNameFactory::TYPE_ID))
|
|
|
+ ->withRequiredNumber("amount")
|
|
|
+ ->whichIsGreaterOrEqual(1.0)
|
|
|
+ ->withDefault(1.0)
|
|
|
+ ->finishNumber());
|
|
|
+}
|
|
|
+
|
|
|
+const char* QuestRequirementBlockPlaceType::getTypeToken() const
|
|
|
+{
|
|
|
+ return "block_place";
|
|
|
+}
|
|
|
+
|
|
|
+QuestRequirementBlockInteract::QuestRequirementBlockInteract()
|
|
|
+ : QuestRequirement(),
|
|
|
+ blockTypeId(0),
|
|
|
+ itemTypeId(-1)
|
|
|
+{}
|
|
|
+
|
|
|
+void QuestRequirementBlockInteract::processEvent(
|
|
|
+ QuestEvent* zEvent, QuestStorage* zStorage)
|
|
|
+{
|
|
|
+ QuestEventBlockInteract* event
|
|
|
+ = dynamic_cast<QuestEventBlockInteract*>(zEvent);
|
|
|
+ if (event)
|
|
|
+ {
|
|
|
+ if (event->getBlockTypeId() == blockTypeId)
|
|
|
+ {
|
|
|
+ if (itemTypeId != -1 && event->getUsedItemTypeId() != itemTypeId)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ QuestRequirementStorage* zRequirementStorage
|
|
|
+ = zStorage->zStorage(getRequirementId());
|
|
|
+ zRequirementStorage->setFullfilled(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementBlockInteract::addRequirementUIML(QuestStorage* zStorage,
|
|
|
+ Framework::XML::Element* zParent,
|
|
|
+ Framework::Text onClickPrefix)
|
|
|
+{
|
|
|
+ Framework::XML::Element* container = new Framework::XML::Element(
|
|
|
+ "<frame width=\"100%\" height=\"50\" display=\"row\" gap=\"10\"/>");
|
|
|
+ container->setAttribute("style",
|
|
|
+ Framework::Text() += (Framework::Fenster::Style::Sichtbar
|
|
|
+ | Framework::Fenster::Style::Erlaubt));
|
|
|
+ container->setAttribute(
|
|
|
+ "id", Framework::Text("requirement_") += getRequirementId());
|
|
|
+ // TODO: add icon of block
|
|
|
+ auto text
|
|
|
+ = new Framework::XML::Element("<text width=\"auto\" height=\"auto\"/>");
|
|
|
+ text->setAttribute("id",
|
|
|
+ Framework::Text("requirement_description_") += getRequirementId());
|
|
|
+ text->setText(description);
|
|
|
+ container->addChild(text);
|
|
|
+ auto status = new Framework::XML::Element(
|
|
|
+ "<text margin-top=\"10\" width=\"auto\" height=\"auto\"/>");
|
|
|
+ status->setAttribute("align-top", text->getAttributeValue("id"));
|
|
|
+ status->setAttribute("align-x", text->getAttributeValue("id"));
|
|
|
+ if (zStorage->zStorage(getRequirementId())->isFullfilled())
|
|
|
+ {
|
|
|
+ status->setText("Completed");
|
|
|
+ status->setAttribute("text-color", "0xFF00FF00");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ status->setText("Not completed");
|
|
|
+ status->setAttribute("text-color", "0xFFFF0000");
|
|
|
+ }
|
|
|
+ container->addChild(status);
|
|
|
+ zParent->addChild(container);
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementBlockInteract::setBlockTypeId(int blockTypeId)
|
|
|
+{
|
|
|
+ this->blockTypeId = blockTypeId;
|
|
|
+}
|
|
|
+
|
|
|
+int QuestRequirementBlockInteract::getBlockTypeId() const
|
|
|
+{
|
|
|
+ return blockTypeId;
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementBlockInteract::setItemTypeId(int itemTypeId)
|
|
|
+{
|
|
|
+ this->itemTypeId = itemTypeId;
|
|
|
+}
|
|
|
+
|
|
|
+int QuestRequirementBlockInteract::getItemTypeId() const
|
|
|
+{
|
|
|
+ return itemTypeId;
|
|
|
+}
|
|
|
+
|
|
|
+QuestRequirementBlockInteractType::QuestRequirementBlockInteractType()
|
|
|
+ : QuestRequirementFactoryBase()
|
|
|
+{}
|
|
|
+
|
|
|
+QuestRequirementBlockInteract* QuestRequirementBlockInteractType::createValue(
|
|
|
+ Framework::JSON::JSONObject* zJson) const
|
|
|
+{
|
|
|
+ return new QuestRequirementBlockInteract();
|
|
|
+}
|
|
|
+
|
|
|
+QuestRequirementBlockInteract* QuestRequirementBlockInteractType::fromJson(
|
|
|
+ Framework::JSON::JSONObject* zJson) const
|
|
|
+{
|
|
|
+ QuestRequirementBlockInteract* result
|
|
|
+ = QuestRequirementFactoryBase::fromJson(zJson);
|
|
|
+ result->setBlockTypeId(Game::INSTANCE->getBlockTypeId(
|
|
|
+ zJson->zValue("blockType")->asString()->getString()));
|
|
|
+ if (zJson->hasValue("itemType"))
|
|
|
+ {
|
|
|
+ result->setItemTypeId(Game::INSTANCE->getItemTypeId(
|
|
|
+ zJson->zValue("itemType")->asString()->getString()));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result->setItemTypeId(-1);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+Framework::JSON::JSONObject* QuestRequirementBlockInteractType::toJsonObject(
|
|
|
+ QuestRequirementBlockInteract* zObject) const
|
|
|
+{
|
|
|
+ Framework::JSON::JSONObject* result
|
|
|
+ = QuestRequirementFactoryBase::toJsonObject(zObject);
|
|
|
+ result->addValue("blockType",
|
|
|
+ new Framework::JSON::JSONString(
|
|
|
+ Game::INSTANCE->zBlockType(zObject->getBlockTypeId())->getName()));
|
|
|
+ if (zObject->getItemTypeId() != -1)
|
|
|
+ {
|
|
|
+ result->addValue("itemType",
|
|
|
+ new Framework::JSON::JSONString(
|
|
|
+ Game::INSTANCE->zItemType(zObject->getItemTypeId())
|
|
|
+ ->getName()));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+JSONObjectValidationBuilder* QuestRequirementBlockInteractType::addToValidator(
|
|
|
+ JSONObjectValidationBuilder* builder) const
|
|
|
+{
|
|
|
+ return QuestRequirementFactoryBase::addToValidator(builder
|
|
|
+ ->withRequiredAttribute("blockType",
|
|
|
+ Game::INSTANCE->zTypeRegistry()->getValidator<Framework::Text>(
|
|
|
+ BlockTypeNameFactory::TYPE_ID))
|
|
|
+ ->withOptionalAttribute("itemType",
|
|
|
+ Game::INSTANCE->zTypeRegistry()->getValidator<Framework::Text>(
|
|
|
+ ItemTypeNameFactory::TYPE_ID)));
|
|
|
+}
|
|
|
+
|
|
|
+const char* QuestRequirementBlockInteractType::getTypeToken() const
|
|
|
+{
|
|
|
+ return "block_interact";
|
|
|
+}
|
|
|
+
|
|
|
+QuestRequirementItemInInventory::QuestRequirementItemInInventory()
|
|
|
+ : QuestRequirement(),
|
|
|
+ itemTypeId(0),
|
|
|
+ amount(1)
|
|
|
+{}
|
|
|
+
|
|
|
+void QuestRequirementItemInInventory::processEvent(
|
|
|
+ QuestEvent* zEvent, QuestStorage* zStorage)
|
|
|
+{
|
|
|
+ QuestEventItemPickup* event = dynamic_cast<QuestEventItemPickup*>(zEvent);
|
|
|
+ if (event)
|
|
|
+ {
|
|
|
+ if (event->getItemTypeId() == itemTypeId)
|
|
|
+ {
|
|
|
+ TypeItemFilter filter;
|
|
|
+ filter.setType(Game::INSTANCE->zItemType(itemTypeId));
|
|
|
+ int current = event->zActingEntity()->countAccessableItems(
|
|
|
+ &filter, Direction::NO_DIRECTION);
|
|
|
+ int currentAmount = zStorage->containsKey(getRequirementId())
|
|
|
+ ? (int)zStorage->zValue(getRequirementId())
|
|
|
+ ->asNumber()
|
|
|
+ ->getNumber()
|
|
|
+ : 0;
|
|
|
+ if (currentAmount < current)
|
|
|
+ {
|
|
|
+ currentAmount = current;
|
|
|
+ }
|
|
|
+ zStorage->putValue(getRequirementId(),
|
|
|
+ new Framework::JSON::JSONNumber(currentAmount));
|
|
|
+ if (currentAmount >= amount)
|
|
|
+ {
|
|
|
+ zStorage->zStorage(getRequirementId())->setFullfilled(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementItemInInventory::addRequirementUIML(QuestStorage* zStorage,
|
|
|
+ Framework::XML::Element* zParent,
|
|
|
+ Framework::Text onClickPrefix)
|
|
|
+{
|
|
|
+ Framework::XML::Element* container = new Framework::XML::Element(
|
|
|
+ "<frame width=\"100%\" height=\"50\" display=\"row\" gap=\"10\"/>");
|
|
|
+ container->setAttribute("style",
|
|
|
+ Framework::Text() += (Framework::Fenster::Style::Sichtbar
|
|
|
+ | Framework::Fenster::Style::Erlaubt));
|
|
|
+ container->setAttribute(
|
|
|
+ "id", Framework::Text("requirement_") += getRequirementId());
|
|
|
+ // TODO: add icon of item
|
|
|
+ auto text
|
|
|
+ = new Framework::XML::Element("<text width=\"auto\" height=\"auto\"/>");
|
|
|
+ text->setAttribute("id",
|
|
|
+ Framework::Text("requirement_description_") += getRequirementId());
|
|
|
+ text->setText(description);
|
|
|
+ container->addChild(text);
|
|
|
+ auto status = new Framework::XML::Element(
|
|
|
+ "<text margin-top=\"10\" width=\"auto\" height=\"auto\"/>");
|
|
|
+ status->setAttribute("align-top", text->getAttributeValue("id"));
|
|
|
+ status->setAttribute("align-x", text->getAttributeValue("id"));
|
|
|
+ if (zStorage->zStorage(getRequirementId())->isFullfilled())
|
|
|
+ {
|
|
|
+ Framework::Text completedText = "Completed (";
|
|
|
+ completedText.append() << amount << "/" << amount << ")";
|
|
|
+ status->setText(completedText.getText());
|
|
|
+ status->setAttribute("text-color", "0xFF00FF00");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ int currentAmount = zStorage->containsKey(getRequirementId())
|
|
|
+ ? (int)zStorage->zValue(getRequirementId())
|
|
|
+ ->asNumber()
|
|
|
+ ->getNumber()
|
|
|
+ : 0;
|
|
|
+ Framework::Text completedText = "Not completed (";
|
|
|
+ completedText.append() << currentAmount << "/" << amount << ")";
|
|
|
+ status->setAttribute("text-color", "0xFFFF0000");
|
|
|
+ }
|
|
|
+ container->addChild(status);
|
|
|
+ zParent->addChild(container);
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementItemInInventory::setItemTypeId(int itemTypeId)
|
|
|
+{
|
|
|
+ this->itemTypeId = itemTypeId;
|
|
|
+}
|
|
|
+
|
|
|
+int QuestRequirementItemInInventory::getItemTypeId() const
|
|
|
+{
|
|
|
+ return itemTypeId;
|
|
|
+}
|
|
|
+
|
|
|
+void QuestRequirementItemInInventory::setAmount(int amount)
|
|
|
+{
|
|
|
+ this->amount = amount;
|
|
|
+}
|
|
|
+
|
|
|
+int QuestRequirementItemInInventory::getAmount() const
|
|
|
+{
|
|
|
+ return amount;
|
|
|
+}
|
|
|
+
|
|
|
+QuestRequirementItemInInventoryType::QuestRequirementItemInInventoryType()
|
|
|
+ : QuestRequirementFactoryBase()
|
|
|
+{}
|
|
|
+
|
|
|
+QuestRequirementItemInInventory*
|
|
|
+QuestRequirementItemInInventoryType::createValue(
|
|
|
+ Framework::JSON::JSONObject* zJson) const
|
|
|
+{
|
|
|
+ return new QuestRequirementItemInInventory();
|
|
|
+}
|
|
|
+
|
|
|
+QuestRequirementItemInInventory* QuestRequirementItemInInventoryType::fromJson(
|
|
|
+ Framework::JSON::JSONObject* zJson) const
|
|
|
+{
|
|
|
+ QuestRequirementItemInInventory* result
|
|
|
+ = QuestRequirementFactoryBase::fromJson(zJson);
|
|
|
+ result->setItemTypeId(Game::INSTANCE->getItemTypeId(
|
|
|
+ zJson->zValue("itemType")->asString()->getString()));
|
|
|
+ result->setAmount((int)zJson->zValue("amount")->asNumber()->getNumber());
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+Framework::JSON::JSONObject* QuestRequirementItemInInventoryType::toJsonObject(
|
|
|
+ QuestRequirementItemInInventory* zObject) const
|
|
|
+{
|
|
|
+ Framework::JSON::JSONObject* result
|
|
|
+ = QuestRequirementFactoryBase::toJsonObject(zObject);
|
|
|
+ result->addValue("itemType",
|
|
|
+ new Framework::JSON::JSONString(
|
|
|
+ Game::INSTANCE->zItemType(zObject->getItemTypeId())->getName()));
|
|
|
+ result->addValue("amount",
|
|
|
+ new Framework::JSON::JSONNumber((double)zObject->getAmount()));
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+JSONObjectValidationBuilder*
|
|
|
+QuestRequirementItemInInventoryType::addToValidator(
|
|
|
+ JSONObjectValidationBuilder* builder) const
|
|
|
+{
|
|
|
+ return QuestRequirementFactoryBase::addToValidator(builder
|
|
|
+ ->withRequiredAttribute("itemType",
|
|
|
+ Game::INSTANCE->zTypeRegistry()->getValidator<Framework::Text>(
|
|
|
+ ItemTypeNameFactory::TYPE_ID))
|
|
|
+ ->withRequiredNumber("amount")
|
|
|
+ ->whichIsGreaterOrEqual(1.0)
|
|
|
+ ->withDefault(1.0)
|
|
|
+ ->finishNumber());
|
|
|
+}
|
|
|
+
|
|
|
+const char* QuestRequirementItemInInventoryType::getTypeToken() const
|
|
|
+{
|
|
|
+ return "item_in_inventory";
|
|
|
}
|