BonusCaster.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * BonusCaster.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 "BonusCaster.h"
  12. #include <vcmi/spells/Spell.h>
  13. #include <vcmi/HeroType.h>
  14. #include "../battle/Unit.h"
  15. #include "../bonuses/Bonus.h"
  16. #include "../VCMI_Lib.h"
  17. #include "../CSkillHandler.h"
  18. VCMI_LIB_NAMESPACE_BEGIN
  19. namespace spells
  20. {
  21. BonusCaster::BonusCaster(const Caster * actualCaster_, std::shared_ptr<Bonus> bonus_):
  22. ProxyCaster(actualCaster_),
  23. bonus(std::move(bonus_))
  24. {
  25. }
  26. BonusCaster::~BonusCaster() = default;
  27. void BonusCaster::getCasterName(MetaString & text) const
  28. {
  29. switch(bonus->source)
  30. {
  31. case BonusSource::ARTIFACT:
  32. text.replaceName(bonus->sid.as<ArtifactID>());
  33. break;
  34. case BonusSource::SPELL_EFFECT:
  35. text.replaceName(bonus->sid.as<SpellID>());
  36. break;
  37. case BonusSource::CREATURE_ABILITY:
  38. text.replaceNamePlural(bonus->sid.as<CreatureID>());
  39. break;
  40. case BonusSource::SECONDARY_SKILL:
  41. text.replaceTextID(bonus->sid.as<SecondarySkill>().toEntity(VLC)->getNameTextID());
  42. break;
  43. case BonusSource::HERO_SPECIAL:
  44. text.replaceTextID(bonus->sid.as<HeroTypeID>().toEntity(VLC)->getNameTextID());
  45. break;
  46. default:
  47. actualCaster->getCasterName(text);
  48. break;
  49. }
  50. }
  51. void BonusCaster::getCastDescription(const Spell * spell, const battle::Units & attacked, MetaString & text) const
  52. {
  53. const bool singleTarget = attacked.size() == 1;
  54. const int textIndex = singleTarget ? 195 : 196;
  55. text.appendLocalString(EMetaText::GENERAL_TXT, textIndex);
  56. getCasterName(text);
  57. text.replaceName(spell->getId());
  58. if(singleTarget)
  59. attacked.at(0)->addNameReplacement(text, true);
  60. }
  61. void BonusCaster::spendMana(ServerCallback * server, const int spellCost) const
  62. {
  63. logGlobal->error("Unexpected call to BonusCaster::spendMana");
  64. }
  65. } // namespace spells
  66. VCMI_LIB_NAMESPACE_END