Magic.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Magic.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. /**
  12. * High-level interface for spells subsystem
  13. */
  14. class CSpell;
  15. class PlayerColor;
  16. struct MetaString;
  17. struct CPackForClient;
  18. namespace battle
  19. {
  20. class Unit;
  21. class Destination;
  22. }
  23. namespace spells
  24. {
  25. class Mechanics;
  26. class BattleCast;
  27. using Destination = ::battle::Destination;
  28. using Target = std::vector<Destination>;
  29. struct SchoolInfo;
  30. enum class Mode
  31. {
  32. //ACTIVE, //todo: use
  33. HERO, //deprecated
  34. AFTER_ATTACK,
  35. BEFORE_ATTACK,
  36. MAGIC_MIRROR,
  37. CREATURE_ACTIVE, //deprecated
  38. ENCHANTER,
  39. SPELL_LIKE_ATTACK,
  40. PASSIVE//f.e. opening battle spells
  41. };
  42. enum class AimType
  43. {
  44. NO_TARGET,
  45. CREATURE,
  46. OBSTACLE,
  47. LOCATION
  48. };
  49. class DLL_LINKAGE PacketSender
  50. {
  51. public:
  52. virtual ~PacketSender(){};
  53. virtual void sendAndApply(CPackForClient * info) const = 0;
  54. virtual void complain(const std::string & problem) const = 0;
  55. };
  56. class DLL_LINKAGE Problem
  57. {
  58. public:
  59. typedef int Severity;
  60. enum ESeverity
  61. {
  62. LOWEST = std::numeric_limits<Severity>::min(),
  63. NORMAL = 0,
  64. CRITICAL = std::numeric_limits<Severity>::max()
  65. };
  66. virtual ~Problem() = default;
  67. virtual void add(MetaString && description, Severity severity = CRITICAL) = 0;
  68. virtual void getAll(std::vector<std::string> & target) const = 0;
  69. };
  70. class DLL_LINKAGE Spell
  71. {
  72. public:
  73. virtual ~Spell() = default;
  74. virtual int32_t getIndex() const = 0;
  75. virtual void forEachSchool(const std::function<void (const SchoolInfo &, bool &)> & cb) const = 0;
  76. };
  77. class DLL_LINKAGE Caster
  78. {
  79. public:
  80. virtual ~Caster() = default;
  81. /// returns level on which given spell would be cast by this(0 - none, 1 - basic etc);
  82. /// caster may not know this spell at all
  83. /// optionally returns number of selected school by arg - 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic
  84. virtual ui8 getSpellSchoolLevel(const Spell * spell, int * outSelectedSchool = nullptr) const = 0;
  85. ///default spell school level for effect calculation
  86. virtual int getEffectLevel(const Spell * spell) const = 0;
  87. ///applying sorcery secondary skill etc
  88. virtual int64_t getSpellBonus(const Spell * spell, int64_t base, const battle::Unit * affectedStack) const = 0;
  89. ///only bonus for particular spell
  90. virtual int64_t getSpecificSpellBonus(const Spell * spell, int64_t base) const = 0;
  91. ///default spell-power for damage/heal calculation
  92. virtual int getEffectPower(const Spell * spell) const = 0;
  93. ///default spell-power for timed effects duration
  94. virtual int getEnchantPower(const Spell * spell) const = 0;
  95. ///damage/heal override(ignores spell configuration, effect level and effect power)
  96. virtual int64_t getEffectValue(const Spell * spell) const = 0;
  97. virtual const PlayerColor getOwner() const = 0;
  98. ///only name substitution
  99. virtual void getCasterName(MetaString & text) const = 0;
  100. ///full default text
  101. virtual void getCastDescription(const Spell * spell, MetaString & text) const = 0;
  102. virtual void getCastDescription(const Spell * spell, const std::vector<const battle::Unit *> & attacked, MetaString & text) const = 0;
  103. virtual void spendMana(const PacketSender * server, const int spellCost) const = 0;
  104. };
  105. }