QuestReward.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #pragma once
  2. #include "TypeRegistry.h"
  3. class Entity;
  4. class Item;
  5. class QuestStorage;
  6. class QuestReward : public virtual Framework::ReferenceCounter
  7. {
  8. protected:
  9. Framework::Text rewardId;
  10. public:
  11. QuestReward();
  12. virtual void giveReward(Framework::XML::Element* zParent,
  13. QuestStorage* zStorage,
  14. Entity* zTargetEntity)
  15. = 0;
  16. virtual void addRewardUIML(Framework::XML::Element* zParent,
  17. QuestStorage* zStorage,
  18. Framework::Text onClickPrefix)
  19. = 0;
  20. virtual bool validateSettings(
  21. Framework::XML::Element* zParent, QuestStorage* zStorage);
  22. virtual void api(Framework::StreamReader* message,
  23. Framework::XML::Element* zParent,
  24. QuestStorage* zStorage);
  25. void setRewardId(Framework::Text rewardId);
  26. const Framework::Text& getRewardId() const;
  27. };
  28. template<typename S> class QuestRewardFactoryBase
  29. : public SubTypeFactory<QuestReward, S>
  30. {
  31. public:
  32. QuestRewardFactoryBase()
  33. : SubTypeFactory<QuestReward, S>()
  34. {}
  35. S* fromJson(Framework::JSON::JSONObject* zJson) const override
  36. {
  37. S* result = createValue(zJson);
  38. QuestReward* zRequirement = dynamic_cast<QuestReward*>(result);
  39. zRequirement->setRewardId(
  40. zJson->zValue("rewardId")->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. QuestReward* zRequirement = dynamic_cast<QuestReward*>(zObject);
  47. result->addValue("rewardId",
  48. new Framework::JSON::JSONString(zRequirement->getRewardId()));
  49. return result;
  50. }
  51. JSONObjectValidationBuilder* addToValidator(
  52. JSONObjectValidationBuilder* builder) const override
  53. {
  54. return builder->withRequiredString("rewardId")->finishString();
  55. }
  56. protected:
  57. virtual S* createValue(Framework::JSON::JSONObject* zJson) const = 0;
  58. };
  59. class ItemStackInfo : public virtual Framework::ReferenceCounter
  60. {
  61. private:
  62. Item* item;
  63. int count;
  64. public:
  65. ItemStackInfo();
  66. ~ItemStackInfo();
  67. void setItem(Item* item);
  68. Item* zItem() const;
  69. void setCount(int count);
  70. int getCount() const;
  71. };
  72. class ItemStackInfoType : public ObjectTypeFactory<ItemStackInfo>
  73. {
  74. public:
  75. ItemStackInfoType();
  76. ItemStackInfo* fromJson(Framework::JSON::JSONObject* zJson) const override;
  77. Framework::JSON::JSONObject* toJsonObject(
  78. ItemStackInfo* zObject) const override;
  79. JSONObjectValidationBuilder* addToValidator(
  80. JSONObjectValidationBuilder* builder) const override;
  81. };
  82. class QuestRewardGiveItemsType;
  83. class QuestRewardGiveItems : public QuestReward
  84. {
  85. private:
  86. Framework::RCArray<ItemStackInfo> items;
  87. public:
  88. QuestRewardGiveItems();
  89. void giveReward(Framework::XML::Element* zParent,
  90. QuestStorage* zStorage,
  91. Entity* zTargetEntity) override;
  92. void addRewardUIML(Framework::XML::Element* zParent,
  93. QuestStorage* zStorage,
  94. Framework::Text onClickPrefix) override;
  95. friend QuestRewardGiveItemsType;
  96. };
  97. class QuestRewardGiveItemsType
  98. : public QuestRewardFactoryBase<QuestRewardGiveItems>
  99. {
  100. public:
  101. QuestRewardGiveItemsType();
  102. QuestRewardGiveItems* createValue(
  103. Framework::JSON::JSONObject* zJson) const override;
  104. QuestRewardGiveItems* fromJson(
  105. Framework::JSON::JSONObject* zJson) const override;
  106. Framework::JSON::JSONObject* toJsonObject(
  107. QuestRewardGiveItems* zObject) const override;
  108. JSONObjectValidationBuilder* addToValidator(
  109. JSONObjectValidationBuilder* builder) const override;
  110. const char* getTypeToken() const override;
  111. };