BonusCaster.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 "../NetPacksBase.h"
  13. #include "../HeroBonus.h"
  14. #include "../battle/Unit.h"
  15. namespace spells
  16. {
  17. BonusCaster::BonusCaster(const Caster * actualCaster_, std::shared_ptr<Bonus> bonus_)
  18. : ProxyCaster(actualCaster_),
  19. actualCaster(actualCaster_),
  20. bonus(bonus_)
  21. {
  22. }
  23. BonusCaster::~BonusCaster() = default;
  24. void BonusCaster::getCasterName(MetaString & text) const
  25. {
  26. if(!bonus->description.empty())
  27. text.addReplacement(bonus->description);
  28. else
  29. actualCaster->getCasterName(text);
  30. }
  31. void BonusCaster::getCastDescription(const Spell * spell, const std::vector<const battle::Unit*> & attacked, MetaString & text) const
  32. {
  33. const bool singleTarget = attacked.size() == 1;
  34. const int textIndex = singleTarget ? 195 : 196;
  35. text.addTxt(MetaString::GENERAL_TXT, textIndex);
  36. getCasterName(text);
  37. text.addReplacement(MetaString::SPELL_NAME, spell->getIndex());
  38. if(singleTarget)
  39. attacked.at(0)->addNameReplacement(text, true);
  40. }
  41. void BonusCaster::spendMana(const PacketSender * server, const int spellCost) const
  42. {
  43. logGlobal->error("Unexpected call to BonusCaster::spendMana");
  44. }
  45. } // namespace spells