OregonCore  revision fb2a440-git
Your Favourite TBC server
ConditionMgr.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef CONDITIONMGR_H
19 #define CONDITIONMGR_H
20 
21 #include "LootMgr.h"
22 
23 class Player;
24 class Unit;
25 class WorldObject;
26 class LootTemplate;
27 struct Condition;
28 
30 { // value1 value2 value3
31  CONDITION_NONE = 0, // 0 0 0 always true
32  CONDITION_AURA = 1, // spell_id effindex use target? true if player (or target, if value3) has aura of spell_id with effect effindex
33  CONDITION_ITEM = 2, // item_id count bank true if has #count of item_ids (if 'bank' is set it searches in bank slots too)
34  CONDITION_ITEM_EQUIPPED = 3, // item_id 0 0 true if has item_id equipped
35  CONDITION_ZONEID = 4, // zone_id 0 0 true if in zone_id
36  CONDITION_REPUTATION_RANK = 5, // faction_id min_rank 0 true if has min_rank for faction_id
37  CONDITION_TEAM = 6, // player_team 0, 0 469 - Alliance, 67 - Horde)
38  CONDITION_SKILL = 7, // skill_id skill_value 0 true if has skill_value for skill_id
39  CONDITION_QUESTREWARDED = 8, // quest_id 0 0 true if quest_id was rewarded before
40  CONDITION_QUESTTAKEN = 9, // quest_id 0, 0 true while quest active
41  CONDITION_DRUNKENSTATE = 10, // DrunkenState 0, 0 true if player is drunk enough
42  CONDITION_WORLD_STATE = 11, // index value 0 true if world has the value for the index
43  CONDITION_ACTIVE_EVENT = 12, // event_id 0 0 true if event is active
44  CONDITION_INSTANCE_INFO = 13, // entry data type true if the instance info defined by type (enum InstanceInfo) equals data.
45  CONDITION_QUEST_NONE = 14, // quest_id 0 0 true if doesn't have quest saved
46  CONDITION_CLASS = 15, // class 0 0 true if player's class is equal to class
47  CONDITION_RACE = 16, // race 0 0 true if player's race is equal to race
48  CONDITION_SPELL_SCRIPT_TARGET = 17, // SpellScriptTargetType TargetEntry
49  CONDITION_TITLE = 18, // title id 0 0 true if player has title
50  CONDITION_SPAWNMASK = 19, // spawnMask 0 0 true if in spawnMask
51  CONDITION_GENDER = 20, // gender 0 0 true if player's gender is equal to gender
52  CONDITION_UNIT_STATE = 21, // unitState 0 0 true if unit has unitState
53  CONDITION_MAPID = 22, // map_id 0 0 true if in map_id
54  CONDITION_AREAID = 23, // area_id 0 0 true if in area_id
55  CONDITION_CREATURE_TYPE = 24, // cinfo.type 0 0 true if creature_template.type = value1
56  CONDITION_SPELL = 25, // spell_id 0 0 true if player has learned spell
58  CONDITION_LEVEL = 27, // level opt 0 true if unit's level is equal to param1 (param2 can modify the statement)
59  CONDITION_QUEST_COMPLETE = 28, // quest_id 0 0 true if player has quest_id with all objectives complete, but not yet rewarded
60  CONDITION_NEAR_CREATURE = 29, // creature entry distance dead (0/1) true if there is a creature of entry in range
61  CONDITION_NEAR_GAMEOBJECT = 30, // gameobject entry distance 0 true if there is a gameobject of entry in range
62  CONDITION_OBJECT_ENTRY_GUID = 31, // TypeID entry guid true if object is type TypeID and the entry is 0 or matches entry of the object or matches guid of the object
63  CONDITION_TYPE_MASK = 32, // TypeMask 0 0 true if object is type object's TypeMask matches provided TypeMask
64  CONDITION_RELATION_TO = 33, // ConditionTarget RelationType 0 true if object is in given relation with object specified by ConditionTarget
65  CONDITION_REACTION_TO = 34, // ConditionTarget rankMask 0 true if object's reaction matches rankMask object specified by ConditionTarget
66  CONDITION_DISTANCE_TO = 35, // ConditionTarget distance ComparisonType true if object and ConditionTarget are within distance given by parameters
67  CONDITION_ALIVE = 36, // 0 0 0 true if unit is alive
68  CONDITION_HP_VAL = 37, // hpVal ComparisonType 0 true if unit's hp matches given value
69  CONDITION_HP_PCT = 38, // hpPct ComparisonType 0 true if unit's hp matches given pct
70 };
71 
72 #define CONDITION_MAX 39
73 
102 {
121  CONDITION_SOURCE_TYPE_SPELL_CLICK_EVENT = 18, // Not used in 2.4.3
124  CONDITION_SOURCE_TYPE_VEHICLE_SPELL = 21, // Not used in 2.4.3
126 
128 };
129 
131 {
137 };
138 
139 #define COMP_TYPE_MAX 5
140 
142 {
147  RELATION_PASSENGER_OF, // Unsupported, WotLK.
150 };
151 
152 #define RELATION_MAX 6
153 
155 {
159 };
160 
162 {
164 };
165 
167 {
170  ConditionSourceInfo(WorldObject* target0, WorldObject* target1 = NULL, WorldObject* target2 = NULL)
171  {
172  mConditionTargets[0] = target0;
173  mConditionTargets[1] = target1;
174  mConditionTargets[2] = target2;
175  mLastFailedCondition = NULL;
176  }
177 };
178 
179 struct Condition
180 {
181  ConditionSourceType SourceType; //SourceTypeOrReferenceId
184  uint32 SourceId; // So far, only used in CONDITION_SOURCE_TYPE_SMART_EVENT
186  ConditionType Type; //ConditionTypeOrReference
196 
198  {
199  SourceType = CONDITION_SOURCE_TYPE_NONE;
200  SourceGroup = 0;
201  SourceEntry = 0;
202  SourceId = 0;
203  ElseGroup = 0;
204  Type = CONDITION_NONE;
205  ConditionTarget = 0;
206  ConditionValue1 = 0;
207  ConditionValue2 = 0;
208  ConditionValue3 = 0;
209  ReferenceId = 0;
210  ErrorType = 0;
211  ErrorTextId = 0;
212  ScriptId = 0;
213  NegativeCondition = false;
214  }
215 
216  bool Meets(ConditionSourceInfo& sourceInfo);
217  bool isLoaded() { return Type > CONDITION_NONE || ReferenceId; }
218  uint32 GetMaxAvailableConditionTargets();
219 
220  std::string ToString(bool ext = false) const;
221 };
222 
223 typedef std::list<Condition*> ConditionList;
224 typedef std::map<uint32, ConditionList> ConditionTypeContainer;
225 typedef std::map<ConditionSourceType, ConditionTypeContainer> ConditionContainer;
226 typedef std::map<std::pair<int32, uint32 /*SAI source_type*/>, ConditionTypeContainer> SmartEventConditionContainer;
227 
228 typedef std::map<uint32, ConditionList> ConditionReferenceContainer;//only used for references
229 
231 {
232  public:
233  ConditionMgr();
234  ~ConditionMgr();
235 
236  void LoadConditions(bool isReload = false);
237  bool isConditionTypeValid(Condition* cond);
238  ConditionList GetConditionReferences(uint32 refId);
239 
240  bool IsObjectMeetToConditions(WorldObject* object, ConditionList const& conditions);
241  bool IsObjectMeetToConditions(WorldObject* object1, WorldObject* object2, ConditionList const& conditions);
242  bool IsObjectMeetToConditions(ConditionSourceInfo& sourceInfo, ConditionList const& conditions);
243  ConditionList GetConditionsForNotGroupedEntry(ConditionSourceType sourceType, uint32 entry);
244  ConditionList GetConditionsForSmartEvent(int32 entryOrGuid, uint32 eventId, uint32 sourceType);
245 
246  static bool isGroupable(ConditionSourceType sourceType)
247  {
248  return (sourceType == CONDITION_SOURCE_TYPE_CREATURE_LOOT_TEMPLATE ||
260  sourceType == CONDITION_SOURCE_TYPE_GOSSIP_MENU ||
262  sourceType == CONDITION_SOURCE_TYPE_SMART_EVENT);
263  }
264  static bool CanHaveSourceIdSet(ConditionSourceType sourceType);
265 
267  {
268  char const* Name;
272  };
273  static char const* StaticSourceTypeData[CONDITION_SOURCE_TYPE_MAX];
274  static ConditionTypeInfo const StaticConditionTypeData[CONDITION_MAX];
275 
276  protected:
280 
281  private:
282  bool isSourceTypeValid(Condition* cond);
283  bool addToLootTemplate(Condition* cond, LootTemplate* loot);
284  bool addToGossipMenus(Condition* cond);
285  bool addToGossipMenuItems(Condition* cond);
286  bool IsObjectMeetToConditionList(ConditionSourceInfo& sourceInfo, ConditionList const& conditions);
287 
288  void Clean(); // free up resources
289  std::list<Condition*> AllocatedMemoryStore; // some garbage collection :)
290 };
291 
292 template <class T> bool CompareValues(ComparisionType type, T val1, T val2)
293 {
294  switch (type)
295  {
296  case COMP_TYPE_EQ:
297  return val1 == val2;
298  case COMP_TYPE_HIGH:
299  return val1 > val2;
300  case COMP_TYPE_LOW:
301  return val1 < val2;
302  case COMP_TYPE_HIGH_EQ:
303  return val1 >= val2;
304  case COMP_TYPE_LOW_EQ:
305  return val1 <= val2;
306  }
307  // incorrect parameter
308  ASSERT(false);
309  return false;
310 }
311 
312 #define sConditionMgr Oregon::Singleton<ConditionMgr>::Instance()
313 
314 #endif
static bool isGroupable(ConditionSourceType sourceType)
Definition: ConditionMgr.h:246
uint32 ElseGroup
Definition: ConditionMgr.h:185
ConditionType Type
Definition: ConditionMgr.h:186
ConditionSourceType
Definition: ConditionMgr.h:101
bool CompareValues(ComparisionType type, T val1, T val2)
Definition: ConditionMgr.h:292
MaxConditionTargets
Definition: ConditionMgr.h:161
std::list< Condition * > ConditionList
Definition: ConditionMgr.h:223
#define RELATION_MAX
Definition: ConditionMgr.h:152
ACE_INT32 int32
Definition: Define.h:67
int32 SourceEntry
Definition: ConditionMgr.h:183
bool isLoaded()
Definition: ConditionMgr.h:217
InstanceInfo
Definition: ConditionMgr.h:154
uint32 SourceId
Definition: ConditionMgr.h:184
uint32 ErrorTextId
Definition: ConditionMgr.h:191
ConditionType
Definition: ConditionMgr.h:29
ConditionSourceInfo(WorldObject *target0, WorldObject *target1=NULL, WorldObject *target2=NULL)
Definition: ConditionMgr.h:170
ConditionContainer ConditionStore
Definition: ConditionMgr.h:277
uint32 ErrorType
Definition: ConditionMgr.h:190
ACE_UINT8 uint8
Definition: Define.h:73
uint32 SourceGroup
Definition: ConditionMgr.h:182
std::map< std::pair< int32, uint32 >, ConditionTypeContainer > SmartEventConditionContainer
Definition: ConditionMgr.h:226
std::list< Condition * > AllocatedMemoryStore
Definition: ConditionMgr.h:289
uint8 ConditionTarget
Definition: ConditionMgr.h:194
uint32 ConditionValue3
Definition: ConditionMgr.h:189
SmartEventConditionContainer SmartEventConditionStore
Definition: ConditionMgr.h:279
bool NegativeCondition
Definition: ConditionMgr.h:195
Condition * mLastFailedCondition
Definition: ConditionMgr.h:169
uint32 ConditionValue2
Definition: ConditionMgr.h:188
ConditionReferenceContainer ConditionReferenceStore
Definition: ConditionMgr.h:278
uint32 ScriptId
Definition: ConditionMgr.h:193
uint32 ConditionValue1
Definition: ConditionMgr.h:187
std::map< ConditionSourceType, ConditionTypeContainer > ConditionContainer
Definition: ConditionMgr.h:225
#define ASSERT
Definition: Errors.h:29
WorldObject * mConditionTargets[MAX_CONDITION_TARGETS]
Definition: ConditionMgr.h:168
RelationType
Definition: ConditionMgr.h:141
ComparisionType
Definition: ConditionMgr.h:130
#define CONDITION_MAX
Definition: ConditionMgr.h:72
ACE_UINT32 uint32
Definition: Define.h:71
uint32 ReferenceId
Definition: ConditionMgr.h:192
std::map< uint32, ConditionList > ConditionReferenceContainer
Definition: ConditionMgr.h:228
Definition: Unit.h:908
Definition: Player.h:922
std::map< uint32, ConditionList > ConditionTypeContainer
Definition: ConditionMgr.h:224
ConditionSourceType SourceType
Definition: ConditionMgr.h:181