void HeroBase::SpellCasted(const Spell & spell) { // resource cost Kingdom & kingdom = world.GetKingdom(GetColor()); const payment_t & cost = spell.GetCost(); if(cost.GetValidItemsCount()) kingdom.OddFundsResource(cost); // spell point cost magic_point -= (spell.SpellPoint(this) < magic_point ? spell.SpellPoint(this) : magic_point); // move point cost if(spell.MovePoint()) move_point -= (spell.MovePoint() < move_point ? spell.MovePoint() : move_point); }
bool HeroBase::CanCastSpell(const Spell & spell, std::string* res) const { const Kingdom & kingdom = world.GetKingdom(GetColor()); if(res) { std::ostringstream os; if(HaveSpellBook()) { if(HaveSpell(spell)) { if(HaveSpellPoints(spell)) { if(spell.MovePoint() <= move_point) { if(kingdom.AllowPayment(spell.GetCost())) return true; else os << "resource" << " " << "failed"; } else os << "move points" << " " << "failed"; } else os << _("That spell costs %{mana} mana. You only have %{point} mana, so you can't cast the spell."); } else os << "spell" << " " << "not found"; } else os << "spell book" << " " << "not found"; *res = os.str(); return false; } return HaveSpellBook() && HaveSpell(spell) && HaveSpellPoints(spell) && kingdom.AllowPayment(spell.GetCost()); }