1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-31 22:59:54 +02:00

vcmi: allow obstacles to store another spells

It will be used as trigger spell, if set
If not set, it will be ignored
This commit is contained in:
Konstantin 2023-03-19 03:16:02 +03:00
parent 57c35f39ca
commit db428faeeb
6 changed files with 15 additions and 4 deletions

View File

@ -98,7 +98,8 @@ SpellCreatedObstacle::SpellCreatedObstacle()
removeOnTrigger(false),
revealed(false),
animationYOffset(0),
nativeVisible(true)
nativeVisible(true),
minimalDamage(0)
{
obstacleType = SPELL_CREATED;
}
@ -160,6 +161,7 @@ void SpellCreatedObstacle::serializeJson(JsonSerializeFormat & handler)
handler.serializeInt("casterSpellPower", casterSpellPower);
handler.serializeInt("spellLevel", spellLevel);
handler.serializeInt("casterSide", casterSide);
handler.serializeInt("minimalDamage", minimalDamage);
handler.serializeBool("hidden", hidden);
handler.serializeBool("revealed", revealed);

View File

@ -68,6 +68,7 @@ struct DLL_LINKAGE SpellCreatedObstacle : CObstacleInstance
int32_t turnsRemaining;
int32_t casterSpellPower;
int32_t spellLevel;
int32_t minimalDamage; //How many damage should it do regardless of power and level of caster
si8 casterSide; //0 - obstacle created by attacker; 1 - by defender
bool hidden;
@ -119,6 +120,7 @@ struct DLL_LINKAGE SpellCreatedObstacle : CObstacleInstance
h & nativeVisible;
h & passable;
h & trigger;
h & minimalDamage;
h & trap;
h & customSize;

View File

@ -39,6 +39,8 @@ void Moat::serializeJsonEffect(JsonSerializeFormat & handler)
handler.serializeBool("trap", trap);
handler.serializeBool("removeOnTrigger", removeOnTrigger);
handler.serializeBool("dispellable", dispellable);
handler.serializeInt("moatDamage", moatDamage);
handler.serializeId("triggerAbility", triggerAbility, SpellID::NONE);
{
JsonArraySerializer customSizeJson = handler.enterArray("moatHexes");
customSizeJson.syncSize(moatHexes, JsonNode::JsonType::DATA_INTEGER);
@ -85,12 +87,13 @@ void Moat::placeObstacles(ServerCallback * server, const Mechanics * m, const Ef
obstacle.uniqueID = obstacleIdToGive++;
obstacle.pos = destination.hexValue;
obstacle.obstacleType = dispellable ? CObstacleInstance::SPELL_CREATED : CObstacleInstance::MOAT;
obstacle.ID = m->battle()->battleGetDefendedTown()->subID;
obstacle.ID = triggerAbility;
obstacle.turnsRemaining = -1; //Moat cannot be expired
obstacle.casterSpellPower = m->getEffectPower();
obstacle.spellLevel = m->getEffectLevel(); //todo: level of indirect effect should be also configurable
obstacle.casterSide = BattleSide::DEFENDER; // Moats are always cast by defender
obstacle.minimalDamage = moatDamage; // Minimal moat damage
obstacle.hidden = hidden;
obstacle.passable = true; //Moats always passable
obstacle.trigger = trigger;

View File

@ -25,6 +25,7 @@ private:
ObstacleSideOptions sideOptions; //Defender only
std::vector<BattleHex> moatHexes;
bool dispellable; //For Tower landmines
int moatDamage; // Minimal moat damage
public:
void apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const override;
protected:

View File

@ -221,6 +221,7 @@ void Obstacle::serializeJsonEffect(JsonSerializeFormat & handler)
handler.serializeInt("patchCount", patchCount);
handler.serializeInt("turnsRemaining", turnsRemaining, -1);
handler.serializeId("triggerAbility", triggerAbility, SpellID::NONE);
handler.serializeStruct("attacker", sideOptions.at(BattleSide::ATTACKER));
handler.serializeStruct("defender", sideOptions.at(BattleSide::DEFENDER));
@ -289,8 +290,8 @@ void Obstacle::placeObstacles(ServerCallback * server, const Mechanics * m, cons
SpellCreatedObstacle obstacle;
obstacle.uniqueID = obstacleIdToGive++;
obstacle.pos = destination.hexValue;
obstacle.obstacleType = CObstacleInstance::USUAL;
obstacle.ID = m->getSpellIndex();
obstacle.obstacleType = CObstacleInstance::SPELL_CREATED;
obstacle.ID = triggerAbility;
obstacle.turnsRemaining = turnsRemaining;
obstacle.casterSpellPower = m->getEffectPower();

View File

@ -11,6 +11,7 @@
#pragma once
#include "LocationEffect.h"
#include "../../GameConstants.h"
#include "../../battle/BattleHex.h"
#include "../../battle/CObstacleInstance.h"
@ -62,6 +63,7 @@ protected:
bool trap = false;
bool removeOnTrigger = false;
bool hideNative = false;
SpellID triggerAbility;
private:
int32_t patchCount = 0; //random patches to place, for massive spells should be >= 1, for non-massive ones if >= 1, then place only this number inside a target (like H5 landMine)
int32_t turnsRemaining = -1;