mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Pandora and events work as rewardable object
This commit is contained in:
parent
06f01c3b82
commit
c1c13cfafb
@ -25,297 +25,117 @@
|
|||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
void CGPandoraBox::init()
|
||||||
|
{
|
||||||
|
blockVisit = true;
|
||||||
|
|
||||||
|
for(auto & i : configuration.info)
|
||||||
|
i.reward.removeObject = true;
|
||||||
|
}
|
||||||
|
|
||||||
void CGPandoraBox::initObj(CRandomGenerator & rand)
|
void CGPandoraBox::initObj(CRandomGenerator & rand)
|
||||||
{
|
{
|
||||||
blockVisit = (ID==Obj::PANDORAS_BOX); //block only if it's really pandora's box (events also derive from that class)
|
init();
|
||||||
hasGuardians = stacks.size();
|
|
||||||
|
CRewardableObject::initObj(rand);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const
|
void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const
|
||||||
{
|
{
|
||||||
BlockingDialog bd (true, false);
|
auto setText = [](MetaString & text, int tId, const CGHeroInstance * h)
|
||||||
bd.player = h->getOwner();
|
|
||||||
bd.text.appendLocalString (EMetaText::ADVOB_TXT, 14);
|
|
||||||
cb->showBlockingDialog (&bd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CGPandoraBox::giveContentsUpToExp(const CGHeroInstance *h) const
|
|
||||||
{
|
|
||||||
afterSuccessfulVisit();
|
|
||||||
|
|
||||||
InfoWindow iw;
|
|
||||||
iw.type = EInfoWindowMode::AUTO;
|
|
||||||
iw.player = h->getOwner();
|
|
||||||
|
|
||||||
bool changesPrimSkill = false;
|
|
||||||
for(const auto & elem : primskills)
|
|
||||||
{
|
{
|
||||||
if(elem)
|
text.appendLocalString(EMetaText::ADVOB_TXT, tId);
|
||||||
|
text.replaceRawString(h->getNameTranslated());
|
||||||
|
};
|
||||||
|
|
||||||
|
for(auto i : getAvailableRewards(h, Rewardable::EEventType::EVENT_FIRST_VISIT))
|
||||||
|
{
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
changesPrimSkill = true;
|
if(ps)
|
||||||
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++)
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
unpossessedAbilities.emplace_back(abilities[i], abilityLevels[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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())
|
|
||||||
{
|
|
||||||
iw.components.clear();
|
|
||||||
iw.text.clear();
|
|
||||||
spellsToGive.clear();
|
|
||||||
|
|
||||||
for (; i != spells.cend(); i++)
|
|
||||||
{
|
{
|
||||||
const auto * spell = (*i).toSpell(VLC->spells());
|
setText(txt, 175, h);
|
||||||
if(h->canLearnSpell(spell))
|
break;
|
||||||
{
|
|
||||||
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 (!spellsToGive.empty())
|
|
||||||
{
|
|
||||||
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(r.reward.manaDiff < 0)
|
||||||
if(manaDiff)
|
setText(txt, 176, h);
|
||||||
{
|
if(r.reward.manaDiff > 0)
|
||||||
getText(iw,hadGuardians,manaDiff,176,177,h);
|
setText(txt, 177, h);
|
||||||
iw.components.emplace_back(Component::EComponentType::PRIM_SKILL, 5, manaDiff, 0);
|
|
||||||
cb->showInfoDialog(&iw);
|
for(auto b : r.reward.bonuses)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
cb->showInfoDialog(&iw);
|
if(b.type == BonusType::MORALE)
|
||||||
iw.components.clear();
|
{
|
||||||
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 183); //% has found treasure - once more?
|
if(b.val < 0)
|
||||||
iw.text.replaceRawString(h->getNameTranslated());
|
setText(txt, 178, h);
|
||||||
|
if(b.val > 0)
|
||||||
|
setText(txt, 179, h);
|
||||||
|
}
|
||||||
|
if(b.type == BonusType::LUCK)
|
||||||
|
{
|
||||||
|
if(b.val < 0)
|
||||||
|
setText(txt, 180, h);
|
||||||
|
if(b.val > 0)
|
||||||
|
setText(txt, 181, h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(!iw.components.empty())
|
for(auto res : r.reward.resources)
|
||||||
{
|
{
|
||||||
cb->showInfoDialog(&iw);
|
if(res < 0)
|
||||||
}
|
setText(txt, 182, h);
|
||||||
|
if(res > 0)
|
||||||
cb->giveResources(h->getOwner(), resources);
|
setText(txt, 183, h);
|
||||||
|
|
||||||
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(creatures.stacksCount() == 1 && creatures.Slots().begin()->second->count == 1)
|
if(!r.reward.artifacts.empty())
|
||||||
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 185);
|
setText(txt, 183, h);
|
||||||
else
|
|
||||||
iw.text.appendLocalString(EMetaText::ADVOB_TXT, 186);
|
if(!r.reward.creatures.empty())
|
||||||
|
{
|
||||||
iw.text.replaceRawString(loot.buildList());
|
MetaString loot;
|
||||||
iw.text.replaceRawString(h->getNameTranslated());
|
for(auto c : r.reward.creatures)
|
||||||
|
{
|
||||||
cb->showInfoDialog(&iw);
|
loot.appendRawString("%s");
|
||||||
cb->giveCreatures(this, h, creatures, false);
|
loot.replaceCreatureName(c);
|
||||||
}
|
}
|
||||||
if(!hasGuardians && !msg.empty())
|
|
||||||
{
|
if(r.reward.creatures.size() == 1 && r.reward.creatures[0].count == 1)
|
||||||
iw.text.appendRawString(msg);
|
txt.appendLocalString(EMetaText::ADVOB_TXT, 185);
|
||||||
cb->showInfoDialog(&iw);
|
else
|
||||||
}
|
txt.appendLocalString(EMetaText::ADVOB_TXT, 186);
|
||||||
}
|
|
||||||
|
txt.replaceRawString(loot.buildList());
|
||||||
void CGPandoraBox::getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const
|
txt.replaceRawString(h->getNameTranslated());
|
||||||
{
|
}
|
||||||
if(afterBattle || message.empty())
|
|
||||||
{
|
const_cast<MetaString&>(r.message) = txt;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
else if(getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT).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
|
|
||||||
{
|
{
|
||||||
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);
|
if(!handler.saving)
|
||||||
handler.serializeInt("mana", manaDiff, 0);
|
|
||||||
handler.serializeInt("morale", moraleDiff, 0);
|
|
||||||
handler.serializeInt("luck", luckDiff, 0);
|
|
||||||
|
|
||||||
resources.serializeJson(handler, "resources");
|
|
||||||
|
|
||||||
{
|
{
|
||||||
bool haveSkills = false;
|
//backward compatibility
|
||||||
|
CCreatureSet::serializeJson(handler, "guards", 7);
|
||||||
if(handler.saving)
|
|
||||||
{
|
Rewardable::VisitInfo vinfo;
|
||||||
for(int primskill : primskills)
|
vinfo.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
if(primskill != 0)
|
auto & reward = vinfo.reward;
|
||||||
haveSkills = true;
|
int val;
|
||||||
}
|
handler.serializeInt("experience", reward.heroExperience, 0);
|
||||||
else
|
handler.serializeInt("mana", reward.manaDiff, 0);
|
||||||
{
|
handler.serializeInt("morale", val, 0);
|
||||||
primskills.resize(GameConstants::PRIMARY_SKILLS,0);
|
if(val)
|
||||||
haveSkills = true;
|
reward.bonuses.emplace_back(BonusDuration::ONE_BATTLE, BonusType::MORALE, BonusSource::OBJECT, val, id);
|
||||||
}
|
handler.serializeInt("luck", val, 0);
|
||||||
|
if(val)
|
||||||
if(haveSkills)
|
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 ++)
|
for(int idx = 0; idx < reward.primary.size(); idx ++)
|
||||||
handler.serializeInt(NPrimarySkill::names[idx], primskills[idx], 0);
|
handler.serializeInt(NPrimarySkill::names[idx], reward.primary[idx], 0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
handler.serializeIdArray("artifacts", reward.artifacts);
|
||||||
|
handler.serializeIdArray("spells", reward.spells);
|
||||||
|
|
||||||
if(handler.saving)
|
handler.enterArray("creatures").serializeStruct(reward.creatures);
|
||||||
{
|
|
||||||
if(!abilities.empty())
|
|
||||||
{
|
{
|
||||||
auto s = handler.enterStruct("secondarySkills");
|
auto s = handler.enterStruct("secondarySkills");
|
||||||
|
for(const auto & p : handler.getCurrent().Struct())
|
||||||
for(size_t idx = 0; idx < abilities.size(); idx++)
|
|
||||||
{
|
{
|
||||||
handler.serializeEnum(CSkillHandler::encodeSkill(abilities[idx]), abilityLevels[idx], NSecondarySkill::levels);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
configuration.info.push_back(vinfo);
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
auto s = handler.enterStruct("secondarySkills");
|
|
||||||
|
|
||||||
const JsonNode & skillMap = handler.getCurrent();
|
void CGEvent::init()
|
||||||
|
{
|
||||||
abilities.clear();
|
blockVisit = false;
|
||||||
abilityLevels.clear();
|
|
||||||
|
for(auto & i : configuration.info)
|
||||||
for(const auto & p : skillMap.Struct())
|
i.reward.removeObject = removeAfterVisit;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
abilities.emplace_back(rawId);
|
|
||||||
abilityLevels.push_back(level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
handler.serializeIdArray("artifacts", artifacts);
|
|
||||||
handler.serializeIdArray("spells", spells);
|
|
||||||
|
|
||||||
creatures.serializeJson(handler, "creatures");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
CRewardableObject::onHeroVisit(h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGEvent::afterSuccessfulVisit() const
|
|
||||||
{
|
|
||||||
if(removeAfterVisit)
|
|
||||||
{
|
|
||||||
cb->removeAfterVisit(this);
|
|
||||||
}
|
|
||||||
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("aIActivable", computerActivate, false);
|
||||||
handler.serializeBool<bool>("humanActivable", humanActivate, true, false, true);
|
handler.serializeBool("humanActivable", humanActivate, true);
|
||||||
handler.serializeBool<bool>("removeAfterVisit", removeAfterVisit, true, false, false);
|
handler.serializeBool("removeAfterVisit", removeAfterVisit, false);
|
||||||
handler.serializeIdArray("availableFor", availableFor);
|
handler.serializeIdArray("availableFor", availableFor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,63 +9,31 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CArmedInstance.h"
|
#include "CRewardableObject.h"
|
||||||
#include "../ResourceSet.h"
|
#include "../ResourceSet.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
struct InfoWindow;
|
struct InfoWindow;
|
||||||
|
|
||||||
class DLL_LINKAGE CGPandoraBox : public CArmedInstance
|
class DLL_LINKAGE CGPandoraBox : public CRewardableObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string message;
|
std::string message;
|
||||||
mutable bool hasGuardians = false; //helper - after battle even though we have no stacks, allows us to know that there was battle
|
|
||||||
|
|
||||||
//gained things:
|
|
||||||
ui32 gainedExp = 0;
|
|
||||||
si32 manaDiff = 0; //amount of gained / lost mana
|
|
||||||
si32 moraleDiff = 0; //morale modifier
|
|
||||||
si32 luckDiff = 0; //luck modifier
|
|
||||||
TResources resources;//gained / lost resources
|
|
||||||
std::vector<si32> primskills;//gained / lost prim skills
|
|
||||||
std::vector<SecondarySkill> abilities; //gained abilities
|
|
||||||
std::vector<si32> abilityLevels; //levels of gained abilities
|
|
||||||
std::vector<ArtifactID> artifacts; //gained artifacts
|
|
||||||
std::vector<SpellID> spells; //gained spells
|
|
||||||
CCreatureSet creatures; //gained creatures
|
|
||||||
|
|
||||||
void initObj(CRandomGenerator & rand) override;
|
void initObj(CRandomGenerator & rand) override;
|
||||||
void onHeroVisit(const CGHeroInstance * h) const override;
|
void onHeroVisit(const CGHeroInstance * h) const override;
|
||||||
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
|
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
|
||||||
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
|
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
|
||||||
void heroLevelUpDone(const CGHeroInstance *hero) const override;
|
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
h & static_cast<CArmedInstance&>(*this);
|
h & static_cast<CRewardableObject&>(*this);
|
||||||
h & message;
|
h & message;
|
||||||
h & hasGuardians;
|
|
||||||
h & gainedExp;
|
|
||||||
h & manaDiff;
|
|
||||||
h & moraleDiff;
|
|
||||||
h & luckDiff;
|
|
||||||
h & resources;
|
|
||||||
h & primskills;
|
|
||||||
h & abilities;
|
|
||||||
h & abilityLevels;
|
|
||||||
h & artifacts;
|
|
||||||
h & spells;
|
|
||||||
h & creatures;
|
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
void giveContentsUpToExp(const CGHeroInstance *h) const;
|
virtual void init();
|
||||||
void giveContentsAfterExp(const CGHeroInstance *h) const;
|
|
||||||
void serializeJsonOptions(JsonSerializeFormat & handler) override;
|
void serializeJsonOptions(JsonSerializeFormat & handler) override;
|
||||||
private:
|
|
||||||
void getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const;
|
|
||||||
void getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const;
|
|
||||||
virtual void afterSuccessfulVisit() const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects
|
class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects
|
||||||
@ -87,10 +55,10 @@ public:
|
|||||||
|
|
||||||
void onHeroVisit(const CGHeroInstance * h) const override;
|
void onHeroVisit(const CGHeroInstance * h) const override;
|
||||||
protected:
|
protected:
|
||||||
|
void init() override;
|
||||||
void serializeJsonOptions(JsonSerializeFormat & handler) override;
|
void serializeJsonOptions(JsonSerializeFormat & handler) override;
|
||||||
private:
|
private:
|
||||||
void activated(const CGHeroInstance * h) const;
|
void activated(const CGHeroInstance * h) const;
|
||||||
void afterSuccessfulVisit() const override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@ -794,20 +794,11 @@ void CGSeerHut::afterAddToMap(CMap* map)
|
|||||||
void CGSeerHut::serializeJsonOptions(JsonSerializeFormat & handler)
|
void CGSeerHut::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||||
{
|
{
|
||||||
//quest and reward
|
//quest and reward
|
||||||
|
CRewardableObject::serializeJsonOptions(handler);
|
||||||
quest->serializeJson(handler, "quest");
|
quest->serializeJson(handler, "quest");
|
||||||
|
|
||||||
if(handler.saving)
|
if(!handler.saving)
|
||||||
{
|
{
|
||||||
CRewardableObject::serializeJsonOptions(handler);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(handler.getCurrent()["reward"].isNull() || handler.getCurrent()["reward"].Struct().empty())
|
|
||||||
{
|
|
||||||
CRewardableObject::serializeJsonOptions(handler);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//backward compatibility
|
//backward compatibility
|
||||||
auto s = handler.enterStruct("reward");
|
auto s = handler.enterStruct("reward");
|
||||||
const JsonNode & rewardsJson = handler.getCurrent();
|
const JsonNode & rewardsJson = handler.getCurrent();
|
||||||
@ -827,7 +818,8 @@ void CGSeerHut::serializeJsonOptions(JsonSerializeFormat & handler)
|
|||||||
int val = 0;
|
int val = 0;
|
||||||
handler.serializeInt(fullIdentifier, val);
|
handler.serializeInt(fullIdentifier, val);
|
||||||
|
|
||||||
Rewardable::Reward reward;
|
Rewardable::VisitInfo vinfo;
|
||||||
|
auto & reward = vinfo.reward;
|
||||||
if(metaTypeName == "experience")
|
if(metaTypeName == "experience")
|
||||||
reward.heroExperience = val;
|
reward.heroExperience = val;
|
||||||
if(metaTypeName == "mana")
|
if(metaTypeName == "mana")
|
||||||
@ -867,9 +859,8 @@ void CGSeerHut::serializeJsonOptions(JsonSerializeFormat & handler)
|
|||||||
reward.creatures.emplace_back(rawId, val);
|
reward.creatures.emplace_back(rawId, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration.info.push_back({});
|
vinfo.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
configuration.info.back().reward = reward;
|
configuration.info.push_back(vinfo);
|
||||||
configuration.info.back().visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -881,14 +872,10 @@ void CGQuestGuard::init(CRandomGenerator & rand)
|
|||||||
|
|
||||||
configuration.info.push_back({});
|
configuration.info.push_back({});
|
||||||
configuration.info.back().visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
configuration.info.back().visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
|
configuration.info.back().reward.removeObject = true;
|
||||||
configuration.canRefuse = true;
|
configuration.canRefuse = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGQuestGuard::completeQuest() const
|
|
||||||
{
|
|
||||||
cb->removeObject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CGQuestGuard::serializeJsonOptions(JsonSerializeFormat & handler)
|
void CGQuestGuard::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||||
{
|
{
|
||||||
//quest only, do not call base class
|
//quest only, do not call base class
|
||||||
@ -946,7 +933,6 @@ void CGKeymasterTent::onHeroVisit( const CGHeroInstance * h ) const
|
|||||||
|
|
||||||
void CGBorderGuard::initObj(CRandomGenerator & rand)
|
void CGBorderGuard::initObj(CRandomGenerator & rand)
|
||||||
{
|
{
|
||||||
//ui32 m13489val = subID; //store color as quest info
|
|
||||||
blockVisit = true;
|
blockVisit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,11 +162,8 @@ public:
|
|||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
h & static_cast<CArmedInstance&>(*this);
|
h & static_cast<CRewardableObject&>(*this);
|
||||||
h & static_cast<IQuestObject&>(*this);
|
h & static_cast<IQuestObject&>(*this);
|
||||||
//h & rewardType;
|
|
||||||
//h & rID;
|
|
||||||
//h & rVal;
|
|
||||||
h & seerName;
|
h & seerName;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
@ -181,7 +178,6 @@ class DLL_LINKAGE CGQuestGuard : public CGSeerHut
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void init(CRandomGenerator & rand) override;
|
void init(CRandomGenerator & rand) override;
|
||||||
void completeQuest() const override;
|
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
|
@ -271,7 +271,6 @@ void CRewardableObject::newTurn(CRandomGenerator & rand) const
|
|||||||
void CRewardableObject::initObj(CRandomGenerator & rand)
|
void CRewardableObject::initObj(CRandomGenerator & rand)
|
||||||
{
|
{
|
||||||
VLC->objtypeh->getHandlerFor(ID, subID)->configureObject(this, rand);
|
VLC->objtypeh->getHandlerFor(ID, subID)->configureObject(this, rand);
|
||||||
assert(!configuration.info.empty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CRewardableObject::CRewardableObject()
|
CRewardableObject::CRewardableObject()
|
||||||
|
@ -1019,34 +1019,46 @@ CGObjectInstance * CMapLoaderH3M::readPandora(const int3 & mapPosition)
|
|||||||
void CMapLoaderH3M::readBoxContent(CGPandoraBox * object, const int3 & mapPosition)
|
void CMapLoaderH3M::readBoxContent(CGPandoraBox * object, const int3 & mapPosition)
|
||||||
{
|
{
|
||||||
readMessageAndGuards(object->message, object, mapPosition);
|
readMessageAndGuards(object->message, object, mapPosition);
|
||||||
|
Rewardable::VisitInfo vinfo;
|
||||||
|
auto & reward = vinfo.reward;
|
||||||
|
|
||||||
|
reward.heroExperience = reader->readUInt32();
|
||||||
|
reward.manaDiff = reader->readInt32();
|
||||||
|
reward.bonuses.emplace_back(BonusDuration::ONE_BATTLE, BonusType::MORALE, BonusSource::OBJECT, reader->readUInt8(), object->id);
|
||||||
|
reward.bonuses.emplace_back(BonusDuration::ONE_BATTLE, BonusType::LUCK, BonusSource::OBJECT, reader->readUInt8(), object->id);
|
||||||
|
|
||||||
object->gainedExp = reader->readUInt32();
|
reader->readResourses(reward.resources);
|
||||||
object->manaDiff = reader->readInt32();
|
|
||||||
object->moraleDiff = reader->readInt8();
|
|
||||||
object->luckDiff = reader->readInt8();
|
|
||||||
|
|
||||||
reader->readResourses(object->resources);
|
|
||||||
|
|
||||||
object->primskills.resize(GameConstants::PRIMARY_SKILLS);
|
|
||||||
for(int x = 0; x < GameConstants::PRIMARY_SKILLS; ++x)
|
for(int x = 0; x < GameConstants::PRIMARY_SKILLS; ++x)
|
||||||
object->primskills[x] = reader->readUInt8();
|
reward.primary.at(x) = reader->readUInt8();
|
||||||
|
|
||||||
int gabn = reader->readUInt8(); //number of gained abilities
|
int gabn = reader->readUInt8(); //number of gained abilities
|
||||||
for(int oo = 0; oo < gabn; ++oo)
|
for(int oo = 0; oo < gabn; ++oo)
|
||||||
{
|
{
|
||||||
object->abilities.emplace_back(reader->readSkill());
|
auto rId = reader->readSkill();
|
||||||
object->abilityLevels.push_back(reader->readUInt8());
|
auto rVal = reader->readUInt8();
|
||||||
|
|
||||||
|
reward.secondary[rId] = rVal;
|
||||||
}
|
}
|
||||||
int gart = reader->readUInt8(); //number of gained artifacts
|
int gart = reader->readUInt8(); //number of gained artifacts
|
||||||
for(int oo = 0; oo < gart; ++oo)
|
for(int oo = 0; oo < gart; ++oo)
|
||||||
object->artifacts.emplace_back(reader->readArtifact());
|
reward.artifacts.push_back(reader->readArtifact());
|
||||||
|
|
||||||
int gspel = reader->readUInt8(); //number of gained spells
|
int gspel = reader->readUInt8(); //number of gained spells
|
||||||
for(int oo = 0; oo < gspel; ++oo)
|
for(int oo = 0; oo < gspel; ++oo)
|
||||||
object->spells.emplace_back(reader->readSpell());
|
reward.spells.push_back(reader->readSpell());
|
||||||
|
|
||||||
int gcre = reader->readUInt8(); //number of gained creatures
|
int gcre = reader->readUInt8(); //number of gained creatures
|
||||||
readCreatureSet(&object->creatures, gcre);
|
for(int oo = 0; oo < gcre; ++oo)
|
||||||
|
{
|
||||||
|
auto rId = reader->readCreature();
|
||||||
|
auto rVal = reader->readUInt16();
|
||||||
|
|
||||||
|
reward.creatures.emplace_back(rId, rVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
vinfo.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
|
object->configuration.info.push_back(vinfo);
|
||||||
|
|
||||||
reader->skipZero(8);
|
reader->skipZero(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1843,7 +1855,8 @@ void CMapLoaderH3M::readSeerHutQuest(CGSeerHut * hut, const int3 & position)
|
|||||||
if(hut->quest->missionType)
|
if(hut->quest->missionType)
|
||||||
{
|
{
|
||||||
auto rewardType = reader->readUInt8();
|
auto rewardType = reader->readUInt8();
|
||||||
Rewardable::Reward reward;
|
Rewardable::VisitInfo vinfo;
|
||||||
|
auto & reward = vinfo.reward;
|
||||||
switch(rewardType)
|
switch(rewardType)
|
||||||
{
|
{
|
||||||
case 0: //NOTHING
|
case 0: //NOTHING
|
||||||
@ -1922,9 +1935,8 @@ void CMapLoaderH3M::readSeerHutQuest(CGSeerHut * hut, const int3 & position)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hut->configuration.info.push_back({});
|
vinfo.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
hut->configuration.info.back().reward = reward;
|
hut->configuration.info.push_back(vinfo);
|
||||||
hut->configuration.info.back().visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -235,7 +235,12 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
{
|
{
|
||||||
auto factory = VLC->objtypeh->getHandlerFor(Obj::PANDORAS_BOX, 0);
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::PANDORAS_BOX, 0);
|
||||||
auto * obj = dynamic_cast<CGPandoraBox *>(factory->create());
|
auto * obj = dynamic_cast<CGPandoraBox *>(factory->create());
|
||||||
obj->resources[EGameResID::GOLD] = i * 5000;
|
|
||||||
|
Rewardable::VisitInfo reward;
|
||||||
|
reward.reward.resources[EGameResID::GOLD] = i * 5000;
|
||||||
|
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
|
obj->configuration.info.push_back(reward);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
oi.setTemplate(Obj::PANDORAS_BOX, 0, zone.getTerrainType());
|
oi.setTemplate(Obj::PANDORAS_BOX, 0, zone.getTerrainType());
|
||||||
@ -251,7 +256,12 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
{
|
{
|
||||||
auto factory = VLC->objtypeh->getHandlerFor(Obj::PANDORAS_BOX, 0);
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::PANDORAS_BOX, 0);
|
||||||
auto * obj = dynamic_cast<CGPandoraBox *>(factory->create());
|
auto * obj = dynamic_cast<CGPandoraBox *>(factory->create());
|
||||||
obj->gainedExp = i * 5000;
|
|
||||||
|
Rewardable::VisitInfo reward;
|
||||||
|
reward.reward.heroExperience = i * 5000;
|
||||||
|
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
|
obj->configuration.info.push_back(reward);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
oi.setTemplate(Obj::PANDORAS_BOX, 0, zone.getTerrainType());
|
oi.setTemplate(Obj::PANDORAS_BOX, 0, zone.getTerrainType());
|
||||||
@ -307,8 +317,12 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
{
|
{
|
||||||
auto factory = VLC->objtypeh->getHandlerFor(Obj::PANDORAS_BOX, 0);
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::PANDORAS_BOX, 0);
|
||||||
auto * obj = dynamic_cast<CGPandoraBox *>(factory->create());
|
auto * obj = dynamic_cast<CGPandoraBox *>(factory->create());
|
||||||
auto * stack = new CStackInstance(creature, creaturesAmount);
|
|
||||||
obj->creatures.putStack(SlotID(0), stack);
|
Rewardable::VisitInfo reward;
|
||||||
|
reward.reward.creatures.emplace_back(creature, creaturesAmount);
|
||||||
|
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
|
obj->configuration.info.push_back(reward);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
oi.setTemplate(Obj::PANDORAS_BOX, 0, zone.getTerrainType());
|
oi.setTemplate(Obj::PANDORAS_BOX, 0, zone.getTerrainType());
|
||||||
@ -333,10 +347,13 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
}
|
}
|
||||||
|
|
||||||
RandomGeneratorUtil::randomShuffle(spells, zone.getRand());
|
RandomGeneratorUtil::randomShuffle(spells, zone.getRand());
|
||||||
|
Rewardable::VisitInfo reward;
|
||||||
for(int j = 0; j < std::min(12, static_cast<int>(spells.size())); j++)
|
for(int j = 0; j < std::min(12, static_cast<int>(spells.size())); j++)
|
||||||
{
|
{
|
||||||
obj->spells.push_back(spells[j]->id);
|
reward.reward.spells.push_back(spells[j]->id);
|
||||||
}
|
}
|
||||||
|
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
|
obj->configuration.info.push_back(reward);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
@ -362,10 +379,13 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
}
|
}
|
||||||
|
|
||||||
RandomGeneratorUtil::randomShuffle(spells, zone.getRand());
|
RandomGeneratorUtil::randomShuffle(spells, zone.getRand());
|
||||||
|
Rewardable::VisitInfo reward;
|
||||||
for(int j = 0; j < std::min(15, static_cast<int>(spells.size())); j++)
|
for(int j = 0; j < std::min(15, static_cast<int>(spells.size())); j++)
|
||||||
{
|
{
|
||||||
obj->spells.push_back(spells[j]->id);
|
reward.reward.spells.push_back(spells[j]->id);
|
||||||
}
|
}
|
||||||
|
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
|
obj->configuration.info.push_back(reward);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
@ -390,10 +410,13 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
}
|
}
|
||||||
|
|
||||||
RandomGeneratorUtil::randomShuffle(spells, zone.getRand());
|
RandomGeneratorUtil::randomShuffle(spells, zone.getRand());
|
||||||
|
Rewardable::VisitInfo reward;
|
||||||
for(int j = 0; j < std::min(60, static_cast<int>(spells.size())); j++)
|
for(int j = 0; j < std::min(60, static_cast<int>(spells.size())); j++)
|
||||||
{
|
{
|
||||||
obj->spells.push_back(spells[j]->id);
|
reward.reward.spells.push_back(spells[j]->id);
|
||||||
}
|
}
|
||||||
|
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
|
obj->configuration.info.push_back(reward);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
@ -442,11 +465,10 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
||||||
auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
||||||
|
|
||||||
Rewardable::Reward reward;
|
Rewardable::VisitInfo reward;
|
||||||
reward.creatures.emplace_back(creature->getId(), creaturesAmount);
|
reward.reward.creatures.emplace_back(creature->getId(), creaturesAmount);
|
||||||
obj->configuration.info.push_back({});
|
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
obj->configuration.info.back().reward = reward;
|
obj->configuration.info.push_back(reward);
|
||||||
obj->configuration.info.back().visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
|
||||||
|
|
||||||
obj->quest->missionType = CQuest::MISSION_ART;
|
obj->quest->missionType = CQuest::MISSION_ART;
|
||||||
|
|
||||||
@ -494,11 +516,10 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
||||||
auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
||||||
|
|
||||||
Rewardable::Reward reward;
|
Rewardable::VisitInfo reward;
|
||||||
reward.heroExperience = generator.getConfig().questRewardValues[i];
|
reward.reward.heroExperience = generator.getConfig().questRewardValues[i];
|
||||||
obj->configuration.info.push_back({});
|
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
obj->configuration.info.back().reward = reward;
|
obj->configuration.info.push_back(reward);
|
||||||
obj->configuration.info.back().visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
|
||||||
|
|
||||||
obj->quest->missionType = CQuest::MISSION_ART;
|
obj->quest->missionType = CQuest::MISSION_ART;
|
||||||
ArtifactID artid = qap->drawRandomArtifact();
|
ArtifactID artid = qap->drawRandomArtifact();
|
||||||
@ -519,11 +540,10 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
||||||
auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
||||||
|
|
||||||
Rewardable::Reward reward;
|
Rewardable::VisitInfo reward;
|
||||||
reward.resources[EGameResID::GOLD] = generator.getConfig().questRewardValues[i];
|
reward.reward.resources[EGameResID::GOLD] = generator.getConfig().questRewardValues[i];
|
||||||
obj->configuration.info.push_back({});
|
reward.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||||
obj->configuration.info.back().reward = reward;
|
obj->configuration.info.push_back(reward);
|
||||||
obj->configuration.info.back().visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
|
||||||
|
|
||||||
obj->quest->missionType = CQuest::MISSION_ART;
|
obj->quest->missionType = CQuest::MISSION_ART;
|
||||||
ArtifactID artid = qap->drawRandomArtifact();
|
ArtifactID artid = qap->drawRandomArtifact();
|
||||||
|
Loading…
Reference in New Issue
Block a user