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:
parent
c3012105e2
commit
1194419884
@ -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,
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 &());
|
||||
|
Loading…
Reference in New Issue
Block a user