2
0
Эх сурвалжийг харах

Implemented HERO_SPELL_CASTS_PER_COMBAT_TURN bonus

Ivan Savenko 5 сар өмнө
parent
commit
700eeb6bd4

+ 6 - 0
config/gameConfig.json

@@ -582,6 +582,12 @@
 					"type" : "MANA_PER_KNOWLEDGE_PERCENTAGE", //1000% mana per knowledge
 					"val" : 1000,
 					"valueType" : "BASE_NUMBER"
+				},
+				"spellCastsPerTurn" :
+				{
+					"type" : "HERO_SPELL_CASTS_PER_COMBAT_TURN", //1 spell can be cast by hero per turn during combat
+					"val" : 1,
+					"valueType" : "BASE_NUMBER"
 				}
 			}
 		},

+ 1 - 1
lib/battle/BattleInfo.cpp

@@ -602,7 +602,7 @@ EGateState BattleInfo::getGateState() const
 	return si.gateState;
 }
 
-uint32_t BattleInfo::getCastSpells(BattleSide side) const
+int32_t BattleInfo::getCastSpells(BattleSide side) const
 {
 	return getSide(side).castSpellsCount;
 }

+ 1 - 1
lib/battle/BattleInfo.h

@@ -110,7 +110,7 @@ public:
 	EWallState getWallState(EWallPart partOfWall) const override;
 	EGateState getGateState() const override;
 
-	uint32_t getCastSpells(BattleSide side) const override;
+	int32_t getCastSpells(BattleSide side) const override;
 	int32_t getEnchanterCounter(BattleSide side) const override;
 
 	const IBonusBearer * getBonusBearer() const override;

+ 1 - 1
lib/battle/BattleProxy.cpp

@@ -105,7 +105,7 @@ EGateState BattleProxy::getGateState() const
 	return subject->battleGetGateState();
 }
 
-uint32_t BattleProxy::getCastSpells(BattleSide side) const
+int32_t BattleProxy::getCastSpells(BattleSide side) const
 {
 	return subject->battleCastSpells(side);
 }

+ 1 - 1
lib/battle/BattleProxy.h

@@ -49,7 +49,7 @@ public:
 	EWallState getWallState(EWallPart partOfWall) const override;
 	EGateState getGateState() const override;
 
-	uint32_t getCastSpells(BattleSide side) const override;
+	int32_t getCastSpells(BattleSide side) const override;
 	int32_t getEnchanterCounter(BattleSide side) const override;
 
 	const IBonusBearer * getBonusBearer() const override;

+ 5 - 6
lib/battle/CBattleInfoCallback.cpp

