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

Remove copy-pasted code in rewardable town building leading to hero not

registered as visitor
This commit is contained in:
Ivan Savenko 2024-10-11 15:02:48 +00:00
parent d1e7cb72c2
commit c55a75cc4e
4 changed files with 21 additions and 28 deletions

View File

@ -95,19 +95,7 @@ void CRewardableObject::blockingDialogAnswered(const CGHeroInstance * hero, int3
}
else
{
if (answer == 0)
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
{
throw std::runtime_error("Unhandled choice");
}
onBlockingDialogAnswered(hero, answer);
}
}

View File

@ -131,21 +131,7 @@ void TownRewardableBuildingInstance::heroLevelUpDone(const CGHeroInstance *hero)
void TownRewardableBuildingInstance::blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const
{
if(answer == 0)
return; // player refused
if(visitors.find(hero->id) != visitors.end())
return; // query not for this building
if(answer > 0 && answer-1 < configuration.info.size())
{
auto list = getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT);
grantReward(list[answer - 1], hero);
}
else
{
throw std::runtime_error("Unhandled choice");
}
onBlockingDialogAnswered(hero, answer);
}
void TownRewardableBuildingInstance::grantReward(ui32 rewardID, const CGHeroInstance * hero) const

View File

@ -366,4 +366,21 @@ void Rewardable::Interface::doHeroVisit(const CGHeroInstance *h) const
}
}
void Rewardable::Interface::onBlockingDialogAnswered(const CGHeroInstance * hero, int32_t answer) const
{
if (answer == 0)
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
{
throw std::runtime_error("Unhandled choice");
}
}
VCMI_LIB_NAMESPACE_END

View File

@ -48,6 +48,8 @@ protected:
virtual void markAsVisited(const CGHeroInstance * hero) const = 0;
virtual void markAsScouted(const CGHeroInstance * hero) const = 0;
virtual void grantReward(ui32 rewardID, const CGHeroInstance * hero) const = 0;
void onBlockingDialogAnswered(const CGHeroInstance * hero, int32_t answer) const;
public:
/// filters list of visit info and returns rewards that can be granted to current hero