TargetCondition.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 Object createAbsoluteLevel() const = 0;
  36. virtual Object createAbsoluteSpell() const = 0;
  37. virtual Object createElemental() const = 0;
  38. virtual Object createNormalLevel() const = 0;
  39. virtual Object createNormalSpell() const = 0;
  40. virtual Object createConfigurable(std::string scope, std::string type, std::string identifier) const = 0;
  41. virtual Object createReceptiveFeature() const = 0;
  42. virtual Object createImmunityNegation() const = 0;
  43. };
  44. class DLL_LINKAGE TargetCondition : public IReceptiveCheck
  45. {
  46. public:
  47. using Item = TargetConditionItem;
  48. using ItemVector = std::vector<std::shared_ptr<Item>>;
  49. using ItemFactory = TargetConditionItemFactory;
  50. ItemVector normal;
  51. ItemVector absolute;
  52. ItemVector negation;
  53. TargetCondition();
  54. virtual ~TargetCondition();
  55. bool isReceptive(const Mechanics * m, const battle::Unit * target) const override;
  56. void serializeJson(JsonSerializeFormat & handler, const ItemFactory * itemFactory);
  57. protected:
  58. private:
  59. bool check(const ItemVector & condition, const Mechanics * m, const battle::Unit * target) const;
  60. void loadConditions(const JsonNode & source, bool exclusive, bool inverted, const ItemFactory * itemFactory);
  61. };
  62. }