Przeglądaj źródła

cast only on self

Laserlicht 1 rok temu
rodzic
commit
e6cb87abac

+ 4 - 0
config/schemas/spell.json

@@ -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."

+ 3 - 0
docs/modders/Entities_Format/Spell_Format.md

@@ -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,

+ 1 - 0
include/vcmi/spells/Spell.h

@@ -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;

+ 14 - 9
lib/spells/BattleSpellMechanics.cpp

@@ -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);
 }

+ 8 - 0
lib/spells/CSpellHandler.cpp

@@ -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());

+ 2 - 0
lib/spells/CSpellHandler.h

@@ -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
 

+ 1 - 0
test/mock/mock_spells_Spell.h

@@ -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 &));