BonusCaster.cpp 2.0 KB

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