2015-02-02 10:40:06 +02:00
|
|
|
/*
|
|
|
|
* BattleSpellMechanics.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
|
|
|
|
#include "BattleSpellMechanics.h"
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "Problem.h"
|
|
|
|
#include "CSpellHandler.h"
|
|
|
|
|
|
|
|
#include "../battle/IBattleState.h"
|
|
|
|
#include "../battle/CBattleInfoCallback.h"
|
|
|
|
|
2017-03-17 17:48:44 +02:00
|
|
|
#include "../CStack.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "../NetPacks.h"
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
namespace spells
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
namespace SRSLPraserHelpers
|
2015-09-16 06:33:36 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
static int XYToHex(int x, int y)
|
|
|
|
{
|
|
|
|
return x + GameConstants::BFIELD_WIDTH * y;
|
|
|
|
}
|
2015-09-16 06:33:36 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
static int XYToHex(std::pair<int, int> xy)
|
2015-09-16 06:33:36 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return XYToHex(xy.first, xy.second);
|
2015-09-16 06:33:36 +02:00
|
|
|
}
|
2015-09-16 08:44:18 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
static int hexToY(int battleFieldPosition)
|
|
|
|
{
|
|
|
|
return battleFieldPosition/GameConstants::BFIELD_WIDTH;
|
|
|
|
}
|
2015-09-16 06:33:36 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
static int hexToX(int battleFieldPosition)
|
|
|
|
{
|
|
|
|
int pos = battleFieldPosition - hexToY(battleFieldPosition) * GameConstants::BFIELD_WIDTH;
|
|
|
|
return pos;
|
|
|
|
}
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
static std::pair<int, int> hexToPair(int battleFieldPosition)
|
|
|
|
{
|
|
|
|
return std::make_pair(hexToX(battleFieldPosition), hexToY(battleFieldPosition));
|
|
|
|
}
|
2015-04-03 02:28:20 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
//moves hex by one hex in given direction
|
|
|
|
//0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left
|
|
|
|
static std::pair<int, int> gotoDir(int x, int y, int direction)
|
2015-04-03 02:28:20 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
switch(direction)
|
2016-02-15 12:34:37 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
case 0: //top left
|
|
|
|
return std::make_pair((y%2) ? x-1 : x, y-1);
|
|
|
|
case 1: //top right
|
|
|
|
return std::make_pair((y%2) ? x : x+1, y-1);
|
|
|
|
case 2: //right
|
|
|
|
return std::make_pair(x+1, y);
|
|
|
|
case 3: //right bottom
|
|
|
|
return std::make_pair((y%2) ? x : x+1, y+1);
|
|
|
|
case 4: //left bottom
|
|
|
|
return std::make_pair((y%2) ? x-1 : x, y+1);
|
|
|
|
case 5: //left
|
|
|
|
return std::make_pair(x-1, y);
|
|
|
|
default:
|
|
|
|
throw std::runtime_error("Disaster: wrong direction in SRSLPraserHelpers::gotoDir!\n");
|
2015-04-03 02:28:20 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
2016-09-30 00:54:40 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
static std::pair<int, int> gotoDir(std::pair<int, int> xy, int direction)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return gotoDir(xy.first, xy.second, direction);
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
static bool isGoodHex(std::pair<int, int> xy)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return xy.first >=0 && xy.first < GameConstants::BFIELD_WIDTH && xy.second >= 0 && xy.second < GameConstants::BFIELD_HEIGHT;
|
2015-02-26 19:59:18 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
//helper function for rangeInHexes
|
|
|
|
static std::set<ui16> getInRange(unsigned int center, int low, int high)
|
|
|
|
{
|
|
|
|
std::set<ui16> ret;
|
|
|
|
if(low == 0)
|
|
|
|
{
|
|
|
|
ret.insert(center);
|
|
|
|
}
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::pair<int, int> mainPointForLayer[6]; //A, B, C, D, E, F points
|
|
|
|
for(auto & elem : mainPointForLayer)
|
|
|
|
elem = hexToPair(center);
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
for(int it=1; it<=high; ++it) //it - distance to the center
|
|
|
|
{
|
|
|
|
for(int b=0; b<6; ++b)
|
|
|
|
mainPointForLayer[b] = gotoDir(mainPointForLayer[b], b);
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(it>=low)
|
|
|
|
{
|
|
|
|
std::pair<int, int> curHex;
|
2016-03-05 03:46:32 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
//adding lines (A-b, B-c, C-d, etc)
|
|
|
|
for(int v=0; v<6; ++v)
|
|
|
|
{
|
|
|
|
curHex = mainPointForLayer[v];
|
|
|
|
for(int h=0; h<it; ++h)
|
|
|
|
{
|
|
|
|
if(isGoodHex(curHex))
|
|
|
|
ret.insert(XYToHex(curHex));
|
|
|
|
curHex = gotoDir(curHex, (v+2)%6);
|
|
|
|
}
|
|
|
|
}
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
} //if(it>=low)
|
|
|
|
}
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
return ret;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
BattleSpellMechanics::BattleSpellMechanics(const IBattleCast * event, std::shared_ptr<effects::Effects> effects_, std::shared_ptr<IReceptiveCheck> targetCondition_)
|
|
|
|
: BaseMechanics(event),
|
|
|
|
effects(effects_),
|
|
|
|
targetCondition(targetCondition_)
|
|
|
|
{}
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
BattleSpellMechanics::~BattleSpellMechanics() = default;
|
2015-09-16 06:56:02 +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
|
|
|
void BattleSpellMechanics::applyEffects(ServerCallback * server, const Target & targets, bool indirect, bool ignoreImmunity) const
|
2017-07-04 13:24:46 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
auto callback = [&](const effects::Effect * effect, bool & stop)
|
|
|
|
{
|
|
|
|
if(indirect == effect->indirect)
|
|
|
|
{
|
|
|
|
if(ignoreImmunity)
|
|
|
|
{
|
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
|
|
|
effect->apply(server, this, targets);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EffectTarget filtered = effect->filterTarget(this, targets);
|
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
|
|
|
effect->apply(server, this, filtered);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
effects->forEachEffect(getEffectLevel(), callback);
|
2017-07-04 13:24:46 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
bool BattleSpellMechanics::canBeCast(Problem & problem) const
|
2016-09-11 12:48:14 +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
|
|
|
auto genProblem = battle()->battleCanCastSpell(caster, mode);
|
|
|
|
if(genProblem != ESpellCastProblem::OK)
|
|
|
|
return adaptProblem(genProblem, problem);
|
|
|
|
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case Mode::HERO:
|
|
|
|
{
|
|
|
|
const CGHeroInstance * castingHero = dynamic_cast<const CGHeroInstance *>(caster);//todo: unify hero|creature spell cost
|
|
|
|
if(!castingHero)
|
|
|
|
{
|
|
|
|
logGlobal->debug("CSpell::canBeCast: invalid caster");
|
|
|
|
genProblem = ESpellCastProblem::NO_HERO_TO_CAST_SPELL;
|
|
|
|
}
|
|
|
|
else if(!castingHero->getArt(ArtifactPosition::SPELLBOOK))
|
|
|
|
genProblem = ESpellCastProblem::NO_SPELLBOOK;
|
|
|
|
else if(!castingHero->canCastThisSpell(owner))
|
|
|
|
genProblem = ESpellCastProblem::HERO_DOESNT_KNOW_SPELL;
|
|
|
|
else if(castingHero->mana < battle()->battleGetSpellCost(owner, castingHero)) //not enough mana
|
|
|
|
genProblem = ESpellCastProblem::NOT_ENOUGH_MANA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(genProblem != ESpellCastProblem::OK)
|
|
|
|
return adaptProblem(genProblem, problem);
|
|
|
|
|
|
|
|
if(!owner->isCombat())
|
|
|
|
return adaptProblem(ESpellCastProblem::ADVMAP_SPELL_INSTEAD_OF_BATTLE_SPELL, problem);
|
|
|
|
|
|
|
|
const PlayerColor player = caster->getCasterOwner();
|
|
|
|
const auto side = battle()->playerToSide(player);
|
|
|
|
|
|
|
|
if(!side)
|
|
|
|
return adaptProblem(ESpellCastProblem::INVALID, problem);
|
|
|
|
|
|
|
|
//effect like Recanter's Cloak. Blocks also passive casting.
|
|
|
|
//TODO: check creature abilities to block
|
|
|
|
//TODO: check any possible caster
|
|
|
|
|
|
|
|
if(battle()->battleMaxSpellLevel(side.get()) < getSpellLevel() || battle()->battleMinSpellLevel(side.get()) > getSpellLevel())
|
|
|
|
return adaptProblem(ESpellCastProblem::SPELL_LEVEL_LIMIT_EXCEEDED, problem);
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
return effects->applicable(problem, this);
|
2016-09-11 12:48:14 +02:00
|
|
|
}
|
|
|
|
|
2021-02-20 03:57:50 +02:00
|
|
|
bool BattleSpellMechanics::canBeCastAt(const Target & target, Problem & problem) const
|
2016-09-11 12:48:14 +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
|
|
|
if(!canBeCast(problem))
|
|
|
|
return false;
|
2016-09-11 12:48:14 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
Target spellTarget = transformSpellTarget(target);
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
return effects->applicable(problem, this, target, spellTarget);
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::vector<const CStack *> BattleSpellMechanics::getAffectedStacks(const Target & target) const
|
2015-04-03 00:52:20 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
Target spellTarget = transformSpellTarget(target);
|
2016-09-29 15:50:33 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
EffectTarget all;
|
|
|
|
|
|
|
|
effects->forEachEffect(getEffectLevel(), [&all, &target, &spellTarget, this](const effects::Effect * e, bool & stop)
|
2015-09-18 07:04:13 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
EffectTarget one = e->transformTarget(this, target, spellTarget);
|
|
|
|
vstd::concatenate(all, one);
|
|
|
|
});
|
2015-04-03 02:02:16 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::set<const CStack *> stacks;
|
2015-04-03 00:16:41 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
for(const Destination & dest : all)
|
2015-04-03 02:01:05 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(dest.unitValue)
|
2015-04-03 02:01:05 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
//FIXME: remove and return battle::Unit
|
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
|
|
|
stacks.insert(battle()->battleGetStackByID(dest.unitValue->unitId(), false));
|
2015-04-03 02:01:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::vector<const CStack *> res;
|
|
|
|
std::copy(stacks.begin(), stacks.end(), std::back_inserter(res));
|
|
|
|
return res;
|
2017-06-06 06:53:51 +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
|
|
|
void BattleSpellMechanics::cast(ServerCallback * server, const Target & target)
|
2015-03-18 12:27:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
BattleSpellCast sc;
|
2015-03-19 09:35:05 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
int spellCost = 0;
|
2015-03-19 09:35:05 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
sc.side = casterSide;
|
|
|
|
sc.spellID = getSpellId();
|
|
|
|
sc.tile = target.at(0).hexValue;
|
2015-03-19 09:35:05 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
sc.castByHero = mode == Mode::HERO;
|
2018-03-04 10:13:07 +02:00
|
|
|
sc.casterStack = caster->getCasterUnitId();
|
2017-07-20 06:08:49 +02:00
|
|
|
sc.manaGained = 0;
|
2015-03-19 09:35:05 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
sc.activeCast = false;
|
|
|
|
affectedUnits.clear();
|
2015-03-19 09:35:05 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
const CGHeroInstance * otherHero = nullptr;
|
2015-03-18 12:27:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
//check it there is opponent hero
|
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 ui8 otherSide = battle()->otherSide(casterSide);
|
2015-03-19 09:35:05 +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
|
|
|
if(battle()->battleHasHero(otherSide))
|
|
|
|
otherHero = battle()->battleGetFightingHero(otherSide);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
2015-03-18 13:12:26 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
//calculate spell cost
|
|
|
|
if(mode == Mode::HERO)
|
|
|
|
{
|
|
|
|
auto casterHero = dynamic_cast<const CGHeroInstance *>(caster);
|
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
|
|
|
spellCost = battle()->battleGetSpellCost(owner, casterHero);
|
2015-03-19 09:35:05 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(nullptr != otherHero) //handle mana channel
|
2015-03-18 13:12:26 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
int manaChannel = 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
|
|
|
for(const CStack * stack : battle()->battleGetAllStacks(true)) //TODO: shouldn't bonus system handle it somehow?
|
2015-03-18 13:12:26 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(stack->owner == otherHero->tempOwner)
|
2015-03-18 13:12:26 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
vstd::amax(manaChannel, stack->valOfBonuses(Bonus::MANA_CHANNELING));
|
2015-03-18 13:12:26 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
sc.manaGained = (manaChannel * spellCost) / 100;
|
2015-03-18 13:28:34 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
sc.activeCast = true;
|
2017-07-12 21:01:10 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
else if(mode == Mode::CREATURE_ACTIVE || mode == Mode::ENCHANTER)
|
2016-09-18 15:30:03 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
spellCost = 1;
|
|
|
|
sc.activeCast = true;
|
2016-09-18 15:30:03 +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
|
|
|
beforeCast(sc, *server->getRNG(), target);
|
|
|
|
|
|
|
|
BattleLogMessage castDescription;
|
2015-03-19 09:35:05 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
switch (mode)
|
2015-03-18 15:39:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
case Mode::CREATURE_ACTIVE:
|
|
|
|
case Mode::ENCHANTER:
|
|
|
|
case Mode::HERO:
|
|
|
|
case Mode::PASSIVE:
|
|
|
|
{
|
|
|
|
MetaString line;
|
|
|
|
caster->getCastDescription(owner, affectedUnits, line);
|
2018-03-02 12:22:51 +02:00
|
|
|
if(!line.message.empty())
|
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
|
|
|
castDescription.lines.push_back(line);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
break;
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
default:
|
|
|
|
break;
|
2015-03-18 16:48:32 +02:00
|
|
|
}
|
2015-03-19 09:35:05 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
doRemoveEffects(server, affectedUnits, std::bind(&BattleSpellMechanics::counteringSelector, this, _1));
|
2016-03-01 14:14:27 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
for(auto & unit : affectedUnits)
|
|
|
|
sc.affectedCres.insert(unit->unitId());
|
2016-03-01 14:14:27 +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
|
|
|
if(!castDescription.lines.empty())
|
|
|
|
server->apply(&castDescription);
|
2015-03-18 15:39:07 +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
|
|
|
server->apply(&sc);
|
|
|
|
|
|
|
|
for(auto & p : effectsToApply)
|
|
|
|
p.first->apply(server, this, p.second);
|
2016-09-05 10:36:25 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
// afterCast();
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(sc.activeCast)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
caster->spendMana(server, spellCost);
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(sc.manaGained > 0)
|
|
|
|
{
|
|
|
|
assert(otherHero);
|
|
|
|
otherHero->spendMana(server, -sc.manaGained);
|
|
|
|
}
|
|
|
|
}
|
2017-06-06 06:53:51 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void BattleSpellMechanics::beforeCast(BattleSpellCast & sc, vstd::RNG & rng, const Target & target)
|
2016-03-04 18:11:42 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
affectedUnits.clear();
|
2016-03-04 18:11:42 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
Target spellTarget = transformSpellTarget(target);
|
2016-03-04 18:11:42 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::vector <const battle::Unit *> resisted;
|
2016-03-04 18:11:42 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
auto rangeGen = rng.getInt64Range(0, 99);
|
2016-09-23 12:14:12 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
auto filterResisted = [&, this](const battle::Unit * unit) -> bool
|
|
|
|
{
|
|
|
|
if(isNegativeSpell())
|
|
|
|
{
|
|
|
|
//magic resistance
|
|
|
|
const int prob = std::min(unit->magicResistance(), 100); //probability of resistance in %
|
|
|
|
if(rangeGen() < prob)
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-23 19:27:55 +02:00
|
|
|
return false;
|
2017-07-20 06:08:49 +02:00
|
|
|
};
|
2016-09-23 19:27:55 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
auto filterUnit = [&](const battle::Unit * unit)
|
|
|
|
{
|
|
|
|
if(filterResisted(unit))
|
|
|
|
resisted.push_back(unit);
|
|
|
|
else
|
|
|
|
affectedUnits.push_back(unit);
|
|
|
|
};
|
2016-09-23 19:27:55 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
//prepare targets
|
|
|
|
effectsToApply = effects->prepare(this, target, spellTarget);
|
2016-09-24 10:25:29 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::set<const battle::Unit *> unitTargets = collectTargets();
|
2017-07-01 17:59:53 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
//process them
|
|
|
|
for(auto unit : unitTargets)
|
|
|
|
filterUnit(unit);
|
2016-09-23 19:27:55 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
//and update targets
|
|
|
|
for(auto & p : effectsToApply)
|
2016-09-23 12:14:12 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
vstd::erase_if(p.second, [&](const Destination & d)
|
|
|
|
{
|
|
|
|
if(!d.unitValue)
|
|
|
|
return false;
|
|
|
|
return vstd::contains(resisted, d.unitValue);
|
|
|
|
});
|
2016-09-23 12:14:12 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(mode == Mode::MAGIC_MIRROR)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2018-03-04 10:13:07 +02:00
|
|
|
if(caster->getCasterUnitId() >= 0)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2018-03-04 10:13:07 +02:00
|
|
|
addCustomEffect(sc, caster->getCasterUnitId(), 3);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
2016-09-05 12:34:48 +02:00
|
|
|
}
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
for(auto unit : resisted)
|
|
|
|
addCustomEffect(sc, unit, 78);
|
2016-09-05 12:34:48 +02:00
|
|
|
}
|
2015-02-02 11:22:19 +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
|
|
|
void BattleSpellMechanics::castEval(ServerCallback * server, const Target & target)
|
2017-06-06 06:53:51 +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
|
|
|
affectedUnits.clear();
|
2017-07-20 06:08:49 +02:00
|
|
|
//TODO: evaluate caster updates (mana usage etc.)
|
|
|
|
//TODO: evaluate random values
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
Target spellTarget = transformSpellTarget(target);
|
2016-09-24 10:25:29 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
effectsToApply = effects->prepare(this, target, spellTarget);
|
2016-09-24 10:25:29 +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
|
|
|
std::set<const battle::Unit *> unitTargets = collectTargets();
|
2016-09-05 12:34:48 +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
|
|
|
auto selector = std::bind(&BattleSpellMechanics::counteringSelector, this, _1);
|
2017-06-06 06:53:51 +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
|
|
|
std::copy(std::begin(unitTargets), std::end(unitTargets), std::back_inserter(affectedUnits));
|
|
|
|
doRemoveEffects(server, affectedUnits, selector);
|
2016-09-05 12:34:48 +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
|
|
|
for(auto & p : effectsToApply)
|
|
|
|
p.first->apply(server, this, p.second);
|
2016-09-05 10:36:25 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void BattleSpellMechanics::addCustomEffect(BattleSpellCast & sc, const battle::Unit * target, ui32 effect)
|
2018-03-04 10:13:07 +02:00
|
|
|
{
|
|
|
|
addCustomEffect(sc, target->unitId(), effect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BattleSpellMechanics::addCustomEffect(BattleSpellCast & sc, ui32 targetId, ui32 effect)
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
CustomEffectInfo customEffect;
|
|
|
|
customEffect.effect = effect;
|
2018-03-04 10:13:07 +02:00
|
|
|
customEffect.stack = targetId;
|
2017-07-20 06:08:49 +02:00
|
|
|
sc.customEffects.push_back(customEffect);
|
2017-06-06 06:53:51 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::set<const battle::Unit *> BattleSpellMechanics::collectTargets() const
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
std::set<const battle::Unit *> result;
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
for(const auto & p : effectsToApply)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
for(const Destination & d : p.second)
|
|
|
|
if(d.unitValue)
|
|
|
|
result.insert(d.unitValue);
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
return result;
|
2017-06-06 06:53:51 +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
|
|
|
void BattleSpellMechanics::doRemoveEffects(ServerCallback * server, const std::vector<const battle::Unit *> & targets, const CSelector & selector)
|
2016-09-05 12:34:48 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
SetStackEffect sse;
|
2016-09-05 12:34:48 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
for(auto unit : targets)
|
2016-09-05 12:34:48 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
std::vector<Bonus> buffer;
|
|
|
|
auto bl = unit->getBonuses(selector);
|
2016-09-05 12:34:48 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
for(auto item : *bl)
|
|
|
|
buffer.emplace_back(*item);
|
2016-09-05 12:34:48 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(!buffer.empty())
|
|
|
|
sse.toRemove.push_back(std::make_pair(unit->unitId(), buffer));
|
|
|
|
}
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(!sse.toRemove.empty())
|
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
|
|
|
server->apply(&sse);
|
2016-09-05 12:34:48 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
bool BattleSpellMechanics::counteringSelector(const Bonus * bonus) const
|
2016-09-05 12:34:48 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(bonus->source != Bonus::SPELL_EFFECT)
|
|
|
|
return false;
|
2016-09-05 12:34:48 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
for(const SpellID & id : owner->counteredSpells)
|
2016-09-05 12:34:48 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(bonus->sid == id.toEnum())
|
|
|
|
return true;
|
2016-09-05 12:34:48 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
return false;
|
2016-09-05 12:34:48 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::set<BattleHex> BattleSpellMechanics::spellRangeInHexes(BattleHex centralHex) const
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
using namespace SRSLPraserHelpers;
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::set<BattleHex> ret;
|
|
|
|
std::string rng = owner->getLevelInfo(getRangeLevel()).range + ','; //copy + artificial comma for easier handling
|
|
|
|
|
|
|
|
if(rng.size() >= 2 && rng[0] != 'X') //there is at least one hex in range (+artificial comma)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
std::string number1, number2;
|
|
|
|
int beg, end;
|
|
|
|
bool readingFirst = true;
|
|
|
|
for(auto & elem : rng)
|
2016-03-01 11:20:38 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(std::isdigit(elem) ) //reading number
|
2017-07-01 17:59:53 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(readingFirst)
|
|
|
|
number1 += elem;
|
|
|
|
else
|
|
|
|
number2 += elem;
|
2017-07-01 17:59:53 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
else if(elem == ',') //comma
|
|
|
|
{
|
|
|
|
//calculating variables
|
|
|
|
if(readingFirst)
|
|
|
|
{
|
|
|
|
beg = atoi(number1.c_str());
|
|
|
|
number1 = "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
end = atoi(number2.c_str());
|
|
|
|
number2 = "";
|
|
|
|
}
|
|
|
|
//obtaining new hexes
|
|
|
|
std::set<ui16> curLayer;
|
|
|
|
if(readingFirst)
|
|
|
|
{
|
|
|
|
curLayer = getInRange(centralHex, beg, beg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curLayer = getInRange(centralHex, beg, end);
|
|
|
|
readingFirst = true;
|
|
|
|
}
|
|
|
|
//adding obtained hexes
|
|
|
|
for(auto & curLayer_it : curLayer)
|
|
|
|
{
|
|
|
|
ret.insert(curLayer_it);
|
|
|
|
}
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
else if(elem == '-') //dash
|
|
|
|
{
|
|
|
|
beg = atoi(number1.c_str());
|
|
|
|
number1 = "";
|
|
|
|
readingFirst = false;
|
|
|
|
}
|
|
|
|
}
|
2016-09-18 15:30:03 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
return ret;
|
2016-03-01 11:20:38 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
Target BattleSpellMechanics::transformSpellTarget(const Target & aimPoint) const
|
2016-03-01 11:20:38 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
Target spellTarget;
|
2016-03-01 11:20:38 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(aimPoint.size() < 1)
|
2016-03-01 10:55:09 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
logGlobal->error("Aimed spell cast with no destination.");
|
2016-03-01 10:55:09 +02:00
|
|
|
}
|
2017-07-04 13:24:46 +02:00
|
|
|
else
|
2016-09-18 15:30:03 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
const Destination & primary = aimPoint.at(0);
|
2018-10-29 17:56:14 +02:00
|
|
|
BattleHex aimPointHex = primary.hexValue;
|
2015-04-03 02:02:16 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
//transform primary spell target with spell range (if it`s valid), leave anything else to effects
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2018-10-29 17:56:14 +02:00
|
|
|
if(aimPointHex.isValid())
|
2015-04-02 23:35:29 +02:00
|
|
|
{
|
2018-10-29 17:56:14 +02:00
|
|
|
auto spellRange = spellRangeInHexes(aimPointHex);
|
2017-07-20 06:08:49 +02:00
|
|
|
for(auto & hex : spellRange)
|
|
|
|
spellTarget.push_back(Destination(hex));
|
2015-04-02 23:35:29 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-03 02:02:16 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(spellTarget.empty())
|
|
|
|
spellTarget.push_back(Destination(BattleHex::INVALID));
|
2015-04-02 23:35:29 +02:00
|
|
|
|
2019-01-19 12:52:02 +02:00
|
|
|
return spellTarget;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::vector<AimType> BattleSpellMechanics::getTargetTypes() const
|
2015-09-16 08:44:18 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
auto ret = BaseMechanics::getTargetTypes();
|
2015-10-01 01:36:00 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(!ret.empty())
|
2015-10-01 01:36:00 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
effects->forEachEffect(getEffectLevel(), [&](const effects::Effect * e, bool & stop)
|
|
|
|
{
|
|
|
|
e->adjustTargetTypes(ret);
|
|
|
|
stop = ret.empty();
|
|
|
|
});
|
2015-10-01 01:36:00 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
return ret;
|
2015-09-16 08:44:18 +02:00
|
|
|
}
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::vector<Destination> BattleSpellMechanics::getPossibleDestinations(size_t index, AimType aimType, const Target & current) const
|
2016-09-05 10:36:25 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
//TODO: BattleSpellMechanics::getPossibleDestinations
|
2016-09-05 10:36:25 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(index != 0)
|
|
|
|
return std::vector<Destination>();
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::vector<Destination> ret;
|
2016-03-04 15:42:55 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
switch(aimType)
|
2016-09-29 09:45:22 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
case AimType::CREATURE:
|
|
|
|
case AimType::LOCATION:
|
|
|
|
for(int i = 0; i < GameConstants::BFIELD_SIZE; i++)
|
2016-09-29 17:55:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
BattleHex dest(i);
|
|
|
|
if(dest.isAvailable())
|
2016-09-29 17:55:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
Target tmp = current;
|
|
|
|
tmp.emplace_back(dest);
|
|
|
|
|
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
|
|
|
detail::ProblemImpl ingored;
|
|
|
|
|
2021-02-20 03:57:50 +02:00
|
|
|
if(canBeCastAt(tmp, ingored))
|
2017-07-20 06:08:49 +02:00
|
|
|
ret.emplace_back(dest);
|
2016-09-29 17:55:07 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
break;
|
|
|
|
case AimType::NO_TARGET:
|
|
|
|
ret.emplace_back();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2016-09-29 17:55:07 +02:00
|
|
|
}
|
2016-09-29 09:45:22 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
return ret;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
bool BattleSpellMechanics::isReceptive(const battle::Unit * target) const
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return targetCondition->isReceptive(this, target);
|
2017-06-06 06:53:51 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::vector<BattleHex> BattleSpellMechanics::rangeInHexes(BattleHex centralHex, bool * outDroppedHexes) const
|
2015-04-02 23:02:15 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(isMassive() || !centralHex.isValid())
|
|
|
|
return std::vector<BattleHex>(1, BattleHex::INVALID);
|
2016-09-18 15:30:03 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
Target aimPoint;
|
|
|
|
aimPoint.push_back(Destination(centralHex));
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
Target spellTarget = transformSpellTarget(aimPoint);
|
2015-04-02 23:02:15 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::set<BattleHex> effectRange;
|
2015-04-02 23:02:15 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
effects->forEachEffect(getEffectLevel(), [&](const effects::Effect * effect, bool & stop)
|
2015-09-30 21:38:50 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(!effect->indirect)
|
2015-09-30 21:38:50 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
effect->adjustAffectedHexes(effectRange, this, spellTarget);
|
2015-09-30 21:38:50 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
});
|
2016-09-06 11:26:01 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::vector<BattleHex> ret;
|
|
|
|
ret.reserve(effectRange.size());
|
2016-09-06 11:26:01 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::copy(effectRange.begin(), effectRange.end(), std::back_inserter(ret));
|
2016-09-24 08:27:58 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
return ret;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
2015-02-26 19:59:18 +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 Spell * BattleSpellMechanics::getSpell() const
|
|
|
|
{
|
|
|
|
return owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-18 15:30:03 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
|