TargetCondition.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * TargetCondition.h, 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. #pragma once
  11. #include "ISpellMechanics.h"
  12. class JsonNode;
  13. class JsonSerializeFormat;
  14. namespace battle
  15. {
  16. class Unit;
  17. }
  18. namespace spells
  19. {
  20. class Mechanics;
  21. class DLL_LINKAGE TargetConditionItem : public IReceptiveCheck
  22. {
  23. public:
  24. TargetConditionItem();
  25. virtual ~TargetConditionItem();
  26. virtual void setInverted(bool value) = 0;
  27. virtual void setExclusive(bool value) = 0;
  28. virtual bool isExclusive() const = 0;
  29. };
  30. class DLL_LINKAGE TargetConditionItemFactory
  31. {
  32. public:
  33. using Object = std::shared_ptr<TargetConditionItem>;
  34. static const TargetConditionItemFactory * getDefault();
  35. virtual ~TargetConditionItemFactory() = default;
  36. virtual Object createAbsoluteLevel() const = 0;
  37. virtual Object createAbsoluteSpell() const = 0;
  38. virtual Object createElemental() const = 0;
  39. virtual Object createNormalLevel() const = 0;
  40. virtual Object createNormalSpell() const = 0;
  41. virtual Object createConfigurable(std::string scope, std::string type, std::string identifier) const = 0;
  42. virtual Object createReceptiveFeature() const = 0;
  43. virtual Object createImmunityNegation() const = 0;
  44. };
  45. class DLL_LINKAGE TargetCondition : public IReceptiveCheck
  46. {
  47. public:
  48. using Item = TargetConditionItem;
  49. using ItemVector = std::vector<std::shared_ptr<Item>>;
  50. using ItemFactory = TargetConditionItemFactory;
  51. ItemVector normal;
  52. ItemVector absolute;
  53. ItemVector negation;
  54. TargetCondition();
  55. virtual ~TargetCondition();
  56. bool isReceptive(const Mechanics * m, const battle::Unit * target) const override;
  57. void serializeJson(JsonSerializeFormat & handler, const ItemFactory * itemFactory);
  58. protected:
  59. private:
  60. bool check(const ItemVector & condition, const Mechanics * m, const battle::Unit * target) const;
  61. void loadConditions(const JsonNode & source, bool exclusive, bool inverted, const ItemFactory * itemFactory);
  62. };
  63. }