QuestRequirement.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. void fromJson(S* zResult, Framework::JSON::JSONObject* zJson) const override
  33. {
  34. QuestRequirement* zRequirement
  35. = dynamic_cast<QuestRequirement*>(zResult);
  36. zRequirement->setRequirementId(
  37. zJson->zValue("id")->asString()->getString());
  38. zRequirement->setDescription(
  39. zJson->zValue("description")->asString()->getString());
  40. }
  41. void toJson(S* zObject, Framework::JSON::JSONObject* zResult) const override
  42. {
  43. QuestRequirement* zRequirement
  44. = dynamic_cast<QuestRequirement*>(zObject);
  45. zResult->addValue("id",
  46. new Framework::JSON::JSONString(zRequirement->getRequirementId()));
  47. zResult->addValue("description",
  48. new Framework::JSON::JSONString(zRequirement->getDescription()));
  49. }
  50. JSONObjectValidationBuilder* addToValidator(
  51. JSONObjectValidationBuilder* builder) const override
  52. {
  53. return builder->withRequiredString("id")
  54. ->finishString()
  55. ->withRequiredString("description")
  56. ->finishString();
  57. }
  58. };
  59. class QuestRequirementOpenDialogType;
  60. class QuestRequirementOpenDialog : public QuestRequirement
  61. {
  62. private:
  63. Framework::Text dialogId;
  64. public:
  65. QuestRequirementOpenDialog();
  66. void processEvent(QuestEvent* zEvent, QuestStorage* zStorage) override;
  67. void addRequirementUIML(QuestStorage* zStorage,
  68. Framework::XML::Element* zParent,
  69. Framework::Text onClickPrefix) override;
  70. void setDialogId(Framework::Text dialogId);
  71. const Framework::Text& getDialogId() const;
  72. friend QuestRequirementOpenDialogType;
  73. };
  74. class QuestRequirementOpenDialogType
  75. : public QuestRequirementFactoryBase<QuestRequirementOpenDialog>
  76. {
  77. public:
  78. QuestRequirementOpenDialogType();
  79. QuestRequirementOpenDialog* createValue(
  80. Framework::JSON::JSONObject* zJson) const override;
  81. void fromJson(QuestRequirementOpenDialog* zResult,
  82. Framework::JSON::JSONObject* zJson) const override;
  83. void toJson(QuestRequirementOpenDialog* zObject,
  84. Framework::JSON::JSONObject* zResult) const override;
  85. JSONObjectValidationBuilder* addToValidator(
  86. JSONObjectValidationBuilder* builder) const override;
  87. Framework::Text getTypeToken() const override;
  88. };
  89. class QuestRequirementBlockBreak : public QuestRequirement
  90. {};
  91. class QuestRequirementBlockPlace : public QuestRequirement
  92. {};
  93. class QuestRequirementBlockInteract : public QuestRequirement
  94. {};
  95. class QuestRequirementCraft : public QuestRequirement
  96. {};
  97. class QuestRequirementItemInInventory : public QuestRequirement
  98. {};