@@ -114,17 +114,16 @@ ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(const spells::Caster *
 	{
 	case spells::Mode::HERO:
 	{
-		if(battleCastSpells(side) > 0)
-			return ESpellCastProblem::CASTS_PER_TURN_LIMIT;
-
-		const auto * hero = dynamic_cast<const CGHeroInstance *>(caster);
+		const auto * hero = caster->getHeroCaster();
 
 		if(!hero)
 			return ESpellCastProblem::NO_HERO_TO_CAST_SPELL;
-		if(hero->hasBonusOfType(BonusType::BLOCK_ALL_MAGIC))
-			return ESpellCastProblem::MAGIC_IS_BLOCKED;
 		if(!hero->hasSpellbook())
 			return ESpellCastProblem::NO_SPELLBOOK;
+		if(hero->hasBonusOfType(BonusType::BLOCK_ALL_MAGIC))
+			return ESpellCastProblem::MAGIC_IS_BLOCKED;
+		if(battleCastSpells(side) >= hero->valOfBonuses(BonusType::HERO_SPELL_CASTS_PER_COMBAT_TURN))
+			return ESpellCastProblem::CASTS_PER_TURN_LIMIT;
 	}
 		break;
 	default:

+ 1 - 1
lib/battle/CBattleInfoEssentials.cpp

@@ -256,7 +256,7 @@ InfoAboutHero CBattleInfoEssentials::battleGetHeroInfo(BattleSide side) const
 	return InfoAboutHero(hero, infoLevel);
 }
 
-uint32_t CBattleInfoEssentials::battleCastSpells(BattleSide side) const
+int32_t CBattleInfoEssentials::battleCastSpells(BattleSide side) const
 {
 	RETURN_IF_NOT_BATTLE(-1);
 	return getBattle()->getCastSpells(side);

+ 1 - 1
lib/battle/CBattleInfoEssentials.h

@@ -78,7 +78,7 @@ public:
 	bool playerHasAccessToHeroInfo(const PlayerColor & player, const CGHeroInstance * h) const;
 	TownFortifications battleGetFortifications() const;
 	bool battleHasHero(BattleSide side) const;
-	uint32_t battleCastSpells(BattleSide side) const; //how many spells has given side cast
+	int32_t battleCastSpells(BattleSide side) const; //how many spells has given side cast
 	const CGHeroInstance * battleGetFightingHero(BattleSide side) const; //deprecated for players callback, easy to get wrong
 	const CArmedInstance * battleGetArmyObject(BattleSide side) const;
 	InfoAboutHero battleGetHeroInfo(BattleSide side) const;

+ 1 - 1
lib/battle/IBattleState.h

@@ -63,7 +63,7 @@ public:
 	/// Returns list of all spells used by specified side (and that can be learned by opposite hero)
 	virtual std::vector<SpellID> getUsedSpells(BattleSide side) const = 0;
 
-	virtual uint32_t getCastSpells(BattleSide side) const = 0;
+	virtual int32_t getCastSpells(BattleSide side) const = 0;
 	virtual int32_t getEnchanterCounter(BattleSide side) const = 0;
 
 	virtual ui8 getTacticDist() const = 0;

+ 1 - 0
lib/bonuses/BonusEnum.h

@@ -183,6 +183,7 @@ class JsonNode;
 	BONUS_NAME(MECHANICAL) /*eg. factory creatures, cannot be rised or healed, only neutral morale, repairable by engineer */ \
 	BONUS_NAME(PRISM_HEX_ATTACK_BREATH) /*eg. dragons*/	\
 	BONUS_NAME(BASE_TILE_MOVEMENT_COST) /*minimal cost for moving offroad*/	\
+	BONUS_NAME(HERO_SPELL_CASTS_PER_COMBAT_TURN) /**/	\
 	/* end of list */
 
 

+ 3 - 0
server/processors/PlayerMessageProcessor.cpp

@@ -383,6 +383,9 @@ void PlayerMessageProcessor::cheatGiveSpells(PlayerColor player, const CGHeroIns
 		gameHandler->sendAndApply(giveBonus);
 	}
 
+	giveBonus.bonus = Bonus(BonusDuration::PERMANENT, BonusType::HERO_SPELL_CASTS_PER_COMBAT_TURN, BonusSource::OTHER, 99, BonusSourceID());
+	gameHandler->sendAndApply(giveBonus);
+
 	///Give mana
 	SetMana sm;
 	sm.hid = hero->id;

+ 1 - 1
test/mock/mock_battle_IBattleState.h

@@ -29,7 +29,7 @@ public:
 	MOCK_CONST_METHOD1(getSidePlayer, PlayerColor(BattleSide));
 	MOCK_CONST_METHOD1(getSideArmy, const CArmedInstance *(BattleSide));
 	MOCK_CONST_METHOD1(getSideHero, const CGHeroInstance *(BattleSide));
-	MOCK_CONST_METHOD1(getCastSpells, uint32_t(BattleSide));
+	MOCK_CONST_METHOD1(getCastSpells, int32_t(BattleSide));
 	MOCK_CONST_METHOD1(getEnchanterCounter, int32_t(BattleSide));
 	MOCK_CONST_METHOD0(getTacticDist, ui8());
 	MOCK_CONST_METHOD0(getTacticsSide, BattleSide());