1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #pragma once
- #include <ReferenceCounter.h>
- #include "DropCondition.h"
- #include "Game.h"
- #include "TypeRegistry.h"
- class DropConfig : public virtual Framework::ReferenceCounter
- {
- private:
- DropCondition* condition;
- public:
- DropConfig();
- virtual ~DropConfig();
- void setCondition(DropCondition* condition);
- virtual void initialize();
- const DropCondition* zCondition() const;
- void onObjectDestroyed(Entity* zActor,
- Item* zItem,
- ItemSkill* zUsedSkill,
- Framework::Either<Block*, Entity*> zDestroyedObject) const;
- protected:
- virtual void doDrop(Entity* zActor,
- Item* zItem,
- ItemSkill* zUsedSkill,
- Framework::Either<Block*, Entity*> zDestroyedObject) const
- = 0;
- };
- template<typename T> class DropConfigFactory
- : public SubTypeFactory<DropConfig, T>
- {
- public:
- DropConfigFactory()
- : SubTypeFactory<DropConfig, T>()
- {}
- virtual JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override
- {
- return builder->withRequiredAttribute("condition",
- Game::INSTANCE->zTypeRegistry()->getValidator<DropCondition>());
- }
- T* fromJson(Framework::JSON::JSONObject* zJson) const
- {
- T* result = createInstance(zJson);
- DropCondition* condition
- = Game::INSTANCE->zTypeRegistry()->fromJson<DropCondition>(
- zJson->zValue("condition"));
- result->setCondition(condition);
- return result;
- }
- Framework::JSON::JSONObject* toJsonObject(T* zObject) const override
- {
- Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
- result->addValue("condition",
- Game::INSTANCE->zTypeRegistry()->toJson(zObject->zCondition()));
- addToJson(result, zObject);
- return result;
- }
- protected:
- virtual T* createInstance(Framework::JSON::JSONObject* zObject) const = 0;
- virtual void addToJson(Framework::JSON::JSONObject* zJson, T* zObject) const
- = 0;
- };
|