Effect.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Effect.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "Effect.h"
  12. #include "Registry.h"
  13. #include "../../serializer/JsonSerializeFormat.h"
  14. namespace spells
  15. {
  16. namespace effects
  17. {
  18. Effect::Effect()
  19. : indirect(false),
  20. optional(false)
  21. {
  22. }
  23. Effect::~Effect() = default;
  24. bool Effect::applicable(Problem & problem, const Mechanics * m) const
  25. {
  26. return true;
  27. }
  28. bool Effect::applicable(Problem & problem, const Mechanics * m, const EffectTarget & target) const
  29. {
  30. return true;
  31. }
  32. void Effect::serializeJson(JsonSerializeFormat & handler)
  33. {
  34. handler.serializeBool("indirect", indirect, false);
  35. handler.serializeBool("optional", optional, false);
  36. serializeJsonEffect(handler);
  37. }
  38. std::shared_ptr<Effect> Effect::create(const std::string & type)
  39. {
  40. auto factory = Registry::get()->find(type);
  41. if(factory)
  42. {
  43. std::shared_ptr<Effect> ret;
  44. ret.reset(factory->create());
  45. return ret;
  46. }
  47. else
  48. {
  49. logGlobal->error("Unknown effect type '%s'", type);
  50. return std::shared_ptr<Effect>();
  51. }
  52. }
  53. }
  54. }