Преглед на файлове

effects: Moat now includes battlefield bonus

This is an implementation which works exactly like in H3
Konstantin преди 2 години
родител
ревизия
ecae600563
променени са 3 файла, в които са добавени 113 реда и са изтрити 1 реда
  1. 56 0
      config/spells/moats.json
  2. 54 0
      lib/spells/effects/Moat.cpp
  3. 3 1
      lib/spells/effects/Moat.h

+ 56 - 0
config/spells/moats.json

@@ -68,6 +68,14 @@
                         "moatDamage" : 70,
                         "moatHexes" : [[11, 28, 44, 61, 77, 111, 129, 146, 164, 181]],
 						"defender" :{
+						},
+						"bonus" :{
+							"primarySkill" : {
+								"val" : -3,
+								"type" : "PRIMARY_SKILL",
+								"subtype" : "primSkill.defence",
+								"valueType" : "ADDITIVE_VALUE"
+							}
 						}
                     }
                 },
@@ -158,6 +166,14 @@
                         "moatDamage" : 70,
                         "moatHexes" : [[11, 28, 44, 61, 77, 111, 129, 146, 164, 181]],
 						"defender" :{
+						},
+						"bonus" :{
+							"primarySkill" : {
+								"val" : -3,
+								"type" : "PRIMARY_SKILL",
+								"subtype" : "primSkill.defence",
+								"valueType" : "ADDITIVE_VALUE"
+							}
 						}
                     }
                 },
@@ -300,6 +316,14 @@
                         "moatDamage" : 90,
                         "moatHexes" : [[11, 28, 44, 61, 77, 111, 129, 146, 164, 181]],
 						"defender" :{
+						},
+						"bonus" :{
+							"primarySkill" : {
+								"val" : -3,
+								"type" : "PRIMARY_SKILL",
+								"subtype" : "primSkill.defence",
+								"valueType" : "ADDITIVE_VALUE"
+							}
 						}
                     }
                 },
@@ -390,6 +414,14 @@
                         "moatDamage" : 70,
                         "moatHexes" : [[11, 28, 44, 61, 77, 111, 129, 146, 164, 181]],
 						"defender" :{
+						},
+						"bonus" :{
+							"primarySkill" : {
+								"val" : -3,
+								"type" : "PRIMARY_SKILL",
+								"subtype" : "primSkill.defence",
+								"valueType" : "ADDITIVE_VALUE"
+							}
 						}
                     }
                 },
@@ -480,6 +512,14 @@
                         "moatDamage" : 90,
                         "moatHexes" : [[11, 28, 44, 61, 77, 111, 129, 146, 164, 181]],
 						"defender" :{
+						},
+						"bonus" :{
+							"primarySkill" : {
+								"val" : -3,
+								"type" : "PRIMARY_SKILL",
+								"subtype" : "primSkill.defence",
+								"valueType" : "ADDITIVE_VALUE"
+							}
 						}
                     }
                 },
@@ -570,6 +610,14 @@
                         "moatDamage" : 70,
                         "moatHexes" : [[11, 28, 44, 61, 77, 111, 129, 146, 164, 181]],
 						"defender" :{
+						},
+						"bonus" :{
+							"primarySkill" : {
+								"val" : -3,
+								"type" : "PRIMARY_SKILL",
+								"subtype" : "primSkill.defence",
+								"valueType" : "ADDITIVE_VALUE"
+							}
 						}
                     }
                 },
@@ -660,6 +708,14 @@
                         "moatDamage" : 90,
                         "moatHexes" : [[10, 11, 27, 28, 43, 44, 60, 61, 76, 77, 94, 110, 111, 128, 129, 145, 146, 163, 164, 180, 181]],
 						"defender" :{
+						},
+						"bonus" :{
+							"primarySkill" : {
+								"val" : -3,
+								"type" : "PRIMARY_SKILL",
+								"subtype" : "primSkill.defence",
+								"valueType" : "ADDITIVE_VALUE"
+							}
 						}
                     }
                 },

+ 54 - 0
lib/spells/effects/Moat.cpp

@@ -59,6 +59,51 @@ void Moat::serializeJsonEffect(JsonSerializeFormat & handler)
 	serializeMoatHexes(handler, "moatHexes", moatHexes);
 	handler.serializeId("triggerAbility", triggerAbility, SpellID::NONE);
 	handler.serializeStruct("defender", sideOptions); //Moats are defender only
+
+	assert(!handler.saving);
+	{
+		auto guard = handler.enterStruct("bonus");
+		const JsonNode & data = handler.getCurrent();
+
+		for(const auto & p : data.Struct())
+		{
+			//TODO: support JsonSerializeFormat in Bonus
+			auto guard = handler.enterStruct(p.first);
+			const JsonNode & bonusNode = handler.getCurrent();
+			auto b = JsonUtils::parseBonus(bonusNode);
+			bonus.push_back(b);
+		}
+	}
+}
+
+void Moat::convertBonus(const Mechanics * m, std::vector<Bonus> & converted) const
+{
+
+	for(const auto & b : bonus)
+	{
+		Bonus nb(*b);
+
+		//Moat battlefield effect is always permanent
+		nb.duration = Bonus::ONE_BATTLE;
+
+		if(m->battle()->battleGetDefendedTown() && m->battle()->battleGetSiegeLevel() >= CGTownInstance::CITADEL)
+		{
+			nb.sid = Bonus::getSid32(m->battle()->battleGetDefendedTown()->town->faction->getIndex(), BuildingID::CITADEL);
+			nb.source = Bonus::TOWN_STRUCTURE;
+		}
+		else
+		{
+			nb.sid = m->getSpellIndex(); //for all
+			nb.source = Bonus::SPELL_EFFECT;//for all
+		}
+		std::set<BattleHex> flatMoatHexes;
+
+		for(const auto & moatPatch : moatHexes)
+			flatMoatHexes.insert(moatPatch.begin(), moatPatch.end());
+
+		nb.limiter = std::make_shared<UnitOnHexLimiter>(std::move(flatMoatHexes));
+		converted.push_back(nb);
+	}
 }
 
 void Moat::apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const
@@ -69,6 +114,15 @@ void Moat::apply(ServerCallback * server, const Mechanics * m, const EffectTarge
 	{
 		EffectTarget moat;
 		placeObstacles(server, m, moat);
+
+		std::vector<Bonus> converted;
+		convertBonus(m, converted);
+		for(auto & b : converted)
+		{
+			GiveBonus gb(GiveBonus::ETarget::BATTLE);
+			gb.bonus = b;
+			server->apply(&gb);
+		}
 	}
 }
 

+ 3 - 1
lib/spells/effects/Moat.h

@@ -23,7 +23,8 @@ class Moat : public Obstacle
 {
 private:
 	ObstacleSideOptions sideOptions; //Defender only
-	std::vector<std::vector<BattleHex>> moatHexes;
+	std::vector<std::vector<BattleHex>> moatHexes; //Determine number of moat patches and hexes
+	std::vector<std::shared_ptr<Bonus>> bonus; //For battle-wide bonuses
 	bool dispellable; //For Tower landmines
 	int moatDamage; // Minimal moat damage
 public:
@@ -31,6 +32,7 @@ public:
 protected:
 	void serializeJsonEffect(JsonSerializeFormat & handler) override;
 	void placeObstacles(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const override;
+	void convertBonus(const Mechanics * m, std::vector<Bonus> & converted) const;
 };
 
 }