1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Backpack limit part3 finishQuest

This commit is contained in:
SoundSSGood 2023-03-19 20:41:01 +02:00
parent e23766280f
commit ca5c9910a4
3 changed files with 29 additions and 12 deletions

View File

@ -238,6 +238,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const
iw.components.emplace_back(Component::EComponentType::ARTIFACT, elem, 0, 0);
loot << "%s";
loot.addReplacement(MetaString::ART_NAMES, elem);
if(ArtifactUtils::isPossibleToGetArt(hero, elem))
cb->giveHeroNewArtifact(hero, VLC->arth->objects[elem], ArtifactPosition::FIRST_AVAILABLE);
}
//display loot

View File

@ -248,6 +248,7 @@ void CGPandoraBox::giveContentsAfterExp(const CGHeroInstance *h) const
cb->giveResources(h->getOwner(), resources);
for(const auto & elem : artifacts)
if(ArtifactUtils::isPossibleToGetArt(h, elem))
cb->giveHeroNewArtifact(h, VLC->arth->objects[elem],ArtifactPosition::FIRST_AVAILABLE);
iw.components.clear();

View File

@ -140,18 +140,26 @@ bool CQuest::checkQuest(const CGHeroInstance * h) const
return true;
return false;
case MISSION_ART:
{
// if the object was deserialized
if(artifactsRequirements.empty())
for(const auto & id : m5arts)
++artifactsRequirements[id];
size_t reqSlots = 0;
for(const auto & elem : artifactsRequirements)
{
// check required amount of artifacts
if(h->getArtPosCount(elem.first, false, true, true) < elem.second)
return false;
if(!h->hasArt(elem.first))
reqSlots += h->getAssemblyByConstituent(elem.first)->constituentsInfo.size() - 2;
}
if(ArtifactUtils::isBackpackFreeSlots(h, reqSlots))
return true;
else
return false;
}
case MISSION_ARMY:
return checkMissionArmy(this, h);
case MISSION_RESOURCES:
@ -788,19 +796,26 @@ void CGSeerHut::finishQuest(const CGHeroInstance * h, ui32 accept) const
case CQuest::MISSION_ART:
for(auto & elem : quest->m5arts)
{
if(!h->hasArt(elem))
if(h->hasArt(elem))
{
cb->removeArtifact(ArtifactLocation(h, h->getArtPos(elem, false)));
}
else
{
// first we need to disassemble this backpack artifact
const auto * assembly = h->getAssemblyByConstituent(elem);
assert(assembly);
for(const auto & ci : assembly->constituentsInfo)
{
cb->giveHeroNewArtifact(h, ci.art->artType, ArtifactPosition::PRE_FIRST);
}
// remove the assembly
auto parts = assembly->constituentsInfo;
// Remove the assembly
cb->removeArtifact(ArtifactLocation(h, h->getArtPos(assembly)));
// Disassemble this backpack artifact
for(const auto & ci : parts)
{
if(ci.art->artType->getId() != elem)
cb->giveHeroNewArtifact(h, ci.art->artType, GameConstants::BACKPACK_START);
}
}
cb->removeArtifact(ArtifactLocation(h, h->getArtPos(elem, false)));
}
break;
case CQuest::MISSION_ARMY: