From e9279cfbc47c5a1e27c1ab57b4dc2c8f9ae289a1 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Mon, 1 May 2023 00:14:25 +0400 Subject: [PATCH] Blocking dialogs supported --- lib/CTownHandler.cpp | 4 ++-- lib/mapObjects/CGTownBuilding.cpp | 25 +++++++++++++++---------- lib/mapObjects/CGTownInstance.cpp | 21 ++++++++++++++++++++- lib/mapObjects/CGTownInstance.h | 1 + lib/rewardable/Interface.cpp | 1 - 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index 5f614aa24..a6932254e 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -628,10 +628,10 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons bonus->sid = Bonus::getSid32(ret->town->faction->getIndex(), ret->bid); } - if(!source["rewards"].isNull() && ret->subId == BuildingSubID::NONE) + if(source["type"].String() == "configurable" && ret->subId == BuildingSubID::NONE) { ret->subId = BuildingSubID::CONFIGURABLE_REWARD; - ret->rewardableObjectInfo.init(source["rewards"]); + ret->rewardableObjectInfo.init(source); } } //MODS COMPATIBILITY FOR 0.96 diff --git a/lib/mapObjects/CGTownBuilding.cpp b/lib/mapObjects/CGTownBuilding.cpp index 40bf23c35..5a578680b 100644 --- a/lib/mapObjects/CGTownBuilding.cpp +++ b/lib/mapObjects/CGTownBuilding.cpp @@ -315,13 +315,18 @@ void CTownRewardableBuilding::heroLevelUpDone(const CGHeroInstance *hero) const void CTownRewardableBuilding::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const { + if(visitors.find(hero->id) != visitors.end()) + return; // query not for this building + if(answer == 0) + { + cb->setObjProperty(town->id, ObjProperty::STRUCTURE_CLEAR_VISITORS, indexOnTV); return; // player refused + } if(answer > 0 && answer-1 < configuration.info.size()) { auto list = getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT); - //markAsVisited(hero); grantReward(list[answer - 1], hero); } else @@ -332,8 +337,8 @@ void CTownRewardableBuilding::blockingDialogAnswered(const CGHeroInstance *hero, void CTownRewardableBuilding::grantReward(ui32 rewardID, const CGHeroInstance * hero) const { - //cb->setObjProperty(town->id, ObjProperty::REWARD_SELECT, manaVortex->indexOnTV); //reset visitors for Mana Vortex - //cb->setObjProperty(ObjectInstanceID(indexOnTV), ObjProperty::REWARD_SELECT, rewardID); + town->addHeroToStructureVisitors(hero, indexOnTV); + grantRewardBeforeLevelup(cb, configuration.info.at(rewardID), hero); // hero is not blocked by levelup dialog - grant remainer immediately @@ -368,6 +373,8 @@ void CTownRewardableBuilding::onHeroVisit(const CGHeroInstance *h) const { auto vi = configuration.info.at(index); logGlobal->debug("Granting reward %d. Message says: %s", index, vi.message.toString()); + + town->addHeroToStructureVisitors(h, indexOnTV); //adding to visitors InfoWindow iw; iw.player = h->tempOwner; @@ -377,7 +384,7 @@ void CTownRewardableBuilding::onHeroVisit(const CGHeroInstance *h) const if(!iw.components.empty() || !iw.text.toString().empty()) cb->showInfoDialog(&iw); - //grantReward(index, h); + grantReward(index, h); }; auto selectRewardsMessage = [&](const std::vector & rewards, const MetaString & dialog) -> void { @@ -400,8 +407,6 @@ void CTownRewardableBuilding::onHeroVisit(const CGHeroInstance *h) const if(!wasVisitedBefore(h)) { - town->addHeroToStructureVisitors(h, indexOnTV); - auto rewards = getAvailableRewards(h, Rewardable::EEventType::EVENT_FIRST_VISIT); logGlobal->debug("Visiting object with %d possible rewards", rewards.size()); @@ -442,11 +447,11 @@ void CTownRewardableBuilding::onHeroVisit(const CGHeroInstance *h) const } } - if(getAvailableRewards(h, Rewardable::EEventType::EVENT_FIRST_VISIT).empty()) + /*if(getAvailableRewards(h, Rewardable::EEventType::EVENT_FIRST_VISIT).empty()) { - //ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD_TEAM, id, h->id); - //cb->sendAndApply(&cov); - } + ChangeObjectVisitors cov(ChangeObjectVisitors::VISITOR_ADD_TEAM, id, h->id); + cb->sendAndApply(&cov); + }*/ } else { diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index 1b68c2c15..62078b211 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -53,7 +53,7 @@ void CGTownInstance::setPropertyDer(ui8 what, ui32 val) ///this is freakin' overcomplicated solution switch (what) { - case ObjProperty::STRUCTURE_ADD_VISITING_HERO: + case ObjProperty::STRUCTURE_ADD_VISITING_HERO: bonusingBuildings[val]->setProperty (ObjProperty::VISITORS, visitingHero->id.getNum()); break; case ObjProperty::STRUCTURE_CLEAR_VISITORS: @@ -260,6 +260,12 @@ void CGTownInstance::setOwner(const PlayerColor & player) const cb->setOwner(this, player); } +void CGTownInstance::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const +{ + for (auto building : bonusingBuildings) + building->blockingDialogAnswered(hero, answer); +} + void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const { if(!cb->gameState()->getPlayerRelations( getOwner(), h->getOwner() ))//if this is enemy @@ -383,6 +389,19 @@ void CGTownInstance::addTownBonuses(CRandomGenerator & rand) { auto * newBuilding = new CTownRewardableBuilding(kvp.second->bid, kvp.second->subId, this); kvp.second->rewardableObjectInfo.configureObject(newBuilding->configuration, rand); + for(auto & rewardInfo : newBuilding->configuration.info) + { + for (auto & bonus : rewardInfo.reward.bonuses) + { + bonus.source = Bonus::TOWN_STRUCTURE; + bonus.sid = kvp.second->bid; + //TODO: bonus.description = object->getObjectName(); + if (bonus.type == Bonus::MORALE) + rewardInfo.reward.extraComponents.emplace_back(Component::EComponentType::MORALE, 0, bonus.val, 0); + if (bonus.type == Bonus::LUCK) + rewardInfo.reward.extraComponents.emplace_back(Component::EComponentType::LUCK, 0, bonus.val, 0); + } + } bonusingBuildings.push_back(newBuilding); } } diff --git a/lib/mapObjects/CGTownInstance.h b/lib/mapObjects/CGTownInstance.h index fd9c9dd95..167bf9f27 100644 --- a/lib/mapObjects/CGTownInstance.h +++ b/lib/mapObjects/CGTownInstance.h @@ -206,6 +206,7 @@ public: protected: void setPropertyDer(ui8 what, ui32 val) override; void serializeJsonOptions(JsonSerializeFormat & handler) override; + void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override; private: void setOwner(const PlayerColor & owner) const; diff --git a/lib/rewardable/Interface.cpp b/lib/rewardable/Interface.cpp index 8e4261c83..fd23a3095 100644 --- a/lib/rewardable/Interface.cpp +++ b/lib/rewardable/Interface.cpp @@ -92,7 +92,6 @@ void Rewardable::Interface::grantRewardAfterLevelup(IGameCallback * cb, const Re for(const Bonus & bonus : info.reward.bonuses) { - assert(bonus.source == Bonus::OBJECT); GiveBonus gb; gb.who = GiveBonus::ETarget::HERO; gb.bonus = bonus;