ISpellMechanics.cpp 17 KB

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