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:
parent
e23766280f
commit
ca5c9910a4
@ -238,7 +238,8 @@ 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);
|
||||
cb->giveHeroNewArtifact(hero, VLC->arth->objects[elem], ArtifactPosition::FIRST_AVAILABLE);
|
||||
if(ArtifactUtils::isPossibleToGetArt(hero, elem))
|
||||
cb->giveHeroNewArtifact(hero, VLC->arth->objects[elem], ArtifactPosition::FIRST_AVAILABLE);
|
||||
}
|
||||
//display loot
|
||||
if (!iw.components.empty())
|
||||
|
@ -248,7 +248,8 @@ void CGPandoraBox::giveContentsAfterExp(const CGHeroInstance *h) const
|
||||
cb->giveResources(h->getOwner(), resources);
|
||||
|
||||
for(const auto & elem : artifacts)
|
||||
cb->giveHeroNewArtifact(h, VLC->arth->objects[elem],ArtifactPosition::FIRST_AVAILABLE);
|
||||
if(ArtifactUtils::isPossibleToGetArt(h, elem))
|
||||
cb->giveHeroNewArtifact(h, VLC->arth->objects[elem],ArtifactPosition::FIRST_AVAILABLE);
|
||||
|
||||
iw.components.clear();
|
||||
iw.text.clear();
|
||||
|
@ -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;
|
||||
}
|
||||
return true;
|
||||
if(ArtifactUtils::isBackpackFreeSlots(h, reqSlots))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
case MISSION_ARMY:
|
||||
return checkMissionArmy(this, h);
|
||||
case MISSION_RESOURCES:
|
||||
@ -786,21 +794,28 @@ void CGSeerHut::finishQuest(const CGHeroInstance * h, ui32 accept) const
|
||||
switch (quest->missionType)
|
||||
{
|
||||
case CQuest::MISSION_ART:
|
||||
for (auto & elem : quest->m5arts)
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user