TargetCondition.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 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. bool isReceptive(const Mechanics * m, const battle::Unit * target) const override;
  54. void serializeJson(JsonSerializeFormat & handler, const ItemFactory * itemFactory);
  55. protected:
  56. private:
  57. bool check(const ItemVector & condition, const Mechanics * m, const battle::Unit * target) const;
  58. void loadConditions(const JsonNode & source, bool exclusive, bool inverted, const ItemFactory * itemFactory);
  59. };
  60. }
  61. VCMI_LIB_NAMESPACE_END