Quest.h 5.6 KB

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