2015-02-26 19:59:18 +02:00
|
|
|
/*
|
|
|
|
* CSpellHandler.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
#include "StdInc.h"
|
|
|
|
|
|
|
|
#include <cctype>
|
|
|
|
|
|
|
|
#include "CSpellHandler.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "Problem.h"
|
2015-02-02 10:25:26 +02:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
#include <vcmi/spells/Caster.h>
|
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
#include "../filesystem/Filesystem.h"
|
|
|
|
|
2023-08-19 23:22:31 +02:00
|
|
|
#include "../constants/StringConstants.h"
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2017-06-24 16:42:05 +02:00
|
|
|
#include "../battle/BattleInfo.h"
|
2017-06-24 15:51:07 +02:00
|
|
|
#include "../battle/CBattleInfoCallback.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "../battle/Unit.h"
|
2024-02-14 15:48:06 +02:00
|
|
|
#include "../json/JsonBonus.h"
|
2024-02-11 23:09:01 +02:00
|
|
|
#include "../json/JsonUtils.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "../mapObjects/CGHeroInstance.h" //todo: remove
|
2023-07-30 19:12:25 +02:00
|
|
|
#include "../modding/IdentifierStorage.h"
|
|
|
|
#include "../modding/ModUtility.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../serializer/CSerializer.h"
|
|
|
|
#include "../texts/CLegacyConfigParser.h"
|
|
|
|
#include "../texts/CGeneralTextHandler.h"
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2015-03-10 22:14:58 +02:00
|
|
|
#include "ISpellMechanics.h"
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
namespace SpellConfig
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
static const std::string LEVEL_NAMES[] = {"none", "basic", "advanced", "expert"};
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2023-05-05 20:28:07 +02:00
|
|
|
const spells::SchoolInfo SCHOOL[4] =
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2023-10-05 17:18:14 +02:00
|
|
|
SpellSchool::AIR,
|
2023-05-05 16:56:04 +02:00
|
|
|
"air"
|
2017-07-20 06:08:49 +02:00
|
|
|
},
|
2016-10-17 02:33:29 +02:00
|
|
|
{
|
2023-10-05 17:18:14 +02:00
|
|
|
SpellSchool::FIRE,
|
2023-05-05 16:56:04 +02:00
|
|
|
"fire"
|
2017-07-20 06:08:49 +02:00
|
|
|
},
|
|
|
|
{
|
2023-10-05 17:18:14 +02:00
|
|
|
SpellSchool::WATER,
|
2023-05-05 16:56:04 +02:00
|
|
|
"water"
|
2017-07-20 06:08:49 +02:00
|
|
|
},
|
|
|
|
{
|
2023-10-05 17:18:14 +02:00
|
|
|
SpellSchool::EARTH,
|
2023-05-05 16:56:04 +02:00
|
|
|
"earth"
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//order as described in http://bugs.vcmi.eu/view.php?id=91
|
2023-05-05 20:28:07 +02:00
|
|
|
static const SpellSchool SCHOOL_ORDER[4] =
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2023-10-05 17:18:14 +02:00
|
|
|
SpellSchool::AIR, //=0
|
|
|
|
SpellSchool::FIRE, //=1
|
|
|
|
SpellSchool::EARTH,//=3(!)
|
|
|
|
SpellSchool::WATER //=2(!)
|
2017-07-20 06:08:49 +02:00
|
|
|
};
|
|
|
|
} //namespace SpellConfig
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
///CSpell
|
|
|
|
CSpell::CSpell():
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
id(SpellID::NONE),
|
|
|
|
level(0),
|
2016-11-27 21:37:41 +02:00
|
|
|
power(0),
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
combat(false),
|
|
|
|
creatureAbility(false),
|
2024-01-16 15:01:42 +02:00
|
|
|
castOnSelf(false),
|
2015-02-02 10:25:26 +02:00
|
|
|
positiveness(ESpellPositiveness::NEUTRAL),
|
|
|
|
defaultProbability(0),
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
rising(false),
|
|
|
|
damage(false),
|
|
|
|
offensive(false),
|
|
|
|
special(true),
|
2023-03-21 11:18:31 +02:00
|
|
|
nonMagical(false),
|
2023-02-11 17:18:05 +02:00
|
|
|
targetType(spells::AimType::NO_TARGET)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
levels.resize(GameConstants::SPELL_SCHOOL_LEVELS);
|
|
|
|
}
|
|
|
|
|
2023-02-11 17:18:05 +02:00
|
|
|
//must be instantiated in .cpp file for access to complete types of all member fields
|
|
|
|
CSpell::~CSpell() = default;
|
2015-02-02 10:25:26 +02:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
bool CSpell::adventureCast(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
assert(env);
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2023-02-11 17:18:05 +02:00
|
|
|
if(!adventureMechanics)
|
2016-09-04 07:19:28 +02:00
|
|
|
{
|
|
|
|
env->complain("Invalid adventure spell cast attempt!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return adventureMechanics->adventureCast(env, parameters);
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const CSpell::LevelInfo & CSpell::getLevelInfo(const int32_t level) const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
if(level < 0 || level >= GameConstants::SPELL_SCHOOL_LEVELS)
|
|
|
|
{
|
2023-12-10 19:17:58 +02:00
|
|
|
logGlobal->error("CSpell::getLevelInfo: invalid school mastery level %d", level);
|
|
|
|
return levels.at(MasteryLevel::EXPERT);
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return levels.at(level);
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
int64_t CSpell::calculateDamage(const spells::Caster * caster) const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
//check if spell really does damage - if not, return 0
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
if(!isDamage())
|
2015-02-02 10:25:26 +02:00
|
|
|
return 0;
|
2017-07-20 06:08:49 +02:00
|
|
|
auto rawDamage = calculateRawEffectValue(caster->getEffectLevel(this), caster->getEffectPower(this), 1);
|
|
|
|
|
|
|
|
return caster->getSpellBonus(this, rawDamage, nullptr);
|
|
|
|
}
|
|
|
|
|
2023-08-21 21:10:32 +02:00
|
|
|
bool CSpell::hasSchool(SpellSchool which) const
|
2023-06-06 17:34:04 +02:00
|
|
|
{
|
|
|
|
return school.count(which) && school.at(which);
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
bool CSpell::canBeCast(const CBattleInfoCallback * cb, spells::Mode mode, const spells::Caster * caster) const
|
|
|
|
{
|
|
|
|
//if caller do not interested in description just discard it and do not pollute even debug log
|
|
|
|
spells::detail::ProblemImpl problem;
|
|
|
|
return canBeCast(problem, cb, mode, caster);
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
bool CSpell::canBeCast(spells::Problem & problem, const CBattleInfoCallback * cb, spells::Mode mode, const spells::Caster * caster) const
|
2015-03-18 15:39:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
spells::BattleCast event(cb, caster, mode, this);
|
|
|
|
auto mechanics = battleMechanics(&event);
|
|
|
|
|
|
|
|
return mechanics->canBeCast(problem);
|
2015-03-18 15:39:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
spells::AimType CSpell::getTargetType() const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
return targetType;
|
|
|
|
}
|
|
|
|
|
2023-08-21 21:10:32 +02:00
|
|
|
void CSpell::forEachSchool(const std::function<void(const SpellSchool &, bool &)>& cb) const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
bool stop = false;
|
2023-05-05 20:28:07 +02:00
|
|
|
for(auto iter : SpellConfig::SCHOOL_ORDER)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2023-11-05 18:58:07 +02:00
|
|
|
const spells::SchoolInfo & cnf = SpellConfig::SCHOOL[iter.getNum()];
|
2015-02-02 10:25:26 +02:00
|
|
|
if(school.at(cnf.id))
|
|
|
|
{
|
2023-08-21 21:10:32 +02:00
|
|
|
cb(cnf.id, stop);
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
if(stop)
|
|
|
|
break;
|
2015-02-26 19:59:18 +02:00
|
|
|
}
|
|
|
|
}
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
SpellID CSpell::getId() const
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2023-01-02 00:06:42 +02:00
|
|
|
std::string CSpell::getNameTextID() const
|
|
|
|
{
|
|
|
|
TextIdentifier id("spell", modScope, identifier, "name");
|
|
|
|
return id.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CSpell::getNameTranslated() const
|
|
|
|
{
|
|
|
|
return VLC->generaltexth->translate(getNameTextID());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CSpell::getDescriptionTextID(int32_t level) const
|
|
|
|
{
|
|
|
|
TextIdentifier id("spell", modScope, identifier, "description", SpellConfig::LEVEL_NAMES[level]);
|
|
|
|
return id.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CSpell::getDescriptionTranslated(int32_t level) const
|
|
|
|
{
|
|
|
|
return VLC->generaltexth->translate(getDescriptionTextID(level));
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
}
|
|
|
|
|
2023-01-18 23:56:01 +02:00
|
|
|
std::string CSpell::getJsonKey() const
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
{
|
2023-03-27 13:56:39 +02:00
|
|
|
return modScope + ':' + identifier;
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
}
|
|
|
|
|
2024-08-10 16:08:04 +02:00
|
|
|
std::string CSpell::getModScope() const
|
|
|
|
{
|
|
|
|
return modScope;
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
int32_t CSpell::getIndex() const
|
|
|
|
{
|
|
|
|
return id.toEnum();
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
int32_t CSpell::getIconIndex() const
|
|
|
|
{
|
|
|
|
return getIndex();
|
|
|
|
}
|
|
|
|
|
2018-03-02 12:22:51 +02:00
|
|
|
int32_t CSpell::getLevel() const
|
|
|
|
{
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
bool CSpell::isCombat() const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
return combat;
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
bool CSpell::isAdventure() const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
return !combat;
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CSpell::isCreatureAbility() const
|
|
|
|
{
|
|
|
|
return creatureAbility;
|
|
|
|
}
|
|
|
|
|
2023-03-21 11:18:31 +02:00
|
|
|
bool CSpell::isMagical() const
|
|
|
|
{
|
|
|
|
return !nonMagical;
|
|
|
|
}
|
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
bool CSpell::isPositive() const
|
|
|
|
{
|
|
|
|
return positiveness == POSITIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CSpell::isNegative() const
|
|
|
|
{
|
|
|
|
return positiveness == NEGATIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CSpell::isNeutral() const
|
|
|
|
{
|
|
|
|
return positiveness == NEUTRAL;
|
|
|
|
}
|
|
|
|
|
2016-09-29 22:14:22 +02:00
|
|
|
boost::logic::tribool CSpell::getPositiveness() const
|
|
|
|
{
|
|
|
|
switch (positiveness)
|
|
|
|
{
|
|
|
|
case CSpell::POSITIVE:
|
|
|
|
return true;
|
|
|
|
case CSpell::NEGATIVE:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return boost::logic::indeterminate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
bool CSpell::isDamage() const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
return damage;
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
bool CSpell::isOffensive() const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
return offensive;
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
bool CSpell::isSpecial() const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
return special;
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CSpell::hasEffects() const
|
|
|
|
{
|
2016-11-02 19:11:01 +02:00
|
|
|
return !levels[0].effects.empty() || !levels[0].cumulativeEffects.empty();
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
bool CSpell::hasBattleEffects() const
|
|
|
|
{
|
|
|
|
return levels[0].battleEffects.getType() == JsonNode::JsonType::DATA_STRUCT && !levels[0].battleEffects.Struct().empty();
|
|
|
|
}
|
|
|
|
|
2024-01-16 15:01:42 +02:00
|
|
|
bool CSpell::canCastOnSelf() const
|
|
|
|
{
|
|
|
|
return castOnSelf;
|
|
|
|
}
|
|
|
|
|
2024-09-14 14:49:52 +02:00
|
|
|
bool CSpell::canCastWithoutSkip() const
|
|
|
|
{
|
|
|
|
return castWithoutSkip;
|
|
|
|
}
|
|
|
|
|
2015-02-26 19:59:18 +02:00
|
|
|
const std::string & CSpell::getIconImmune() const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
return iconImmune;
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const std::string & CSpell::getIconBook() const
|
|
|
|
{
|
|
|
|
return iconBook;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string & CSpell::getIconEffect() const
|
|
|
|
{
|
|
|
|
return iconEffect;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string & CSpell::getIconScenarioBonus() const
|
|
|
|
{
|
|
|
|
return iconScenarioBonus;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string & CSpell::getIconScroll() const
|
|
|
|
{
|
|
|
|
return iconScroll;
|
|
|
|
}
|
|
|
|
|
2023-09-04 12:03:15 +02:00
|
|
|
const AudioPath & CSpell::getCastSound() const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
return castSound;
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
int32_t CSpell::getCost(const int32_t skillLevel) const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
return getLevelInfo(skillLevel).cost;
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
int32_t CSpell::getBasePower() const
|
|
|
|
{
|
|
|
|
return power;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t CSpell::getLevelPower(const int32_t skillLevel) const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
return getLevelInfo(skillLevel).power;
|
|
|
|
}
|
|
|
|
|
2023-04-09 17:26:32 +02:00
|
|
|
si32 CSpell::getProbability(const FactionID & factionId) const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
if(!vstd::contains(probabilities,factionId))
|
|
|
|
{
|
|
|
|
return defaultProbability;
|
|
|
|
}
|
|
|
|
return probabilities.at(factionId);
|
|
|
|
}
|
|
|
|
|
2023-04-16 19:42:56 +02:00
|
|
|
void CSpell::getEffects(std::vector<Bonus> & lst, const int level, const bool cumulative, const si32 duration, std::optional<si32 *> maxDuration) const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
if(level < 0 || level >= GameConstants::SPELL_SCHOOL_LEVELS)
|
|
|
|
{
|
2017-08-11 19:03:05 +02:00
|
|
|
logGlobal->error("invalid school level %d", level);
|
2015-02-02 10:25:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-02 19:11:01 +02:00
|
|
|
const auto & levelObject = levels.at(level);
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2016-11-02 19:11:01 +02:00
|
|
|
if(levelObject.effects.empty() && levelObject.cumulativeEffects.empty())
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2023-01-02 00:06:42 +02:00
|
|
|
logGlobal->error("This spell (%s) has no effects for level %d", getNameTranslated(), level);
|
2015-02-02 10:25:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-02 19:11:01 +02:00
|
|
|
const auto & effects = cumulative ? levelObject.cumulativeEffects : levelObject.effects;
|
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
lst.reserve(lst.size() + effects.size());
|
|
|
|
|
2022-05-19 14:14:50 +02:00
|
|
|
for(const auto& b : effects)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2016-11-02 19:11:01 +02:00
|
|
|
Bonus nb(*b);
|
|
|
|
|
|
|
|
//use configured duration if present
|
|
|
|
if(nb.turnsRemain == 0)
|
|
|
|
nb.turnsRemain = duration;
|
|
|
|
if(maxDuration)
|
2023-04-16 19:42:56 +02:00
|
|
|
vstd::amax(*(maxDuration.value()), nb.turnsRemain);
|
2016-11-02 19:11:01 +02:00
|
|
|
|
|
|
|
lst.push_back(nb);
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
int64_t CSpell::adjustRawDamage(const spells::Caster * caster, const battle::Unit * affectedCreature, int64_t rawDamage) const
|
2015-09-16 14:43:39 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
auto ret = rawDamage;
|
2015-09-16 14:43:39 +02:00
|
|
|
//affected creature-specific part
|
|
|
|
if(nullptr != affectedCreature)
|
|
|
|
{
|
2023-08-19 15:58:37 +02:00
|
|
|
const auto * bearer = affectedCreature->getBonusBearer();
|
2015-09-16 14:43:39 +02:00
|
|
|
//applying protections - when spell has more then one elements, only one protection should be applied (I think)
|
2023-08-21 21:10:32 +02:00
|
|
|
forEachSchool([&](const SpellSchool & cnf, bool & stop)
|
2015-09-16 14:43:39 +02:00
|
|
|
{
|
2023-10-21 13:50:42 +02:00
|
|
|
if(bearer->hasBonusOfType(BonusType::SPELL_DAMAGE_REDUCTION, BonusSubtypeID(cnf)))
|
2015-09-16 14:43:39 +02:00
|
|
|
{
|
2023-10-21 13:50:42 +02:00
|
|
|
ret *= 100 - bearer->valOfBonuses(BonusType::SPELL_DAMAGE_REDUCTION, BonusSubtypeID(cnf));
|
2015-09-16 14:43:39 +02:00
|
|
|
ret /= 100;
|
2023-02-11 17:18:05 +02:00
|
|
|
stop = true; //only bonus from one school is used
|
2015-09-16 14:43:39 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-10-21 13:50:42 +02:00
|
|
|
CSelector selector = Selector::typeSubtype(BonusType::SPELL_DAMAGE_REDUCTION, BonusSubtypeID(SpellSchool::ANY));
|
2023-08-19 15:58:37 +02:00
|
|
|
auto cachingStr = "type_SPELL_DAMAGE_REDUCTION_s_ANY";
|
2017-08-01 15:59:45 +02:00
|
|
|
|
2023-03-21 11:24:48 +02:00
|
|
|
//general spell dmg reduction, works only on magical effects
|
2023-08-19 15:58:37 +02:00
|
|
|
if(bearer->hasBonus(selector, cachingStr) && isMagical())
|
2015-09-16 14:43:39 +02:00
|
|
|
{
|
2023-08-19 15:58:37 +02:00
|
|
|
ret *= 100 - bearer->valOfBonuses(selector, cachingStr);
|
2015-09-16 14:43:39 +02:00
|
|
|
ret /= 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
//dmg increasing
|
2023-10-21 13:50:42 +02:00
|
|
|
if(bearer->hasBonusOfType(BonusType::MORE_DAMAGE_FROM_SPELL, BonusSubtypeID(id)))
|
2015-09-16 14:43:39 +02:00
|
|
|
{
|
2023-10-21 13:50:42 +02:00
|
|
|
ret *= 100 + bearer->valOfBonuses(BonusType::MORE_DAMAGE_FROM_SPELL, BonusSubtypeID(id));
|
2015-09-16 14:43:39 +02:00
|
|
|
ret /= 100;
|
|
|
|
}
|
2024-09-19 03:14:45 +02:00
|
|
|
|
|
|
|
//invincible
|
|
|
|
if(bearer->hasBonusOfType(BonusType::INVINCIBLE))
|
|
|
|
ret = 0;
|
2015-09-16 14:43:39 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
ret = caster->getSpellBonus(this, ret, affectedCreature);
|
2015-09-16 14:43:39 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
int64_t CSpell::calculateRawEffectValue(int32_t effectLevel, int32_t basePowerMultiplier, int32_t levelPowerMultiplier) const
|
2015-09-16 14:43:39 +02:00
|
|
|
{
|
2023-02-11 17:18:05 +02:00
|
|
|
return static_cast<int64_t>(basePowerMultiplier) * getBasePower() + levelPowerMultiplier * getLevelPower(effectLevel);
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpell::setIsOffensive(const bool val)
|
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
offensive = val;
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
if(val)
|
|
|
|
{
|
|
|
|
positiveness = CSpell::NEGATIVE;
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
damage = true;
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpell::setIsRising(const bool val)
|
|
|
|
{
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
rising = val;
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
if(val)
|
|
|
|
{
|
|
|
|
positiveness = CSpell::POSITIVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
JsonNode CSpell::convertTargetCondition(const BTVector & immunity, const BTVector & absImmunity, const BTVector & limit, const BTVector & absLimit) const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
static const std::string CONDITION_NORMAL = "normal";
|
|
|
|
static const std::string CONDITION_ABSOLUTE = "absolute";
|
|
|
|
|
2023-05-01 00:20:01 +02:00
|
|
|
#define BONUS_NAME(x) { BonusType::x, #x },
|
|
|
|
static const std::map<BonusType, std::string> bonusNameRMap = { BONUS_LIST };
|
2017-07-20 06:08:49 +02:00
|
|
|
#undef BONUS_NAME
|
|
|
|
|
|
|
|
JsonNode res;
|
|
|
|
|
|
|
|
auto convertVector = [&](const std::string & targetName, const BTVector & source, const std::string & value)
|
|
|
|
{
|
|
|
|
for(auto bonusType : source)
|
|
|
|
{
|
|
|
|
auto iter = bonusNameRMap.find(bonusType);
|
|
|
|
if(iter != bonusNameRMap.end())
|
|
|
|
{
|
2023-07-30 19:12:25 +02:00
|
|
|
auto fullId = ModUtility::makeFullIdentifier("", "bonus", iter->second);
|
2017-07-20 06:08:49 +02:00
|
|
|
res[targetName][fullId].String() = value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
logGlobal->error("Invalid bonus type %d", static_cast<int32_t>(bonusType));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto convertSection = [&](const std::string & targetName, const BTVector & normal, const BTVector & absolute)
|
|
|
|
{
|
|
|
|
convertVector(targetName, normal, CONDITION_NORMAL);
|
|
|
|
convertVector(targetName, absolute, CONDITION_ABSOLUTE);
|
|
|
|
};
|
|
|
|
|
|
|
|
convertSection("allOf", limit, absLimit);
|
|
|
|
convertSection("noneOf", immunity, absImmunity);
|
|
|
|
|
|
|
|
return res;
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpell::setupMechanics()
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
mechanics = spells::ISpellMechanicsFactory::get(this);
|
2016-09-04 07:19:28 +02:00
|
|
|
adventureMechanics = IAdventureSpellMechanics::createMechanics(this);
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
const IAdventureSpellMechanics & CSpell::getAdventureMechanics() const
|
|
|
|
{
|
|
|
|
return *adventureMechanics;
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::unique_ptr<spells::Mechanics> CSpell::battleMechanics(const spells::IBattleCast * event) const
|
|
|
|
{
|
|
|
|
return mechanics->create(event);
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
void CSpell::registerIcons(const IconRegistar & cb) const
|
|
|
|
{
|
2022-11-29 14:47:51 +02:00
|
|
|
cb(getIndex(), 0, "SPELLS", iconBook);
|
|
|
|
cb(getIndex()+1, 0, "SPELLINT", iconEffect);
|
|
|
|
cb(getIndex(), 0, "SPELLBON", iconScenarioBonus);
|
|
|
|
cb(getIndex(), 0, "SPELLSCR", iconScroll);
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSpell::updateFrom(const JsonNode & data)
|
|
|
|
{
|
|
|
|
//todo:CSpell::updateFrom
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpell::serializeJson(JsonSerializeFormat & handler)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-09-12 22:52:04 +02:00
|
|
|
///CSpell::AnimationInfo
|
2022-12-22 00:25:35 +02:00
|
|
|
CSpell::AnimationItem::AnimationItem() :
|
|
|
|
verticalPosition(VerticalPosition::TOP),
|
|
|
|
pause(0)
|
2015-09-12 22:52:04 +02:00
|
|
|
{
|
2016-02-13 18:41:28 +02:00
|
|
|
|
2015-09-12 22:52:04 +02:00
|
|
|
}
|
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
///CSpell::AnimationInfo
|
2023-08-23 14:07:50 +02:00
|
|
|
AnimationPath CSpell::AnimationInfo::selectProjectile(const double angle) const
|
2015-02-26 19:59:18 +02:00
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
AnimationPath res;
|
2015-02-02 10:25:26 +02:00
|
|
|
double maximum = 0.0;
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
for(const auto & info : projectile)
|
|
|
|
{
|
2022-12-01 22:06:42 +02:00
|
|
|
if(info.minimumAngle < angle && info.minimumAngle >= maximum)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
maximum = info.minimumAngle;
|
|
|
|
res = info.resourceName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-04 01:06:02 +02:00
|
|
|
return res;
|
2015-02-26 19:59:18 +02:00
|
|
|
}
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
///CSpell::TargetInfo
|
2017-07-20 06:08:49 +02:00
|
|
|
CSpell::TargetInfo::TargetInfo(const CSpell * spell, const int level, spells::Mode mode)
|
|
|
|
: type(spell->getTargetType()),
|
|
|
|
smart(false),
|
|
|
|
massive(false),
|
|
|
|
clearAffected(false),
|
|
|
|
clearTarget(false)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2023-02-11 17:18:05 +02:00
|
|
|
const auto & levelInfo = spell->getLevelInfo(level);
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
smart = levelInfo.smartTarget;
|
2024-08-10 14:22:21 +02:00
|
|
|
massive = levelInfo.range.empty();
|
2017-07-20 06:08:49 +02:00
|
|
|
clearAffected = levelInfo.clearAffected;
|
|
|
|
clearTarget = levelInfo.clearTarget;
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
2015-02-26 19:59:18 +02:00
|
|
|
bool DLL_LINKAGE isInScreenRange(const int3 & center, const int3 & pos)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
int3 diff = pos - center;
|
2019-03-20 21:58:15 +02:00
|
|
|
return diff.x >= -9 && diff.x <= 9 && diff.y >= -8 && diff.y <= 8;
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///CSpellHandler
|
2023-03-15 21:34:29 +02:00
|
|
|
std::vector<JsonNode> CSpellHandler::loadLegacyData()
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
using namespace SpellConfig;
|
|
|
|
std::vector<JsonNode> legacyData;
|
|
|
|
|
2023-09-01 23:26:14 +02:00
|
|
|
CLegacyConfigParser parser(TextPath::builtin("DATA/SPTRAITS.TXT"));
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2015-02-26 19:59:18 +02:00
|
|
|
auto readSchool = [&](JsonMap & schools, const std::string & name)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
if (parser.readString() == "x")
|
|
|
|
{
|
|
|
|
schools[name].Bool() = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-19 12:52:02 +02:00
|
|
|
auto read = [&](bool combat, bool ability)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2024-02-13 13:18:10 +02:00
|
|
|
JsonNode lineNode;
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
const auto id = legacyData.size();
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
lineNode["index"].Integer() = id;
|
2015-02-02 10:25:26 +02:00
|
|
|
lineNode["type"].String() = ability ? "ability" : (combat ? "combat" : "adventure");
|
|
|
|
|
|
|
|
lineNode["name"].String() = parser.readString();
|
|
|
|
|
|
|
|
parser.readString(); //ignored unused abbreviated name
|
2020-10-01 10:38:06 +02:00
|
|
|
lineNode["level"].Integer() = static_cast<si64>(parser.readNumber());
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
auto& schools = lineNode["school"].Struct();
|
|
|
|
|
|
|
|
readSchool(schools, "earth");
|
|
|
|
readSchool(schools, "water");
|
|
|
|
readSchool(schools, "fire");
|
|
|
|
readSchool(schools, "air");
|
|
|
|
|
|
|
|
auto& levels = lineNode["levels"].Struct();
|
|
|
|
|
|
|
|
auto getLevel = [&](const size_t idx)->JsonMap&
|
|
|
|
{
|
|
|
|
assert(idx < GameConstants::SPELL_SCHOOL_LEVELS);
|
|
|
|
return levels[LEVEL_NAMES[idx]].Struct();
|
|
|
|
};
|
|
|
|
|
|
|
|
auto costs = parser.readNumArray<si32>(GameConstants::SPELL_SCHOOL_LEVELS);
|
2020-10-01 10:38:06 +02:00
|
|
|
lineNode["power"].Integer() = static_cast<si64>(parser.readNumber());
|
2015-02-02 10:25:26 +02:00
|
|
|
auto powers = parser.readNumArray<si32>(GameConstants::SPELL_SCHOOL_LEVELS);
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
auto & chances = lineNode["gainChance"].Struct();
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2023-08-18 12:38:19 +02:00
|
|
|
for(const auto & name : NFaction::names)
|
2023-02-11 17:18:05 +02:00
|
|
|
chances[name].Integer() = static_cast<si64>(parser.readNumber());
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
auto AIVals = parser.readNumArray<si32>(GameConstants::SPELL_SCHOOL_LEVELS);
|
|
|
|
|
|
|
|
std::vector<std::string> descriptions;
|
2015-02-26 19:59:18 +02:00
|
|
|
for(size_t i = 0; i < GameConstants::SPELL_SCHOOL_LEVELS; i++)
|
2015-02-02 10:25:26 +02:00
|
|
|
descriptions.push_back(parser.readString());
|
|
|
|
|
|
|
|
parser.readString(); //ignore attributes. All data present in JSON
|
|
|
|
|
|
|
|
//save parsed level specific data
|
|
|
|
for(size_t i = 0; i < GameConstants::SPELL_SCHOOL_LEVELS; i++)
|
|
|
|
{
|
|
|
|
auto& level = getLevel(i);
|
|
|
|
level["description"].String() = descriptions[i];
|
2017-07-20 06:08:49 +02:00
|
|
|
level["cost"].Integer() = costs[i];
|
|
|
|
level["power"].Integer() = powers[i];
|
|
|
|
level["aiValue"].Integer() = AIVals[i];
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
legacyData.push_back(lineNode);
|
|
|
|
}
|
|
|
|
while (parser.endLine() && !parser.isNextEntryEmpty());
|
|
|
|
};
|
|
|
|
|
|
|
|
auto skip = [&](int cnt)
|
|
|
|
{
|
|
|
|
for(int i=0; i<cnt; i++)
|
|
|
|
parser.endLine();
|
|
|
|
};
|
|
|
|
|
|
|
|
skip(5);// header
|
|
|
|
read(false,false); //read adventure map spells
|
|
|
|
skip(3);
|
|
|
|
read(true,false); //read battle spells
|
|
|
|
skip(3);
|
|
|
|
read(true,true);//read creature abilities
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
//TODO: maybe move to config
|
2015-02-02 10:25:26 +02:00
|
|
|
//clone Acid Breath attributes for Acid Breath damage effect
|
|
|
|
JsonNode temp = legacyData[SpellID::ACID_BREATH_DEFENSE];
|
2017-07-20 06:08:49 +02:00
|
|
|
temp["index"].Integer() = SpellID::ACID_BREATH_DAMAGE;
|
2015-02-02 10:25:26 +02:00
|
|
|
legacyData.push_back(temp);
|
|
|
|
|
|
|
|
objects.resize(legacyData.size());
|
|
|
|
|
|
|
|
return legacyData;
|
|
|
|
}
|
|
|
|
|
2018-03-31 07:56:40 +02:00
|
|
|
const std::vector<std::string> & CSpellHandler::getTypeNames() const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2018-03-31 07:56:40 +02:00
|
|
|
static const std::vector<std::string> typeNames = { "spell" };
|
|
|
|
return typeNames;
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
2024-08-10 14:22:21 +02:00
|
|
|
std::vector<int> CSpellHandler::spellRangeInHexes(std::string input) const
|
|
|
|
{
|
|
|
|
std::set<BattleHex> ret;
|
|
|
|
std::string rng = input + ','; //copy + artificial comma for easier handling
|
|
|
|
|
2024-08-20 00:41:47 +02:00
|
|
|
if(rng.size() >= 2 && std::tolower(rng[0]) != 'x') //there is at least one hex in range (+artificial comma)
|
2024-08-10 14:22:21 +02:00
|
|
|
{
|
|
|
|
std::string number1;
|
|
|
|
std::string number2;
|
|
|
|
int beg = 0;
|
|
|
|
int end = 0;
|
|
|
|
bool readingFirst = true;
|
|
|
|
for(auto & elem : rng)
|
|
|
|
{
|
|
|
|
if(std::isdigit(elem) ) //reading number
|
|
|
|
{
|
|
|
|
if(readingFirst)
|
|
|
|
number1 += elem;
|
|
|
|
else
|
|
|
|
number2 += elem;
|
|
|
|
}
|
|
|
|
else if(elem == ',') //comma
|
|
|
|
{
|
|
|
|
//calculating variables
|
|
|
|
if(readingFirst)
|
|
|
|
{
|
|
|
|
beg = std::stoi(number1);
|
|
|
|
number1 = "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
end = std::stoi(number2);
|
|
|
|
number2 = "";
|
|
|
|
}
|
|
|
|
//obtaining new hexes
|
|
|
|
std::set<ui16> curLayer;
|
|
|
|
if(readingFirst)
|
|
|
|
{
|
|
|
|
ret.insert(beg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(int i = beg; i <= end; ++i)
|
|
|
|
ret.insert(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(elem == '-') //dash
|
|
|
|
{
|
|
|
|
beg = std::stoi(number1);
|
|
|
|
number1 = "";
|
|
|
|
readingFirst = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::vector<int>(ret.begin(), ret.end());
|
|
|
|
}
|
|
|
|
|
2024-05-17 00:05:51 +02:00
|
|
|
std::shared_ptr<CSpell> CSpellHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2023-01-18 23:56:01 +02:00
|
|
|
assert(identifier.find(':') == std::string::npos);
|
|
|
|
assert(!scope.empty());
|
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
using namespace SpellConfig;
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
SpellID id(static_cast<si32>(index));
|
|
|
|
|
2024-05-17 00:05:51 +02:00
|
|
|
auto spell = std::make_shared<CSpell>();
|
2017-07-20 06:08:49 +02:00
|
|
|
spell->id = id;
|
2016-02-13 18:41:28 +02:00
|
|
|
spell->identifier = identifier;
|
2023-01-02 00:06:42 +02:00
|
|
|
spell->modScope = scope;
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
const auto type = json["type"].String();
|
|
|
|
|
|
|
|
if(type == "ability")
|
|
|
|
{
|
|
|
|
spell->creatureAbility = true;
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
spell->combat = true;
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
spell->creatureAbility = false;
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
spell->combat = type == "combat";
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 15:03:49 +02:00
|
|
|
VLC->generaltexth->registerString(scope, spell->getNameTextID(), json["name"].String());
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2023-01-02 00:06:42 +02:00
|
|
|
logMod->trace("%s: loading spell %s", __FUNCTION__, spell->getNameTranslated());
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
const auto schoolNames = json["school"];
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
for(const spells::SchoolInfo & info : SpellConfig::SCHOOL)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
spell->school[info.id] = schoolNames[info.jsonName].Bool();
|
|
|
|
}
|
|
|
|
|
2024-01-16 15:01:42 +02:00
|
|
|
spell->castOnSelf = json["canCastOnSelf"].Bool();
|
2024-09-14 14:49:52 +02:00
|
|
|
spell->castWithoutSkip = json["canCastWithoutSkip"].Bool();
|
2020-10-01 10:38:06 +02:00
|
|
|
spell->level = static_cast<si32>(json["level"].Integer());
|
|
|
|
spell->power = static_cast<si32>(json["power"].Integer());
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2020-10-01 10:38:06 +02:00
|
|
|
spell->defaultProbability = static_cast<si32>(json["defaultGainChance"].Integer());
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
for(const auto & node : json["gainChance"].Struct())
|
|
|
|
{
|
2020-10-01 10:38:06 +02:00
|
|
|
const int chance = static_cast<int>(node.second.Integer());
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2024-02-13 14:34:16 +02:00
|
|
|
VLC->identifiers()->requestIdentifier(node.second.getModScope(), "faction", node.first, [=](si32 factionID)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2023-04-09 17:26:32 +02:00
|
|
|
spell->probabilities[FactionID(factionID)] = chance;
|
2015-02-02 10:25:26 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
auto targetType = json["targetType"].String();
|
|
|
|
|
|
|
|
if(targetType == "NO_TARGET")
|
2017-07-20 06:08:49 +02:00
|
|
|
spell->targetType = spells::AimType::NO_TARGET;
|
2015-02-02 10:25:26 +02:00
|
|
|
else if(targetType == "CREATURE")
|
2017-07-20 06:08:49 +02:00
|
|
|
spell->targetType = spells::AimType::CREATURE;
|
2015-02-02 10:25:26 +02:00
|
|
|
else if(targetType == "OBSTACLE")
|
2017-07-20 06:08:49 +02:00
|
|
|
spell->targetType = spells::AimType::OBSTACLE;
|
2015-02-02 10:25:26 +02:00
|
|
|
else if(targetType == "LOCATION")
|
2017-07-20 06:08:49 +02:00
|
|
|
spell->targetType = spells::AimType::LOCATION;
|
2015-02-26 19:59:18 +02:00
|
|
|
else
|
2023-01-02 00:06:42 +02:00
|
|
|
logMod->warn("Spell %s: target type %s - assumed NO_TARGET.", spell->getNameTranslated(), (targetType.empty() ? "empty" : "unknown ("+targetType+")"));
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
for(const auto & counteredSpell: json["counters"].Struct())
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
if(counteredSpell.second.Bool())
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2024-02-13 14:34:16 +02:00
|
|
|
VLC->identifiers()->requestIdentifier(counteredSpell.second.getModScope(), "spell", counteredSpell.first, [=](si32 id)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2023-02-11 17:18:05 +02:00
|
|
|
spell->counteredSpells.emplace_back(id);
|
2015-02-02 10:25:26 +02:00
|
|
|
});
|
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
//TODO: more error checking - f.e. conflicting flags
|
|
|
|
const auto flags = json["flags"];
|
|
|
|
|
|
|
|
//by default all flags are set to false in constructor
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
spell->damage = flags["damage"].Bool(); //do this before "offensive"
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2023-03-21 11:18:31 +02:00
|
|
|
spell->nonMagical = flags["nonMagical"].Bool();
|
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
if(flags["offensive"].Bool())
|
|
|
|
{
|
|
|
|
spell->setIsOffensive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(flags["rising"].Bool())
|
|
|
|
{
|
|
|
|
spell->setIsRising(true);
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const bool implicitPositiveness = spell->offensive || spell->rising; //(!) "damage" does not mean NEGATIVE --AVS
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
if(flags["indifferent"].Bool())
|
|
|
|
{
|
|
|
|
spell->positiveness = CSpell::NEUTRAL;
|
|
|
|
}
|
|
|
|
else if(flags["negative"].Bool())
|
|
|
|
{
|
|
|
|
spell->positiveness = CSpell::NEGATIVE;
|
|
|
|
}
|
|
|
|
else if(flags["positive"].Bool())
|
|
|
|
{
|
|
|
|
spell->positiveness = CSpell::POSITIVE;
|
|
|
|
}
|
|
|
|
else if(!implicitPositiveness)
|
|
|
|
{
|
|
|
|
spell->positiveness = CSpell::NEUTRAL; //duplicates constructor but, just in case
|
2023-01-02 00:06:42 +02:00
|
|
|
logMod->error("Spell %s: no positiveness specified, assumed NEUTRAL.", spell->getNameTranslated());
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
spell->special = flags["special"].Bool();
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2023-07-17 17:21:28 +02:00
|
|
|
spell->onlyOnWaterMap = json["onlyOnWaterMap"].Bool();
|
|
|
|
|
2023-05-01 00:20:01 +02:00
|
|
|
auto findBonus = [&](const std::string & name, std::vector<BonusType> & vec)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
auto it = bonusNameMap.find(name);
|
|
|
|
if(it == bonusNameMap.end())
|
|
|
|
{
|
2023-01-02 00:06:42 +02:00
|
|
|
logMod->error("Spell %s: invalid bonus name %s", spell->getNameTranslated(), name);
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-01 00:20:01 +02:00
|
|
|
vec.push_back(static_cast<BonusType>(it->second));
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-01 00:20:01 +02:00
|
|
|
auto readBonusStruct = [&](const std::string & name, std::vector<BonusType> & vec)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
|
|
|
for(auto bonusData: json[name].Struct())
|
|
|
|
{
|
|
|
|
const std::string bonusId = bonusData.first;
|
|
|
|
const bool flag = bonusData.second.Bool();
|
|
|
|
|
|
|
|
if(flag)
|
|
|
|
findBonus(bonusId, vec);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(json["targetCondition"].isNull())
|
|
|
|
{
|
|
|
|
CSpell::BTVector immunities;
|
|
|
|
CSpell::BTVector absoluteImmunities;
|
|
|
|
CSpell::BTVector limiters;
|
|
|
|
CSpell::BTVector absoluteLimiters;
|
|
|
|
|
|
|
|
readBonusStruct("immunity", immunities);
|
|
|
|
readBonusStruct("absoluteImmunity", absoluteImmunities);
|
|
|
|
readBonusStruct("limit", limiters);
|
|
|
|
readBonusStruct("absoluteLimit", absoluteLimiters);
|
|
|
|
|
|
|
|
if(!(immunities.empty() && absoluteImmunities.empty() && limiters.empty() && absoluteLimiters.empty()))
|
|
|
|
{
|
2023-01-02 00:06:42 +02:00
|
|
|
logMod->warn("Spell %s has old target condition format. Expected configuration: ", spell->getNameTranslated());
|
2017-07-20 06:08:49 +02:00
|
|
|
spell->targetCondition = spell->convertTargetCondition(immunities, absoluteImmunities, limiters, absoluteLimiters);
|
2024-02-12 01:22:16 +02:00
|
|
|
logMod->warn("\n\"targetCondition\" : %s", spell->targetCondition.toString());
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
spell->targetCondition = json["targetCondition"];
|
|
|
|
|
|
|
|
//TODO: could this be safely merged instead of discarding?
|
|
|
|
if(!json["immunity"].isNull())
|
2023-01-02 00:06:42 +02:00
|
|
|
logMod->warn("Spell %s 'immunity' field mixed with 'targetCondition' discarded", spell->getNameTranslated());
|
2017-07-20 06:08:49 +02:00
|
|
|
if(!json["absoluteImmunity"].isNull())
|
2023-01-02 00:06:42 +02:00
|
|
|
logMod->warn("Spell %s 'absoluteImmunity' field mixed with 'targetCondition' discarded", spell->getNameTranslated());
|
2017-07-20 06:08:49 +02:00
|
|
|
if(!json["limit"].isNull())
|
2023-01-02 00:06:42 +02:00
|
|
|
logMod->warn("Spell %s 'limit' field mixed with 'targetCondition' discarded", spell->getNameTranslated());
|
2017-07-20 06:08:49 +02:00
|
|
|
if(!json["absoluteLimit"].isNull())
|
2023-01-02 00:06:42 +02:00
|
|
|
logMod->warn("Spell %s 'absoluteLimit' field mixed with 'targetCondition' discarded", spell->getNameTranslated());
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
const JsonNode & graphicsNode = json["graphics"];
|
|
|
|
|
|
|
|
spell->iconImmune = graphicsNode["iconImmune"].String();
|
|
|
|
spell->iconBook = graphicsNode["iconBook"].String();
|
|
|
|
spell->iconEffect = graphicsNode["iconEffect"].String();
|
|
|
|
spell->iconScenarioBonus = graphicsNode["iconScenarioBonus"].String();
|
|
|
|
spell->iconScroll = graphicsNode["iconScroll"].String();
|
|
|
|
|
|
|
|
const JsonNode & animationNode = json["animation"];
|
2015-02-26 19:59:18 +02:00
|
|
|
|
|
|
|
auto loadAnimationQueue = [&](const std::string & jsonName, CSpell::TAnimationQueue & q)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2015-02-26 19:59:18 +02:00
|
|
|
auto queueNode = animationNode[jsonName].Vector();
|
2015-02-02 10:25:26 +02:00
|
|
|
for(const JsonNode & item : queueNode)
|
2015-02-26 19:59:18 +02:00
|
|
|
{
|
2015-02-02 10:25:26 +02:00
|
|
|
CSpell::TAnimation newItem;
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2017-11-26 23:18:18 +02:00
|
|
|
if(item.getType() == JsonNode::JsonType::DATA_STRING)
|
2023-08-23 14:07:50 +02:00
|
|
|
newItem.resourceName = AnimationPath::fromJson(item);
|
2017-11-26 23:18:18 +02:00
|
|
|
else if(item.getType() == JsonNode::JsonType::DATA_STRUCT)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
newItem.resourceName = AnimationPath::fromJson(item["defName"]);
|
2022-12-22 00:25:35 +02:00
|
|
|
newItem.effectName = item["effectName"].String();
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
auto vPosStr = item["verticalPosition"].String();
|
|
|
|
if("bottom" == vPosStr)
|
|
|
|
newItem.verticalPosition = VerticalPosition::BOTTOM;
|
2015-02-26 19:59:18 +02:00
|
|
|
}
|
2016-11-13 12:38:42 +02:00
|
|
|
else if(item.isNumber())
|
2015-03-22 12:49:14 +02:00
|
|
|
{
|
2020-10-01 10:38:06 +02:00
|
|
|
newItem.pause = static_cast<int>(item.Float());
|
2015-03-22 12:49:14 +02:00
|
|
|
}
|
2016-02-13 18:41:28 +02:00
|
|
|
|
2015-02-26 19:59:18 +02:00
|
|
|
q.push_back(newItem);
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
};
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
loadAnimationQueue("affect", spell->animationInfo.affect);
|
|
|
|
loadAnimationQueue("cast", spell->animationInfo.cast);
|
2015-02-26 19:59:18 +02:00
|
|
|
loadAnimationQueue("hit", spell->animationInfo.hit);
|
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
const JsonVector & projectile = animationNode["projectile"].Vector();
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
for(const JsonNode & item : projectile)
|
|
|
|
{
|
|
|
|
CSpell::ProjectileInfo info;
|
2023-08-23 14:07:50 +02:00
|
|
|
info.resourceName = AnimationPath::fromJson(item["defName"]);
|
2015-02-02 10:25:26 +02:00
|
|
|
info.minimumAngle = item["minimumAngle"].Float();
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
spell->animationInfo.projectile.push_back(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
const JsonNode & soundsNode = json["sounds"];
|
2023-09-04 12:03:15 +02:00
|
|
|
spell->castSound = AudioPath::fromJson(soundsNode["cast"]);
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
//load level attributes
|
|
|
|
const int levelsCount = GameConstants::SPELL_SCHOOL_LEVELS;
|
|
|
|
|
|
|
|
for(int levelIndex = 0; levelIndex < levelsCount; levelIndex++)
|
|
|
|
{
|
|
|
|
const JsonNode & levelNode = json["levels"][LEVEL_NAMES[levelIndex]];
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
CSpell::LevelInfo & levelObject = spell->levels[levelIndex];
|
|
|
|
|
2020-10-01 10:38:06 +02:00
|
|
|
const si32 levelPower = levelObject.power = static_cast<si32>(levelNode["power"].Integer());
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2023-01-18 23:56:01 +02:00
|
|
|
if (!spell->isCreatureAbility())
|
2023-02-09 15:03:49 +02:00
|
|
|
VLC->generaltexth->registerString(scope, spell->getDescriptionTextID(levelIndex), levelNode["description"].String());
|
2023-01-02 00:06:42 +02:00
|
|
|
|
2020-10-01 10:38:06 +02:00
|
|
|
levelObject.cost = static_cast<si32>(levelNode["cost"].Integer());
|
|
|
|
levelObject.AIValue = static_cast<si32>(levelNode["aiValue"].Integer());
|
2015-02-02 10:25:26 +02:00
|
|
|
levelObject.smartTarget = levelNode["targetModifier"]["smart"].Bool();
|
|
|
|
levelObject.clearTarget = levelNode["targetModifier"]["clearTarget"].Bool();
|
2015-02-26 19:59:18 +02:00
|
|
|
levelObject.clearAffected = levelNode["targetModifier"]["clearAffected"].Bool();
|
2024-08-10 14:22:21 +02:00
|
|
|
levelObject.range = spellRangeInHexes(levelNode["range"].String());
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
for(const auto & elem : levelNode["effects"].Struct())
|
|
|
|
{
|
|
|
|
const JsonNode & bonusNode = elem.second;
|
2016-09-19 23:36:35 +02:00
|
|
|
auto b = JsonUtils::parseBonus(bonusNode);
|
2015-02-02 10:25:26 +02:00
|
|
|
const bool usePowerAsValue = bonusNode["val"].isNull();
|
|
|
|
|
2023-10-21 13:50:42 +02:00
|
|
|
b->sid = BonusSourceID(spell->id); //for all
|
2023-05-01 00:20:01 +02:00
|
|
|
b->source = BonusSource::SPELL_EFFECT;//for all
|
2015-02-02 10:25:26 +02:00
|
|
|
|
|
|
|
if(usePowerAsValue)
|
|
|
|
b->val = levelPower;
|
|
|
|
|
2016-11-02 19:11:01 +02:00
|
|
|
levelObject.effects.push_back(b);
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2016-11-02 19:11:01 +02:00
|
|
|
for(const auto & elem : levelNode["cumulativeEffects"].Struct())
|
|
|
|
{
|
|
|
|
const JsonNode & bonusNode = elem.second;
|
|
|
|
auto b = JsonUtils::parseBonus(bonusNode);
|
|
|
|
const bool usePowerAsValue = bonusNode["val"].isNull();
|
|
|
|
|
2023-10-21 13:50:42 +02:00
|
|
|
b->sid = BonusSourceID(spell->id); //for all
|
2023-05-01 00:20:01 +02:00
|
|
|
b->source = BonusSource::SPELL_EFFECT;//for all
|
2016-11-02 19:11:01 +02:00
|
|
|
|
|
|
|
if(usePowerAsValue)
|
|
|
|
b->val = levelPower;
|
|
|
|
|
|
|
|
levelObject.cumulativeEffects.push_back(b);
|
|
|
|
}
|
2015-02-02 10:25:26 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(levelNode["battleEffects"].getType() == JsonNode::JsonType::DATA_STRUCT && !levelNode["battleEffects"].Struct().empty())
|
|
|
|
{
|
|
|
|
levelObject.battleEffects = levelNode["battleEffects"];
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
if(!levelObject.cumulativeEffects.empty() || !levelObject.effects.empty() || spell->isOffensive())
|
2023-01-02 00:06:42 +02:00
|
|
|
logGlobal->error("Mixing %s special effects with old format effects gives unpredictable result", spell->getNameTranslated());
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
}
|
2015-02-02 10:25:26 +02:00
|
|
|
return spell;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellHandler::afterLoadFinalization()
|
|
|
|
{
|
2023-12-31 23:43:35 +02:00
|
|
|
for(auto & spell : objects)
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
spell->setupMechanics();
|
2015-02-02 10:25:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSpellHandler::beforeValidate(JsonNode & object)
|
|
|
|
{
|
|
|
|
//handle "base" level info
|
2015-02-26 19:59:18 +02:00
|
|
|
|
|
|
|
JsonNode & levels = object["levels"];
|
|
|
|
JsonNode & base = levels["base"];
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
auto inheritNode = [&](const std::string & name)
|
|
|
|
{
|
2015-02-02 10:25:26 +02:00
|
|
|
JsonUtils::inherit(levels[name],base);
|
|
|
|
};
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
inheritNode("none");
|
|
|
|
inheritNode("basic");
|
|
|
|
inheritNode("advanced");
|
|
|
|
inheritNode("expert");
|
|
|
|
}
|
|
|
|
|
2023-11-05 15:24:26 +02:00
|
|
|
std::set<SpellID> CSpellHandler::getDefaultAllowed() const
|
2015-02-02 10:25:26 +02:00
|
|
|
{
|
2023-11-05 15:24:26 +02:00
|
|
|
std::set<SpellID> allowedSpells;
|
2016-02-21 19:58:09 +02:00
|
|
|
|
2023-12-31 23:43:35 +02:00
|
|
|
for(auto const & s : objects)
|
2023-11-05 15:24:26 +02:00
|
|
|
if (!s->isSpecial() && !s->isCreatureAbility())
|
|
|
|
allowedSpells.insert(s->getId());
|
2016-02-21 19:58:09 +02:00
|
|
|
|
2015-02-02 10:25:26 +02:00
|
|
|
return allowedSpells;
|
2022-07-26 15:07:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|