1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
|
/*
* CRewardableObject.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "CObjectHandler.h"
#include "CArmedInstance.h"
#include "../NetPacksBase.h"
#include "../ResourceSet.h"
VCMI_LIB_NAMESPACE_BEGIN
class CRandomRewardObjectInfo;
/// Limiters of rewards. Rewards will be granted to hero only if he satisfies requirements
/// Note: for this is only a test - it won't remove anything from hero (e.g. artifacts or creatures)
/// NOTE: in future should (partially) replace seer hut/quest guard quests checks
class DLL_LINKAGE CRewardLimiter
{
public:
/// how many times this reward can be granted, 0 for unlimited
si32 numOfGrants;
/// day of week, unused if 0, 1-7 will test for current day of week
si32 dayOfWeek;
/// level that hero needs to have
si32 minLevel;
/// resources player needs to have in order to trigger reward
TResources resources;
/// skills hero needs to have
std::vector<si32> primary;
std::map<SecondarySkill, si32> secondary;
/// artifacts that hero needs to have (equipped or in backpack) to trigger this
/// Note: does not checks for multiple copies of the same arts
std::vector<ArtifactID> artifacts;
/// creatures that hero needs to have
std::vector<CStackBasicDescriptor> creatures;
CRewardLimiter():
numOfGrants(0),
dayOfWeek(0),
minLevel(0),
primary(4, 0)
{}
bool heroAllowed(const CGHeroInstance * hero) const;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & numOfGrants;
h & dayOfWeek;
h & minLevel;
h & resources;
h & primary;
h & secondary;
h & artifacts;
h & creatures;
}
};
/// Reward that can be granted to a hero
/// NOTE: eventually should replace seer hut rewards and events/pandoras
class DLL_LINKAGE CRewardInfo
{
public:
/// resources that will be given to player
TResources resources;
/// received experience
ui32 gainedExp;
/// received levels (converted into XP during grant)
ui32 gainedLevels;
/// mana given to/taken from hero, fixed value
si32 manaDiff;
/// fixed value, in form of percentage from max
si32 manaPercentage;
/// movement points, only for current day. Bonuses should be used to grant MP on any other day
si32 movePoints;
/// fixed value, in form of percentage from max
si32 movePercentage;
/// list of bonuses, e.g. morale/luck
std::vector<Bonus> bonuses;
/// skills that hero may receive or lose
std::vector<si32> primary;
std::map<SecondarySkill, si32> secondary;
/// objects that hero may receive
std::vector<ArtifactID> artifacts;
std::vector<SpellID> spells;
std::vector<CStackBasicDescriptor> creatures;
/// list of components that will be added to reward description. First entry in list will override displayed component
std::vector<Component> extraComponents;
/// if set to true, object will be removed after granting reward
bool removeObject;
/// Generates list of components that describes reward for a specific hero
virtual void loadComponents(std::vector<Component> & comps,
const CGHeroInstance * h) const;
Component getDisplayedComponent(const CGHeroInstance * h) const;
CRewardInfo() :
gainedExp(0),
gainedLevels(0),
manaDiff(0),
manaPercentage(-1),
movePoints(0),
movePercentage(-1),
primary(4, 0),
removeObject(false)
{}
template <typename Handler> void serialize(Handler &h, const int version)
{
h & resources;
h & extraComponents;
h & removeObject;
h & manaPercentage;
h & movePercentage;
h & gainedExp;
h & gainedLevels;
h & manaDiff;
h & movePoints;
h & primary;
h & secondary;
h & bonuses;
h & artifacts;
h & spells;
h & creatures;
}
};
class DLL_LINKAGE CVisitInfo
{
public:
CRewardLimiter limiter;
CRewardInfo reward;
/// Message that will be displayed on granting of this reward, if not empty
MetaString message;
/// Chance for this reward to be selected in case of random choice
si32 selectChance;
/// How many times this reward has been granted since last reset
si32 numOfGrants;
CVisitInfo():
selectChance(0),
numOfGrants(0)
{}
template <typename Handler> void serialize(Handler &h, const int version)
{
h & limiter;
h & reward;
h & message;
h & selectChance;
h & numOfGrants;
}
};
namespace Rewardable
{
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.
/// Inherits from CArmedInstance for proper trasfer of armies
class DLL_LINKAGE CRewardableObject : public CArmedInstance
{
/// function that must be called if hero got level-up during grantReward call
void grantRewardAfterLevelup(const CVisitInfo & reward, const CGHeroInstance * hero) const;
/// grants reward to hero
void grantRewardBeforeLevelup(const CVisitInfo & reward, const CGHeroInstance * hero) const;
protected:
/// controls selection of reward granted to player
enum ESelectMode
{
SELECT_FIRST, // first reward that matches limiters
SELECT_PLAYER, // player can select from all allowed rewards
SELECT_RANDOM // reward will be selected from allowed randomly
};
enum EVisitMode
{
VISIT_UNLIMITED, // any number of times. Side effect - object hover text won't contain visited/not visited text
VISIT_ONCE, // only once, first to visit get all the rewards
VISIT_HERO, // every hero can visit object once
VISIT_BONUS, // can be visited by any hero that don't have bonus from this object
VISIT_PLAYER // every player can visit object once
};
/// filters list of visit info and returns rewards that can be granted to current hero
virtual std::vector<ui32> getAvailableRewards(const CGHeroInstance * hero) const;
virtual void grantReward(ui32 rewardID, const CGHeroInstance * hero) const;
virtual CVisitInfo getVisitInfo(int index, const CGHeroInstance *h) const;
virtual void triggerRewardReset() const;
/// Rewards that can be granted by an object
std::vector<CVisitInfo> info;
/// MetaString's that contain text for messages for specific situations
MetaString onSelect;
MetaString onVisited;
MetaString onEmpty;
/// how reward will be selected, uses ESelectMode enum
ui8 selectMode;
/// contols who can visit an object, uses EVisitMode enum
ui8 visitMode;
/// reward selected by player
ui16 selectedReward;
/// object visitability info will be reset each resetDuration days
ui16 resetDuration;
/// if true - player can refuse visiting an object (e.g. Tomb)
bool canRefuse;
public:
void setPropertyDer(ui8 what, ui32 val) override;
std::string getHoverText(PlayerColor player) const override;
std::string getHoverText(const CGHeroInstance * hero) const override;
/// Visitability checks. Note that hero check includes check for hero owner (returns true if object was visited by player)
bool wasVisited(PlayerColor player) const override;
bool wasVisited(const CGHeroInstance * h) const override;
/// gives reward to player or ask for choice in case of multiple rewards
void onHeroVisit(const CGHeroInstance *h) const override;
///possibly resets object state
void newTurn(CRandomGenerator & rand) const override;
/// gives second part of reward after hero level-ups for proper granting of spells/mana
void heroLevelUpDone(const CGHeroInstance *hero) const override;
/// applies player selection of reward
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
/// function that will be called once reward is fully granted to hero
virtual void onRewardGiven(const CGHeroInstance * hero) const;
void initObj(CRandomGenerator & rand) override;
CRewardableObject();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CArmedInstance&>(*this);
h & info;
h & canRefuse;
h & resetDuration;
h & onSelect;
h & onVisited;
h & onEmpty;
h & visitMode;
h & selectMode;
h & selectedReward;
}
// for configuration/object setup
friend class CRandomRewardObjectInfo;
};
class DLL_LINKAGE CGPickable : public CRewardableObject //campfire, treasure chest, Flotsam, Shipwreck Survivor, Sea Chest
{
public:
void initObj(CRandomGenerator & rand) override;
CGPickable();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CRewardableObject&>(*this);
}
};
class DLL_LINKAGE CGBonusingObject : public CRewardableObject //objects giving bonuses to luck/morale/movement
{
protected:
CVisitInfo getVisitInfo(int index, const CGHeroInstance *h) const override;
void grantReward(ui32 rewardID, const CGHeroInstance * hero) const override;
public:
void initObj(CRandomGenerator & rand) override;
CGBonusingObject();
void onHeroVisit(const CGHeroInstance *h) const override;
bool wasVisited(const CGHeroInstance * h) const override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CRewardableObject&>(*this);
}
};
class DLL_LINKAGE CGOnceVisitable : public CRewardableObject // wagon, corpse, lean to, warriors tomb
{
public:
void initObj(CRandomGenerator & rand) override;
CGOnceVisitable();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CRewardableObject&>(*this);
}
};
class DLL_LINKAGE CGVisitableOPH : public CRewardableObject //objects visitable only once per hero
{
public:
void initObj(CRandomGenerator & rand) override;
CGVisitableOPH();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CRewardableObject&>(*this);
}
};
class DLL_LINKAGE CGVisitableOPW : public CRewardableObject //objects visitable once per week
{
protected:
void triggerRewardReset() const override;
public:
void initObj(CRandomGenerator & rand) override;
CGVisitableOPW();
void setPropertyDer(ui8 what, ui32 val) override;
void setRandomReward(CRandomGenerator & rand);
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CRewardableObject&>(*this);
}
};
///Special case - magic spring that has two separate visitable entrances
class DLL_LINKAGE CGMagicSpring : public CGVisitableOPW
{
protected:
std::vector<ui32> getAvailableRewards(const CGHeroInstance * hero) const override;
public:
void initObj(CRandomGenerator & rand) override;
std::vector<int3> getVisitableOffsets() const;
int3 getVisitableOffset() const override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CGVisitableOPW&>(*this);
}
};
//TODO:
// MAX
// class DLL_LINKAGE CGPandoraBox : public CArmedInstance
// class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects
// class DLL_LINKAGE CGSeerHut : public CArmedInstance, public IQuestObject //army is used when giving reward
// class DLL_LINKAGE CGQuestGuard : public CGSeerHut
// class DLL_LINKAGE CBank : public CArmedInstance
// class DLL_LINKAGE CGPyramid : public CBank
// EXTRA
// class DLL_LINKAGE COPWBonus : public CGTownBuilding
// class DLL_LINKAGE CTownBonus : public CGTownBuilding
// class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards
// class DLL_LINKAGE CGKeymasterTent : public CGKeys
// class DLL_LINKAGE CGBorderGuard : public CGKeys, public IQuestObject
// POSSIBLE
// class DLL_LINKAGE CGSignBottle : public CGObjectInstance //signs and ocean bottles
// class DLL_LINKAGE CGWitchHut : public CPlayersVisited
// class DLL_LINKAGE CGScholar : public CGObjectInstance
VCMI_LIB_NAMESPACE_END
|