mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-15 11:46:56 +02:00
Support for "selectAll" reward
This commit is contained in:
parent
29a78c14a2
commit
5e36ef92c7
@ -50,6 +50,38 @@ void CRewardableObject::selectRewardWthMessage(const CGHeroInstance * contextHer
|
|||||||
sd.text = dialog;
|
sd.text = dialog;
|
||||||
sd.components = loadComponents(contextHero, rewardIndices);
|
sd.components = loadComponents(contextHero, rewardIndices);
|
||||||
cb->showBlockingDialog(&sd);
|
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
|
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
|
case Rewardable::SELECT_RANDOM: // give random
|
||||||
grantRewardWithMessage(h, *RandomGeneratorUtil::nextItem(rewards, cb->gameState()->getRandomGenerator()), true);
|
grantRewardWithMessage(h, *RandomGeneratorUtil::nextItem(rewards, cb->gameState()->getRandomGenerator()), true);
|
||||||
break;
|
break;
|
||||||
|
case Rewardable::SELECT_ALL: // grant all possible
|
||||||
|
auto rewards = getAvailableRewards(h, Rewardable::EEventType::EVENT_FIRST_VISIT);
|
||||||
|
grantAllRewardsWthMessage(h, rewards, true);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,8 @@ protected:
|
|||||||
virtual void grantRewardWithMessage(const CGHeroInstance * contextHero, int rewardIndex, bool markAsVisit) const;
|
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 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::vector<Component> loadComponents(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices) const;
|
||||||
|
|
||||||
std::string getDisplayTextImpl(PlayerColor player, const CGHeroInstance * hero, bool includeDescription) const;
|
std::string getDisplayTextImpl(PlayerColor player, const CGHeroInstance * hero, bool includeDescription) const;
|
||||||
|
@ -36,6 +36,7 @@ enum ESelectMode
|
|||||||
SELECT_FIRST, // first reward that matches limiters
|
SELECT_FIRST, // first reward that matches limiters
|
||||||
SELECT_PLAYER, // player can select from all allowed rewards
|
SELECT_PLAYER, // player can select from all allowed rewards
|
||||||
SELECT_RANDOM, // one random reward from all mathing limiters
|
SELECT_RANDOM, // one random reward from all mathing limiters
|
||||||
|
SELECT_ALL // grant all rewards that match limiters
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class EEventType
|
enum class EEventType
|
||||||
@ -46,7 +47,7 @@ enum class EEventType
|
|||||||
EVENT_NOT_AVAILABLE
|
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"};
|
const std::array<std::string, 6> VisitModeString{"unlimited", "once", "hero", "bonus", "limiter", "player"};
|
||||||
|
|
||||||
struct DLL_LINKAGE ResetInfo
|
struct DLL_LINKAGE ResetInfo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user