mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-30 08:57:00 +02:00
cast only on self
This commit is contained in:
parent
7f8f09c8fa
commit
e6cb87abac
@ -171,6 +171,10 @@
|
||||
"type" : "boolean",
|
||||
"description" : "If used as creature spell, unit can cast this spell on itself"
|
||||
},
|
||||
"canCastOnlyOnSelf" : {
|
||||
"type" : "boolean",
|
||||
"description" : "If used as creature spell, unit can cast this spell only on itself"
|
||||
},
|
||||
"canCastWithoutSkip" : {
|
||||
"type" : "boolean",
|
||||
"description" : "If used the creature will not skip the turn after casting a spell."
|
||||
|
@ -64,6 +64,9 @@
|
||||
// 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, then creature capable of casting this spell can cast this spell only on itself
|
||||
"canCastOnlyOnSelf" : false,
|
||||
|
||||
// If true the creature will not skip the turn after casting a spell
|
||||
"canCastWithoutSkip": false,
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
|
||||
virtual bool hasSchool(SpellSchool school) const = 0;
|
||||
virtual bool canCastOnSelf() const = 0;
|
||||
virtual bool canCastOnlyOnSelf() const = 0;
|
||||
virtual bool canCastWithoutSkip() const = 0;
|
||||
virtual void forEachSchool(const SchoolCallback & cb) const = 0;
|
||||
virtual int32_t getCost(const int32_t skillLevel) const = 0;
|
||||
|
@ -217,23 +217,28 @@ bool BattleSpellMechanics::canBeCastAt(const Target & target, Problem & problem)
|
||||
|
||||
const battle::Unit * mainTarget = nullptr;
|
||||
|
||||
if (!getSpell()->canCastOnSelf())
|
||||
if(spellTarget.front().unitValue)
|
||||
{
|
||||
if(spellTarget.front().unitValue)
|
||||
{
|
||||
mainTarget = target.front().unitValue;
|
||||
}
|
||||
else if(spellTarget.front().hexValue.isValid())
|
||||
{
|
||||
mainTarget = battle()->battleGetUnitByPos(target.front().hexValue, true);
|
||||
}
|
||||
mainTarget = target.front().unitValue;
|
||||
}
|
||||
else if(spellTarget.front().hexValue.isValid())
|
||||
{
|
||||
mainTarget = battle()->battleGetUnitByPos(target.front().hexValue, true);
|
||||
}
|
||||
|
||||
if (!getSpell()->canCastOnSelf() && !getSpell()->canCastOnlyOnSelf())
|
||||
{
|
||||
if(mainTarget && mainTarget == caster)
|
||||
return false; // can't cast on self
|
||||
|
||||
if(mainTarget && mainTarget->hasBonusOfType(BonusType::INVINCIBLE) && !getSpell()->getPositiveness())
|
||||
return false;
|
||||
}
|
||||
else if(getSpell()->canCastOnlyOnSelf())
|
||||
{
|
||||
if(mainTarget && mainTarget != caster)
|
||||
return false; // can't cast on others
|
||||
}
|
||||
|
||||
return effects->applicable(problem, this, target, spellTarget);
|
||||
}
|
||||
|
@ -79,6 +79,8 @@ CSpell::CSpell():
|
||||
combat(false),
|
||||
creatureAbility(false),
|
||||
castOnSelf(false),
|
||||
castOnlyOnSelf(false),
|
||||
castWithoutSkip(false),
|
||||
positiveness(ESpellPositiveness::NEUTRAL),
|
||||
defaultProbability(0),
|
||||
rising(false),
|
||||
@ -298,6 +300,11 @@ bool CSpell::canCastOnSelf() const
|
||||
return castOnSelf;
|
||||
}
|
||||
|
||||
bool CSpell::canCastOnlyOnSelf() const
|
||||
{
|
||||
return castOnlyOnSelf;
|
||||
}
|
||||
|
||||
bool CSpell::canCastWithoutSkip() const
|
||||
{
|
||||
return castWithoutSkip;
|
||||
@ -788,6 +795,7 @@ std::shared_ptr<CSpell> CSpellHandler::loadFromJson(const std::string & scope, c
|
||||
}
|
||||
|
||||
spell->castOnSelf = json["canCastOnSelf"].Bool();
|
||||
spell->castOnlyOnSelf = json["canCastOnlyOnSelf"].Bool();
|
||||
spell->castWithoutSkip = json["canCastWithoutSkip"].Bool();
|
||||
spell->level = static_cast<si32>(json["level"].Integer());
|
||||
spell->power = static_cast<si32>(json["power"].Integer());
|
||||
|
@ -167,6 +167,7 @@ public:
|
||||
|
||||
bool hasSchool(SpellSchool school) const override;
|
||||
bool canCastOnSelf() const override;
|
||||
bool canCastOnlyOnSelf() const override;
|
||||
bool canCastWithoutSkip() const override;
|
||||
|
||||
/**
|
||||
@ -297,6 +298,7 @@ private:
|
||||
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
|
||||
bool castOnlyOnSelf; // if set, creature caster can cast this spell on itself
|
||||
bool castWithoutSkip; // if set the creature will not skip the turn after casting a spell
|
||||
si8 positiveness; //1 if spell is positive for influenced stacks, 0 if it is indifferent, -1 if it's negative
|
||||
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
MOCK_CONST_METHOD0(isSpecial, bool());
|
||||
MOCK_CONST_METHOD0(isMagical, bool());
|
||||
MOCK_CONST_METHOD0(canCastOnSelf, bool());
|
||||
MOCK_CONST_METHOD0(canCastOnlyOnSelf, bool());
|
||||
MOCK_CONST_METHOD0(canCastWithoutSkip, bool());
|
||||
MOCK_CONST_METHOD1(hasSchool, bool(SpellSchool));
|
||||
MOCK_CONST_METHOD1(forEachSchool, void(const SchoolCallback &));
|
||||
|
Loading…
Reference in New Issue
Block a user