Browse Source

+smart target, +hit animation

AlexVinS 10 năm trước cách đây
mục cha
commit
9600446cf9

+ 11 - 1
client/battle/CBattleInterface.cpp

@@ -1188,7 +1188,7 @@ void CBattleInterface::hexLclicked(int whichOne)
 
 void CBattleInterface::stackIsCatapulting(const CatapultAttack & ca)
 {
-	if(ca.attacker != -1) //no shooting animation for spells like earthquake
+	if(ca.attacker != -1)
 	{
 		const CStack * stack = curInt->cb->battleGetStackByID(ca.attacker);
 		for(auto attackInfo : ca.attackedParts)
@@ -1196,6 +1196,16 @@ void CBattleInterface::stackIsCatapulting(const CatapultAttack & ca)
 			addNewAnim(new CShootingAnimation(this, stack, attackInfo.destinationTile, nullptr, true, attackInfo.damageDealt));
 		}		
 	}
+	else
+	{
+		//no attacker stack, assume spell-related (earthquake) - only hit animation 
+		for(auto attackInfo : ca.attackedParts)
+		{
+			Point destPos = CClickableHex::getXYUnitAnim(attackInfo.destinationTile, nullptr, this) + Point(99, 120);
+	
+			addNewAnim(new CSpellEffectAnimation(this, "SGEXPL.DEF", destPos.x, destPos.y));
+		}
+	}	
 
 	waitForAnims();
 

+ 1 - 0
config/spells/other.json

@@ -86,6 +86,7 @@
 		},
 		"levels" : {
 			"base":{
+				"targetModifier":{"smart":true},
 				"range" : "X"
 			}
 		},

+ 1 - 1
lib/CBattleCallback.cpp

@@ -1599,7 +1599,7 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell
 	if(!spell->combatSpell)
 		return ESpellCastProblem::ADVMAP_SPELL_INSTEAD_OF_BATTLE_SPELL;
 
-	const ESpellCastProblem::ESpellCastProblem specificProblem = spell->canBeCasted(this);
+	const ESpellCastProblem::ESpellCastProblem specificProblem = spell->canBeCasted(this, player);
 	
 	if(specificProblem != ESpellCastProblem::OK)
 		return specificProblem;	

+ 9 - 2
lib/spells/BattleSpellMechanics.cpp

@@ -196,7 +196,7 @@ void EarthquakeMechanics::applyBattleEffects(const SpellCastEnvironment * env, B
 		
 		attackInfo.damageDealt = 1;
 		attackInfo.attackedPart = target;
-		attackInfo.destinationTile = BattleHex::INVALID;
+		attackInfo.destinationTile = parameters.cb->wallPartToBattleHex(target);
 		
 		ca.attackedParts.push_back(attackInfo);
 		
@@ -236,7 +236,7 @@ void EarthquakeMechanics::applyBattleEffects(const SpellCastEnvironment * env, B
 	env->sendAndApply(&ca);
 }
 
-ESpellCastProblem::ESpellCastProblem EarthquakeMechanics::canBeCasted(const CBattleInfoCallback * cb) const
+ESpellCastProblem::ESpellCastProblem EarthquakeMechanics::canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const
 {
 	if(nullptr == cb->battleGetDefendedTown())
 	{
@@ -248,6 +248,13 @@ ESpellCastProblem::ESpellCastProblem EarthquakeMechanics::canBeCasted(const CBat
 		return ESpellCastProblem::NO_APPROPRIATE_TARGET;
 	}
 	
+	if(owner->getTargetInfo(0).smart) //TODO: use real spell level
+	{
+		//if spell targeting is smart, then only attacker can use it
+		if(cb->playerToSide(player) != 0)
+			return ESpellCastProblem::NO_APPROPRIATE_TARGET;
+	}
+		
 	return ESpellCastProblem::OK;
 }
 

+ 1 - 1
lib/spells/BattleSpellMechanics.h

@@ -48,7 +48,7 @@ class DLL_LINKAGE EarthquakeMechanics : public DefaultSpellMechanics
 {
 public:
 	EarthquakeMechanics(CSpell * s): DefaultSpellMechanics(s){};
-	ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb) const override;	
+	ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const override;	
 protected:
 	void applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const override;	
 };

+ 1 - 1
lib/spells/CDefaultSpellMechanics.cpp

@@ -712,7 +712,7 @@ std::set<const CStack *> DefaultSpellMechanics::getAffectedStacks(SpellTargeting
 	return attackedCres;
 }
 
-ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::canBeCasted(const CBattleInfoCallback * cb) const
+ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const
 {
 	//no problems by default, this method is for spell-specific problems	
 	return ESpellCastProblem::OK;

+ 1 - 1
lib/spells/CDefaultSpellMechanics.h

@@ -33,7 +33,7 @@ public:
 	std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const override;
 	std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const override;
 
-	ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb) const override;
+	ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const override;
 	
 	ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const override;
 

+ 2 - 2
lib/spells/CSpellHandler.cpp

@@ -234,9 +234,9 @@ ui32 CSpell::calculateDamage(const CGHeroInstance * caster, const CStack * affec
 	return ret;
 }
 
-ESpellCastProblem::ESpellCastProblem CSpell::canBeCasted(const CBattleInfoCallback * cb) const
+ESpellCastProblem::ESpellCastProblem CSpell::canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const
 {
-	return mechanics->canBeCasted(cb);
+	return mechanics->canBeCasted(cb, player);
 }
 
 std::vector<BattleHex> CSpell::rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool *outDroppedHexes) const

+ 1 - 1
lib/spells/CSpellHandler.h

@@ -302,7 +302,7 @@ public:
 	///internal interface (for callbacks)
 	
 	///Checks general but spell-specific problems for all casting modes. Use only during battle.
-	ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb) const;
+	ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const;
 
 	///checks for creature immunity / anything that prevent casting *at given target* - doesn't take into account general problems such as not having spellbook or mana points etc.
 	ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const;

+ 1 - 1
lib/spells/ISpellMechanics.h

@@ -39,7 +39,7 @@ public:
 	virtual std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const = 0;
 	virtual std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const = 0;
 	
-	virtual ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb) const = 0;
+	virtual ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const = 0;
 	
 	virtual ESpellCastProblem::ESpellCastProblem isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const = 0;