QuestReward.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. void fromJson(S* zResult, Framework::JSON::JSONObject* zJson) const override
  36. {
  37. QuestReward* zRequirement = dynamic_cast<QuestReward*>(zResult);
  38. zRequirement->setRewardId(zJson->zValue("rewardId")->asString()->getString());
  39. }
  40. void toJson(S* zObject, Framework::JSON::JSONObject* zResult) const override
  41. {
  42. QuestReward* zRequirement = dynamic_cast<QuestReward*>(zObject);
  43. zResult->addValue(
  44. "rewardId", new Framework::JSON::JSONString(zRequirement->getRewardId()));
  45. }
  46. JSONObjectValidationBuilder* addToValidator(
  47. JSONObjectValidationBuilder* builder) const override
  48. {
  49. return builder->withRequiredString("rewardId")->finishString();
  50. }
  51. };
  52. class ItemStackInfo : public virtual Framework::ReferenceCounter
  53. {
  54. private:
  55. Item* item;
  56. int count;
  57. public:
  58. ItemStackInfo();
  59. ~ItemStackInfo();
  60. void setItem(Item* item);
  61. Item* zItem() const;
  62. void setCount(int count);
  63. int getCount() const;
  64. };
  65. class ItemStackInfoType : public TypeFactory<ItemStackInfo>
  66. {
  67. public:
  68. ItemStackInfoType();
  69. ItemStackInfo* createValue(
  70. Framework::JSON::JSONObject* zJson) const override;
  71. void fromJson(ItemStackInfo* zResult,
  72. Framework::JSON::JSONObject* zJson) const override;
  73. void toJson(ItemStackInfo* zObject,
  74. Framework::JSON::JSONObject* zResult) const override;
  75. JSONObjectValidationBuilder* addToValidator(
  76. JSONObjectValidationBuilder* builder) const override;
  77. };
  78. class QuestRewardGiveItemsType;
  79. class QuestRewardGiveItems : public QuestReward
  80. {
  81. private:
  82. Framework::RCArray<ItemStackInfo> items;
  83. public:
  84. QuestRewardGiveItems();
  85. void giveReward(Framework::XML::Element* zParent,
  86. QuestStorage* zStorage,
  87. Entity* zTargetEntity) override;
  88. void addRewardUIML(Framework::XML::Element* zParent,
  89. QuestStorage* zStorage,
  90. Framework::Text onClickPrefix) override;
  91. friend QuestRewardGiveItemsType;
  92. };
  93. class QuestRewardGiveItemsType
  94. : public QuestRewardFactoryBase<QuestRewardGiveItems>
  95. {
  96. public:
  97. QuestRewardGiveItemsType();
  98. QuestRewardGiveItems* createValue(
  99. Framework::JSON::JSONObject* zJson) const override;
  100. void fromJson(QuestRewardGiveItems* zResult,
  101. Framework::JSON::JSONObject* zJson) const override;
  102. void toJson(QuestRewardGiveItems* zObject,
  103. Framework::JSON::JSONObject* zResult) const override;
  104. JSONObjectValidationBuilder* addToValidator(
  105. JSONObjectValidationBuilder* builder) const override;
  106. Framework::Text getTypeToken() const override;
  107. };