Bläddra i källkod

remove healedHP calculation from battlestate

AlexVinS 11 år sedan
förälder
incheckning
fa9c1e8637
4 ändrade filer med 14 tillägg och 19 borttagningar
  1. 0 13
      lib/BattleState.cpp
  2. 0 2
      lib/CBattleCallback.h
  3. 5 1
      lib/CSpellHandler.h
  4. 9 3
      lib/SpellMechanics.cpp

+ 0 - 13
lib/BattleState.cpp

@@ -159,19 +159,6 @@ CStack * BattleInfo::generateNewStack(const CStackBasicDescriptor &base, bool at
 	return ret;
 }
 
-//Archangel
-ui32 CBattleInfoCallback::calculateHealedHP(int healedHealth, const CSpell * spell, const CStack * stack) const
-{
-	bool resurrect = spell->isRisingSpell();
-	return std::min<ui32>(healedHealth, stack->MaxHealth() - stack->firstHPleft + (resurrect ? stack->baseAmount * stack->MaxHealth() : 0));
-}
-//Casted by stack, no hero bonus applied
-ui32 CBattleInfoCallback::calculateHealedHP(const CSpell * spell, int usedSpellPower, int spellSchoolLevel, const CStack * stack) const
-{
-	bool resurrect = spell->isRisingSpell();
-	int healedHealth = usedSpellPower * spell->power + spell->getPower(spellSchoolLevel);
-	return std::min<ui32>(healedHealth, stack->MaxHealth() - stack->firstHPleft + (resurrect ? stack->baseAmount * stack->MaxHealth() : 0));
-}
 bool BattleInfo::resurrects(SpellID spellid) const
 {
 	return spellid.toSpell()->isRisingSpell();

+ 0 - 2
lib/CBattleCallback.h

@@ -281,8 +281,6 @@ public:
 	ESpellCastProblem::ESpellCastProblem battleCanCastThisSpellHere(PlayerColor player, const CSpell * spell, ECastingMode::ECastingMode mode, BattleHex dest) const; //checks if given player can cast given spell at given tile in given mode
 	ESpellCastProblem::ESpellCastProblem battleCanCreatureCastThisSpell(const CSpell * spell, BattleHex destination) const; //determines if creature can cast a spell here
 	std::vector<BattleHex> battleGetPossibleTargets(PlayerColor player, const CSpell *spell) const;
-	ui32 calculateHealedHP(int healedHealth, const CSpell * spell, const CStack * stack) const; //for Archangel
-	ui32 calculateHealedHP(const CSpell * spell, int usedSpellPower, int spellSchoolLevel, const CStack * stack) const; //healing spells casted by stacks
 
 	SpellID battleGetRandomStackSpell(const CStack * stack, ERandomSpell mode) const;
 	SpellID getRandomBeneficialSpell(const CStack * subject) const;

+ 5 - 1
lib/CSpellHandler.h

@@ -30,6 +30,7 @@ class CBattleInfoCallback;
 class BattleInfo;
 
 struct CPackForClient;
+struct BattleSpellCast;
 class CRandomGenerator;
 
 struct SpellSchoolInfo
@@ -254,7 +255,6 @@ public:
 	}
 	friend class CSpellHandler;
 	friend class Graphics;
-
 private:
 	void setIsOffensive(const bool val);
 	void setIsRising(const bool val);
@@ -322,6 +322,10 @@ public:
 	{
 		h & objects ;
 	}
+public:	
+	///Client-Server events. Shall be called only when applying packets	
+	//void afterSpellCast(BattleInfo * battle, BattleSpellCast * packet) const;
+	
 protected:
 	CSpell * loadFromJson(const JsonNode & json) override;
 };

+ 9 - 3
lib/SpellMechanics.cpp

@@ -453,7 +453,7 @@ int DefaultSpellMechanics::calculateDuration(const CGHeroInstance * caster, int
 }
 
 
-void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment* env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
+void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
 {
 	//applying effects
 	if(owner->isOffensiveSpell())
@@ -607,12 +607,18 @@ void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment* env,
 			hi.stackID = (attackedCre)->ID;
 			if (parameters.casterStack) //casted by creature
 			{
+				const bool resurrect = owner->isRisingSpell();
 				if (hpGained)
 				{
-					hi.healedHP = parameters.cb->calculateHealedHP(hpGained, owner, attackedCre); //archangel
+					//archangel
+					hi.healedHP = std::min<ui32>(hpGained, attackedCre->MaxHealth() - attackedCre->firstHPleft + (resurrect ? attackedCre->baseAmount * attackedCre->MaxHealth() : 0));
 				}
 				else
-					hi.healedHP = parameters.cb->calculateHealedHP(owner, parameters.usedSpellPower, parameters.spellLvl, attackedCre); //any typical spell (commander's cure or animate dead)
+				{
+					//any typical spell (commander's cure or animate dead)
+					int healedHealth = parameters.usedSpellPower * owner->power + owner->getPower(parameters.spellLvl);
+					hi.healedHP = std::min<ui32>(healedHealth, attackedCre->MaxHealth() - attackedCre->firstHPleft + (resurrect ? attackedCre->baseAmount * attackedCre->MaxHealth() : 0));
+				}					
 			}
 			else
 				hi.healedHP = owner->calculateHealedHP(parameters.caster, attackedCre, parameters.selectedStack); //Casted by hero