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. VCMI_LIB_NAMESPACE_BEGIN
  13. class JsonNode;
  14. class JsonSerializeFormat;
  15. namespace battle
  16. {
  17. class Unit;
  18. }
  19. namespace spells
  20. {
  21. class Mechanics;
  22. class DLL_LINKAGE TargetConditionItem : public IReceptiveCheck
  23. {
  24. public:
  25. virtual void setInverted(bool value) = 0;
  26. virtual void setExclusive(bool value) = 0;
  27. virtual bool isExclusive() const = 0;
  28. };
  29. class DLL_LINKAGE TargetConditionItemFactory
  30. {
  31. public:
  32. using Object = std::shared_ptr<TargetConditionItem>;
  33. static const TargetConditionItemFactory * getDefault();
  34. virtual ~TargetConditionItemFactory() = default;
  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 createFromJsonStruct(const JsonNode & jsonStruct) 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. bool isReceptive(const Mechanics * m, const battle::Unit * target) const override;
  55. void serializeJson(JsonSerializeFormat & handler, const ItemFactory * itemFactory);
  56. protected:
  57. private:
  58. bool check(const ItemVector & condition, const Mechanics * m, const battle::Unit * target) const;
  59. void loadConditions(const JsonNode & source, bool exclusive, bool inverted, const ItemFactory * itemFactory);
  60. };
  61. }
  62. VCMI_LIB_NAMESPACE_END