ISpellMechanics.cpp 17 KB

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