|
@@ -25,297 +25,117 @@
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
-void CGPandoraBox::initObj(CRandomGenerator & rand)
|
|
|
|
|
|
+void CGPandoraBox::init()
|
|
{
|
|
{
|
|
- blockVisit = (ID==Obj::PANDORAS_BOX); //block only if it's really pandora's box (events also derive from that class)
|
|
|
|
- hasGuardians = stacks.size();
|
|
|
|
|
|
+ blockVisit = true;
|
|
|
|
+
|
|
|
|
+ for(auto & i : configuration.info)
|
|
|
|
+ i.reward.removeObject = true;
|
|
}
|
|
}
|
|
|
|
|
|
-void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const
|
|
|
|
|
|
+void CGPandoraBox::initObj(CRandomGenerator & rand)
|
|
{
|
|
{
|
|
- BlockingDialog bd (true, false);
|
|
|
|
- bd.player = h->getOwner();
|
|
|
|
- bd.text.appendLocalString (EMetaText::ADVOB_TXT, 14);
|
|
|
|
- cb->showBlockingDialog (&bd);
|
|
|
|
|
|
+ init();
|
|
|
|
+
|
|
|
|
+ CRewardableObject::initObj(rand);
|
|
}
|
|
}
|
|
|
|
|
|
-void CGPandoraBox::giveContentsUpToExp(const CGHeroInstance *h) const
|
|
|
|
|
|
+void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const
|
|
{
|
|
{
|
|
- afterSuccessfulVisit();
|
|
|
|
-
|
|
|
|
- InfoWindow iw;
|
|
|
|
- iw.type = EInfoWindowMode::AUTO;
|
|
|
|
- iw.player = h->getOwner();
|
|
|
|
-
|
|
|
|
- bool changesPrimSkill = false;
|
|
|
|
- for(const auto & elem : primskills)
|
|
|
|
|
|
+ auto setText = [](MetaString & text, int tId, const CGHeroInstance * h)
|
|
{
|
|
{
|
|
- if(elem)
|
|
|
|
- {
|
|
|
|
- changesPrimSkill = true;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- std::vector<std::pair<SecondarySkill, ui8>> unpossessedAbilities; //ability + ability level
|
|
|
|
- int abilitiesRequiringSlot = 0;
|
|
|
|
-
|
|
|
|
- //filter out unnecessary secondary skills
|
|
|
|
- for (int i = 0; i < abilities.size(); i++)
|
|
|
|
|
|
+ text.appendLocalString(EMetaText::ADVOB_TXT, tId);
|
|
|
|
+ text.replaceRawString(h->getNameTranslated());
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ for(auto i : getAvailableRewards(h, Rewardable::EEventType::EVENT_FIRST_VISIT))
|
|
{
|
|
{
|
|
- int curLev = h->getSecSkillLevel(abilities[i]);
|
|
|
|
- bool abilityCanUseSlot = !curLev && ((h->secSkills.size() + abilitiesRequiringSlot) < GameConstants::SKILL_PER_HERO); //limit new abilities to number of slots
|
|
|
|
-
|
|
|
|
- if (abilityCanUseSlot)
|
|
|
|
- abilitiesRequiringSlot++;
|
|
|
|
-
|
|
|
|
- if ((curLev && curLev < abilityLevels[i]) || abilityCanUseSlot)
|
|
|
|
|
|
+ MetaString txt;
|
|
|
|
+ auto & r = configuration.info[i];
|
|
|
|
+
|
|
|
|
+ if(r.reward.spells.size() == 1)
|
|
|
|
+ setText(txt, 184, h);
|
|
|
|
+ else if(!r.reward.spells.empty())
|
|
|
|
+ setText(txt, 188, h);
|
|
|
|
+
|
|
|
|
+ if(r.reward.heroExperience || !r.reward.secondary.empty())
|
|
|
|
+ setText(txt, 175, h);
|
|
|
|
+
|
|
|
|
+ for(int ps : r.reward.primary)
|
|
{
|
|
{
|
|
- unpossessedAbilities.emplace_back(abilities[i], abilityLevels[i]);
|
|
|
|
|
|
+ if(ps)
|
|
|
|
+ {
|
|
|
|
+ setText(txt, 175, h);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- if(gainedExp || changesPrimSkill || !unpossessedAbilities.empty())
|
|
|
|
- {
|
|
|
|
- TExpType expVal = h->calculateXp(gainedExp);
|
|
|
|
- //getText(iw,afterBattle,175,h); //wtf?
|
|
|
|
- iw.text.appendLocalString(EMetaText::ADVOB_TXT, 175); //%s learns something
|
|
|
|
- iw.text.replaceRawString(h->getNameTranslated());
|
|
|
|
-
|
|
|
|
- if(expVal)
|
|
|
|
- iw.components.emplace_back(Component::EComponentType::EXPERIENCE, 0, static_cast<si32>(expVal), 0);
|
|
|
|
-
|
|
|
|
- for(int i=0; i<primskills.size(); i++)
|
|
|
|
- if(primskills[i])
|
|
|
|
- iw.components.emplace_back(Component::EComponentType::PRIM_SKILL, i, primskills[i], 0);
|
|
|
|
-
|
|
|
|
- for(const auto & abilityData : unpossessedAbilities)
|
|
|
|
- iw.components.emplace_back(Component::EComponentType::SEC_SKILL, abilityData.first, abilityData.second, 0);
|
|
|
|
-
|
|
|
|
- cb->showInfoDialog(&iw);
|
|
|
|
-
|
|
|
|
- //give sec skills
|
|
|
|
- for(const auto & abilityData : unpossessedAbilities)
|
|
|
|
- cb->changeSecSkill(h, abilityData.first, abilityData.second, true);
|
|
|
|
-
|
|
|
|
- assert(h->secSkills.size() <= GameConstants::SKILL_PER_HERO);
|
|
|
|
-
|
|
|
|
- //give prim skills
|
|
|
|
- for(int i=0; i<primskills.size(); i++)
|
|
|
|
- if(primskills[i])
|
|
|
|
- cb->changePrimSkill(h,static_cast<PrimarySkill>(i),primskills[i],false);
|
|
|
|
-
|
|
|
|
- assert(!cb->isVisitCoveredByAnotherQuery(this, h));
|
|
|
|
-
|
|
|
|
- //give exp
|
|
|
|
- if(expVal)
|
|
|
|
- cb->changePrimSkill(h, PrimarySkill::EXPERIENCE, expVal, false);
|
|
|
|
- }
|
|
|
|
- //else { } //TODO:Create information that box was empty for now, and deliver to CGPandoraBox::giveContentsAfterExp or refactor
|
|
|
|
-
|
|
|
|
- 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;
|
|
|
|
- iw.type = EInfoWindowMode::AUTO;
|
|
|
|
- iw.player = h->getOwner();
|
|
|
|
-
|
|
|
|
- //TODO: reuse this code for Scholar skill
|
|
|
|
- if(!spells.empty())
|
|
|
|
- {
|
|
|
|
- std::set<SpellID> spellsToGive;
|
|
|
|
-
|
|
|
|
- auto i = spells.cbegin();
|
|
|
|
- while (i != spells.cend())
|
|
|
|
|
|
+
|
|
|
|
+ if(r.reward.manaDiff < 0)
|
|
|
|
+ setText(txt, 176, h);
|
|
|
|
+ if(r.reward.manaDiff > 0)
|
|
|
|
+ setText(txt, 177, h);
|
|
|
|
+
|
|
|
|
+ for(auto b : r.reward.bonuses)
|
|
{
|
|
{
|
|
- iw.components.clear();
|
|
|
|
- iw.text.clear();
|
|
|
|
- spellsToGive.clear();
|
|
|
|
-
|
|
|
|
- for (; i != spells.cend(); i++)
|
|
|
|
|
|
+ if(b.type == BonusType::MORALE)
|
|
{
|
|
{
|
|
- const auto * spell = (*i).toSpell(VLC->spells());
|
|
|
|
- if(h->canLearnSpell(spell))
|
|
|
|
- {
|
|
|
|
- iw.components.emplace_back(Component::EComponentType::SPELL, *i, 0, 0);
|
|
|
|
- spellsToGive.insert(*i);
|
|
|
|
- }
|
|
|
|
- if(spellsToGive.size() == 8) //display up to 8 spells at once
|
|
|
|
- {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ if(b.val < 0)
|
|
|
|
+ setText(txt, 178, h);
|
|
|
|
+ if(b.val > 0)
|
|
|
|
+ setText(txt, 179, h);
|
|
}
|
|
}
|
|
- if (!spellsToGive.empty())
|
|
|
|
|
|
+ if(b.type == BonusType::LUCK)
|
|
{
|
|
{
|
|
- if (spellsToGive.size() > 1)
|
|
|
|
- {
|
|
|
|
- iw.text.appendLocalString(EMetaText::ADVOB_TXT, 188); //%s learns spells
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- iw.text.appendLocalString(EMetaText::ADVOB_TXT, 184); //%s learns a spell
|
|
|
|
- }
|
|
|
|
- iw.text.replaceRawString(h->getNameTranslated());
|
|
|
|
- cb->changeSpells(h, true, spellsToGive);
|
|
|
|
- cb->showInfoDialog(&iw);
|
|
|
|
|
|
+ if(b.val < 0)
|
|
|
|
+ setText(txt, 180, h);
|
|
|
|
+ if(b.val > 0)
|
|
|
|
+ setText(txt, 181, h);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- if(manaDiff)
|
|
|
|
- {
|
|
|
|
- getText(iw,hadGuardians,manaDiff,176,177,h);
|
|
|
|
- iw.components.emplace_back(Component::EComponentType::PRIM_SKILL, 5, manaDiff, 0);
|
|
|
|
- cb->showInfoDialog(&iw);
|
|
|
|
- cb->setManaPoints(h->id, h->mana + manaDiff);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(moraleDiff)
|
|
|
|
- {
|
|
|
|
- getText(iw,hadGuardians,moraleDiff,178,179,h);
|
|
|
|
- iw.components.emplace_back(Component::EComponentType::MORALE, 0, moraleDiff, 0);
|
|
|
|
- cb->showInfoDialog(&iw);
|
|
|
|
- GiveBonus gb;
|
|
|
|
- gb.bonus = Bonus(BonusDuration::ONE_BATTLE,BonusType::MORALE,BonusSource::OBJECT,moraleDiff,id.getNum(),"");
|
|
|
|
- gb.id = h->id.getNum();
|
|
|
|
- cb->giveHeroBonus(&gb);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(luckDiff)
|
|
|
|
- {
|
|
|
|
- getText(iw,hadGuardians,luckDiff,180,181,h);
|
|
|
|
- iw.components.emplace_back(Component::EComponentType::LUCK, 0, luckDiff, 0);
|
|
|
|
- cb->showInfoDialog(&iw);
|
|
|
|
- GiveBonus gb;
|
|
|
|
- gb.bonus = Bonus(BonusDuration::ONE_BATTLE,BonusType::LUCK,BonusSource::OBJECT,luckDiff,id.getNum(),"");
|
|
|
|
- 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)
|
|
|
|
- iw.components.emplace_back(Component::EComponentType::RESOURCE, i, resources[i], 0);
|
|
|
|
- }
|
|
|
|
- if(!iw.components.empty())
|
|
|
|
- {
|
|
|
|
- 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)
|
|
|
|
- iw.components.emplace_back(Component::EComponentType::RESOURCE, i, resources[i], 0);
|
|
|
|
- }
|
|
|
|
- if(!iw.components.empty())
|
|
|
|
- {
|
|
|
|
- getText(iw,hadGuardians,183,h);
|
|
|
|
- cb->showInfoDialog(&iw);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- iw.components.clear();
|
|
|
|
- // getText(iw,afterBattle,183,h);
|
|
|
|
- iw.text.appendLocalString(EMetaText::ADVOB_TXT, 183); //% has found treasure
|
|
|
|
- iw.text.replaceRawString(h->getNameTranslated());
|
|
|
|
- for(const auto & elem : artifacts)
|
|
|
|
- {
|
|
|
|
- iw.components.emplace_back(Component::EComponentType::ARTIFACT, elem, 0, 0);
|
|
|
|
- if(iw.components.size() >= 14)
|
|
|
|
|
|
+
|
|
|
|
+ for(auto res : r.reward.resources)
|
|
{
|
|
{
|
|
- cb->showInfoDialog(&iw);
|
|
|
|
- iw.components.clear();
|
|
|
|
- iw.text.appendLocalString(EMetaText::ADVOB_TXT, 183); //% has found treasure - once more?
|
|
|
|
- iw.text.replaceRawString(h->getNameTranslated());
|
|
|
|
|
|
+ if(res < 0)
|
|
|
|
+ setText(txt, 182, h);
|
|
|
|
+ if(res > 0)
|
|
|
|
+ setText(txt, 183, h);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- if(!iw.components.empty())
|
|
|
|
- {
|
|
|
|
- cb->showInfoDialog(&iw);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- cb->giveResources(h->getOwner(), resources);
|
|
|
|
-
|
|
|
|
- for(const auto & elem : artifacts)
|
|
|
|
- cb->giveHeroNewArtifact(h, VLC->arth->objects[elem],ArtifactPosition::FIRST_AVAILABLE);
|
|
|
|
-
|
|
|
|
- iw.components.clear();
|
|
|
|
- iw.text.clear();
|
|
|
|
-
|
|
|
|
- if(creatures.stacksCount())
|
|
|
|
- { //this part is taken straight from creature bank
|
|
|
|
- MetaString loot;
|
|
|
|
- for(const auto & elem : creatures.Slots())
|
|
|
|
- { //build list of joined creatures
|
|
|
|
- iw.components.emplace_back(*elem.second);
|
|
|
|
- loot.appendRawString("%s");
|
|
|
|
- loot.replaceCreatureName(*elem.second);
|
|
|
|
|
|
+
|
|
|
|
+ if(!r.reward.artifacts.empty())
|
|
|
|
+ setText(txt, 183, h);
|
|
|
|
+
|
|
|
|
+ if(!r.reward.creatures.empty())
|
|
|
|
+ {
|
|
|
|
+ MetaString loot;
|
|
|
|
+ for(auto c : r.reward.creatures)
|
|
|
|
+ {
|
|
|
|
+ loot.appendRawString("%s");
|
|
|
|
+ loot.replaceCreatureName(c);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(r.reward.creatures.size() == 1 && r.reward.creatures[0].count == 1)
|
|
|
|
+ txt.appendLocalString(EMetaText::ADVOB_TXT, 185);
|
|
|
|
+ else
|
|
|
|
+ txt.appendLocalString(EMetaText::ADVOB_TXT, 186);
|
|
|
|
+
|
|
|
|
+ txt.replaceRawString(loot.buildList());
|
|
|
|
+ txt.replaceRawString(h->getNameTranslated());
|
|
}
|
|
}
|
|
-
|
|
|
|
- if(creatures.stacksCount() == 1 && creatures.Slots().begin()->second->count == 1)
|
|
|
|
- iw.text.appendLocalString(EMetaText::ADVOB_TXT, 185);
|
|
|
|
- else
|
|
|
|
- iw.text.appendLocalString(EMetaText::ADVOB_TXT, 186);
|
|
|
|
-
|
|
|
|
- iw.text.replaceRawString(loot.buildList());
|
|
|
|
- iw.text.replaceRawString(h->getNameTranslated());
|
|
|
|
-
|
|
|
|
- cb->showInfoDialog(&iw);
|
|
|
|
- cb->giveCreatures(this, h, creatures, false);
|
|
|
|
- }
|
|
|
|
- if(!hasGuardians && !msg.empty())
|
|
|
|
- {
|
|
|
|
- iw.text.appendRawString(msg);
|
|
|
|
- cb->showInfoDialog(&iw);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void CGPandoraBox::getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const
|
|
|
|
-{
|
|
|
|
- if(afterBattle || message.empty())
|
|
|
|
- {
|
|
|
|
- iw.text.appendLocalString(EMetaText::ADVOB_TXT,text);//%s has lost treasure.
|
|
|
|
- iw.text.replaceRawString(h->getNameTranslated());
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- iw.text.appendRawString(message);
|
|
|
|
- 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();
|
|
|
|
- if(afterBattle || message.empty())
|
|
|
|
- {
|
|
|
|
- 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());
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- iw.text.appendRawString(message);
|
|
|
|
- afterBattle = true;
|
|
|
|
|
|
+
|
|
|
|
+ const_cast<MetaString&>(r.message) = txt;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ BlockingDialog bd (true, false);
|
|
|
|
+ bd.player = h->getOwner();
|
|
|
|
+ bd.text.appendLocalString(EMetaText::ADVOB_TXT, 14);
|
|
|
|
+ cb->showBlockingDialog(&bd);
|
|
}
|
|
}
|
|
|
|
|
|
void CGPandoraBox::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
|
|
void CGPandoraBox::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
|
|
{
|
|
{
|
|
if(result.winner == 0)
|
|
if(result.winner == 0)
|
|
{
|
|
{
|
|
- giveContentsUpToExp(hero);
|
|
|
|
|
|
+ CRewardableObject::onHeroVisit(hero);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -328,117 +148,87 @@ void CGPandoraBox::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answe
|
|
hero->showInfoDialog(16, 0, EInfoWindowMode::MODAL);
|
|
hero->showInfoDialog(16, 0, EInfoWindowMode::MODAL);
|
|
cb->startBattleI(hero, this); //grants things after battle
|
|
cb->startBattleI(hero, this); //grants things after battle
|
|
}
|
|
}
|
|
- else if(message.empty() && resources.empty()
|
|
|
|
- && primskills.empty() && abilities.empty()
|
|
|
|
- && abilityLevels.empty() && artifacts.empty()
|
|
|
|
- && spells.empty() && creatures.stacksCount() == 0
|
|
|
|
- && gainedExp == 0 && manaDiff == 0 && moraleDiff == 0 && luckDiff == 0) //if it gives nothing without battle
|
|
|
|
|
|
+ else if(getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT).empty())
|
|
{
|
|
{
|
|
hero->showInfoDialog(15);
|
|
hero->showInfoDialog(15);
|
|
cb->removeObject(this);
|
|
cb->removeObject(this);
|
|
}
|
|
}
|
|
else //if it gives something without battle
|
|
else //if it gives something without battle
|
|
{
|
|
{
|
|
- giveContentsUpToExp(hero);
|
|
|
|
|
|
+ CRewardableObject::onHeroVisit(hero);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void CGPandoraBox::heroLevelUpDone(const CGHeroInstance *hero) const
|
|
|
|
-{
|
|
|
|
- giveContentsAfterExp(hero);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void CGPandoraBox::afterSuccessfulVisit() const
|
|
|
|
-{
|
|
|
|
- cb->removeAfterVisit(this);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void CGPandoraBox::serializeJsonOptions(JsonSerializeFormat & handler)
|
|
void CGPandoraBox::serializeJsonOptions(JsonSerializeFormat & handler)
|
|
{
|
|
{
|
|
- CCreatureSet::serializeJson(handler, "guards", 7);
|
|
|
|
|
|
+ CRewardableObject::serializeJsonOptions(handler);
|
|
handler.serializeString("guardMessage", message);
|
|
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");
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ if(!handler.saving)
|
|
{
|
|
{
|
|
- bool haveSkills = false;
|
|
|
|
-
|
|
|
|
- if(handler.saving)
|
|
|
|
- {
|
|
|
|
- for(int primskill : primskills)
|
|
|
|
- if(primskill != 0)
|
|
|
|
- haveSkills = true;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- primskills.resize(GameConstants::PRIMARY_SKILLS,0);
|
|
|
|
- haveSkills = true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(haveSkills)
|
|
|
|
|
|
+ //backward compatibility
|
|
|
|
+ CCreatureSet::serializeJson(handler, "guards", 7);
|
|
|
|
+
|
|
|
|
+ Rewardable::VisitInfo vinfo;
|
|
|
|
+ vinfo.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
|
|
|
+ auto & reward = vinfo.reward;
|
|
|
|
+ int val;
|
|
|
|
+ handler.serializeInt("experience", reward.heroExperience, 0);
|
|
|
|
+ handler.serializeInt("mana", reward.manaDiff, 0);
|
|
|
|
+ handler.serializeInt("morale", val, 0);
|
|
|
|
+ if(val)
|
|
|
|
+ reward.bonuses.emplace_back(BonusDuration::ONE_BATTLE, BonusType::MORALE, BonusSource::OBJECT, val, id);
|
|
|
|
+ handler.serializeInt("luck", val, 0);
|
|
|
|
+ if(val)
|
|
|
|
+ reward.bonuses.emplace_back(BonusDuration::ONE_BATTLE, BonusType::LUCK, BonusSource::OBJECT, val, id);
|
|
|
|
+
|
|
|
|
+ reward.resources.serializeJson(handler, "resources");
|
|
{
|
|
{
|
|
auto s = handler.enterStruct("primarySkills");
|
|
auto s = handler.enterStruct("primarySkills");
|
|
- for(int idx = 0; idx < primskills.size(); idx ++)
|
|
|
|
- handler.serializeInt(NPrimarySkill::names[idx], primskills[idx], 0);
|
|
|
|
|
|
+ for(int idx = 0; idx < reward.primary.size(); idx ++)
|
|
|
|
+ handler.serializeInt(NPrimarySkill::names[idx], reward.primary[idx], 0);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ handler.serializeIdArray("artifacts", reward.artifacts);
|
|
|
|
+ handler.serializeIdArray("spells", reward.spells);
|
|
|
|
|
|
- if(handler.saving)
|
|
|
|
- {
|
|
|
|
- if(!abilities.empty())
|
|
|
|
|
|
+ handler.enterArray("creatures").serializeStruct(reward.creatures);
|
|
|
|
+
|
|
{
|
|
{
|
|
auto s = handler.enterStruct("secondarySkills");
|
|
auto s = handler.enterStruct("secondarySkills");
|
|
-
|
|
|
|
- for(size_t idx = 0; idx < abilities.size(); idx++)
|
|
|
|
- {
|
|
|
|
- handler.serializeEnum(CSkillHandler::encodeSkill(abilities[idx]), abilityLevels[idx], NSecondarySkill::levels);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- auto s = handler.enterStruct("secondarySkills");
|
|
|
|
-
|
|
|
|
- const JsonNode & skillMap = handler.getCurrent();
|
|
|
|
-
|
|
|
|
- abilities.clear();
|
|
|
|
- abilityLevels.clear();
|
|
|
|
-
|
|
|
|
- for(const auto & p : skillMap.Struct())
|
|
|
|
- {
|
|
|
|
- const std::string skillName = p.first;
|
|
|
|
- const std::string levelId = p.second.String();
|
|
|
|
-
|
|
|
|
- const int rawId = CSkillHandler::decodeSkill(skillName);
|
|
|
|
- if(rawId < 0)
|
|
|
|
- {
|
|
|
|
- logGlobal->error("Invalid secondary skill %s", skillName);
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const int level = vstd::find_pos(NSecondarySkill::levels, levelId);
|
|
|
|
- if(level < 0)
|
|
|
|
|
|
+ for(const auto & p : handler.getCurrent().Struct())
|
|
{
|
|
{
|
|
- logGlobal->error("Invalid secondary skill level %s", levelId);
|
|
|
|
- continue;
|
|
|
|
|
|
+ const std::string skillName = p.first;
|
|
|
|
+ const std::string levelId = p.second.String();
|
|
|
|
+
|
|
|
|
+ const int rawId = CSkillHandler::decodeSkill(skillName);
|
|
|
|
+ if(rawId < 0)
|
|
|
|
+ {
|
|
|
|
+ logGlobal->error("Invalid secondary skill %s", skillName);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const int level = vstd::find_pos(NSecondarySkill::levels, levelId);
|
|
|
|
+ if(level < 0)
|
|
|
|
+ {
|
|
|
|
+ logGlobal->error("Invalid secondary skill level %s", levelId);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ reward.secondary[rawId] = level;
|
|
}
|
|
}
|
|
-
|
|
|
|
- abilities.emplace_back(rawId);
|
|
|
|
- abilityLevels.push_back(level);
|
|
|
|
}
|
|
}
|
|
|
|
+ configuration.info.push_back(vinfo);
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
-
|
|
|
|
- handler.serializeIdArray("artifacts", artifacts);
|
|
|
|
- handler.serializeIdArray("spells", spells);
|
|
|
|
-
|
|
|
|
- creatures.serializeJson(handler, "creatures");
|
|
|
|
|
|
+void CGEvent::init()
|
|
|
|
+{
|
|
|
|
+ blockVisit = false;
|
|
|
|
+
|
|
|
|
+ for(auto & i : configuration.info)
|
|
|
|
+ i.reward.removeObject = removeAfterVisit;
|
|
}
|
|
}
|
|
|
|
|
|
void CGEvent::onHeroVisit( const CGHeroInstance * h ) const
|
|
void CGEvent::onHeroVisit( const CGHeroInstance * h ) const
|
|
@@ -470,27 +260,17 @@ void CGEvent::activated( const CGHeroInstance * h ) const
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- giveContentsUpToExp(h);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void CGEvent::afterSuccessfulVisit() const
|
|
|
|
-{
|
|
|
|
- if(removeAfterVisit)
|
|
|
|
- {
|
|
|
|
- cb->removeAfterVisit(this);
|
|
|
|
|
|
+ CRewardableObject::onHeroVisit(h);
|
|
}
|
|
}
|
|
- else if(hasGuardians)
|
|
|
|
- hasGuardians = false;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void CGEvent::serializeJsonOptions(JsonSerializeFormat & handler)
|
|
void CGEvent::serializeJsonOptions(JsonSerializeFormat & handler)
|
|
{
|
|
{
|
|
CGPandoraBox::serializeJsonOptions(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);
|
|
|
|
|
|
+ handler.serializeBool("aIActivable", computerActivate, false);
|
|
|
|
+ handler.serializeBool("humanActivable", humanActivate, true);
|
|
|
|
+ handler.serializeBool("removeAfterVisit", removeAfterVisit, false);
|
|
handler.serializeIdArray("availableFor", availableFor);
|
|
handler.serializeIdArray("availableFor", availableFor);
|
|
}
|
|
}
|
|
|
|
|