2022-07-26 15:07:42 +02:00
|
|
|
/*
|
2014-06-05 20:26:50 +03:00
|
|
|
* CGPandoraBox.cpp, part of VCMI engine
|
2014-06-05 19:52:14 +03:00
|
|
|
*
|
|
|
|
* 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 "CGPandoraBox.h"
|
|
|
|
|
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/Spell.h>
|
|
|
|
#include <vcmi/spells/Service.h>
|
|
|
|
|
2014-06-05 20:26:50 +03:00
|
|
|
#include "../NetPacks.h"
|
2014-06-05 23:51:24 +03:00
|
|
|
#include "../CSoundBase.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2018-03-31 07:56:40 +02:00
|
|
|
#include "../CSkillHandler.h"
|
2014-06-25 17:11:07 +03:00
|
|
|
#include "../StartInfo.h"
|
|
|
|
#include "../IGameCallback.h"
|
2016-11-13 12:38:42 +02:00
|
|
|
#include "../StringConstants.h"
|
|
|
|
#include "../serializer/JsonSerializeFormat.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGPandoraBox::initObj(CRandomGenerator & rand)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
blockVisit = (ID==Obj::PANDORAS_BOX); //block only if it's really pandora's box (events also derive from that class)
|
|
|
|
hasGuardians = stacks.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const
|
|
|
|
{
|
|
|
|
BlockingDialog bd (true, false);
|
|
|
|
bd.player = h->getOwner();
|
2023-06-18 11:18:25 +02:00
|
|
|
bd.text.appendLocalString (EMetaText::ADVOB_TXT, 14);
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->showBlockingDialog (&bd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGPandoraBox::giveContentsUpToExp(const CGHeroInstance *h) const
|
|
|
|
{
|
2015-11-28 22:03:26 +02:00
|
|
|
afterSuccessfulVisit();
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
InfoWindow iw;
|
2023-03-07 03:09:19 +02:00
|
|
|
iw.type = EInfoWindowMode::AUTO;
|
2014-06-05 19:52:14 +03:00
|
|
|
iw.player = h->getOwner();
|
|
|
|
|
|
|
|
bool changesPrimSkill = false;
|
2023-02-12 22:39:17 +02:00
|
|
|
for(const auto & elem : primskills)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
if(elem)
|
|
|
|
{
|
|
|
|
changesPrimSkill = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-10-09 12:38:54 +02:00
|
|
|
|
2016-09-20 12:40:58 +02:00
|
|
|
std::vector<std::pair<SecondarySkill, ui8>> unpossessedAbilities; //ability + ability level
|
|
|
|
int abilitiesRequiringSlot = 0;
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2016-09-20 12:40:58 +02:00
|
|
|
//filter out unnecessary secondary skills
|
|
|
|
for (int i = 0; i < abilities.size(); i++)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2016-09-20 12:40:58 +02:00
|
|
|
int curLev = h->getSecSkillLevel(abilities[i]);
|
|
|
|
bool abilityCanUseSlot = !curLev && ((h->secSkills.size() + abilitiesRequiringSlot) < GameConstants::SKILL_PER_HERO); //limit new abilities to number of slots
|
2016-09-19 20:05:57 +02:00
|
|
|
|
2016-09-20 12:40:58 +02:00
|
|
|
if (abilityCanUseSlot)
|
|
|
|
abilitiesRequiringSlot++;
|
2016-09-19 20:05:57 +02:00
|
|
|
|
2016-09-20 12:40:58 +02:00
|
|
|
if ((curLev && curLev < abilityLevels[i]) || abilityCanUseSlot)
|
|
|
|
{
|
2023-02-12 22:39:17 +02:00
|
|
|
unpossessedAbilities.emplace_back(abilities[i], abilityLevels[i]);
|
2016-09-19 20:05:57 +02:00
|
|
|
}
|
2016-09-20 12:40:58 +02:00
|
|
|
}
|
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
if(gainedExp || changesPrimSkill || !unpossessedAbilities.empty())
|
2016-09-20 12:40:58 +02:00
|
|
|
{
|
2014-06-05 19:52:14 +03:00
|
|
|
TExpType expVal = h->calculateXp(gainedExp);
|
|
|
|
//getText(iw,afterBattle,175,h); //wtf?
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 175); //%s learns something
|
|
|
|
iw.text.replaceRawString(h->getNameTranslated());
|
2016-10-09 12:38:54 +02:00
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
if(expVal)
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::EXPERIENCE, 0, static_cast<si32>(expVal), 0);
|
2016-10-09 12:38:54 +02:00
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
for(int i=0; i<primskills.size(); i++)
|
|
|
|
if(primskills[i])
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::PRIM_SKILL, i, primskills[i], 0);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
for(const auto & abilityData : unpossessedAbilities)
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::SEC_SKILL, abilityData.first, abilityData.second, 0);
|
2016-10-09 12:38:54 +02:00
|
|
|
|
2016-09-20 12:40:58 +02:00
|
|
|
cb->showInfoDialog(&iw);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
//give sec skills
|
2023-02-12 22:39:17 +02:00
|
|
|
for(const auto & abilityData : unpossessedAbilities)
|
2016-09-20 12:40:58 +02:00
|
|
|
cb->changeSecSkill(h, abilityData.first, abilityData.second, true);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2016-09-19 20:05:57 +02:00
|
|
|
assert(h->secSkills.size() <= GameConstants::SKILL_PER_HERO);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
//give prim skills
|
|
|
|
for(int i=0; i<primskills.size(); i++)
|
|
|
|
if(primskills[i])
|
|
|
|
cb->changePrimSkill(h,static_cast<PrimarySkill::PrimarySkill>(i),primskills[i],false);
|
|
|
|
|
|
|
|
assert(!cb->isVisitCoveredByAnotherQuery(this, h));
|
|
|
|
|
|
|
|
//give exp
|
|
|
|
if(expVal)
|
|
|
|
cb->changePrimSkill(h, PrimarySkill::EXPERIENCE, expVal, false);
|
|
|
|
}
|
2016-09-20 12:40:58 +02:00
|
|
|
//else { } //TODO:Create information that box was empty for now, and deliver to CGPandoraBox::giveContentsAfterExp or refactor
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
if(!cb->isVisitCoveredByAnotherQuery(this, h))
|
|
|
|
giveContentsAfterExp(h);
|
|
|
|
//Otherwise continuation occurs via post-level-up callback.
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGPandoraBox::giveContentsAfterExp(const CGHeroInstance *h) const
|
|
|
|
{
|
|
|
|
bool hadGuardians = hasGuardians; //copy, because flag will be emptied after issuing first post-battle message
|
|
|
|
|
|
|
|
std::string msg = message; //in case box is removed in the meantime
|
|
|
|
InfoWindow iw;
|
2023-03-07 03:09:19 +02:00
|
|
|
iw.type = EInfoWindowMode::AUTO;
|
2014-06-05 19:52:14 +03:00
|
|
|
iw.player = h->getOwner();
|
|
|
|
|
2016-06-06 09:30:45 +02:00
|
|
|
//TODO: reuse this code for Scholar skill
|
2023-02-12 22:39:17 +02:00
|
|
|
if(!spells.empty())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2016-10-09 12:38:54 +02:00
|
|
|
std::set<SpellID> spellsToGive;
|
2016-06-06 09:30:45 +02:00
|
|
|
|
|
|
|
auto i = spells.cbegin();
|
|
|
|
while (i != spells.cend())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2016-06-06 09:30:45 +02:00
|
|
|
iw.components.clear();
|
|
|
|
iw.text.clear();
|
|
|
|
spellsToGive.clear();
|
|
|
|
|
|
|
|
for (; i != spells.cend(); i++)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-02-12 22:39:17 +02:00
|
|
|
const auto * spell = (*i).toSpell(VLC->spells());
|
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(h->canLearnSpell(spell))
|
2016-06-06 09:30:45 +02:00
|
|
|
{
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::SPELL, *i, 0, 0);
|
2016-06-06 09:30:45 +02:00
|
|
|
spellsToGive.insert(*i);
|
|
|
|
}
|
2016-10-09 12:38:54 +02:00
|
|
|
if(spellsToGive.size() == 8) //display up to 8 spells at once
|
2016-06-06 09:30:45 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!spellsToGive.empty())
|
|
|
|
{
|
|
|
|
if (spellsToGive.size() > 1)
|
|
|
|
{
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 188); //%s learns spells
|
2016-06-06 09:30:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 184); //%s learns a spell
|
2016-06-06 09:30:45 +02:00
|
|
|
}
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.replaceRawString(h->getNameTranslated());
|
2016-06-06 09:30:45 +02:00
|
|
|
cb->changeSpells(h, true, spellsToGive);
|
|
|
|
cb->showInfoDialog(&iw);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(manaDiff)
|
|
|
|
{
|
|
|
|
getText(iw,hadGuardians,manaDiff,176,177,h);
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::PRIM_SKILL, 5, manaDiff, 0);
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
cb->setManaPoints(h->id, h->mana + manaDiff);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(moraleDiff)
|
|
|
|
{
|
|
|
|
getText(iw,hadGuardians,moraleDiff,178,179,h);
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::MORALE, 0, moraleDiff, 0);
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
GiveBonus gb;
|
2023-05-01 00:20:01 +02:00
|
|
|
gb.bonus = Bonus(BonusDuration::ONE_BATTLE,BonusType::MORALE,BonusSource::OBJECT,moraleDiff,id.getNum(),"");
|
2014-06-05 19:52:14 +03:00
|
|
|
gb.id = h->id.getNum();
|
|
|
|
cb->giveHeroBonus(&gb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(luckDiff)
|
|
|
|
{
|
|
|
|
getText(iw,hadGuardians,luckDiff,180,181,h);
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::LUCK, 0, luckDiff, 0);
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
GiveBonus gb;
|
2023-05-01 00:20:01 +02:00
|
|
|
gb.bonus = Bonus(BonusDuration::ONE_BATTLE,BonusType::LUCK,BonusSource::OBJECT,luckDiff,id.getNum(),"");
|
2014-06-05 19:52:14 +03:00
|
|
|
gb.id = h->id.getNum();
|
|
|
|
cb->giveHeroBonus(&gb);
|
|
|
|
}
|
|
|
|
|
|
|
|
iw.components.clear();
|
|
|
|
iw.text.clear();
|
|
|
|
for(int i=0; i<resources.size(); i++)
|
|
|
|
{
|
|
|
|
if(resources[i] < 0)
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::RESOURCE, i, resources[i], 0);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2023-02-12 22:39:17 +02:00
|
|
|
if(!iw.components.empty())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
getText(iw,hadGuardians,182,h);
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
}
|
|
|
|
|
|
|
|
iw.components.clear();
|
|
|
|
iw.text.clear();
|
|
|
|
for(int i=0; i<resources.size(); i++)
|
|
|
|
{
|
|
|
|
if(resources[i] > 0)
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::RESOURCE, i, resources[i], 0);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2023-02-12 22:39:17 +02:00
|
|
|
if(!iw.components.empty())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
getText(iw,hadGuardians,183,h);
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
}
|
|
|
|
|
|
|
|
iw.components.clear();
|
|
|
|
// getText(iw,afterBattle,183,h);
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 183); //% has found treasure
|
|
|
|
iw.text.replaceRawString(h->getNameTranslated());
|
2023-02-12 22:39:17 +02:00
|
|
|
for(const auto & elem : artifacts)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-03-10 14:54:12 +02:00
|
|
|
iw.components.emplace_back(Component::EComponentType::ARTIFACT, elem, 0, 0);
|
2014-06-05 19:52:14 +03:00
|
|
|
if(iw.components.size() >= 14)
|
|
|
|
{
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
iw.components.clear();
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 183); //% has found treasure - once more?
|
|
|
|
iw.text.replaceRawString(h->getNameTranslated());
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
2023-02-12 22:39:17 +02:00
|
|
|
if(!iw.components.empty())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
}
|
|
|
|
|
2016-11-26 14:14:43 +02:00
|
|
|
cb->giveResources(h->getOwner(), resources);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
for(const auto & elem : artifacts)
|
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
|
|
|
cb->giveHeroNewArtifact(h, VLC->arth->objects[elem],ArtifactPosition::FIRST_AVAILABLE);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
iw.components.clear();
|
|
|
|
iw.text.clear();
|
|
|
|
|
2015-12-24 20:30:57 +02:00
|
|
|
if(creatures.stacksCount())
|
2014-06-05 19:52:14 +03:00
|
|
|
{ //this part is taken straight from creature bank
|
|
|
|
MetaString loot;
|
2023-02-12 22:39:17 +02:00
|
|
|
for(const auto & elem : creatures.Slots())
|
2014-06-05 19:52:14 +03:00
|
|
|
{ //build list of joined creatures
|
2023-02-12 22:39:17 +02:00
|
|
|
iw.components.emplace_back(*elem.second);
|
2023-06-18 11:18:25 +02:00
|
|
|
loot.appendRawString("%s");
|
|
|
|
loot.replaceCreatureName(*elem.second);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2015-12-24 20:30:57 +02:00
|
|
|
if(creatures.stacksCount() == 1 && creatures.Slots().begin()->second->count == 1)
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 185);
|
2014-06-05 19:52:14 +03:00
|
|
|
else
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 186);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.replaceRawString(loot.buildList());
|
|
|
|
iw.text.replaceRawString(h->getNameTranslated());
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
cb->showInfoDialog(&iw);
|
2016-02-17 10:28:54 +02:00
|
|
|
cb->giveCreatures(this, h, creatures, false);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2023-02-12 22:39:17 +02:00
|
|
|
if(!hasGuardians && !msg.empty())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendRawString(msg);
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGPandoraBox::getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const
|
|
|
|
{
|
2023-02-12 22:39:17 +02:00
|
|
|
if(afterBattle || message.empty())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT,text);//%s has lost treasure.
|
|
|
|
iw.text.replaceRawString(h->getNameTranslated());
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendRawString(message);
|
2014-06-05 19:52:14 +03:00
|
|
|
afterBattle = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGPandoraBox::getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const
|
|
|
|
{
|
|
|
|
iw.components.clear();
|
|
|
|
iw.text.clear();
|
2023-02-12 22:39:17 +02:00
|
|
|
if(afterBattle || message.empty())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT,val < 0 ? negative : positive); //%s's luck takes a turn for the worse / %s's luck increases
|
|
|
|
iw.text.replaceRawString(h->getNameTranslated());
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendRawString(message);
|
2014-06-05 19:52:14 +03:00
|
|
|
afterBattle = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGPandoraBox::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
|
|
|
|
{
|
2016-01-26 07:41:09 +02:00
|
|
|
if(result.winner == 0)
|
|
|
|
{
|
|
|
|
giveContentsUpToExp(hero);
|
|
|
|
}
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGPandoraBox::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
|
|
|
|
{
|
2015-12-24 20:30:57 +02:00
|
|
|
if(answer)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2015-12-24 20:30:57 +02:00
|
|
|
if(stacksCount() > 0) //if pandora's box is protected by army
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-03-08 00:32:21 +02:00
|
|
|
hero->showInfoDialog(16, 0, EInfoWindowMode::MODAL);
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->startBattleI(hero, this); //grants things after battle
|
|
|
|
}
|
2023-02-12 22:39:17 +02:00
|
|
|
else if(message.empty() && resources.empty()
|
|
|
|
&& primskills.empty() && abilities.empty()
|
|
|
|
&& abilityLevels.empty() && artifacts.empty()
|
2023-06-15 22:06:31 +02:00
|
|
|
&& spells.empty() && creatures.stacksCount() == 0
|
2014-06-05 19:52:14 +03:00
|
|
|
&& gainedExp == 0 && manaDiff == 0 && moraleDiff == 0 && luckDiff == 0) //if it gives nothing without battle
|
|
|
|
{
|
2023-03-08 00:32:21 +02:00
|
|
|
hero->showInfoDialog(15);
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->removeObject(this);
|
|
|
|
}
|
|
|
|
else //if it gives something without battle
|
|
|
|
{
|
|
|
|
giveContentsUpToExp(hero);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGPandoraBox::heroLevelUpDone(const CGHeroInstance *hero) const
|
|
|
|
{
|
|
|
|
giveContentsAfterExp(hero);
|
|
|
|
}
|
|
|
|
|
2015-11-28 22:03:26 +02:00
|
|
|
void CGPandoraBox::afterSuccessfulVisit() const
|
|
|
|
{
|
|
|
|
cb->removeAfterVisit(this);
|
|
|
|
}
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
void CGPandoraBox::serializeJsonOptions(JsonSerializeFormat & handler)
|
|
|
|
{
|
|
|
|
CCreatureSet::serializeJson(handler, "guards", 7);
|
|
|
|
handler.serializeString("guardMessage", message);
|
|
|
|
|
|
|
|
handler.serializeInt("experience", gainedExp, 0);
|
|
|
|
handler.serializeInt("mana", manaDiff, 0);
|
|
|
|
handler.serializeInt("morale", moraleDiff, 0);
|
|
|
|
handler.serializeInt("luck", luckDiff, 0);
|
|
|
|
|
|
|
|
resources.serializeJson(handler, "resources");
|
|
|
|
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
bool haveSkills = false;
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(handler.saving)
|
|
|
|
{
|
2023-02-12 22:39:17 +02:00
|
|
|
for(int primskill : primskills)
|
|
|
|
if(primskill != 0)
|
2017-07-20 06:08:49 +02:00
|
|
|
haveSkills = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
primskills.resize(GameConstants::PRIMARY_SKILLS,0);
|
|
|
|
haveSkills = true;
|
|
|
|
}
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(haveSkills)
|
|
|
|
{
|
|
|
|
auto s = handler.enterStruct("primarySkills");
|
|
|
|
for(int idx = 0; idx < primskills.size(); idx ++)
|
|
|
|
handler.serializeInt(PrimarySkill::names[idx], primskills[idx], 0);
|
|
|
|
}
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(handler.saving)
|
|
|
|
{
|
|
|
|
if(!abilities.empty())
|
|
|
|
{
|
|
|
|
auto s = handler.enterStruct("secondarySkills");
|
|
|
|
|
|
|
|
for(size_t idx = 0; idx < abilities.size(); idx++)
|
|
|
|
{
|
2018-03-31 07:56:40 +02:00
|
|
|
handler.serializeEnum(CSkillHandler::encodeSkill(abilities[idx]), abilityLevels[idx], NSecondarySkill::levels);
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto s = handler.enterStruct("secondarySkills");
|
|
|
|
|
|
|
|
const JsonNode & skillMap = handler.getCurrent();
|
|
|
|
|
|
|
|
abilities.clear();
|
|
|
|
abilityLevels.clear();
|
|
|
|
|
|
|
|
for(const auto & p : skillMap.Struct())
|
|
|
|
{
|
2017-08-12 13:36:04 +02:00
|
|
|
const std::string skillName = p.first;
|
|
|
|
const std::string levelId = p.second.String();
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2018-03-31 07:56:40 +02:00
|
|
|
const int rawId = CSkillHandler::decodeSkill(skillName);
|
2016-11-13 12:38:42 +02:00
|
|
|
if(rawId < 0)
|
|
|
|
{
|
2017-08-12 13:36:04 +02:00
|
|
|
logGlobal->error("Invalid secondary skill %s", skillName);
|
2016-11-13 12:38:42 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int level = vstd::find_pos(NSecondarySkill::levels, levelId);
|
|
|
|
if(level < 0)
|
|
|
|
{
|
2017-08-12 13:36:04 +02:00
|
|
|
logGlobal->error("Invalid secondary skill level %s", levelId);
|
2016-11-13 12:38:42 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
abilities.emplace_back(rawId);
|
2016-11-13 12:38:42 +02:00
|
|
|
abilityLevels.push_back(level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
handler.serializeIdArray("artifacts", artifacts);
|
|
|
|
handler.serializeIdArray("spells", spells);
|
2016-11-13 12:38:42 +02:00
|
|
|
|
|
|
|
creatures.serializeJson(handler, "creatures");
|
|
|
|
}
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
void CGEvent::onHeroVisit( const CGHeroInstance * h ) const
|
|
|
|
{
|
|
|
|
if(!(availableFor & (1 << h->tempOwner.getNum())))
|
|
|
|
return;
|
2018-01-05 19:21:07 +02:00
|
|
|
if(cb->getPlayerSettings(h->tempOwner)->isControlledByHuman())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
if(humanActivate)
|
|
|
|
activated(h);
|
|
|
|
}
|
|
|
|
else if(computerActivate)
|
|
|
|
activated(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGEvent::activated( const CGHeroInstance * h ) const
|
|
|
|
{
|
|
|
|
if(stacksCount() > 0)
|
|
|
|
{
|
|
|
|
InfoWindow iw;
|
|
|
|
iw.player = h->tempOwner;
|
2023-02-12 22:39:17 +02:00
|
|
|
if(!message.empty())
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendRawString(message);
|
2014-06-05 19:52:14 +03:00
|
|
|
else
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 16);
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
cb->startBattleI(h, this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
giveContentsUpToExp(h);
|
|
|
|
}
|
|
|
|
}
|
2015-11-28 22:03:26 +02:00
|
|
|
|
|
|
|
void CGEvent::afterSuccessfulVisit() const
|
|
|
|
{
|
|
|
|
if(removeAfterVisit)
|
|
|
|
{
|
|
|
|
cb->removeAfterVisit(this);
|
|
|
|
}
|
|
|
|
else if(hasGuardians)
|
|
|
|
hasGuardians = false;
|
|
|
|
}
|
2016-11-13 12:38:42 +02:00
|
|
|
|
|
|
|
void CGEvent::serializeJsonOptions(JsonSerializeFormat & handler)
|
|
|
|
{
|
|
|
|
CGPandoraBox::serializeJsonOptions(handler);
|
|
|
|
|
|
|
|
handler.serializeBool<bool>("aIActivable", computerActivate, true, false, false);
|
|
|
|
handler.serializeBool<bool>("humanActivable", humanActivate, true, false, true);
|
|
|
|
handler.serializeBool<bool>("removeAfterVisit", removeAfterVisit, true, false, false);
|
|
|
|
|
|
|
|
{
|
|
|
|
auto decodePlayer = [](const std::string & id)->si32
|
|
|
|
{
|
|
|
|
return vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, id);
|
|
|
|
};
|
|
|
|
|
|
|
|
auto encodePlayer = [](si32 idx)->std::string
|
|
|
|
{
|
|
|
|
return GameConstants::PLAYER_COLOR_NAMES[idx];
|
|
|
|
};
|
|
|
|
|
|
|
|
handler.serializeIdArray<ui8, PlayerColor::PLAYER_LIMIT_I>("availableFor", availableFor, GameConstants::ALL_PLAYERS, decodePlayer, encodePlayer);
|
|
|
|
}
|
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|