1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

vcmi: rework ProxyCaster

Now ProxyCaster can be used without hero and can even cast something
with default values.
This commit is contained in:
Konstantin 2023-03-19 02:30:06 +03:00
parent 847437bbfa
commit d90d00eeac
6 changed files with 47 additions and 19 deletions

View File

@ -22,7 +22,6 @@ namespace spells
AbilityCaster::AbilityCaster(const battle::Unit * actualCaster_, int32_t baseSpellLevel_) AbilityCaster::AbilityCaster(const battle::Unit * actualCaster_, int32_t baseSpellLevel_)
: ProxyCaster(actualCaster_), : ProxyCaster(actualCaster_),
actualCaster(actualCaster_),
baseSpellLevel(baseSpellLevel_) baseSpellLevel(baseSpellLevel_)
{ {
} }
@ -32,10 +31,11 @@ AbilityCaster::~AbilityCaster() = default;
int32_t AbilityCaster::getSpellSchoolLevel(const Spell * spell, int32_t * outSelectedSchool) const int32_t AbilityCaster::getSpellSchoolLevel(const Spell * spell, int32_t * outSelectedSchool) const
{ {
auto skill = baseSpellLevel; auto skill = baseSpellLevel;
const auto * unit = dynamic_cast<const battle::Unit*>(actualCaster);
if(spell->getLevel() > 0) if(spell->getLevel() > 0)
{ {
vstd::amax(skill, actualCaster->valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 0)); vstd::amax(skill, unit->valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 0));
} }
vstd::amax(skill, 0); vstd::amax(skill, 0);

View File

@ -29,7 +29,6 @@ public:
void spendMana(ServerCallback * server, const int32_t spellCost) const override; void spendMana(ServerCallback * server, const int32_t spellCost) const override;
private: private:
const battle::Unit * actualCaster;
int32_t baseSpellLevel; int32_t baseSpellLevel;
}; };

View File

@ -24,10 +24,8 @@ namespace spells
BonusCaster::BonusCaster(const Caster * actualCaster_, std::shared_ptr<Bonus> bonus_): BonusCaster::BonusCaster(const Caster * actualCaster_, std::shared_ptr<Bonus> bonus_):
ProxyCaster(actualCaster_), ProxyCaster(actualCaster_),
actualCaster(actualCaster_),
bonus(std::move(bonus_)) bonus(std::move(bonus_))
{ {
} }
BonusCaster::~BonusCaster() = default; BonusCaster::~BonusCaster() = default;

View File

@ -30,7 +30,6 @@ public:
void spendMana(ServerCallback * server, const int spellCost) const override; void spendMana(ServerCallback * server, const int spellCost) const override;
private: private:
const Caster * actualCaster;
std::shared_ptr<Bonus> bonus; std::shared_ptr<Bonus> bonus;
}; };

View File

@ -13,6 +13,8 @@
#include "../GameConstants.h" #include "../GameConstants.h"
#include <vcmi/spells/Spell.h>
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
namespace spells namespace spells
@ -28,62 +30,92 @@ ProxyCaster::~ProxyCaster() = default;
int32_t ProxyCaster::getCasterUnitId() const int32_t ProxyCaster::getCasterUnitId() const
{ {
return actualCaster->getCasterUnitId(); if(actualCaster)
return actualCaster->getCasterUnitId();
return -1;
} }
int32_t ProxyCaster::getSpellSchoolLevel(const Spell * spell, int32_t * outSelectedSchool) const int32_t ProxyCaster::getSpellSchoolLevel(const Spell * spell, int32_t * outSelectedSchool) const
{ {
return actualCaster->getSpellSchoolLevel(spell, outSelectedSchool); if(actualCaster)
return actualCaster->getSpellSchoolLevel(spell, outSelectedSchool);
return 0;
} }
int32_t ProxyCaster::getEffectLevel(const Spell * spell) const int32_t ProxyCaster::getEffectLevel(const Spell * spell) const
{ {
return actualCaster->getEffectLevel(spell); if(actualCaster)
return actualCaster->getEffectLevel(spell);
return 0;
} }
int64_t ProxyCaster::getSpellBonus(const Spell * spell, int64_t base, const battle::Unit * affectedStack) const int64_t ProxyCaster::getSpellBonus(const Spell * spell, int64_t base, const battle::Unit * affectedStack) const
{ {
return actualCaster->getSpellBonus(spell, base, affectedStack); if(actualCaster)
return actualCaster->getSpellBonus(spell, base, affectedStack);
return base;
} }
int64_t ProxyCaster::getSpecificSpellBonus(const Spell * spell, int64_t base) const int64_t ProxyCaster::getSpecificSpellBonus(const Spell * spell, int64_t base) const
{ {
return actualCaster->getSpecificSpellBonus(spell, base); if(actualCaster)
return actualCaster->getSpecificSpellBonus(spell, base);
return base;
} }
int32_t ProxyCaster::getEffectPower(const Spell * spell) const int32_t ProxyCaster::getEffectPower(const Spell * spell) const
{ {
return actualCaster->getEffectPower(spell); if(actualCaster)
return actualCaster->getEffectPower(spell);
return spell->getLevelPower(getEffectLevel(spell));
} }
int32_t ProxyCaster::getEnchantPower(const Spell * spell) const int32_t ProxyCaster::getEnchantPower(const Spell * spell) const
{ {
return actualCaster->getEnchantPower(spell); if(actualCaster)
return actualCaster->getEnchantPower(spell);
return spell->getLevelPower(getEffectLevel(spell));
} }
int64_t ProxyCaster::getEffectValue(const Spell * spell) const int64_t ProxyCaster::getEffectValue(const Spell * spell) const
{ {
return actualCaster->getEffectValue(spell); if(actualCaster)
return actualCaster->getEffectValue(spell);
return 0;
} }
PlayerColor ProxyCaster::getCasterOwner() const PlayerColor ProxyCaster::getCasterOwner() const
{ {
return actualCaster->getCasterOwner(); if(actualCaster)
return actualCaster->getCasterOwner();
return PlayerColor::CANNOT_DETERMINE;
} }
void ProxyCaster::getCasterName(MetaString & text) const void ProxyCaster::getCasterName(MetaString & text) const
{ {
return actualCaster->getCasterName(text); if(actualCaster)
actualCaster->getCasterName(text);
} }
void ProxyCaster::getCastDescription(const Spell * spell, const std::vector<const battle::Unit*> & attacked, MetaString & text) const void ProxyCaster::getCastDescription(const Spell * spell, const std::vector<const battle::Unit*> & attacked, MetaString & text) const
{ {
actualCaster->getCastDescription(spell, attacked, text); if(actualCaster)
actualCaster->getCastDescription(spell, attacked, text);
} }
void ProxyCaster::spendMana(ServerCallback * server, const int32_t spellCost) const void ProxyCaster::spendMana(ServerCallback * server, const int32_t spellCost) const
{ {
actualCaster->spendMana(server, spellCost); if(actualCaster)
actualCaster->spendMana(server, spellCost);
} }
} }

View File

@ -36,7 +36,7 @@ public:
void getCastDescription(const Spell * spell, const std::vector<const battle::Unit *> & attacked, MetaString & text) const override; void getCastDescription(const Spell * spell, const std::vector<const battle::Unit *> & attacked, MetaString & text) const override;
void spendMana(ServerCallback * server, const int32_t spellCost) const override; void spendMana(ServerCallback * server, const int32_t spellCost) const override;
private: protected:
const Caster * actualCaster; const Caster * actualCaster;
}; };