123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #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<typename S> class QuestRewardFactoryBase
- : public SubTypeFactory<QuestReward, S>
- {
- public:
- QuestRewardFactoryBase()
- : SubTypeFactory<QuestReward, S>()
- {}
- S* fromJson(Framework::JSON::JSONObject* zJson) const override
- {
- S* result = createValue(zJson);
- QuestReward* zRequirement = dynamic_cast<QuestReward*>(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<QuestReward*>(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<ItemStackInfo>
- {
- 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<ItemStackInfo> 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<QuestRewardGiveItems>
- {
- 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;
- };
|