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

Added option to allow self-casting

This commit is contained in:
Ivan Savenko 2024-01-16 15:01:42 +02:00
parent c3012105e2
commit 1194419884
6 changed files with 27 additions and 9 deletions

View File

@ -61,6 +61,10 @@
"positive": true,
},
// If true, then creature capable of casting this spell can cast this spell on itself
// If false, then creature can only cast this spell on other units
"canCastOnSelf" : false,
// If true, spell won't be available on a map without water
"onlyOnWaterMap" : true,

View File

@ -44,6 +44,7 @@ public:
virtual bool isMagical() const = 0; //Should this spell considered as magical effect or as ability (like dendroid's bind)
virtual bool hasSchool(SpellSchool school) const = 0;
virtual bool canCastOnSelf() const = 0;
virtual void forEachSchool(const SchoolCallback & cb) const = 0;
virtual int32_t getCost(const int32_t skillLevel) const = 0;

View File

@ -215,6 +215,8 @@ bool BattleSpellMechanics::canBeCastAt(const Target & target, Problem & problem)
const battle::Unit * mainTarget = nullptr;
if (!getSpell()->canCastOnSelf())
{
if(spellTarget.front().unitValue)
{
mainTarget = target.front().unitValue;
@ -226,6 +228,7 @@ bool BattleSpellMechanics::canBeCastAt(const Target & target, Problem & problem)
if (mainTarget && mainTarget == caster)
return false; // can't cast on self
}
return effects->applicable(problem, this, target, spellTarget);
}

View File

@ -76,6 +76,7 @@ CSpell::CSpell():
power(0),
combat(false),
creatureAbility(false),
castOnSelf(false),
positiveness(ESpellPositiveness::NEUTRAL),
defaultProbability(0),
rising(false),
@ -285,6 +286,11 @@ bool CSpell::hasBattleEffects() const
return levels[0].battleEffects.getType() == JsonNode::JsonType::DATA_STRUCT && !levels[0].battleEffects.Struct().empty();
}
bool CSpell::canCastOnSelf() const
{
return castOnSelf;
}
const std::string & CSpell::getIconImmune() const
{
return iconImmune;
@ -702,6 +708,7 @@ CSpell * CSpellHandler::loadFromJson(const std::string & scope, const JsonNode &
spell->school[info.id] = schoolNames[info.jsonName].Bool();
}
spell->castOnSelf = json["canCastOnSelf"].Bool();
spell->level = static_cast<si32>(json["level"].Integer());
spell->power = static_cast<si32>(json["power"].Integer());

View File

@ -203,6 +203,7 @@ public:
int64_t calculateDamage(const spells::Caster * caster) const override;
bool hasSchool(SpellSchool school) const override;
bool canCastOnSelf() const override;
/**
* Calls cb for each school this spell belongs to
@ -329,6 +330,7 @@ private:
si32 power; //spell's power
bool combat; //is this spell combat (true) or adventure (false)
bool creatureAbility; //if true, only creatures can use this spell
bool castOnSelf; // if set, creature caster can cast this spell on itself
si8 positiveness; //1 if spell is positive for influenced stacks, 0 if it is indifferent, -1 if it's negative
std::unique_ptr<spells::ISpellMechanicsFactory> mechanics;//(!) do not serialize

View File

@ -45,6 +45,7 @@ public:
MOCK_CONST_METHOD0(isOffensive, bool());
MOCK_CONST_METHOD0(isSpecial, bool());
MOCK_CONST_METHOD0(isMagical, bool());
MOCK_CONST_METHOD0(canCastOnSelf, bool());
MOCK_CONST_METHOD1(hasSchool, bool(SpellSchool));
MOCK_CONST_METHOD1(forEachSchool, void(const SchoolCallback &));
MOCK_CONST_METHOD0(getCastSound, const std::string &());