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:
parent
847437bbfa
commit
d90d00eeac
@ -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);
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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,61 +30,91 @@ ProxyCaster::~ProxyCaster() = default;
|
|||||||
|
|
||||||
int32_t ProxyCaster::getCasterUnitId() const
|
int32_t ProxyCaster::getCasterUnitId() const
|
||||||
{
|
{
|
||||||
|
if(actualCaster)
|
||||||
return actualCaster->getCasterUnitId();
|
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
|
||||||
{
|
{
|
||||||
|
if(actualCaster)
|
||||||
return actualCaster->getSpellSchoolLevel(spell, outSelectedSchool);
|
return actualCaster->getSpellSchoolLevel(spell, outSelectedSchool);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ProxyCaster::getEffectLevel(const Spell * spell) const
|
int32_t ProxyCaster::getEffectLevel(const Spell * spell) const
|
||||||
{
|
{
|
||||||
|
if(actualCaster)
|
||||||
return actualCaster->getEffectLevel(spell);
|
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
|
||||||
{
|
{
|
||||||
|
if(actualCaster)
|
||||||
return actualCaster->getSpellBonus(spell, base, affectedStack);
|
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
|
||||||
{
|
{
|
||||||
|
if(actualCaster)
|
||||||
return actualCaster->getSpecificSpellBonus(spell, base);
|
return actualCaster->getSpecificSpellBonus(spell, base);
|
||||||
|
|
||||||
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ProxyCaster::getEffectPower(const Spell * spell) const
|
int32_t ProxyCaster::getEffectPower(const Spell * spell) const
|
||||||
{
|
{
|
||||||
|
if(actualCaster)
|
||||||
return actualCaster->getEffectPower(spell);
|
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
|
||||||
{
|
{
|
||||||
|
if(actualCaster)
|
||||||
return actualCaster->getEnchantPower(spell);
|
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
|
||||||
{
|
{
|
||||||
|
if(actualCaster)
|
||||||
return actualCaster->getEffectValue(spell);
|
return actualCaster->getEffectValue(spell);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerColor ProxyCaster::getCasterOwner() const
|
PlayerColor ProxyCaster::getCasterOwner() const
|
||||||
{
|
{
|
||||||
|
if(actualCaster)
|
||||||
return actualCaster->getCasterOwner();
|
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
|
||||||
{
|
{
|
||||||
|
if(actualCaster)
|
||||||
actualCaster->getCastDescription(spell, attacked, text);
|
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
|
||||||
{
|
{
|
||||||
|
if(actualCaster)
|
||||||
actualCaster->spendMana(server, spellCost);
|
actualCaster->spendMana(server, spellCost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user