ISpellMechanics.cpp 18 KB

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