Quest.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #pragma once
  2. #include <JSON.h>
  3. #include "QuestEvent.h"
  4. #include "QuestRequirement.h"
  5. #include "QuestReward.h"
  6. #include "TypeRegistry.h"
  7. class QuestRequirementStorageType;
  8. class QuestRequirementStorage : public virtual Framework::ReferenceCounter
  9. {
  10. private:
  11. Framework::Text requirementId;
  12. bool fulfilled;
  13. public:
  14. QuestRequirementStorage();
  15. void setFullfilled(bool fullfilled);
  16. bool isFullfilled() const;
  17. void setRequirementId(Framework::Text requirementId);
  18. const Framework::Text& getRequirementId() const;
  19. friend QuestRequirementStorageType;
  20. };
  21. class QuestRequirementStorageType
  22. : public ObjectTypeFactory<QuestRequirementStorage>
  23. {
  24. public:
  25. QuestRequirementStorageType();
  26. QuestRequirementStorage* fromJson(
  27. Framework::JSON::JSONObject* zJson) const override;
  28. Framework::JSON::JSONObject* toJsonObject(
  29. QuestRequirementStorage* zObject) const override;
  30. JSONObjectValidationBuilder* addToValidator(
  31. JSONObjectValidationBuilder* builder) const override;
  32. };
  33. class QuestStorageType;
  34. class QuestStorage : public virtual Framework::ReferenceCounter
  35. {
  36. private:
  37. Framework::Text questId;
  38. bool finished;
  39. bool rewarded;
  40. bool visible;
  41. Framework::RCArray<QuestRequirementStorage> requirements;
  42. Framework::JSON::JSONObject* data;
  43. public:
  44. QuestStorage();
  45. ~QuestStorage();
  46. void setQuestFinished(bool finished);
  47. void setQuestRewarded(bool rewarded);
  48. bool isQuestFinished() const;
  49. bool isQuestRewarded() const;
  50. QuestRequirementStorage* zStorage(Framework::Text requirementId);
  51. void setQuestId(Framework::Text questId);
  52. const Framework::Text& getQuestId() const;
  53. bool isVisible() const;
  54. void setVisible(bool visible);
  55. void putValue(Framework::Text key, Framework::JSON::JSONValue* value);
  56. Framework::JSON::JSONValue* getValue(Framework::Text key) const;
  57. Framework::JSON::JSONValue* zValue(Framework::Text key) const;
  58. bool containsKey(Framework::Text key) const;
  59. friend QuestStorageType;
  60. };
  61. class QuestStorageType : public ObjectTypeFactory<QuestStorage>
  62. {
  63. public:
  64. QuestStorageType();
  65. QuestStorage* fromJson(Framework::JSON::JSONObject* zJson) const override;
  66. Framework::JSON::JSONObject* toJsonObject(
  67. QuestStorage* zObject) const override;
  68. JSONObjectValidationBuilder* addToValidator(
  69. JSONObjectValidationBuilder* builder) const override;
  70. };
  71. class QuestPartyType;
  72. class QuestParty : public virtual Framework::ReferenceCounter
  73. {
  74. private:
  75. Framework::Array<int> memberEntityIds;
  76. Framework::RCArray<QuestStorage> questStorage;
  77. public:
  78. QuestParty();
  79. void addMember(int memberEntityId);
  80. void removeMember(int memberEntityId);
  81. bool isMember(int memberEntityId) const;
  82. bool isEmpty() const;
  83. QuestStorage* zQuestStorage(Framework::Text questId);
  84. QuestParty* clone() const;
  85. friend QuestPartyType;
  86. };
  87. class QuestPartyType : public ObjectTypeFactory<QuestParty>
  88. {
  89. public:
  90. QuestPartyType();
  91. QuestParty* fromJson(Framework::JSON::JSONObject* zJson) const override;
  92. Framework::JSON::JSONObject* toJsonObject(
  93. QuestParty* zObject) const override;
  94. JSONObjectValidationBuilder* addToValidator(
  95. JSONObjectValidationBuilder* builder) const override;
  96. };
  97. class QuestType;
  98. class QuestManager;
  99. class QuestDialog;
  100. class Quest : public virtual Framework::ReferenceCounter
  101. {
  102. private:
  103. Framework::Text questId;
  104. Framework::Text questName;
  105. Framework::Text description;
  106. Framework::Text imagePath;
  107. bool mainQuest;
  108. Framework::RCArray<Framework::Text> requiredQuestsIds;
  109. Framework::Array<int> requiredQuestsGroups;
  110. Framework::RCArray<QuestRequirement> requirements;
  111. Framework::RCArray<QuestReward> rewards;
  112. public:
  113. Quest();
  114. void processEvent(QuestEvent* zEvent, QuestStorage* zStorage);
  115. bool isVisible(QuestParty* zParty, QuestManager* zManager);
  116. bool isActive(QuestParty* zParty);
  117. void setQuestId(Framework::Text questId);
  118. const Framework::Text& getQuestId() const;
  119. void setVisible(bool visible, QuestParty* zParty, QuestManager* zManager);
  120. friend QuestType;
  121. friend QuestDialog;
  122. };
  123. class QuestType : public ObjectTypeFactory<Quest>
  124. {
  125. public:
  126. QuestType();
  127. Quest* fromJson(Framework::JSON::JSONObject* zJson) const override;
  128. Framework::JSON::JSONObject* toJsonObject(Quest* zObject) const override;
  129. JSONObjectValidationBuilder* addToValidator(
  130. JSONObjectValidationBuilder* builder) const override;
  131. };
  132. class QuestCollectionType;
  133. class QuestCollection : public virtual Framework::ReferenceCounter
  134. {
  135. private:
  136. Framework::Text name;
  137. Framework::RCArray<Quest> quests;
  138. public:
  139. QuestCollection();
  140. void processEvent(QuestEvent* zEvent, QuestParty* zParty);
  141. bool isVisible(QuestParty* zParty, QuestManager* zManager);
  142. void addQuest(Quest* zQuest);
  143. void setName(Framework::Text name);
  144. const Framework::Text& getName() const;
  145. void setQuestVisible(bool visible,
  146. Framework::Text questId,
  147. QuestParty* zParty,
  148. QuestManager* zManager);
  149. friend QuestCollectionType;
  150. friend QuestDialog;
  151. };
  152. class QuestCollectionType : public ObjectTypeFactory<QuestCollection>
  153. {
  154. public:
  155. QuestCollectionType();
  156. QuestCollection* fromJson(
  157. Framework::JSON::JSONObject* zJson) const override;
  158. Framework::JSON::JSONObject* toJsonObject(
  159. QuestCollection* zObject) const override;
  160. JSONObjectValidationBuilder* addToValidator(
  161. JSONObjectValidationBuilder* builder) const override;
  162. };
  163. class QuestManager : public virtual Framework::ReferenceCounter
  164. {
  165. private:
  166. Framework::RCArray<QuestCollection> questCollections;
  167. Framework::RCArray<QuestParty> parties;
  168. QuestParty* zParty(int entityId);
  169. QuestCollection* zCollection(Framework::Text collectionName);
  170. public:
  171. QuestManager();
  172. void loadQuests();
  173. void saveQuests();
  174. void processEvent(QuestEvent* event);
  175. void setQuestVisible(
  176. bool visible, Framework::Text questId, QuestParty* zParty);
  177. friend QuestDialog;
  178. };