1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Blocking dialogs supported

This commit is contained in:
nordsoft 2023-05-01 00:14:25 +04:00
parent ddb683e237
commit e9279cfbc4
5 changed files with 38 additions and 14 deletions

View File

@ -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

View File

@ -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
@ -369,6 +374,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;
iw.text = vi.message;
@ -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<ui32> & 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
{

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;