QuestRequirement.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #pragma once
  2. #include "QuestEvent.h"
  3. #include "TypeRegistry.h"
  4. class QuestStorage;
  5. class QuestRequirement : public virtual Framework::ReferenceCounter
  6. {
  7. protected:
  8. Framework::Text id;
  9. Framework::Text description;
  10. public:
  11. QuestRequirement();
  12. virtual void processEvent(QuestEvent* zEvent, QuestStorage* zStorage) = 0;
  13. virtual void addRequirementUIML(QuestStorage* zStorage,
  14. Framework::XML::Element* zParent,
  15. Framework::Text onClickPrefix)
  16. = 0;
  17. virtual void api(Framework::StreamReader* message,
  18. Framework::XML::Element* zParent,
  19. QuestStorage* zStorage);
  20. void setRequirementId(Framework::Text id);
  21. const Framework::Text& getRequirementId() const;
  22. void setDescription(Framework::Text description);
  23. const Framework::Text& getDescription() const;
  24. };
  25. template<typename S> class QuestRequirementFactoryBase
  26. : public SubTypeFactory<QuestRequirement, S>
  27. {
  28. public:
  29. QuestRequirementFactoryBase()
  30. : SubTypeFactory<QuestRequirement, S>()
  31. {}
  32. S* fromJson(Framework::JSON::JSONObject* zJson) const override
  33. {
  34. S* result = createValue(zJson);
  35. QuestRequirement* zRequirement
  36. = dynamic_cast<QuestRequirement*>(result);
  37. zRequirement->setRequirementId(
  38. zJson->zValue("id")->asString()->getString());
  39. zRequirement->setDescription(
  40. zJson->zValue("description")->asString()->getString());
  41. return result;
  42. }
  43. Framework::JSON::JSONObject* toJsonObject(S* zObject) const override
  44. {
  45. Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
  46. QuestRequirement* zRequirement
  47. = dynamic_cast<QuestRequirement*>(zObject);
  48. result->addValue("id",
  49. new Framework::JSON::JSONString(zRequirement->getRequirementId()));
  50. result->addValue("description",
  51. new Framework::JSON::JSONString(zRequirement->getDescription()));
  52. return result;
  53. }
  54. JSONObjectValidationBuilder* addToValidator(
  55. JSONObjectValidationBuilder* builder) const override
  56. {
  57. return builder->withRequiredString("id")
  58. ->finishString()
  59. ->withRequiredString("description")
  60. ->finishString();
  61. }
  62. protected:
  63. virtual S* createValue(Framework::JSON::JSONObject* zJson) const = 0;
  64. };
  65. class QuestRequirementOpenDialogType;
  66. class QuestRequirementOpenDialog : public QuestRequirement
  67. {
  68. private:
  69. Framework::Text dialogId;
  70. public:
  71. QuestRequirementOpenDialog();
  72. void processEvent(QuestEvent* zEvent, QuestStorage* zStorage) override;
  73. void addRequirementUIML(QuestStorage* zStorage,
  74. Framework::XML::Element* zParent,
  75. Framework::Text onClickPrefix) override;
  76. void setDialogId(Framework::Text dialogId);
  77. const Framework::Text& getDialogId() const;
  78. friend QuestRequirementOpenDialogType;
  79. };
  80. class QuestRequirementOpenDialogType
  81. : public QuestRequirementFactoryBase<QuestRequirementOpenDialog>
  82. {
  83. public:
  84. QuestRequirementOpenDialogType();
  85. QuestRequirementOpenDialog* createValue(
  86. Framework::JSON::JSONObject* zJson) const override;
  87. QuestRequirementOpenDialog* fromJson(
  88. Framework::JSON::JSONObject* zJson) const override;
  89. Framework::JSON::JSONObject* toJsonObject(
  90. QuestRequirementOpenDialog* zObject) const override;
  91. JSONObjectValidationBuilder* addToValidator(
  92. JSONObjectValidationBuilder* builder) const override;
  93. const char* getTypeToken() const override;
  94. };
  95. class QuestRequirementBlockBreak : public QuestRequirement
  96. {};
  97. class QuestRequirementBlockPlace : public QuestRequirement
  98. {};
  99. class QuestRequirementBlockInteract : public QuestRequirement
  100. {};
  101. class QuestRequirementCraft : public QuestRequirement
  102. {};
  103. class QuestRequirementItemInInventory : public QuestRequirement
  104. {};