#pragma once #include "TypeRegistry.h" class Entity; class Item; class QuestStorage; class QuestReward : public virtual Framework::ReferenceCounter { protected: Framework::Text rewardId; public: QuestReward(); virtual void giveReward(Framework::XML::Element* zParent, QuestStorage* zStorage, Entity* zTargetEntity) = 0; virtual void addRewardUIML(Framework::XML::Element* zParent, QuestStorage* zStorage, Framework::Text onClickPrefix) = 0; virtual bool validateSettings( Framework::XML::Element* zParent, QuestStorage* zStorage); virtual void api(Framework::StreamReader* message, Framework::XML::Element* zParent, QuestStorage* zStorage); void setRewardId(Framework::Text rewardId); const Framework::Text& getRewardId() const; }; template class QuestRewardFactoryBase : public SubTypeFactory { public: QuestRewardFactoryBase() : SubTypeFactory() {} S* fromJson(Framework::JSON::JSONObject* zJson) const override { S* result = createValue(zJson); QuestReward* zRequirement = dynamic_cast(result); zRequirement->setRewardId( zJson->zValue("rewardId")->asString()->getString()); return result; } Framework::JSON::JSONObject* toJsonObject(S* zObject) const override { Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject(); QuestReward* zRequirement = dynamic_cast(zObject); result->addValue("rewardId", new Framework::JSON::JSONString(zRequirement->getRewardId())); return result; } JSONObjectValidationBuilder* addToValidator( JSONObjectValidationBuilder* builder) const override { return builder->withRequiredString("rewardId")->finishString(); } protected: virtual S* createValue(Framework::JSON::JSONObject* zJson) const = 0; }; class ItemStackInfo : public virtual Framework::ReferenceCounter { private: Item* item; int count; public: ItemStackInfo(); ~ItemStackInfo(); void setItem(Item* item); Item* zItem() const; void setCount(int count); int getCount() const; }; class ItemStackInfoType : public ObjectTypeFactory { public: ItemStackInfoType(); ItemStackInfo* fromJson(Framework::JSON::JSONObject* zJson) const override; Framework::JSON::JSONObject* toJsonObject( ItemStackInfo* zObject) const override; JSONObjectValidationBuilder* addToValidator( JSONObjectValidationBuilder* builder) const override; }; class QuestRewardGiveItemsType; class QuestRewardGiveItems : public QuestReward { private: Framework::RCArray items; public: QuestRewardGiveItems(); void giveReward(Framework::XML::Element* zParent, QuestStorage* zStorage, Entity* zTargetEntity) override; void addRewardUIML(Framework::XML::Element* zParent, QuestStorage* zStorage, Framework::Text onClickPrefix) override; friend QuestRewardGiveItemsType; }; class QuestRewardGiveItemsType : public QuestRewardFactoryBase { public: QuestRewardGiveItemsType(); QuestRewardGiveItems* createValue( Framework::JSON::JSONObject* zJson) const override; QuestRewardGiveItems* fromJson( Framework::JSON::JSONObject* zJson) const override; Framework::JSON::JSONObject* toJsonObject( QuestRewardGiveItems* zObject) const override; JSONObjectValidationBuilder* addToValidator( JSONObjectValidationBuilder* builder) const override; const char* getTypeToken() const override; };