2014-06-05 19:52:14 +03:00
|
|
|
/*
|
2014-06-05 20:26:50 +03:00
|
|
|
* CQuest.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 "CQuest.h"
|
|
|
|
|
2021-02-15 14:03:32 +02:00
|
|
|
#include <vcmi/spells/Spell.h>
|
|
|
|
|
2023-05-17 15:52:16 +02:00
|
|
|
#include "../ArtifactUtils.h"
|
2014-06-05 23:51:24 +03:00
|
|
|
#include "../CSoundBase.h"
|
2014-06-05 19:52:14 +03:00
|
|
|
#include "../CGeneralTextHandler.h"
|
|
|
|
#include "../CHeroHandler.h"
|
2023-06-17 14:21:42 +02:00
|
|
|
#include "CGCreature.h"
|
2014-06-25 17:11:07 +03:00
|
|
|
#include "../IGameCallback.h"
|
2023-06-02 20:47:37 +02:00
|
|
|
#include "../mapObjectConstructors/CObjectClassesHandler.h"
|
2016-11-13 12:38:42 +02:00
|
|
|
#include "../serializer/JsonSerializeFormat.h"
|
|
|
|
#include "../GameConstants.h"
|
2023-08-19 23:22:31 +02:00
|
|
|
#include "../constants/StringConstants.h"
|
2023-11-17 21:18:34 +02:00
|
|
|
#include "../CPlayerState.h"
|
2018-03-31 07:56:40 +02:00
|
|
|
#include "../CSkillHandler.h"
|
2017-05-28 15:23:42 +02:00
|
|
|
#include "../mapping/CMap.h"
|
2023-10-23 12:59:15 +02:00
|
|
|
#include "../mapObjects/CGHeroInstance.h"
|
2023-07-30 19:12:25 +02:00
|
|
|
#include "../modding/ModScope.h"
|
|
|
|
#include "../modding/ModUtility.h"
|
2023-10-23 12:59:15 +02:00
|
|
|
#include "../networkPacks/PacksForClient.h"
|
2023-10-10 02:33:17 +02:00
|
|
|
#include "../spells/CSpellHandler.h"
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
//TODO: Remove constructor
|
|
|
|
CQuest::CQuest():
|
|
|
|
qid(-1),
|
2023-10-11 21:10:42 +02:00
|
|
|
isCompleted(false),
|
2023-02-12 22:39:17 +02:00
|
|
|
lastDay(-1),
|
2023-10-11 00:47:19 +02:00
|
|
|
killTarget(ObjectInstanceID::NONE),
|
2023-02-12 22:39:17 +02:00
|
|
|
textOption(0),
|
|
|
|
completedOption(0),
|
|
|
|
stackDirection(0),
|
2023-04-13 18:06:44 +02:00
|
|
|
isCustomFirst(false),
|
2023-02-12 22:39:17 +02:00
|
|
|
isCustomNext(false),
|
2023-10-09 15:54:14 +02:00
|
|
|
isCustomComplete(false),
|
2023-10-09 19:15:34 +02:00
|
|
|
repeatedQuest(false),
|
|
|
|
questName(CQuest::missionName(0))
|
2016-08-22 19:41:37 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-01 20:54:05 +02:00
|
|
|
static std::string visitedTxt(const bool visited)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
int id = visited ? 352 : 353;
|
|
|
|
return VLC->generaltexth->allTexts[id];
|
|
|
|
}
|
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
const std::string & CQuest::missionName(int mission)
|
2022-12-27 23:17:41 +02:00
|
|
|
{
|
2023-10-13 12:52:45 +02:00
|
|
|
static const std::array<std::string, 13> names = {
|
2022-12-27 23:17:41 +02:00
|
|
|
"empty",
|
|
|
|
"heroLevel",
|
|
|
|
"primarySkill",
|
|
|
|
"killHero",
|
|
|
|
"killCreature",
|
|
|
|
"bringArt",
|
|
|
|
"bringCreature",
|
|
|
|
"bringResources",
|
|
|
|
"bringHero",
|
|
|
|
"bringPlayer",
|
2023-10-13 12:52:45 +02:00
|
|
|
"keymaster",
|
|
|
|
"hota",
|
|
|
|
"other"
|
2022-12-27 23:17:41 +02:00
|
|
|
};
|
|
|
|
|
2023-01-01 22:50:38 +02:00
|
|
|
if(static_cast<size_t>(mission) < names.size())
|
2022-12-27 23:17:41 +02:00
|
|
|
return names[static_cast<size_t>(mission)];
|
|
|
|
return names[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string & CQuest::missionState(int state)
|
|
|
|
{
|
|
|
|
static const std::array<std::string, 5> states = {
|
|
|
|
"receive",
|
|
|
|
"visit",
|
|
|
|
"complete",
|
|
|
|
"hover",
|
|
|
|
"description",
|
|
|
|
};
|
|
|
|
|
2023-01-01 22:50:38 +02:00
|
|
|
if(state < states.size())
|
2022-12-27 23:17:41 +02:00
|
|
|
return states[state];
|
|
|
|
return states[0];
|
|
|
|
}
|
|
|
|
|
2021-05-23 13:28:43 +02:00
|
|
|
bool CQuest::checkMissionArmy(const CQuest * q, const CCreatureSet * army)
|
|
|
|
{
|
|
|
|
std::vector<CStackBasicDescriptor>::const_iterator cre;
|
|
|
|
TSlots::const_iterator it;
|
2023-02-12 22:39:17 +02:00
|
|
|
ui32 count = 0;
|
2021-05-23 13:28:43 +02:00
|
|
|
ui32 slotsCount = 0;
|
|
|
|
bool hasExtraCreatures = false;
|
2023-10-11 00:47:19 +02:00
|
|
|
for(cre = q->mission.creatures.begin(); cre != q->mission.creatures.end(); ++cre)
|
2021-05-23 13:28:43 +02:00
|
|
|
{
|
|
|
|
for(count = 0, it = army->Slots().begin(); it != army->Slots().end(); ++it)
|
|
|
|
{
|
|
|
|
if(it->second->type == cre->type)
|
|
|
|
{
|
|
|
|
count += it->second->count;
|
|
|
|
slotsCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
if(static_cast<TQuantity>(count) < cre->count) //not enough creatures of this kind
|
2021-05-23 13:28:43 +02:00
|
|
|
return false;
|
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
hasExtraCreatures |= static_cast<TQuantity>(count) > cre->count;
|
2021-05-23 13:28:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hasExtraCreatures || slotsCount < army->Slots().size();
|
|
|
|
}
|
|
|
|
|
2016-01-29 08:28:37 +02:00
|
|
|
bool CQuest::checkQuest(const CGHeroInstance * h) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-11 00:47:19 +02:00
|
|
|
if(!mission.heroAllowed(h))
|
2023-10-09 05:24:40 +02:00
|
|
|
return false;
|
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
if(killTarget != ObjectInstanceID::NONE)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-10 01:20:55 +02:00
|
|
|
if(CGHeroInstance::cb->getObjByQuestIdentifier(killTarget))
|
2014-06-05 19:52:14 +03:00
|
|
|
return false;
|
|
|
|
}
|
2023-10-09 05:24:40 +02:00
|
|
|
|
|
|
|
return true;
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2023-10-09 02:19:58 +02:00
|
|
|
void CQuest::completeQuest(IGameCallback * cb, const CGHeroInstance *h) const
|
|
|
|
{
|
2023-10-11 00:47:19 +02:00
|
|
|
for(auto & elem : mission.artifacts)
|
2023-10-09 02:19:58 +02:00
|
|
|
{
|
2023-10-09 05:24:40 +02:00
|
|
|
if(h->hasArt(elem))
|
|
|
|
{
|
2023-10-14 21:00:39 +02:00
|
|
|
cb->removeArtifact(ArtifactLocation(h->id, h->getArtPos(elem, false)));
|
2023-10-09 05:24:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto * assembly = h->getAssemblyByConstituent(elem);
|
|
|
|
assert(assembly);
|
|
|
|
auto parts = assembly->getPartsInfo();
|
2023-10-09 02:19:58 +02:00
|
|
|
|
2023-10-09 05:24:40 +02:00
|
|
|
// Remove the assembly
|
2023-10-14 21:00:39 +02:00
|
|
|
cb->removeArtifact(ArtifactLocation(h->id, h->getArtPos(assembly)));
|
2023-10-09 02:19:58 +02:00
|
|
|
|
2023-10-09 05:24:40 +02:00
|
|
|
// Disassemble this backpack artifact
|
|
|
|
for(const auto & ci : parts)
|
2023-10-09 02:19:58 +02:00
|
|
|
{
|
2023-10-09 05:24:40 +02:00
|
|
|
if(ci.art->getTypeId() != elem)
|
|
|
|
cb->giveHeroNewArtifact(h, ci.art->artType, ArtifactPosition::BACKPACK_START);
|
2023-10-09 02:19:58 +02:00
|
|
|
}
|
2023-10-09 05:24:40 +02:00
|
|
|
}
|
2023-10-09 02:19:58 +02:00
|
|
|
}
|
2023-10-09 05:24:40 +02:00
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
cb->takeCreatures(h->id, mission.creatures);
|
|
|
|
cb->giveResources(h->getOwner(), mission.resources);
|
2023-10-09 02:19:58 +02:00
|
|
|
}
|
|
|
|
|
2023-10-10 01:20:55 +02:00
|
|
|
void CQuest::addTextReplacements(MetaString & text, std::vector<Component> & components) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-11 00:47:19 +02:00
|
|
|
if(mission.heroLevel > 0)
|
|
|
|
text.replaceNumber(mission.heroLevel);
|
2023-10-09 19:15:34 +02:00
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
if(mission.heroExperience > 0)
|
|
|
|
text.replaceNumber(mission.heroExperience);
|
2023-10-10 02:33:17 +02:00
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
{ //primary skills
|
|
|
|
MetaString loot;
|
|
|
|
for(int i = 0; i < 4; ++i)
|
|
|
|
{
|
2023-10-11 00:47:19 +02:00
|
|
|
if(mission.primary[i])
|
2023-10-09 19:15:34 +02:00
|
|
|
{
|
|
|
|
loot.appendRawString("%d %s");
|
2023-10-11 00:47:19 +02:00
|
|
|
loot.replaceNumber(mission.primary[i]);
|
2023-10-09 19:15:34 +02:00
|
|
|
loot.replaceRawString(VLC->generaltexth->primarySkillNames[i]);
|
|
|
|
}
|
|
|
|
}
|
2023-10-10 02:33:17 +02:00
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
for(auto & skill : mission.secondary)
|
2023-10-10 02:33:17 +02:00
|
|
|
{
|
|
|
|
loot.appendTextID(VLC->skillh->getById(skill.first)->getNameTextID());
|
|
|
|
}
|
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
for(auto & spell : mission.spells)
|
2023-10-10 02:33:17 +02:00
|
|
|
{
|
|
|
|
loot.appendTextID(VLC->spellh->getById(spell)->getNameTextID());
|
|
|
|
}
|
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
if(!loot.empty())
|
|
|
|
text.replaceRawString(loot.buildList());
|
|
|
|
}
|
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
if(killTarget != ObjectInstanceID::NONE && !heroName.empty())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-31 11:09:56 +02:00
|
|
|
components.emplace_back(ComponentType::HERO_PORTRAIT, heroPortrait);
|
2023-10-09 19:15:34 +02:00
|
|
|
addKillTargetReplacements(text);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2023-10-09 19:15:34 +02:00
|
|
|
|
2023-11-12 19:18:00 +02:00
|
|
|
if(killTarget != ObjectInstanceID::NONE && stackToKill != CreatureID::NONE)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-11-12 19:18:00 +02:00
|
|
|
components.emplace_back(ComponentType::CREATURE, stackToKill);
|
2023-10-09 19:15:34 +02:00
|
|
|
addKillTargetReplacements(text);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2023-10-09 19:15:34 +02:00
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
if(!mission.heroes.empty())
|
|
|
|
text.replaceRawString(VLC->heroh->getById(mission.heroes.front())->getNameTranslated());
|
2023-10-09 19:15:34 +02:00
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
if(!mission.artifacts.empty())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-09 19:15:34 +02:00
|
|
|
MetaString loot;
|
2023-10-11 00:47:19 +02:00
|
|
|
for(const auto & elem : mission.artifacts)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-09 19:15:34 +02:00
|
|
|
loot.appendRawString("%s");
|
2023-11-02 22:01:49 +02:00
|
|
|
loot.replaceName(elem);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2023-10-09 19:15:34 +02:00
|
|
|
text.replaceRawString(loot.buildList());
|
|
|
|
}
|
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
if(!mission.creatures.empty())
|
2023-10-09 19:15:34 +02:00
|
|
|
{
|
|
|
|
MetaString loot;
|
2023-10-11 00:47:19 +02:00
|
|
|
for(const auto & elem : mission.creatures)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-09 19:15:34 +02:00
|
|
|
loot.appendRawString("%s");
|
2023-11-02 22:01:49 +02:00
|
|
|
loot.replaceName(elem);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2023-10-09 19:15:34 +02:00
|
|
|
text.replaceRawString(loot.buildList());
|
|
|
|
}
|
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
if(mission.resources.nonZero())
|
2023-10-09 19:15:34 +02:00
|
|
|
{
|
|
|
|
MetaString loot;
|
2023-11-08 16:13:08 +02:00
|
|
|
for(auto i : GameResID::ALL_RESOURCES())
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-11 00:47:19 +02:00
|
|
|
if(mission.resources[i])
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-09 19:15:34 +02:00
|
|
|
loot.appendRawString("%d %s");
|
2023-10-11 00:47:19 +02:00
|
|
|
loot.replaceNumber(mission.resources[i]);
|
2023-11-08 16:13:08 +02:00
|
|
|
loot.replaceName(i);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
2023-10-09 19:15:34 +02:00
|
|
|
text.replaceRawString(loot.buildList());
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2023-10-09 19:15:34 +02:00
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
if(!mission.players.empty())
|
2023-10-10 02:33:17 +02:00
|
|
|
{
|
|
|
|
MetaString loot;
|
2023-10-11 00:47:19 +02:00
|
|
|
for(auto & p : mission.players)
|
2023-11-02 22:01:49 +02:00
|
|
|
loot.appendName(p);
|
2023-10-10 02:33:17 +02:00
|
|
|
|
|
|
|
text.replaceRawString(loot.buildList());
|
|
|
|
}
|
2023-10-14 00:15:15 +02:00
|
|
|
|
|
|
|
if(lastDay >= 0)
|
|
|
|
text.replaceNumber(lastDay - IObjectInterface::cb->getDate(Date::DAY));
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
void CQuest::getVisitText(MetaString &iwText, std::vector<Component> &components, bool firstVisit, const CGHeroInstance * h) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-09 19:15:34 +02:00
|
|
|
bool failRequirements = (h ? !checkQuest(h) : true);
|
2023-10-11 00:47:19 +02:00
|
|
|
mission.loadComponents(components, h);
|
2015-02-13 23:57:33 +02:00
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
if(firstVisit)
|
|
|
|
iwText.appendRawString(firstVisitText.toString());
|
|
|
|
else if(failRequirements)
|
|
|
|
iwText.appendRawString(nextVisitText.toString());
|
|
|
|
|
2023-10-14 00:15:15 +02:00
|
|
|
if(lastDay >= 0)
|
|
|
|
iwText.appendTextID(TextIdentifier("core", "seerhut", "time", textOption).get());
|
|
|
|
|
2023-10-10 01:20:55 +02:00
|
|
|
addTextReplacements(iwText, components);
|
2023-10-09 19:15:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CQuest::getRolloverText(MetaString &ms, bool onHover) const
|
|
|
|
{
|
2016-01-29 08:28:37 +02:00
|
|
|
if(onHover)
|
2023-06-18 11:18:25 +02:00
|
|
|
ms.appendRawString("\n\n");
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2022-12-27 23:17:41 +02:00
|
|
|
std::string questState = missionState(onHover ? 3 : 4);
|
|
|
|
|
2023-10-14 00:15:15 +02:00
|
|
|
ms.appendTextID(TextIdentifier("core", "seerhut", "quest", questName, questState, textOption).get());
|
2014-06-05 19:52:14 +03:00
|
|
|
|
2023-10-10 01:20:55 +02:00
|
|
|
std::vector<Component> components;
|
|
|
|
addTextReplacements(ms, components);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2023-09-13 01:40:07 +02:00
|
|
|
void CQuest::getCompletionText(MetaString &iwText) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-09-27 23:49:27 +02:00
|
|
|
iwText.appendRawString(completedText.toString());
|
2023-10-09 19:15:34 +02:00
|
|
|
|
2023-10-10 01:20:55 +02:00
|
|
|
std::vector<Component> components;
|
|
|
|
addTextReplacements(iwText, components);
|
2023-10-09 19:15:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CQuest::defineQuestName()
|
|
|
|
{
|
|
|
|
//standard quests
|
|
|
|
questName = CQuest::missionName(0);
|
2023-10-13 12:52:45 +02:00
|
|
|
if(mission != Rewardable::Limiter{}) questName = CQuest::missionName(12);
|
2023-10-11 00:47:19 +02:00
|
|
|
if(mission.heroLevel > 0) questName = CQuest::missionName(1);
|
|
|
|
for(auto & s : mission.primary) if(s) questName = CQuest::missionName(2);
|
|
|
|
if(!mission.spells.empty()) questName = CQuest::missionName(2);
|
|
|
|
if(!mission.secondary.empty()) questName = CQuest::missionName(2);
|
|
|
|
if(killTarget != ObjectInstanceID::NONE && !heroName.empty()) questName = CQuest::missionName(3);
|
2023-11-12 19:18:00 +02:00
|
|
|
if(killTarget != ObjectInstanceID::NONE && stackToKill != CreatureID::NONE) questName = CQuest::missionName(4);
|
2023-10-11 00:47:19 +02:00
|
|
|
if(!mission.artifacts.empty()) questName = CQuest::missionName(5);
|
|
|
|
if(!mission.creatures.empty()) questName = CQuest::missionName(6);
|
|
|
|
if(mission.resources.nonZero()) questName = CQuest::missionName(7);
|
|
|
|
if(!mission.heroes.empty()) questName = CQuest::missionName(8);
|
|
|
|
if(!mission.players.empty()) questName = CQuest::missionName(9);
|
2023-10-13 12:52:45 +02:00
|
|
|
if(mission.daysPassed > 0 || !mission.heroClasses.empty()) questName = CQuest::missionName(11);
|
2023-10-09 19:15:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CQuest::addKillTargetReplacements(MetaString &out) const
|
|
|
|
{
|
|
|
|
if(!heroName.empty())
|
|
|
|
out.replaceTextID(heroName);
|
2023-11-12 19:18:00 +02:00
|
|
|
if(stackToKill != CreatureID::NONE)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-11-12 19:18:00 +02:00
|
|
|
out.replaceNamePlural(stackToKill);
|
2023-10-09 19:15:34 +02:00
|
|
|
out.replaceRawString(VLC->generaltexth->arraytxt[147+stackDirection]);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
void CQuest::serializeJson(JsonSerializeFormat & handler, const std::string & fieldName)
|
|
|
|
{
|
|
|
|
auto q = handler.enterStruct(fieldName);
|
|
|
|
|
2023-09-27 23:49:27 +02:00
|
|
|
handler.serializeStruct("firstVisitText", firstVisitText);
|
|
|
|
handler.serializeStruct("nextVisitText", nextVisitText);
|
|
|
|
handler.serializeStruct("completedText", completedText);
|
2023-10-09 15:54:14 +02:00
|
|
|
handler.serializeBool("repeatedQuest", repeatedQuest, false);
|
2016-11-13 12:38:42 +02:00
|
|
|
|
|
|
|
if(!handler.saving)
|
|
|
|
{
|
2023-02-12 22:39:17 +02:00
|
|
|
isCustomFirst = !firstVisitText.empty();
|
|
|
|
isCustomNext = !nextVisitText.empty();
|
|
|
|
isCustomComplete = !completedText.empty();
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
2023-10-09 05:24:40 +02:00
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
handler.serializeInt("timeLimit", lastDay, -1);
|
2023-10-11 00:47:19 +02:00
|
|
|
handler.serializeStruct("limiter", mission);
|
|
|
|
handler.serializeInstance("killTarget", killTarget, ObjectInstanceID::NONE);
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
if(!handler.saving) //compatibility with legacy vmaps
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2023-10-09 19:15:34 +02:00
|
|
|
std::string missionType = "None";
|
|
|
|
handler.serializeString("missionType", missionType);
|
|
|
|
if(missionType == "None")
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(missionType == "Level")
|
2023-10-12 12:52:01 +02:00
|
|
|
handler.serializeInt("heroLevel", mission.heroLevel);
|
2023-10-09 19:15:34 +02:00
|
|
|
|
|
|
|
if(missionType == "PrimaryStat")
|
2023-04-13 18:06:44 +02:00
|
|
|
{
|
2023-10-09 19:15:34 +02:00
|
|
|
auto primarySkills = handler.enterStruct("primarySkills");
|
|
|
|
for(int i = 0; i < GameConstants::PRIMARY_SKILLS; ++i)
|
2023-10-11 00:47:19 +02:00
|
|
|
handler.serializeInt(NPrimarySkill::names[i], mission.primary[i], 0);
|
2023-10-09 19:15:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(missionType == "Artifact")
|
2023-10-11 00:47:19 +02:00
|
|
|
handler.serializeIdArray<ArtifactID>("artifacts", mission.artifacts);
|
2023-10-09 19:15:34 +02:00
|
|
|
|
|
|
|
if(missionType == "Army")
|
|
|
|
{
|
|
|
|
auto a = handler.enterArray("creatures");
|
2023-10-11 00:47:19 +02:00
|
|
|
a.serializeStruct(mission.creatures);
|
2023-10-09 19:15:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(missionType == "Resources")
|
|
|
|
{
|
|
|
|
auto r = handler.enterStruct("resources");
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
for(size_t idx = 0; idx < (GameConstants::RESOURCE_QUANTITY - 1); idx++)
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2023-10-11 00:47:19 +02:00
|
|
|
handler.serializeInt(GameConstants::RESOURCE_NAMES[idx], mission.resources[idx], 0);
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
2023-10-09 19:15:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(missionType == "Hero")
|
|
|
|
{
|
2023-11-02 16:31:12 +02:00
|
|
|
HeroTypeID temp;
|
|
|
|
handler.serializeId("hero", temp, HeroTypeID::NONE);
|
2023-10-11 00:47:19 +02:00
|
|
|
mission.heroes.emplace_back(temp);
|
2023-10-09 19:15:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(missionType == "Player")
|
|
|
|
{
|
2023-11-02 16:31:12 +02:00
|
|
|
PlayerColor temp;
|
|
|
|
handler.serializeId("player", temp, PlayerColor::NEUTRAL);
|
2023-10-11 00:47:19 +02:00
|
|
|
mission.players.emplace_back(temp);
|
2023-04-13 18:06:44 +02:00
|
|
|
}
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
bool IQuestObject::checkQuest(const CGHeroInstance* h) const
|
|
|
|
{
|
|
|
|
return quest->checkQuest(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IQuestObject::getVisitText(MetaString &text, std::vector<Component> &components, bool FirstVisit, const CGHeroInstance * h) const
|
|
|
|
{
|
2023-10-10 01:20:55 +02:00
|
|
|
quest->getVisitText(text, components, FirstVisit, h);
|
2023-10-09 19:15:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IQuestObject::afterAddToMapCommon(CMap * map) const
|
|
|
|
{
|
|
|
|
map->addNewQuestInstance(quest);
|
|
|
|
}
|
|
|
|
|
2014-06-05 19:52:14 +03:00
|
|
|
void CGSeerHut::setObjToKill()
|
|
|
|
{
|
2023-10-18 00:13:32 +02:00
|
|
|
if(quest->killTarget == ObjectInstanceID::NONE)
|
|
|
|
return;
|
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
if(getCreatureToKill(true))
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-11-12 19:18:00 +02:00
|
|
|
quest->stackToKill = getCreatureToKill(false)->getCreature();
|
|
|
|
assert(quest->stackToKill != CreatureID::NONE);
|
2014-06-05 19:52:14 +03:00
|
|
|
quest->stackDirection = checkDirection();
|
|
|
|
}
|
2023-10-09 19:15:34 +02:00
|
|
|
else if(getHeroToKill(true))
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-01-02 13:27:03 +02:00
|
|
|
quest->heroName = getHeroToKill(false)->getNameTranslated();
|
2023-09-28 18:43:04 +02:00
|
|
|
quest->heroPortrait = getHeroToKill(false)->getPortraitSource();
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGSeerHut::init(CRandomGenerator & rand)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2022-12-27 23:17:41 +02:00
|
|
|
auto names = VLC->generaltexth->findStringsWithPrefix("core.seerhut.names");
|
|
|
|
|
2023-04-13 18:06:44 +02:00
|
|
|
auto seerNameID = *RandomGeneratorUtil::nextItem(names, rand);
|
|
|
|
seerName = VLC->generaltexth->translate(seerNameID);
|
2016-09-09 19:30:36 +02:00
|
|
|
quest->textOption = rand.nextInt(2);
|
|
|
|
quest->completedOption = rand.nextInt(1, 3);
|
2023-09-13 01:40:07 +02:00
|
|
|
|
|
|
|
configuration.canRefuse = true;
|
|
|
|
configuration.visitMode = Rewardable::EVisitMode::VISIT_ONCE;
|
|
|
|
configuration.selectMode = Rewardable::ESelectMode::SELECT_PLAYER;
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGSeerHut::initObj(CRandomGenerator & rand)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2016-09-09 19:30:36 +02:00
|
|
|
init(rand);
|
2023-09-13 01:40:07 +02:00
|
|
|
|
|
|
|
CRewardableObject::initObj(rand);
|
2023-10-09 19:15:34 +02:00
|
|
|
|
2023-10-10 01:53:25 +02:00
|
|
|
setObjToKill();
|
2023-10-09 19:15:34 +02:00
|
|
|
quest->defineQuestName();
|
|
|
|
|
2023-10-11 00:47:19 +02:00
|
|
|
if(quest->mission == Rewardable::Limiter{} && quest->killTarget == ObjectInstanceID::NONE)
|
2023-10-11 21:10:42 +02:00
|
|
|
quest->isCompleted = true;
|
2023-10-10 01:20:55 +02:00
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
if(quest->questName == quest->missionName(0))
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-09 19:15:34 +02:00
|
|
|
quest->firstVisitText.appendTextID(TextIdentifier("core", "seehut", "empty", quest->completedOption).get());
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-09 19:15:34 +02:00
|
|
|
if(!quest->isCustomFirst)
|
|
|
|
quest->firstVisitText.appendTextID(TextIdentifier("core", "seerhut", "quest", quest->questName, quest->missionState(0), quest->textOption).get());
|
|
|
|
if(!quest->isCustomNext)
|
|
|
|
quest->nextVisitText.appendTextID(TextIdentifier("core", "seerhut", "quest", quest->questName, quest->missionState(1), quest->textOption).get());
|
|
|
|
if(!quest->isCustomComplete)
|
2023-10-10 01:53:25 +02:00
|
|
|
quest->completedText.appendTextID(TextIdentifier("core", "seerhut", "quest", quest-> questName, quest->missionState(2), quest->textOption).get());
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2023-10-13 12:52:45 +02:00
|
|
|
|
|
|
|
quest->getCompletionText(configuration.onSelect);
|
|
|
|
for(auto & i : configuration.info)
|
|
|
|
quest->getCompletionText(i.message);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2016-01-29 08:28:37 +02:00
|
|
|
void CGSeerHut::getRolloverText(MetaString &text, bool onHover) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-09 19:15:34 +02:00
|
|
|
quest->getRolloverText(text, onHover);//TODO: simplify?
|
2016-01-29 08:28:37 +02:00
|
|
|
if(!onHover)
|
2023-06-18 11:18:25 +02:00
|
|
|
text.replaceRawString(seerName);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2014-06-24 20:39:36 +03:00
|
|
|
std::string CGSeerHut::getHoverText(PlayerColor player) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2014-06-24 20:39:36 +03:00
|
|
|
std::string hoverName = getObjectName();
|
2023-10-11 21:10:42 +02:00
|
|
|
if(ID == Obj::SEER_HUT && quest->activeForPlayers.count(player))
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2014-06-24 20:39:36 +03:00
|
|
|
hoverName = VLC->generaltexth->allTexts[347];
|
2016-01-29 08:28:37 +02:00
|
|
|
boost::algorithm::replace_first(hoverName, "%s", seerName);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2014-06-24 20:39:36 +03:00
|
|
|
|
2023-10-11 21:10:42 +02:00
|
|
|
if(quest->activeForPlayers.count(player)
|
|
|
|
&& (quest->mission != Rewardable::Limiter{}
|
|
|
|
|| quest->killTarget != ObjectInstanceID::NONE)) //rollover when the quest is active
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
MetaString ms;
|
|
|
|
getRolloverText (ms, true);
|
|
|
|
hoverName += ms.toString();
|
|
|
|
}
|
|
|
|
return hoverName;
|
|
|
|
}
|
|
|
|
|
2023-11-02 15:50:24 +02:00
|
|
|
std::string CGSeerHut::getHoverText(const CGHeroInstance * hero) const
|
|
|
|
{
|
|
|
|
return getHoverText(hero->getOwner());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CGSeerHut::getPopupText(PlayerColor player) const
|
|
|
|
{
|
|
|
|
return getHoverText(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CGSeerHut::getPopupText(const CGHeroInstance * hero) const
|
|
|
|
{
|
|
|
|
return getHoverText(hero->getOwner());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Component> CGSeerHut::getPopupComponents(PlayerColor player) const
|
|
|
|
{
|
|
|
|
std::vector<Component> result;
|
2023-11-02 15:59:03 +02:00
|
|
|
if (quest->activeForPlayers.count(player))
|
|
|
|
quest->mission.loadComponents(result, nullptr);
|
2023-11-02 15:50:24 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Component> CGSeerHut::getPopupComponents(const CGHeroInstance * hero) const
|
|
|
|
{
|
|
|
|
std::vector<Component> result;
|
2023-11-02 15:59:03 +02:00
|
|
|
if (quest->activeForPlayers.count(hero->getOwner()))
|
|
|
|
quest->mission.loadComponents(result, hero);
|
2023-11-02 15:50:24 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-11-06 18:27:16 +02:00
|
|
|
void CGSeerHut::setPropertyDer(ObjProperty what, ObjPropertyID identifier)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2016-01-29 08:28:37 +02:00
|
|
|
switch(what)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-11-06 18:27:16 +02:00
|
|
|
case ObjProperty::SEERHUT_VISITED:
|
2023-10-11 21:10:42 +02:00
|
|
|
{
|
2023-11-06 18:27:16 +02:00
|
|
|
quest->activeForPlayers.emplace(identifier.as<PlayerColor>());
|
2014-06-05 19:52:14 +03:00
|
|
|
break;
|
2023-10-11 21:10:42 +02:00
|
|
|
}
|
2023-11-06 18:27:16 +02:00
|
|
|
case ObjProperty::SEERHUT_COMPLETE:
|
2023-10-11 21:10:42 +02:00
|
|
|
{
|
2023-11-06 18:27:16 +02:00
|
|
|
quest->isCompleted = identifier.getNum();
|
2023-10-11 21:10:42 +02:00
|
|
|
quest->activeForPlayers.clear();
|
|
|
|
break;
|
|
|
|
}
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGSeerHut::newTurn(CRandomGenerator & rand) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-09-13 01:40:07 +02:00
|
|
|
CRewardableObject::newTurn(rand);
|
2016-01-29 08:28:37 +02:00
|
|
|
if(quest->lastDay >= 0 && quest->lastDay <= cb->getDate() - 1) //time is up
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-11-06 18:27:16 +02:00
|
|
|
cb->setObjPropertyValue(id, ObjProperty::SEERHUT_COMPLETE, true);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-29 08:28:37 +02:00
|
|
|
void CGSeerHut::onHeroVisit(const CGHeroInstance * h) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
InfoWindow iw;
|
|
|
|
iw.player = h->getOwner();
|
2023-10-11 21:10:42 +02:00
|
|
|
if(!quest->isCompleted)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-11 21:10:42 +02:00
|
|
|
bool firstVisit = !quest->activeForPlayers.count(h->getOwner());
|
2014-06-05 19:52:14 +03:00
|
|
|
bool failRequirements = !checkQuest(h);
|
|
|
|
|
2016-01-29 08:28:37 +02:00
|
|
|
if(firstVisit)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-11-06 18:27:16 +02:00
|
|
|
cb->setObjPropertyID(id, ObjProperty::SEERHUT_VISITED, h->getOwner());
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
AddQuest aq;
|
|
|
|
aq.quest = QuestInfo (quest, this, visitablePos());
|
|
|
|
aq.player = h->tempOwner;
|
2016-01-29 08:28:37 +02:00
|
|
|
cb->sendAndApply(&aq); //TODO: merge with setObjProperty?
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2016-01-29 08:28:37 +02:00
|
|
|
if(firstVisit || failRequirements)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-09 19:15:34 +02:00
|
|
|
getVisitText (iw.text, iw.components, firstVisit, h);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
}
|
2016-01-29 08:28:37 +02:00
|
|
|
if(!failRequirements) // propose completion, also on first visit
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-09-13 01:40:07 +02:00
|
|
|
CRewardableObject::onHeroVisit(h);
|
2014-06-05 19:52:14 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendRawString(VLC->generaltexth->seerEmpty[quest->completedOption]);
|
2014-06-05 19:52:14 +03:00
|
|
|
if (ID == Obj::SEER_HUT)
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.replaceRawString(seerName);
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->showInfoDialog(&iw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int CGSeerHut::checkDirection() const
|
|
|
|
{
|
|
|
|
int3 cord = getCreatureToKill()->pos;
|
2023-02-12 22:39:17 +02:00
|
|
|
if(static_cast<double>(cord.x) / static_cast<double>(cb->getMapSize().x) < 0.34) //north
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-02-12 22:39:17 +02:00
|
|
|
if(static_cast<double>(cord.y) / static_cast<double>(cb->getMapSize().y) < 0.34) //northwest
|
2014-06-05 19:52:14 +03:00
|
|
|
return 8;
|
2023-02-12 22:39:17 +02:00
|
|
|
else if(static_cast<double>(cord.y) / static_cast<double>(cb->getMapSize().y) < 0.67) //north
|
2014-06-05 19:52:14 +03:00
|
|
|
return 1;
|
|
|
|
else //northeast
|
|
|
|
return 2;
|
|
|
|
}
|
2023-02-12 22:39:17 +02:00
|
|
|
else if(static_cast<double>(cord.x) / static_cast<double>(cb->getMapSize().x) < 0.67) //horizontal
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-02-12 22:39:17 +02:00
|
|
|
if(static_cast<double>(cord.y) / static_cast<double>(cb->getMapSize().y) < 0.34) //west
|
2014-06-05 19:52:14 +03:00
|
|
|
return 7;
|
2023-02-12 22:39:17 +02:00
|
|
|
else if(static_cast<double>(cord.y) / static_cast<double>(cb->getMapSize().y) < 0.67) //central
|
2014-06-05 19:52:14 +03:00
|
|
|
return 9;
|
|
|
|
else //east
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
else //south
|
|
|
|
{
|
2023-02-12 22:39:17 +02:00
|
|
|
if(static_cast<double>(cord.y) / static_cast<double>(cb->getMapSize().y) < 0.34) //southwest
|
2014-06-05 19:52:14 +03:00
|
|
|
return 6;
|
2023-02-12 22:39:17 +02:00
|
|
|
else if(static_cast<double>(cord.y) / static_cast<double>(cb->getMapSize().y) < 0.67) //south
|
2014-06-05 19:52:14 +03:00
|
|
|
return 5;
|
|
|
|
else //southeast
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const CGHeroInstance * CGSeerHut::getHeroToKill(bool allowNull) const
|
|
|
|
{
|
2023-10-09 05:24:40 +02:00
|
|
|
const CGObjectInstance *o = cb->getObjByQuestIdentifier(quest->killTarget);
|
2014-06-05 19:52:14 +03:00
|
|
|
if(allowNull && !o)
|
|
|
|
return nullptr;
|
2023-02-12 22:39:17 +02:00
|
|
|
return dynamic_cast<const CGHeroInstance *>(o);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const CGCreature * CGSeerHut::getCreatureToKill(bool allowNull) const
|
|
|
|
{
|
2023-10-09 05:24:40 +02:00
|
|
|
const CGObjectInstance *o = cb->getObjByQuestIdentifier(quest->killTarget);
|
2014-06-05 19:52:14 +03:00
|
|
|
if(allowNull && !o)
|
|
|
|
return nullptr;
|
2023-02-12 22:39:17 +02:00
|
|
|
return dynamic_cast<const CGCreature *>(o);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGSeerHut::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
|
|
|
|
{
|
2023-09-13 01:40:07 +02:00
|
|
|
CRewardableObject::blockingDialogAnswered(hero, answer);
|
|
|
|
if(answer)
|
2023-10-09 02:19:58 +02:00
|
|
|
{
|
|
|
|
quest->completeQuest(cb, hero);
|
2023-11-06 18:27:16 +02:00
|
|
|
cb->setObjPropertyValue(id, ObjProperty::SEERHUT_COMPLETE, !quest->repeatedQuest); //mission complete
|
2023-10-09 02:19:58 +02:00
|
|
|
}
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2017-05-28 15:23:42 +02:00
|
|
|
void CGSeerHut::afterAddToMap(CMap* map)
|
|
|
|
{
|
|
|
|
IQuestObject::afterAddToMapCommon(map);
|
|
|
|
}
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
void CGSeerHut::serializeJsonOptions(JsonSerializeFormat & handler)
|
|
|
|
{
|
|
|
|
//quest and reward
|
2023-09-15 15:29:41 +02:00
|
|
|
CRewardableObject::serializeJsonOptions(handler);
|
2016-11-13 12:38:42 +02:00
|
|
|
quest->serializeJson(handler, "quest");
|
2023-09-15 15:29:41 +02:00
|
|
|
|
|
|
|
if(!handler.saving)
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2023-09-17 22:19:45 +02:00
|
|
|
//backward compatibility for VCMI maps that use old SeerHut format
|
2023-09-13 02:14:35 +02:00
|
|
|
auto s = handler.enterStruct("reward");
|
2023-09-15 10:06:06 +02:00
|
|
|
const JsonNode & rewardsJson = handler.getCurrent();
|
|
|
|
|
2023-09-13 02:14:35 +02:00
|
|
|
std::string fullIdentifier;
|
|
|
|
std::string metaTypeName;
|
|
|
|
std::string scope;
|
|
|
|
std::string identifier;
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2023-09-15 10:06:06 +02:00
|
|
|
auto iter = rewardsJson.Struct().begin();
|
|
|
|
fullIdentifier = iter->first;
|
2016-11-13 12:38:42 +02:00
|
|
|
|
2023-07-30 19:12:25 +02:00
|
|
|
ModUtility::parseIdentifier(fullIdentifier, scope, metaTypeName, identifier);
|
2023-09-13 02:14:35 +02:00
|
|
|
if(!std::set<std::string>{"resource", "primarySkill", "secondarySkill", "artifact", "spell", "creature", "experience", "mana", "morale", "luck"}.count(metaTypeName))
|
2016-11-13 12:38:42 +02:00
|
|
|
return;
|
2023-09-15 10:06:06 +02:00
|
|
|
|
2023-09-13 02:14:35 +02:00
|
|
|
int val = 0;
|
|
|
|
handler.serializeInt(fullIdentifier, val);
|
|
|
|
|
2023-09-15 15:29:41 +02:00
|
|
|
Rewardable::VisitInfo vinfo;
|
|
|
|
auto & reward = vinfo.reward;
|
2023-09-13 02:14:35 +02:00
|
|
|
if(metaTypeName == "experience")
|
|
|
|
reward.heroExperience = val;
|
|
|
|
if(metaTypeName == "mana")
|
|
|
|
reward.manaDiff = val;
|
|
|
|
if(metaTypeName == "morale")
|
2023-10-21 14:06:18 +02:00
|
|
|
reward.bonuses.emplace_back(BonusDuration::ONE_BATTLE, BonusType::MORALE, BonusSource::OBJECT_INSTANCE, val, BonusSourceID(id));
|
2023-09-13 02:14:35 +02:00
|
|
|
if(metaTypeName == "luck")
|
2023-10-21 14:06:18 +02:00
|
|
|
reward.bonuses.emplace_back(BonusDuration::ONE_BATTLE, BonusType::LUCK, BonusSource::OBJECT_INSTANCE, val, BonusSourceID(id));
|
2023-09-13 02:14:35 +02:00
|
|
|
if(metaTypeName == "resource")
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2023-09-13 02:14:35 +02:00
|
|
|
auto rawId = *VLC->identifiers()->getIdentifier(ModScope::scopeMap(), fullIdentifier, false);
|
|
|
|
reward.resources[rawId] = val;
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
2023-09-13 02:14:35 +02:00
|
|
|
if(metaTypeName == "primarySkill")
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2023-09-13 02:14:35 +02:00
|
|
|
auto rawId = *VLC->identifiers()->getIdentifier(ModScope::scopeMap(), fullIdentifier, false);
|
|
|
|
reward.primary.at(rawId) = val;
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
2023-09-13 02:14:35 +02:00
|
|
|
if(metaTypeName == "secondarySkill")
|
2016-11-13 12:38:42 +02:00
|
|
|
{
|
2023-09-13 02:14:35 +02:00
|
|
|
auto rawId = *VLC->identifiers()->getIdentifier(ModScope::scopeMap(), fullIdentifier, false);
|
|
|
|
reward.secondary[rawId] = val;
|
|
|
|
}
|
|
|
|
if(metaTypeName == "artifact")
|
|
|
|
{
|
|
|
|
auto rawId = *VLC->identifiers()->getIdentifier(ModScope::scopeMap(), fullIdentifier, false);
|
|
|
|
reward.artifacts.push_back(rawId);
|
|
|
|
}
|
|
|
|
if(metaTypeName == "spell")
|
|
|
|
{
|
|
|
|
auto rawId = *VLC->identifiers()->getIdentifier(ModScope::scopeMap(), fullIdentifier, false);
|
|
|
|
reward.spells.push_back(rawId);
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
2023-09-13 02:14:35 +02:00
|
|
|
if(metaTypeName == "creature")
|
|
|
|
{
|
|
|
|
auto rawId = *VLC->identifiers()->getIdentifier(ModScope::scopeMap(), fullIdentifier, false);
|
|
|
|
reward.creatures.emplace_back(rawId, val);
|
|
|
|
}
|
|
|
|
|
2023-09-15 15:29:41 +02:00
|
|
|
vinfo.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
|
|
|
configuration.info.push_back(vinfo);
|
2023-09-13 02:14:35 +02:00
|
|
|
}
|
2016-11-13 12:38:42 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGQuestGuard::init(CRandomGenerator & rand)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
blockVisit = true;
|
2016-09-09 19:30:36 +02:00
|
|
|
quest->textOption = rand.nextInt(3, 5);
|
|
|
|
quest->completedOption = rand.nextInt(4, 5);
|
2023-09-13 01:40:07 +02:00
|
|
|
|
|
|
|
configuration.info.push_back({});
|
|
|
|
configuration.info.back().visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
2023-11-02 17:12:58 +02:00
|
|
|
configuration.info.back().reward.removeObject = subID.getNum() == 0 ? true : false;
|
2023-09-13 01:40:07 +02:00
|
|
|
configuration.canRefuse = true;
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2023-10-11 23:15:24 +02:00
|
|
|
void CGQuestGuard::onHeroVisit(const CGHeroInstance * h) const
|
|
|
|
{
|
|
|
|
if(!quest->isCompleted)
|
|
|
|
CGSeerHut::onHeroVisit(h);
|
|
|
|
else
|
2023-11-06 18:27:16 +02:00
|
|
|
cb->setObjPropertyValue(id, ObjProperty::SEERHUT_COMPLETE, false);
|
2023-10-11 23:15:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGQuestGuard::passableFor(PlayerColor color) const
|
|
|
|
{
|
|
|
|
return quest->isCompleted;
|
|
|
|
}
|
|
|
|
|
2016-11-13 12:38:42 +02:00
|
|
|
void CGQuestGuard::serializeJsonOptions(JsonSerializeFormat & handler)
|
|
|
|
{
|
|
|
|
//quest only, do not call base class
|
|
|
|
quest->serializeJson(handler, "quest");
|
|
|
|
}
|
|
|
|
|
2023-02-12 22:39:17 +02:00
|
|
|
bool CGKeys::wasMyColorVisited(const PlayerColor & player) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-11-17 21:18:34 +02:00
|
|
|
return cb->getPlayerState(player)->visitedObjectsGlobal.count({ID, subID}) != 0;
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2014-06-24 20:39:36 +03:00
|
|
|
std::string CGKeys::getHoverText(PlayerColor player) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2014-06-24 20:39:36 +03:00
|
|
|
return getObjectName() + "\n" + visitedTxt(wasMyColorVisited(player));
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2014-06-24 20:39:36 +03:00
|
|
|
std::string CGKeys::getObjectName() const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-11-02 18:45:46 +02:00
|
|
|
return VLC->generaltexth->tentColors[subID.getNum()] + " " + CGObjectInstance::getObjectName();
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGKeymasterTent::wasVisited (PlayerColor player) const
|
|
|
|
{
|
|
|
|
return wasMyColorVisited (player);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGKeymasterTent::onHeroVisit( const CGHeroInstance * h ) const
|
|
|
|
{
|
|
|
|
int txt_id;
|
|
|
|
if (!wasMyColorVisited (h->getOwner()) )
|
|
|
|
{
|
2023-11-17 21:18:34 +02:00
|
|
|
ChangeObjectVisitors cow;
|
|
|
|
cow.mode = ChangeObjectVisitors::VISITOR_GLOBAL;
|
|
|
|
cow.hero = h->id;
|
|
|
|
cow.object = id;
|
|
|
|
cb->sendAndApply(&cow);
|
2014-06-05 19:52:14 +03:00
|
|
|
txt_id=19;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
txt_id=20;
|
2023-03-08 00:32:21 +02:00
|
|
|
h->showInfoDialog(txt_id);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2016-09-09 19:30:36 +02:00
|
|
|
void CGBorderGuard::initObj(CRandomGenerator & rand)
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
blockVisit = true;
|
|
|
|
}
|
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
void CGBorderGuard::getVisitText(MetaString &text, std::vector<Component> &components, bool FirstVisit, const CGHeroInstance * h) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2023-10-09 19:15:34 +02:00
|
|
|
text.appendLocalString(EMetaText::ADVOB_TXT, 18);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2023-10-09 19:15:34 +02:00
|
|
|
void CGBorderGuard::getRolloverText(MetaString &text, bool onHover) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
if (!onHover)
|
2023-06-17 22:15:55 +02:00
|
|
|
{
|
2023-11-02 18:45:46 +02:00
|
|
|
text.appendRawString(VLC->generaltexth->tentColors[subID.getNum()]);
|
2023-06-18 11:18:25 +02:00
|
|
|
text.appendRawString(" ");
|
|
|
|
text.appendRawString(VLC->objtypeh->getObjectName(Obj::KEYMASTER, subID));
|
2023-06-17 22:15:55 +02:00
|
|
|
}
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2016-01-29 08:28:37 +02:00
|
|
|
bool CGBorderGuard::checkQuest(const CGHeroInstance * h) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
return wasMyColorVisited (h->tempOwner);
|
|
|
|
}
|
|
|
|
|
2016-01-29 08:28:37 +02:00
|
|
|
void CGBorderGuard::onHeroVisit(const CGHeroInstance * h) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
if (wasMyColorVisited (h->getOwner()) )
|
|
|
|
{
|
|
|
|
BlockingDialog bd (true, false);
|
|
|
|
bd.player = h->getOwner();
|
2023-06-18 11:18:25 +02:00
|
|
|
bd.text.appendLocalString (EMetaText::ADVOB_TXT, 17);
|
2014-06-05 19:52:14 +03:00
|
|
|
cb->showBlockingDialog (&bd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-08 00:32:21 +02:00
|
|
|
h->showInfoDialog(18);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
AddQuest aq;
|
|
|
|
aq.quest = QuestInfo (quest, this, visitablePos());
|
|
|
|
aq.player = h->tempOwner;
|
|
|
|
cb->sendAndApply (&aq);
|
|
|
|
//TODO: add this quest only once OR check for multiple instances later
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGBorderGuard::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
|
|
|
|
{
|
|
|
|
if (answer)
|
2023-09-18 21:09:55 +02:00
|
|
|
cb->removeObject(this, hero->getOwner());
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
|
|
|
|
2017-05-28 15:23:42 +02:00
|
|
|
void CGBorderGuard::afterAddToMap(CMap * map)
|
|
|
|
{
|
|
|
|
IQuestObject::afterAddToMapCommon(map);
|
|
|
|
}
|
|
|
|
|
2016-01-29 08:28:37 +02:00
|
|
|
void CGBorderGate::onHeroVisit(const CGHeroInstance * h) const //TODO: passability
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
|
|
|
if (!wasMyColorVisited (h->getOwner()) )
|
|
|
|
{
|
2023-03-08 00:32:21 +02:00
|
|
|
h->showInfoDialog(18);
|
2014-06-05 19:52:14 +03:00
|
|
|
|
|
|
|
AddQuest aq;
|
|
|
|
aq.quest = QuestInfo (quest, this, visitablePos());
|
|
|
|
aq.player = h->tempOwner;
|
|
|
|
cb->sendAndApply (&aq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-24 02:26:36 +03:00
|
|
|
bool CGBorderGate::passableFor(PlayerColor color) const
|
2014-06-05 19:52:14 +03:00
|
|
|
{
|
2014-06-24 02:26:36 +03:00
|
|
|
return wasMyColorVisited(color);
|
2014-06-05 19:52:14 +03:00
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|