ISpellMechanics.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /*
  2. * ISpellMechanics.cpp, 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. #include "StdInc.h"
  11. #include "ISpellMechanics.h"
  12. #include "../CRandomGenerator.h"
  13. #include "../HeroBonus.h"
  14. #include "../battle/CBattleInfoCallback.h"
  15. #include "../battle/IBattleState.h"
  16. #include "../battle/Unit.h"
  17. #include "../mapObjects/CGHeroInstance.h"
  18. #include "../serializer/JsonDeserializer.h"
  19. #include "../serializer/JsonSerializer.h"
  20. #include "TargetCondition.h"
  21. #include "Problem.h"
  22. #include "AdventureSpellMechanics.h"
  23. #include "BattleSpellMechanics.h"
  24. #include "effects/Effects.h"
  25. #include "effects/Registry.h"
  26. #include "effects/Damage.h"
  27. #include "effects/Timed.h"
  28. #include "CSpellHandler.h"
  29. #include "../NetPacks.h"
  30. #include "../CHeroHandler.h"//todo: remove
  31. #include "../IGameCallback.h"//todo: remove
  32. namespace spells
  33. {
  34. static std::shared_ptr<TargetCondition> makeCondition(const CSpell * s)
  35. {
  36. std::shared_ptr<TargetCondition> res = std::make_shared<TargetCondition>();
  37. JsonDeserializer deser(nullptr, s->targetCondition);
  38. res->serializeJson(deser, TargetConditionItemFactory::getDefault());
  39. return res;
  40. }
  41. class CustomMechanicsFactory : public ISpellMechanicsFactory
  42. {
  43. public:
  44. std::unique_ptr<Mechanics> create(const IBattleCast * event) const override
  45. {
  46. BattleSpellMechanics * ret = new BattleSpellMechanics(event, effects, targetCondition);
  47. return std::unique_ptr<Mechanics>(ret);
  48. }
  49. protected:
  50. std::shared_ptr<effects::Effects> effects;
  51. CustomMechanicsFactory(const CSpell * s)
  52. : ISpellMechanicsFactory(s), effects(new effects::Effects)
  53. {
  54. targetCondition = makeCondition(s);
  55. }
  56. void loadEffects(const JsonNode & config, const int level)
  57. {
  58. JsonDeserializer deser(nullptr, config);
  59. effects->serializeJson(VLC->spellEffects(), deser, level);
  60. }
  61. private:
  62. std::shared_ptr<IReceptiveCheck> targetCondition;
  63. };
  64. class ConfigurableMechanicsFactory : public CustomMechanicsFactory
  65. {
  66. public:
  67. ConfigurableMechanicsFactory(const CSpell * s)
  68. : CustomMechanicsFactory(s)
  69. {
  70. for(int level = 0; level < GameConstants::SPELL_SCHOOL_LEVELS; level++)
  71. loadEffects(s->getLevelInfo(level).battleEffects, level);
  72. }
  73. };
  74. //to be used for spells configured with old format
  75. class FallbackMechanicsFactory : public CustomMechanicsFactory
  76. {
  77. public:
  78. FallbackMechanicsFactory(const CSpell * s)
  79. : CustomMechanicsFactory(s)
  80. {
  81. for(int level = 0; level < GameConstants::SPELL_SCHOOL_LEVELS; level++)
  82. {
  83. const CSpell::LevelInfo & levelInfo = s->getLevelInfo(level);
  84. assert(levelInfo.battleEffects.isNull());
  85. if(s->isOffensive())
  86. {
  87. //default constructed object should be enough
  88. effects->add("directDamage", std::make_shared<effects::Damage>(), level);
  89. }
  90. std::shared_ptr<effects::Effect> effect;
  91. if(!levelInfo.effects.empty())
  92. {
  93. auto timed = new effects::Timed();
  94. timed->cumulative = false;
  95. timed->bonus = levelInfo.effects;
  96. effect.reset(timed);
  97. }
  98. if(!levelInfo.cumulativeEffects.empty())
  99. {
  100. auto timed = new effects::Timed();
  101. timed->cumulative = true;
  102. timed->bonus = levelInfo.cumulativeEffects;
  103. effect.reset(timed);
  104. }
  105. if(effect)
  106. effects->add("timed", effect, level);
  107. }
  108. }
  109. };
  110. BattleCast::BattleCast(const CBattleInfoCallback * cb_, const Caster * caster_, const Mode mode_, const CSpell * spell_)
  111. : spell(spell_),
  112. cb(cb_),
  113. caster(caster_),
  114. mode(mode_),
  115. magicSkillLevel(),
  116. effectPower(),
  117. effectDuration(),
  118. effectValue(),
  119. smart(boost::logic::indeterminate),
  120. massive(boost::logic::indeterminate)
  121. {
  122. gameCb = IObjectInterface::cb; //FIXME: pass player callback (problem is that BattleAI do not have one)
  123. }
  124. BattleCast::BattleCast(const BattleCast & orig, const Caster * caster_)
  125. : spell(orig.spell),
  126. cb(orig.cb),
  127. gameCb(orig.gameCb),
  128. caster(caster_),
  129. mode(Mode::MAGIC_MIRROR),
  130. magicSkillLevel(orig.magicSkillLevel),
  131. effectPower(orig.effectPower),
  132. effectDuration(orig.effectDuration),
  133. effectValue(orig.effectValue),
  134. smart(true),
  135. massive(false)
  136. {
  137. }
  138. BattleCast::~BattleCast() = default;
  139. const CSpell * BattleCast::getSpell() const
  140. {
  141. return spell;
  142. }
  143. Mode BattleCast::getMode() const
  144. {
  145. return mode;
  146. }
  147. const Caster * BattleCast::getCaster() const
  148. {
  149. return caster;
  150. }
  151. const CBattleInfoCallback * BattleCast::getBattle() const
  152. {
  153. return cb;
  154. }
  155. const IGameInfoCallback * BattleCast::getGame() const
  156. {
  157. return gameCb;
  158. }
  159. BattleCast::OptionalValue BattleCast::getSpellLevel() const
  160. {
  161. return magicSkillLevel;
  162. }
  163. BattleCast::OptionalValue BattleCast::getEffectPower() const
  164. {
  165. return effectPower;
  166. }
  167. BattleCast::OptionalValue BattleCast::getEffectDuration() const
  168. {
  169. return effectDuration;
  170. }
  171. BattleCast::OptionalValue64 BattleCast::getEffectValue() const
  172. {
  173. return effectValue;
  174. }
  175. boost::logic::tribool BattleCast::isSmart() const
  176. {
  177. return smart;
  178. }
  179. boost::logic::tribool BattleCast::isMassive() const
  180. {
  181. return massive;
  182. }
  183. void BattleCast::setSpellLevel(BattleCast::Value value)
  184. {
  185. magicSkillLevel = boost::make_optional(value);
  186. }
  187. void BattleCast::setEffectPower(BattleCast::Value value)
  188. {
  189. effectPower = boost::make_optional(value);
  190. }
  191. void BattleCast::setEffectDuration(BattleCast::Value value)
  192. {
  193. effectDuration = boost::make_optional(value);
  194. }
  195. void BattleCast::setEffectValue(BattleCast::Value64 value)
  196. {
  197. effectValue = boost::make_optional(value);
  198. }
  199. void BattleCast::applyEffects(ServerCallback * server, Target target, bool indirect, bool ignoreImmunity) const
  200. {
  201. auto m = spell->battleMechanics(this);
  202. m->applyEffects(server, target, indirect, ignoreImmunity);
  203. }
  204. void BattleCast::cast(ServerCallback * server, Target target)
  205. {
  206. if(target.empty())
  207. target.emplace_back();
  208. auto m = spell->battleMechanics(this);
  209. const battle::Unit * mainTarget = nullptr;
  210. if(target.front().unitValue)
  211. {
  212. mainTarget = target.front().unitValue;
  213. }
  214. else if(target.front().hexValue.isValid())
  215. {
  216. mainTarget = cb->battleGetUnitByPos(target.front().hexValue, true);
  217. }
  218. bool tryMagicMirror = (mainTarget != nullptr) && (mode == Mode::HERO || mode == Mode::CREATURE_ACTIVE);//TODO: recheck
  219. tryMagicMirror = tryMagicMirror && (mainTarget->unitOwner() != caster->getCasterOwner()) && !spell->isPositive();//TODO: recheck
  220. m->cast(server, target);
  221. //Magic Mirror effect
  222. if(tryMagicMirror)
  223. {
  224. const std::string magicMirrorCacheStr = "type_MAGIC_MIRROR";
  225. static const auto magicMirrorSelector = Selector::type()(Bonus::MAGIC_MIRROR);
  226. auto rangeGen = server->getRNG()->getInt64Range(0, 99);
  227. const int mirrorChance = mainTarget->valOfBonuses(magicMirrorSelector, magicMirrorCacheStr);
  228. if(rangeGen() < mirrorChance)
  229. {
  230. auto mirrorTargets = cb->battleGetUnitsIf([this](const battle::Unit * unit)
  231. {
  232. //Get all caster stacks. Magic mirror can reflect to immune creature (with no effect)
  233. return unit->unitOwner() == caster->getCasterOwner() && unit->isValidTarget(true);
  234. });
  235. if(!mirrorTargets.empty())
  236. {
  237. auto mirrorDestination = (*RandomGeneratorUtil::nextItem(mirrorTargets, *server->getRNG()));
  238. Target mirrorTarget;
  239. mirrorTarget.emplace_back(mirrorDestination);
  240. BattleCast mirror(*this, mainTarget);
  241. mirror.cast(server, mirrorTarget);
  242. }
  243. }
  244. }
  245. }
  246. void BattleCast::castEval(ServerCallback * server, Target target)
  247. {
  248. //TODO: make equivalent to normal cast
  249. if(target.empty())
  250. target.emplace_back();
  251. auto m = spell->battleMechanics(this);
  252. //TODO: reflection
  253. //TODO: random effects evaluation
  254. m->castEval(server, target);
  255. }
  256. bool BattleCast::castIfPossible(ServerCallback * server, Target target)
  257. {
  258. if(spell->canBeCast(cb, mode, caster))
  259. {
  260. cast(server, target);
  261. return true;
  262. }
  263. return false;
  264. }
  265. std::vector<Target> BattleCast::findPotentialTargets() const
  266. {
  267. //TODO: for more than 2 destinations per target much more efficient algorithm is required
  268. auto m = spell->battleMechanics(this);
  269. auto targetTypes = m->getTargetTypes();
  270. if(targetTypes.empty() || targetTypes.size() > 2)
  271. {
  272. return std::vector<Target>();
  273. }
  274. else
  275. {
  276. std::vector<Target> previous;
  277. std::vector<Target> next;
  278. for(size_t index = 0; index < targetTypes.size(); index++)
  279. {
  280. std::swap(previous, next);
  281. next.clear();
  282. std::vector<Destination> destinations;
  283. if(previous.empty())
  284. {
  285. Target empty;
  286. destinations = m->getPossibleDestinations(index, targetTypes.at(index), empty);
  287. for(auto & destination : destinations)
  288. {
  289. Target target;
  290. target.emplace_back(destination);
  291. next.push_back(target);
  292. }
  293. }
  294. else
  295. {
  296. for(const Target & current : previous)
  297. {
  298. destinations = m->getPossibleDestinations(index, targetTypes.at(index), current);
  299. for(auto & destination : destinations)
  300. {
  301. Target target = current;
  302. target.emplace_back(destination);
  303. next.push_back(target);
  304. }
  305. }
  306. }
  307. if(next.empty())
  308. break;
  309. }
  310. return next;
  311. }
  312. }
  313. ///ISpellMechanicsFactory
  314. ISpellMechanicsFactory::ISpellMechanicsFactory(const CSpell * s)
  315. : spell(s)
  316. {
  317. }
  318. ISpellMechanicsFactory::~ISpellMechanicsFactory()
  319. {
  320. }
  321. std::unique_ptr<ISpellMechanicsFactory> ISpellMechanicsFactory::get(const CSpell * s)
  322. {
  323. if(s->hasBattleEffects())
  324. return make_unique<ConfigurableMechanicsFactory>(s);
  325. else
  326. return make_unique<FallbackMechanicsFactory>(s);
  327. }
  328. ///Mechanics
  329. Mechanics::Mechanics()
  330. : caster(nullptr),
  331. casterSide(0)
  332. {
  333. }
  334. Mechanics::~Mechanics() = default;
  335. BaseMechanics::BaseMechanics(const IBattleCast * event)
  336. : Mechanics(),
  337. owner(event->getSpell()),
  338. mode(event->getMode()),
  339. smart(event->isSmart()),
  340. massive(event->isMassive())
  341. {
  342. cb = event->getBattle();
  343. gameCb = event->getGame();
  344. caster = event->getCaster();
  345. //FIXME: do not crash on invalid side
  346. casterSide = cb->playerToSide(caster->getCasterOwner()).get();
  347. {
  348. auto value = event->getSpellLevel();
  349. if(value)
  350. rangeLevel = value.get();
  351. else
  352. rangeLevel = caster->getSpellSchoolLevel(owner);
  353. vstd::abetween(rangeLevel, 0, 3);
  354. }
  355. {
  356. auto value = event->getSpellLevel();
  357. if(value)
  358. effectLevel = value.get();
  359. else
  360. effectLevel = caster->getEffectLevel(owner);
  361. vstd::abetween(effectLevel, 0, 3);
  362. }
  363. {
  364. auto value = event->getEffectPower();
  365. if(value)
  366. effectPower = value.get();
  367. else
  368. effectPower = caster->getEffectPower(owner);
  369. vstd::amax(effectPower, 0);
  370. }
  371. {
  372. auto value = event->getEffectDuration();
  373. if(value)
  374. effectDuration = value.get();
  375. else
  376. effectDuration = caster->getEnchantPower(owner);
  377. vstd::amax(effectDuration, 0); //???
  378. }
  379. {
  380. auto value = event->getEffectValue();
  381. if(value)
  382. {
  383. effectValue = value.get();
  384. }
  385. else
  386. {
  387. auto casterValue = caster->getEffectValue(owner);
  388. if(casterValue == 0)
  389. effectValue = owner->calculateRawEffectValue(effectLevel, effectPower, 1);
  390. else
  391. effectValue = casterValue;
  392. }
  393. vstd::amax(effectValue, 0);
  394. }
  395. }
  396. BaseMechanics::~BaseMechanics() = default;
  397. bool BaseMechanics::adaptGenericProblem(Problem & target) const
  398. {
  399. MetaString text;
  400. // %s recites the incantations but they seem to have no effect.
  401. text.addTxt(MetaString::GENERAL_TXT, 541);
  402. caster->getCasterName(text);
  403. target.add(std::move(text), spells::Problem::NORMAL);
  404. return false;
  405. }
  406. bool BaseMechanics::adaptProblem(ESpellCastProblem::ESpellCastProblem source, Problem & target) const
  407. {
  408. if(source == ESpellCastProblem::OK)
  409. return true;
  410. switch(source)
  411. {
  412. case ESpellCastProblem::SPELL_LEVEL_LIMIT_EXCEEDED:
  413. {
  414. MetaString text;
  415. //TODO: refactor
  416. auto hero = dynamic_cast<const CGHeroInstance *>(caster);
  417. if(!hero)
  418. return adaptGenericProblem(target);
  419. //Recanter's Cloak or similar effect. Try to retrieve bonus
  420. const auto b = hero->getBonusLocalFirst(Selector::type()(Bonus::BLOCK_MAGIC_ABOVE));
  421. //TODO what about other values and non-artifact sources?
  422. if(b && b->val == 2 && b->source == Bonus::ARTIFACT)
  423. {
  424. //The %s prevents %s from casting 3rd level or higher spells.
  425. text.addTxt(MetaString::GENERAL_TXT, 536);
  426. text.addReplacement(MetaString::ART_NAMES, b->sid);
  427. caster->getCasterName(text);
  428. target.add(std::move(text), spells::Problem::NORMAL);
  429. }
  430. else if(b && b->source == Bonus::TERRAIN_OVERLAY && b->sid == BFieldType::CURSED_GROUND)
  431. {
  432. text.addTxt(MetaString::GENERAL_TXT, 537);
  433. target.add(std::move(text), spells::Problem::NORMAL);
  434. }
  435. else
  436. {
  437. return adaptGenericProblem(target);
  438. }
  439. }
  440. break;
  441. case ESpellCastProblem::WRONG_SPELL_TARGET:
  442. case ESpellCastProblem::STACK_IMMUNE_TO_SPELL:
  443. case ESpellCastProblem::NO_APPROPRIATE_TARGET:
  444. {
  445. MetaString text;
  446. text.addTxt(MetaString::GENERAL_TXT, 185);
  447. target.add(std::move(text), spells::Problem::NORMAL);
  448. }
  449. break;
  450. case ESpellCastProblem::INVALID:
  451. {
  452. MetaString text;
  453. text.addReplacement("Internal error during check of spell cast.");
  454. target.add(std::move(text), spells::Problem::CRITICAL);
  455. }
  456. break;
  457. default:
  458. return adaptGenericProblem(target);
  459. }
  460. return false;
  461. }
  462. int32_t BaseMechanics::getSpellIndex() const
  463. {
  464. return getSpellId().toEnum();
  465. }
  466. SpellID BaseMechanics::getSpellId() const
  467. {
  468. return owner->getId();
  469. }
  470. std::string BaseMechanics::getSpellName() const
  471. {
  472. return owner->getName();
  473. }
  474. int32_t BaseMechanics::getSpellLevel() const
  475. {
  476. return owner->getLevel();
  477. }
  478. bool BaseMechanics::isSmart() const
  479. {
  480. if(boost::logic::indeterminate(smart))
  481. {
  482. const CSpell::TargetInfo targetInfo(owner, getRangeLevel(), mode);
  483. return targetInfo.smart;
  484. }
  485. else
  486. {
  487. return (bool)smart;
  488. }
  489. }
  490. bool BaseMechanics::isMassive() const
  491. {
  492. if(boost::logic::indeterminate(massive))
  493. {
  494. const CSpell::TargetInfo targetInfo(owner, getRangeLevel(), mode);
  495. return targetInfo.massive;
  496. }
  497. else
  498. {
  499. return (bool)massive;
  500. }
  501. }
  502. bool BaseMechanics::requiresClearTiles() const
  503. {
  504. const CSpell::TargetInfo targetInfo(owner, getRangeLevel(), mode);
  505. return targetInfo.clearAffected;
  506. }
  507. bool BaseMechanics::alwaysHitFirstTarget() const
  508. {
  509. return mode == Mode::SPELL_LIKE_ATTACK;
  510. }
  511. bool BaseMechanics::isNegativeSpell() const
  512. {
  513. return owner->isNegative();
  514. }
  515. bool BaseMechanics::isPositiveSpell() const
  516. {
  517. return owner->isPositive();
  518. }
  519. int64_t BaseMechanics::adjustEffectValue(const battle::Unit * target) const
  520. {
  521. return owner->adjustRawDamage(caster, target, getEffectValue());
  522. }
  523. int64_t BaseMechanics::applySpellBonus(int64_t value, const battle::Unit * target) const
  524. {
  525. return caster->getSpellBonus(owner, value, target);
  526. }
  527. int64_t BaseMechanics::applySpecificSpellBonus(int64_t value) const
  528. {
  529. return caster->getSpecificSpellBonus(owner, value);
  530. }
  531. int64_t BaseMechanics::calculateRawEffectValue(int32_t basePowerMultiplier, int32_t levelPowerMultiplier) const
  532. {
  533. return owner->calculateRawEffectValue(getEffectLevel(), basePowerMultiplier, levelPowerMultiplier);
  534. }
  535. std::vector<Bonus::BonusType> BaseMechanics::getElementalImmunity() const
  536. {
  537. std::vector<Bonus::BonusType> ret;
  538. owner->forEachSchool([&](const SchoolInfo & cnf, bool & stop)
  539. {
  540. ret.push_back(cnf.immunityBonus);
  541. });
  542. return ret;
  543. }
  544. bool BaseMechanics::ownerMatches(const battle::Unit * unit) const
  545. {
  546. return ownerMatches(unit, owner->getPositiveness());
  547. }
  548. bool BaseMechanics::ownerMatches(const battle::Unit * unit, const boost::logic::tribool positivness) const
  549. {
  550. return cb->battleMatchOwner(caster->getCasterOwner(), unit, positivness);
  551. }
  552. IBattleCast::Value BaseMechanics::getEffectLevel() const
  553. {
  554. return effectLevel;
  555. }
  556. IBattleCast::Value BaseMechanics::getRangeLevel() const
  557. {
  558. return rangeLevel;
  559. }
  560. IBattleCast::Value BaseMechanics::getEffectPower() const
  561. {
  562. return effectPower;
  563. }
  564. IBattleCast::Value BaseMechanics::getEffectDuration() const
  565. {
  566. return effectDuration;
  567. }
  568. IBattleCast::Value64 BaseMechanics::getEffectValue() const
  569. {
  570. return effectValue;
  571. }
  572. PlayerColor BaseMechanics::getCasterColor() const
  573. {
  574. return caster->getCasterOwner();
  575. }
  576. std::vector<AimType> BaseMechanics::getTargetTypes() const
  577. {
  578. std::vector<AimType> ret;
  579. detail::ProblemImpl ingored;
  580. if(canBeCast(ingored))
  581. {
  582. auto spellTargetType = owner->getTargetType();
  583. if(isMassive())
  584. spellTargetType = AimType::NO_TARGET;
  585. else if(spellTargetType == AimType::OBSTACLE)
  586. spellTargetType = AimType::LOCATION;
  587. ret.push_back(spellTargetType);
  588. }
  589. return ret;
  590. }
  591. const CreatureService * BaseMechanics::creatures() const
  592. {
  593. return VLC->creatures(); //todo: redirect
  594. }
  595. const scripting::Service * BaseMechanics::scripts() const
  596. {
  597. return VLC->scripts(); //todo: redirect
  598. }
  599. const Service * BaseMechanics::spells() const
  600. {
  601. return VLC->spells(); //todo: redirect
  602. }
  603. const IGameInfoCallback * BaseMechanics::game() const
  604. {
  605. return gameCb;
  606. }
  607. const CBattleInfoCallback * BaseMechanics::battle() const
  608. {
  609. return cb;
  610. }
  611. } //namespace spells
  612. ///IAdventureSpellMechanics
  613. IAdventureSpellMechanics::IAdventureSpellMechanics(const CSpell * s)
  614. : owner(s)
  615. {
  616. }
  617. std::unique_ptr<IAdventureSpellMechanics> IAdventureSpellMechanics::createMechanics(const CSpell * s)
  618. {
  619. switch (s->id)
  620. {
  621. case SpellID::SUMMON_BOAT:
  622. return make_unique<SummonBoatMechanics>(s);
  623. case SpellID::SCUTTLE_BOAT:
  624. return make_unique<ScuttleBoatMechanics>(s);
  625. case SpellID::DIMENSION_DOOR:
  626. return make_unique<DimensionDoorMechanics>(s);
  627. case SpellID::FLY:
  628. case SpellID::WATER_WALK:
  629. case SpellID::VISIONS:
  630. case SpellID::DISGUISE:
  631. return make_unique<AdventureSpellMechanics>(s); //implemented using bonus system
  632. case SpellID::TOWN_PORTAL:
  633. return make_unique<TownPortalMechanics>(s);
  634. case SpellID::VIEW_EARTH:
  635. return make_unique<ViewEarthMechanics>(s);
  636. case SpellID::VIEW_AIR:
  637. return make_unique<ViewAirMechanics>(s);
  638. default:
  639. return std::unique_ptr<IAdventureSpellMechanics>();
  640. }
  641. }