Planeshift
LootRandomizer Class Reference

This class stores an array of LootModifiers and randomizes loot stats. More...

#include <lootrandomizer.h>

Public Member Functions

void AddLootModifier (LootModifier *entry)
 This adds another item to the entries array. More...
 
void ApplyModifier (psItemStats *baseItem, RandomizedOverlay *overlay, csArray< uint32_t > &modifiersIds)
 Applies modifications to a randomized overlay depending on the requested ids. More...
 
float CalcModifierCostCap (psCharacter *chr)
 Runs the LootModifierCap mathscript and returns the result, used by other function to determine if a modifier can be added. More...
 
LootModifierGetModifier (uint32_t id)
 Gets a loot modifier from it's id. More...
 
float GetModifierPercentProbability (int modifierID, int modifierType)
 Returns the percent probability of a modifier based on the total number of modifiers available of that type. More...
 
bool GetModifiers (uint32_t itemID, csArray< psGMSpawnMods::ItemModifier > &mods)
 Gets a loot modifier from it's id. More...
 
 LootRandomizer (CacheManager *cachemanager)
 Constructor. More...
 
psItemRandomizeItem (psItem *item, float cost, bool lootTesting=false, size_t numModifiers=0)
 This randomizes the current loot item and returns the item with the modifiers applied. More...
 
psItemSetModifiers (psItem *item, csArray< uint32_t > &mods)
 Validates and sets the loot modifiers with the given ids. More...
 
 ~LootRandomizer ()
 Destructor. More...
 

Protected Attributes

float adjective_max
 
csArray< LootModifier * > adjectives
 Keeps all the loot modifiers of type "adjective". More...
 
CacheManagercacheManager
 A reference to the cachemanager. More...
 
csHash< LootModifier *, uint32_t > LootModifiersById
 Keeps all the lootmodifiers for faster access when we know the id. More...
 
MathScriptmodifierCostCalc
 A cached reference to the LootModifierCap math script. More...
 
float prefix_max
 
csArray< LootModifier * > prefixes
 Keeps all the loot modifiers of type "prefix". More...
 
float suffix_max
 
csArray< LootModifier * > suffixes
 Keeps all the loot modifiers of type "suffix". More...
 

Detailed Description

This class stores an array of LootModifiers and randomizes loot stats.

Definition at line 69 of file lootrandomizer.h.

Constructor & Destructor Documentation

LootRandomizer::LootRandomizer ( CacheManager cachemanager)

Constructor.

Parameters
cachemanagerA pointer to the cache manager.
LootRandomizer::~LootRandomizer ( )

Destructor.

Member Function Documentation

void LootRandomizer::AddLootModifier ( LootModifier entry)

This adds another item to the entries array.

void LootRandomizer::ApplyModifier ( psItemStats baseItem,
RandomizedOverlay overlay,
csArray< uint32_t > &  modifiersIds 
)

Applies modifications to a randomized overlay depending on the requested ids.

Parameters
baseItemThe basic item which will have the overlay generated for.
overlayA pointer to the overlay where we will save the modifications to apply to this item.
modifiersIdsAn array with all the ids of the modifiers which we will need to apply to the overlay.
float LootRandomizer::CalcModifierCostCap ( psCharacter chr)

Runs the LootModifierCap mathscript and returns the result, used by other function to determine if a modifier can be added.

Parameters
chrThe psCharacter which is being analyzed.
Returns
A number determining the cost cap for the random modifiers.
LootModifier* LootRandomizer::GetModifier ( uint32_t  id)

Gets a loot modifier from it's id.

Parameters
idThe id of the item we are searching for.
Returns
A pointer to the loot modifier which is referenced by the id we were searching for.
float LootRandomizer::GetModifierPercentProbability ( int  modifierID,
int  modifierType 
)

Returns the percent probability of a modifier based on the total number of modifiers available of that type.

Parameters
modifierIDthe ID of the modifier to evaluate.
modifierType0=prefix, 1=suffix, 2=adjective
Returns
the float percentage, or 0 if the modifier is invalid or has no probability
bool LootRandomizer::GetModifiers ( uint32_t  itemID,
csArray< psGMSpawnMods::ItemModifier > &  mods 
)

Gets a loot modifier from it's id.

Parameters
idThe id of the basic item stats we are searching for.
modsThe list of modifiers returned
Returns
True if the array was filled in.
psItem* LootRandomizer::RandomizeItem ( psItem item,
float  cost,
bool  lootTesting = false,
size_t  numModifiers = 0 
)

This randomizes the current loot item and returns the item with the modifiers applied.

Parameters
itemThe item instance which we will be randomizing.
costThe maximum "cost" of the randomization we can apply
See also
CalcModifierCostCap
Parameters
lootTestingSays if we really are applying the modifiers.
numModifiersForces the amount of modifiers to apply.
Returns
A pointer to the resulting item (it's the same pointer which was passed to the function).
psItem* LootRandomizer::SetModifiers ( psItem item,
csArray< uint32_t > &  mods 
)

Validates and sets the loot modifiers with the given ids.

Parameters
itemThe item instance being modified.
modsThe ids of the item modifiers to set.
Returns
A pointer to the modified item.

Member Data Documentation

float LootRandomizer::adjective_max
protected

Definition at line 79 of file lootrandomizer.h.

csArray<LootModifier*> LootRandomizer::adjectives
protected

Keeps all the loot modifiers of type "adjective".

Definition at line 74 of file lootrandomizer.h.

CacheManager* LootRandomizer::cacheManager
protected

A reference to the cachemanager.

Definition at line 168 of file lootrandomizer.h.

csHash<LootModifier*, uint32_t> LootRandomizer::LootModifiersById
protected

Keeps all the lootmodifiers for faster access when we know the id.

Definition at line 75 of file lootrandomizer.h.

MathScript* LootRandomizer::modifierCostCalc
protected

A cached reference to the LootModifierCap math script.

Definition at line 167 of file lootrandomizer.h.

float LootRandomizer::prefix_max
protected

Definition at line 78 of file lootrandomizer.h.

csArray<LootModifier*> LootRandomizer::prefixes
protected

Keeps all the loot modifiers of type "prefix".

Definition at line 72 of file lootrandomizer.h.

float LootRandomizer::suffix_max
protected

Definition at line 80 of file lootrandomizer.h.

csArray<LootModifier*> LootRandomizer::suffixes
protected

Keeps all the loot modifiers of type "suffix".

Definition at line 73 of file lootrandomizer.h.


The documentation for this class was generated from the following file: