Browse Source

Draft fo CHAIN_LIGHTNING
* fix usage of RECEPTIVE bonus

AlexVinS 11 years ago
parent
commit
0015027ec7
3 changed files with 22 additions and 26 deletions
  1. 8 7
      lib/CSpellHandler.cpp
  2. 9 16
      lib/SpellMechanics.cpp
  3. 5 3
      lib/SpellMechanics.h

+ 8 - 7
lib/CSpellHandler.cpp

@@ -659,11 +659,7 @@ void CSpell::getEffects(std::vector<Bonus>& lst, const int level) const
 }
 
 ESpellCastProblem::ESpellCastProblem CSpell::isImmuneBy(const IBonusBearer* obj) const
-{
-	//0. check receptivity
-	if (isPositive() && obj->hasBonusOfType(Bonus::RECEPTIVE)) //accept all positive spells
-		return ESpellCastProblem::OK;	
-	
+{	
 	//todo: use new bonus API
 	//1. Check absolute limiters
 	for(auto b : absoluteLimiters)
@@ -678,6 +674,10 @@ ESpellCastProblem::ESpellCastProblem CSpell::isImmuneBy(const IBonusBearer* obj)
 		if (obj->hasBonusOfType(b))
 			return ESpellCastProblem::STACK_IMMUNE_TO_SPELL;
 	}
+	
+	//check receptivity
+	if (isPositive() && obj->hasBonusOfType(Bonus::RECEPTIVE)) //accept all positive spells
+		return ESpellCastProblem::OK;	
 
 	//3. Check negation
 	//FIXME: Orb of vulnerability mechanics is not such trivial
@@ -794,11 +794,12 @@ void CSpell::setupMechanics()
 	case SpellID::SACRIFICE:
 		mechanics = new SacrificeMechanics(this);
 		break;
+	case SpellID::CHAIN_LIGHTNING:
+		mechanics = new ChainLightningMechanics(this);
+		break;		
 	default:		
 		if(isRisingSpell())
 			mechanics = new SpecialRisingSpellMechanics(this);
-		else if(isOffensiveSpell())
-			mechanics = new OffenciveSpellMechnics(this);
 		else	
 			mechanics = new DefaultSpellMechanics(this);
 		break;

+ 9 - 16
lib/SpellMechanics.cpp

@@ -18,18 +18,6 @@
 
 ///DefaultSpellMechanics
 
-std::set<const CStack *> DefaultSpellMechanics::getAffectedStacks(SpellTargetingContext & ctx) const
-{
-	
-}
-
-
-ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const
-{
-	//by default use general algorithm
-	return owner->isImmuneBy(obj);
-}
-
 bool DefaultSpellMechanics::adventureCast(SpellCastContext& context) const
 {
 	return false; //there is no general algorithm for castind adventure spells
@@ -40,15 +28,20 @@ bool DefaultSpellMechanics::battleCast(SpellCastContext& context) const
 	return false; //todo; DefaultSpellMechanics::battleCast
 }
 
-///OffenciveSpellMechnics
-bool OffenciveSpellMechnics::battleCast(SpellCastContext& context) const
+std::set<const CStack *> DefaultSpellMechanics::getAffectedStacks(SpellTargetingContext & ctx) const
 {
-	assert(owner->isOffensiveSpell());
 	
-	//todo:OffenciveSpellMechnics::battleCast
 }
 
 
+ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const
+{
+	//by default use general algorithm
+	return owner->isImmuneBy(obj);
+}
+
+
+
 ///CloneMechanics
 ESpellCastProblem::ESpellCastProblem CloneMechanics::isImmuneByStack(const CGHeroInstance* caster, const CStack * obj) const
 {

+ 5 - 3
lib/SpellMechanics.h

@@ -25,11 +25,13 @@ public:
 	bool battleCast(SpellCastContext & context) const override; 
 };
 
-class OffenciveSpellMechnics: public DefaultSpellMechanics
+
+
+class ChainLightningMechanics: public DefaultSpellMechanics
 {
 public:
-	OffenciveSpellMechnics(CSpell * s): DefaultSpellMechanics(s){};	
-	bool battleCast(SpellCastContext & context) const override;
+	ChainLightningMechanics(CSpell * s): DefaultSpellMechanics(s){};	
+	
 };
 
 class CloneMechanics: public DefaultSpellMechanics