ISpellMechanics.cpp 17 KB

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