Quest.h 6.5 KB

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