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

backpack assemble

This commit is contained in:
SoundSSGood 2022-11-18 01:32:25 +02:00
parent 16b650136a
commit e9ab894638
4 changed files with 30 additions and 21 deletions

View File

@ -819,13 +819,7 @@ CArtifactsOfHero::ArtPlacePtr CArtifactsOfHero::getArtPlace(int slot)
}
}
void CArtifactsOfHero::artifactAssembled(const ArtifactLocation &al)
{
if(al.isHolder(curHero))
updateWornSlots();
}
void CArtifactsOfHero::artifactDisassembled(const ArtifactLocation & al)
void CArtifactsOfHero::artifactUpdateSlots(const ArtifactLocation & al)
{
if(al.isHolder(curHero))
{
@ -927,7 +921,7 @@ void CWindowWithArtifacts::artifactDisassembled(const ArtifactLocation &artLoc)
{
std::shared_ptr<CArtifactsOfHero> realPtr = artSetWeak.lock();
if(realPtr)
realPtr->artifactDisassembled(artLoc);
realPtr->artifactUpdateSlots(artLoc);
}
}
@ -937,7 +931,7 @@ void CWindowWithArtifacts::artifactAssembled(const ArtifactLocation &artLoc)
{
std::shared_ptr<CArtifactsOfHero> realPtr = artSetWeak.lock();
if(realPtr)
realPtr->artifactAssembled(artLoc);
realPtr->artifactUpdateSlots(artLoc);
}
}

View File

@ -140,8 +140,7 @@ public:
void realizeCurrentTransaction(); //calls callback with parameters stored in commonInfo
void artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst);
void artifactRemoved(const ArtifactLocation &al);
void artifactAssembled(const ArtifactLocation &al);
void artifactDisassembled(const ArtifactLocation &al);
void artifactUpdateSlots(const ArtifactLocation &al);
ArtPlacePtr getArtPlace(int slot);//may return null
void setHero(const CGHeroInstance * hero);

View File

@ -1167,26 +1167,38 @@ DLL_LINKAGE void BulkMoveArtifacts::applyGs(CGameState * gs)
DLL_LINKAGE void AssembledArtifact::applyGs(CGameState *gs)
{
CArtifactSet *artSet = al.getHolderArtSet();
CArtifactSet * artSet = al.getHolderArtSet();
const CArtifactInstance *transformedArt = al.getArt();
assert(transformedArt);
assert(vstd::contains(transformedArt->assemblyPossibilities(artSet, true), builtArt));
bool combineEquipped = true;
if(al.slot >= GameConstants::BACKPACK_START)
combineEquipped = false;
assert(vstd::contains(transformedArt->assemblyPossibilities(artSet, combineEquipped), builtArt));
UNUSED(transformedArt);
auto combinedArt = new CCombinedArtifactInstance(builtArt);
gs->map->addNewArtifactInstance(combinedArt);
//retrieve all constituents
// Retrieve all constituents
for(const CArtifact * constituent : *builtArt->constituents)
{
ArtifactPosition pos = artSet->getArtPos(constituent->id);
ArtifactPosition pos = artSet->getArtPos(constituent->id, combineEquipped);
assert(pos >= 0);
CArtifactInstance *constituentInstance = artSet->getArt(pos);
CArtifactInstance * constituentInstance = artSet->getArt(pos);
//move constituent from hero to be part of new, combined artifact
constituentInstance->removeFrom(ArtifactLocation(al.artHolder, pos));
combinedArt->addAsConstituent(constituentInstance, pos);
if(!vstd::contains(combinedArt->artType->possibleSlots[artSet->bearerType()], al.slot) && vstd::contains(combinedArt->artType->possibleSlots[artSet->bearerType()], pos))
al.slot = pos;
if(combineEquipped)
{
if(!vstd::contains(combinedArt->artType->possibleSlots[artSet->bearerType()], al.slot)
&& vstd::contains(combinedArt->artType->possibleSlots[artSet->bearerType()], pos))
al.slot = pos;
}
else
{
if(al.slot > pos)
al.slot = pos;
}
}
//put new combined artifacts

View File

@ -4031,13 +4031,17 @@ bool CGameHandler::assembleArtifacts (ObjectInstanceID heroID, ArtifactPosition
if (!destArtifact)
COMPLAIN_RET("assembleArtifacts: there is no such artifact instance!");
if (assemble)
if(assemble)
{
CArtifact *combinedArt = VLC->arth->objects[assembleTo];
if (!combinedArt->constituents)
if(!combinedArt->constituents)
COMPLAIN_RET("assembleArtifacts: Artifact being attempted to assemble is not a combined artifacts!");
if (!vstd::contains(destArtifact->assemblyPossibilities(hero, true), combinedArt))
bool combineEquipped = true;
if(artifactSlot >= GameConstants::BACKPACK_START)
combineEquipped = false;
if(!vstd::contains(destArtifact->assemblyPossibilities(hero, combineEquipped), combinedArt))
COMPLAIN_RET("assembleArtifacts: It's impossible to assemble requested artifact!");
if(ArtifactUtils::checkSpellbookIsNeeded(hero, assembleTo, artifactSlot))
giveHeroNewArtifact(hero, VLC->arth->objects[ArtifactID::SPELLBOOK], ArtifactPosition::SPELLBOOK);