1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

effects: Moat now includes battlefield bonus

This is an implementation which works exactly like in H3
This commit is contained in:
Konstantin 2023-03-29 17:23:12 +03:00
parent 53a6fb2836
commit ecae600563
3 changed files with 113 additions and 1 deletions

View File

@ -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"
}
}
}
},

View File

@ -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);
}
}
}

View File

@ -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;
};
}