BonusCaster.cpp 1.4 KB

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