1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-15 13:33:36 +02:00

Support for "selectAll" reward

This commit is contained in:
Tomasz Zieliński 2023-10-31 18:21:50 +01:00
parent 29a78c14a2
commit 5e36ef92c7
3 changed files with 40 additions and 1 deletions

View File

@ -50,6 +50,38 @@ void CRewardableObject::selectRewardWthMessage(const CGHeroInstance * contextHer
sd.text = dialog;
sd.components = loadComponents(contextHero, rewardIndices);
cb->showBlockingDialog(&sd);
}
void CRewardableObject::grantAllRewardsWthMessage(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices, bool markAsVisit) const
{
// TODO: A single message for all rewards?
if (rewardIndices.empty())
return;
auto index = rewardIndices.front();
auto vi = configuration.info.at(index);
logGlobal->debug("Granting reward %d. Message says: %s", index, vi.message.toString());
// show message only if it is not empty or in infobox
if (configuration.infoWindowType != EInfoWindowMode::MODAL || !vi.message.toString().empty())
{
InfoWindow iw;
iw.player = contextHero->tempOwner;
iw.text = vi.message;
iw.components = loadComponents(contextHero, rewardIndices);
iw.type = configuration.infoWindowType;
if(!iw.components.empty() || !iw.text.toString().empty())
cb->showInfoDialog(&iw);
}
// grant reward afterwards. Note that it may remove object
if(markAsVisit)
markAsVisited(contextHero);
for (auto index : rewardIndices)
{
grantReward(index, contextHero);
}
}
std::vector<Component> CRewardableObject::loadComponents(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices) const
@ -116,6 +148,10 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
case Rewardable::SELECT_RANDOM: // give random
grantRewardWithMessage(h, *RandomGeneratorUtil::nextItem(rewards, cb->gameState()->getRandomGenerator()), true);
break;
case Rewardable::SELECT_ALL: // grant all possible
auto rewards = getAvailableRewards(h, Rewardable::EEventType::EVENT_FIRST_VISIT);
grantAllRewardsWthMessage(h, rewards, true);
break;
}
break;
}

View File

@ -37,6 +37,8 @@ protected:
virtual void grantRewardWithMessage(const CGHeroInstance * contextHero, int rewardIndex, bool markAsVisit) const;
virtual void selectRewardWthMessage(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices, const MetaString & dialog) const;
virtual void grantAllRewardsWthMessage(const CGHeroInstance * contextHero, const std::vector<ui32>& rewardIndices, bool markAsVisit) const;
std::vector<Component> loadComponents(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices) const;
std::string getDisplayTextImpl(PlayerColor player, const CGHeroInstance * hero, bool includeDescription) const;

View File

@ -36,6 +36,7 @@ enum ESelectMode
SELECT_FIRST, // first reward that matches limiters
SELECT_PLAYER, // player can select from all allowed rewards
SELECT_RANDOM, // one random reward from all mathing limiters
SELECT_ALL // grant all rewards that match limiters
};
enum class EEventType
@ -46,7 +47,7 @@ enum class EEventType
EVENT_NOT_AVAILABLE
};
const std::array<std::string, 3> SelectModeString{"selectFirst", "selectPlayer", "selectRandom"};
const std::array<std::string, 4> SelectModeString{"selectFirst", "selectPlayer", "selectRandom", "selectAll"};
const std::array<std::string, 6> VisitModeString{"unlimited", "once", "hero", "bonus", "limiter", "player"};
struct DLL_LINKAGE ResetInfo