mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
(somewhat) configurable adventure map spells
- All adventure map spells have most of their parameters in json. - Parameters of adventure map spells can now be defined separately per each mastery level. - It is now possible to add a new spell that will have effect similar to H3 adventure map spell
This commit is contained in:
78
lib/spells/adventure/RemoveObjectEffect.cpp
Normal file
78
lib/spells/adventure/RemoveObjectEffect.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* RemoveObjectEffect.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 "RemoveObjectEffect.h"
|
||||
|
||||
#include "../CSpellHandler.h"
|
||||
|
||||
#include "../../callback/IGameInfoCallback.h"
|
||||
#include "../../mapObjects/CGHeroInstance.h"
|
||||
#include "../../mapping/CMap.h"
|
||||
#include "../../networkPacks/PacksForClient.h"
|
||||
#include "../../modding/IdentifierStorage.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
RemoveObjectEffect::RemoveObjectEffect(const CSpell * s, const JsonNode & config)
|
||||
: AdventureSpellRangedEffect(config)
|
||||
, owner(s)
|
||||
, failMessage(MetaString::createFromTextID("core.genrltxt.337")) //%s tried to scuttle the boat, but failed
|
||||
{
|
||||
for(const auto & objectNode : config["objects"].Struct())
|
||||
{
|
||||
if(objectNode.second.Bool())
|
||||
{
|
||||
LIBRARY->identifiers()->requestIdentifier(objectNode.second.getModScope(), "object", objectNode.first, [this](si32 index)
|
||||
{
|
||||
removedObjects.push_back(MapObjectID(index));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool RemoveObjectEffect::canBeCastAtImpl(spells::Problem & problem, const IGameInfoCallback * cb, const spells::Caster * caster, const int3 & pos) const
|
||||
{
|
||||
if (!AdventureSpellRangedEffect::canBeCastAtImpl(problem, cb, caster, pos))
|
||||
return false;
|
||||
|
||||
const TerrainTile * t = cb->getTile(pos);
|
||||
if(!t || t->visitableObjects.empty())
|
||||
return false;
|
||||
|
||||
const CGObjectInstance * topObject = cb->getObj(t->visitableObjects.back());
|
||||
|
||||
return vstd::contains(removedObjects, topObject->ID);
|
||||
}
|
||||
|
||||
ESpellCastResult RemoveObjectEffect::applyAdventureEffects(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
||||
{
|
||||
const auto schoolLevel = parameters.caster->getSpellSchoolLevel(owner);
|
||||
//check if spell works at all
|
||||
if(env->getRNG()->nextInt(0, 99) >= owner->getLevelPower(schoolLevel)) //power is % chance of success
|
||||
{
|
||||
InfoWindow iw;
|
||||
iw.player = parameters.caster->getCasterOwner();
|
||||
iw.text = failMessage;
|
||||
parameters.caster->getCasterName(iw.text);
|
||||
env->apply(iw);
|
||||
return ESpellCastResult::OK;
|
||||
}
|
||||
|
||||
const TerrainTile & t = env->getMap()->getTile(parameters.pos);
|
||||
|
||||
RemoveObject ro;
|
||||
ro.initiator = parameters.caster->getCasterOwner();
|
||||
ro.objectID = t.visitableObjects.back();
|
||||
env->apply(ro);
|
||||
return ESpellCastResult::OK;
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
Reference in New Issue
Block a user