1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-24 03:47:18 +02:00

Minor changes

This commit is contained in:
nordsoft 2023-04-30 01:43:02 +04:00
parent e47bb3f1f9
commit c39a9cac63
2 changed files with 17 additions and 18 deletions

View File

@ -212,11 +212,6 @@ ui16 Rewardable::Configuration::getResetDuration() const
return resetParameters.period;
}
void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
{
auto grantRewardWithMessage = [&](int index, bool markAsVisit) -> void
@ -292,6 +287,9 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
case Rewardable::SELECT_FIRST: // give first available
grantRewardWithMessage(rewards[0], true);
break;
case Rewardable::SELECT_RANDOM: // give random
grantRewardWithMessage(*RandomGeneratorUtil::nextItem(rewards, cb->gameState()->getRandomGenerator()), true);
break;
}
break;
}
@ -317,7 +315,7 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
void CRewardableObject::heroLevelUpDone(const CGHeroInstance *hero) const
{
grantRewardAfterLevelup(configuration.info[configuration.selectedReward], hero);
grantRewardAfterLevelup(configuration.info[selectedReward], hero);
}
void CRewardableObject::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
@ -476,7 +474,7 @@ bool CRewardableObject::wasVisitedBefore(const CGHeroInstance * contextHero) con
case Rewardable::VISIT_UNLIMITED:
return false;
case Rewardable::VISIT_ONCE:
return configuration.onceVisitableObjectCleared;
return onceVisitableObjectCleared;
case Rewardable::VISIT_PLAYER:
return vstd::contains(cb->getPlayerState(contextHero->getOwner())->visitedObjects, ObjectInstanceID(id));
case Rewardable::VISIT_BONUS:
@ -540,10 +538,10 @@ void CRewardableObject::setPropertyDer(ui8 what, ui32 val)
initObj(cb->gameState()->getRandomGenerator());
break;
case ObjProperty::REWARD_SELECT:
configuration.selectedReward = val;
selectedReward = val;
break;
case ObjProperty::REWARD_CLEARED:
configuration.onceVisitableObjectCleared = val;
onceVisitableObjectCleared = val;
break;
}
}

View File

@ -271,9 +271,10 @@ namespace Rewardable
{
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
};
const std::array<std::string, 3> SelectModeString{"selectFirst", "selectPlayer"};
const std::array<std::string, 3> SelectModeString{"selectFirst", "selectPlayer", "selectRandom"};
const std::array<std::string, 5> VisitModeString{"unlimited", "once", "hero", "bonus", "player"};
/// Base class that can handle granting rewards to visiting heroes.
@ -292,9 +293,6 @@ namespace Rewardable
/// contols who can visit an object, uses EVisitMode enum
ui8 visitMode = Rewardable::VISIT_UNLIMITED;
/// reward selected by player
ui16 selectedReward = 0;
/// how and when should the object be reset
CRewardResetInfo resetParameters;
@ -304,8 +302,6 @@ namespace Rewardable
/// if true - object info will shown in infobox (like resource pickup)
EInfoWindowMode infoWindowType = EInfoWindowMode::AUTO;
bool onceVisitableObjectCleared = false;
EVisitMode getVisitMode() const;
ui16 getResetDuration() const;
@ -322,8 +318,6 @@ namespace Rewardable
h & onSelect;
h & visitMode;
h & selectMode;
h & selectedReward;
h & onceVisitableObjectCleared;
h & infoWindowType;
}
};
@ -342,8 +336,13 @@ protected:
/// grants reward to hero
void grantRewardBeforeLevelup(const CRewardVisitInfo & reward, const CGHeroInstance * hero) const;
/// caster to cast adveture spells
/// caster to cast adveture spells, no serialize
mutable spells::ExternalCaster caster;
/// reward selected by player, no serialize
ui16 selectedReward = 0;
bool onceVisitableObjectCleared = false;
public:
@ -382,6 +381,8 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CArmedInstance&>(*this);
h & configuration;
h & onceVisitableObjectCleared;
}
friend class CRewardableConstructor;