Planeshift
lootrandomizer.h
Go to the documentation of this file.
1 /*
2  * lootrandomizer.h by Stefano Angeleri
3  *
4  * Copyright (C) 2010 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 #ifndef __LOOTRANDOMIZER_H__
20 #define __LOOTRANDOMIZER_H__
21 
22 class RandomizedOverlay;
23 
33 {
34  uint32_t id;
35  uint32_t mod_id;
36  csString modifier_type;
37  csString name;
38  csString effect;
39  csString equip_script;
40  float probability;
42  csString stat_req_modifier;
43  float cost_modifier;
44  csString mesh;
45  csString icon;
46  csString not_usable_with;
47  csHash<bool, uint32_t> itemRestrain;
48 
49  // Return true if this modifier is allowed with the given item stats ID.
50  bool IsAllowed(uint32_t itemID);
51 };
52 
58 {
59  csString name;
60  csString op;
61  float value;
62 };
63 
64 class MathScript;
70 {
71 protected:
72  csArray<LootModifier*> prefixes;
73  csArray<LootModifier*> suffixes;
74  csArray<LootModifier*> adjectives;
75  csHash<LootModifier*, uint32_t> LootModifiersById;
76 
77  // precalculated max values for probability. min is always 0
78  float prefix_max;
80  float suffix_max;
81 
82 public:
88  LootRandomizer(CacheManager* cachemanager);
92  ~LootRandomizer();
93 
97  void AddLootModifier(LootModifier* entry);
98 
105  LootModifier* GetModifier(uint32_t id);
106 
114  bool GetModifiers(uint32_t itemID, csArray<psGMSpawnMods::ItemModifier>& mods);
115 
123  psItem* SetModifiers(psItem* item, csArray<uint32_t>& mods);
124 
134  psItem* RandomizeItem(psItem* item,
135  float cost,
136  bool lootTesting = false,
137  size_t numModifiers = 0);
138 
146  float CalcModifierCostCap(psCharacter* chr);
147 
155  void ApplyModifier(psItemStats* baseItem, RandomizedOverlay* overlay, csArray<uint32_t> &modifiersIds);
156 
164  float GetModifierPercentProbability(int modifierID, int modifierType);
165 
166 protected:
169 
170 private:
171  void AddModifier(LootModifier* oper1, LootModifier* oper2);
172 
185  bool SetAttribute(const csString &op, const csString &attrName, float modifier, RandomizedOverlay* overlay, psItemStats* baseItem, csArray<ValueModifier> &values);
186 
195  void SetAttributeApplyOP(float* value[], float modifier, size_t amount, const csString &op);
196 
206  csString GenerateScriptXML(csString &name, csString &equip_script, csArray<ValueModifier> &values);
207 };
208 
211 #endif
212 
This class stores an array of LootModifiers and randomizes loot stats.
uint32_t id
The id assigned to this modifier in the db. It&#39;s referenced by psitem.
csString not_usable_with
Defines which modifiers this isn&#39;t usable with.
csString op
The operation parsed for this reference to the variable ADD, MUL, VAL (VAL is the default value...
float cost_modifier
The cost of this modifier.
A MathScript is a mini-program to run.
Definition: mathscript.h:442
csHash< LootModifier *, uint32_t > LootModifiersById
Keeps all the lootmodifiers for faster access when we know the id.
float probabilityRange
The probability for this loot modifier expressed as range between current number and previous one...
csString modifier_type
The type of modifier (suffix, prefix, adjective)
float value
The value to apply to the variable through the requested operation in op.
This structure contains the parsed data from Attributes recarding script variables.
csString equip_script
The part of equip_script to add to the item when this modifier is used.
csString stat_req_modifier
The additional requirements to stats when this modifier is used.
csString mesh
The mesh this modifier will use for the random item generated.
csArray< LootModifier * > adjectives
Keeps all the loot modifiers of type "adjective".
csHash< bool, uint32_t > itemRestrain
Contains if the itemid is allowed or not. item id 0 means all items, false means disallowed.
csArray< LootModifier * > suffixes
Keeps all the loot modifiers of type "suffix".
bool IsAllowed(uint32_t itemID)
csString effect
Declares modifiers to some stats like weight, weapon speed, resistance/attack types.
This huge class stores all the properties of any object a player can have in the game.
Definition: psitemstats.h:463
This class manages the caching of data that is unchanging during server operation.
Definition: cachemanager.h:234
float probability
The probability for this loot modifier to happen when generating a random item.
uint32_t mod_id
The modifier position ID.
This class holds one loot modifier The lootRandomizer contions arrays of these.
csString name
The part of name which this modifier will add when used. The position is determined by modifier_type...
csString icon
The icon this modifier will use for the random item generated.
csString name
The name of the variable.
Stores the randomized stats from the loot randomizer, it could be used to apply any global special ef...
Definition: psitem.h:171
csArray< LootModifier * > prefixes
Keeps all the loot modifiers of type "prefix".
CacheManager * cacheManager
A reference to the cachemanager.
This class embodies item instances in the game.
Definition: psitem.h:238
MathScript * modifierCostCalc
A cached reference to the LootModifierCap math script.