TrinityCore
Loading...
Searching...
No Matches
ConditionMgr.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore 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 TRINITY_CONDITIONMGR_H
19#define TRINITY_CONDITIONMGR_H
20
21#include "Define.h"
22#include "Hash.h"
23#include <array>
24#include <string>
25#include <unordered_map>
26#include <unordered_set>
27#include <vector>
28
29class Creature;
30class Player;
31class Unit;
32class WorldObject;
33class LootTemplate;
34struct Condition;
35
37{ // value1 value2 value3
38 CONDITION_NONE = 0, // 0 0 0 always true
39 CONDITION_AURA = 1, // spell_id effindex 0 true if target has aura of spell_id with effect effindex
40 CONDITION_ITEM = 2, // item_id count bank true if has #count of item_ids (if 'bank' is set it searches in bank slots too)
41 CONDITION_ITEM_EQUIPPED = 3, // item_id 0 0 true if has item_id equipped
42 CONDITION_ZONEID = 4, // zone_id 0 0 true if in zone_id
43 CONDITION_REPUTATION_RANK = 5, // faction_id rankMask 0 true if has min_rank for faction_id
44 CONDITION_TEAM = 6, // player_team 0, 0 469 - Alliance, 67 - Horde)
45 CONDITION_SKILL = 7, // skill_id skill_value 0 true if has skill_value for skill_id
46 CONDITION_QUESTREWARDED = 8, // quest_id 0 0 true if quest_id was rewarded before
47 CONDITION_QUESTTAKEN = 9, // quest_id 0, 0 true while quest active
48 CONDITION_DRUNKENSTATE = 10, // DrunkenState 0, 0 true if player is drunk enough
49 CONDITION_WORLD_STATE = 11, // index value 0 true if world has the value for the index
50 CONDITION_ACTIVE_EVENT = 12, // event_id 0 0 true if event is active
51 CONDITION_INSTANCE_INFO = 13, // entry data type true if the instance info defined by type (enum InstanceInfo) equals data.
52 CONDITION_QUEST_NONE = 14, // quest_id 0 0 true if doesn't have quest saved
53 CONDITION_CLASS = 15, // class 0 0 true if player's class is equal to class
54 CONDITION_RACE = 16, // race 0 0 true if player's race is equal to race
55 CONDITION_ACHIEVEMENT = 17, // achievement_id 0 0 true if achievement is complete
56 CONDITION_TITLE = 18, // title id 0 0 true if player has title
57 CONDITION_SPAWNMASK = 19, // spawnMask 0 0 true if in spawnMask
58 CONDITION_GENDER = 20, // gender 0 0 true if player's gender is equal to gender
59 CONDITION_UNIT_STATE = 21, // unitState 0 0 true if unit has unitState
60 CONDITION_MAPID = 22, // map_id 0 0 true if in map_id
61 CONDITION_AREAID = 23, // area_id 0 0 true if in area_id
62 CONDITION_CREATURE_TYPE = 24, // cinfo.type 0 0 true if creature_template.type = value1
63 CONDITION_SPELL = 25, // spell_id 0 0 true if player has learned spell
64 CONDITION_PHASEMASK = 26, // phasemask 0 0 true if object is in phasemask
65 CONDITION_LEVEL = 27, // level ComparisonType 0 true if unit's level is equal to param1 (param2 can modify the statement)
66 CONDITION_QUEST_COMPLETE = 28, // quest_id 0 0 true if player has quest_id with all objectives complete, but not yet rewarded
67 CONDITION_NEAR_CREATURE = 29, // creature entry distance dead (0/1) true if there is a creature of entry in range
68 CONDITION_NEAR_GAMEOBJECT = 30, // gameobject entry distance 0 true if there is a gameobject of entry in range
69 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
70 CONDITION_TYPE_MASK = 32, // TypeMask 0 0 true if object is type object's TypeMask matches provided TypeMask
71 CONDITION_RELATION_TO = 33, // ConditionTarget RelationType 0 true if object is in given relation with object specified by ConditionTarget
72 CONDITION_REACTION_TO = 34, // ConditionTarget rankMask 0 true if object's reaction matches rankMask object specified by ConditionTarget
73 CONDITION_DISTANCE_TO = 35, // ConditionTarget distance ComparisonType true if object and ConditionTarget are within distance given by parameters
74 CONDITION_ALIVE = 36, // 0 0 0 true if unit is alive
75 CONDITION_HP_VAL = 37, // hpVal ComparisonType 0 true if unit's hp matches given value
76 CONDITION_HP_PCT = 38, // hpPct ComparisonType 0 true if unit's hp matches given pct
77 CONDITION_REALM_ACHIEVEMENT = 39, // achievement_id 0 0 true if realm achievement is complete
78 CONDITION_IN_WATER = 40, // 0 0 0 true if unit in water
79 CONDITION_TERRAIN_SWAP = 41, // only for master branch
80 CONDITION_STAND_STATE = 42, // stateType state 0 true if unit matches specified sitstate (0,x: has exactly state x; 1,0: any standing state; 1,1: any sitting state;)
81 CONDITION_DAILY_QUEST_DONE = 43, // quest id 0 0 true if daily quest has been completed for the day
82 CONDITION_CHARMED = 44, // 0 0 0 true if unit is currently charmed
83 CONDITION_PET_TYPE = 45, // mask 0 0 true if player has a pet of given type(s)
84 CONDITION_TAXI = 46, // 0 0 0 true if player is on taxi
85 CONDITION_QUESTSTATE = 47, // quest_id state_mask 0 true if player is in any of the provided quest states for the quest (1 = not taken, 2 = completed, 8 = in progress, 32 = failed, 64 = rewarded)
86 CONDITION_QUEST_OBJECTIVE_PROGRESS = 48, // quest_id objectiveIndex objectiveCount true if player has reached the specified objectiveCount quest progress for the objectiveIndex for the specified quest
87 CONDITION_DIFFICULTY_ID = 49, // Difficulty 0 0 true is map has difficulty id
88 CONDITION_GAMEMASTER = 50, // canBeGM 0 0 true if player is gamemaster (or can be gamemaster)
89 CONDITION_OBJECT_ENTRY_GUID_MASTER = 51, // 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 using master branch TypeID
90 CONDITION_TYPE_MASK_MASTER = 52, // TypeMask 0 0 true if object is type object's TypeMask matches provided TypeMask using master branch TypeMask
91 CONDITION_BATTLE_PET_COUNT = 53, // SpecieId count ComparisonType true if player has `count` of battle pet species
92 CONDITION_SCENARIO_STEP = 54, // ScenarioStepId 0 0 true if player is at scenario with current step equal to ScenarioStepID
93 CONDITION_SCENE_IN_PROGRESS = 55, // SceneScriptPackageId 0 0 true if player is playing a scene with ScriptPackageId equal to given value
94 CONDITION_PLAYER_CONDITION = 56, // PlayerConditionId 0 0 true if player satisfies PlayerCondition
95 CONDITION_PRIVATE_OBJECT = 57, // 0 0 0 true if entity is private object
97 CONDITION_LABEL = 59, // only for master branch
99};
100
129{
150 // Condition source type 20 unused
156 CONDITION_SOURCE_TYPE_PHASE = 26, // only master
158 CONDITION_SOURCE_TYPE_AREATRIGGER = 28, // only master (this refers to dynamically spawned areatriggers, not the ones from AreaTrigger.dbc/db2)
161 CONDITION_SOURCE_TYPE_TRAINER_SPELL = 31, // only master (TODO: cherry-pick)
162 CONDITION_SOURCE_TYPE_OBJECT_ID_VISIBILITY = 32, // only master (TODO: cherry-pick)
163 CONDITION_SOURCE_TYPE_SPAWN_GROUP = 33, // only master (TODO: cherry-pick)
164 CONDITION_SOURCE_TYPE_MAX = 34 // MAX
166
177
185
190
192{
193 WorldObject* mConditionTargets[MAX_CONDITION_TARGETS]; // an array of targets available for conditions
195 ConditionSourceInfo(WorldObject* target0, WorldObject* target1 = nullptr, WorldObject* target2 = nullptr)
196 {
197 mConditionTargets[0] = target0;
198 mConditionTargets[1] = target1;
199 mConditionTargets[2] = target2;
200 mLastFailedCondition = nullptr;
201 }
202};
203
205{
206 ConditionSourceType SourceType; //SourceTypeOrReferenceId
209 uint32 SourceId; // So far, only used in CONDITION_SOURCE_TYPE_SMART_EVENT
211 ConditionTypes ConditionType; //ConditionTypeOrReference
222
224 {
225 SourceType = CONDITION_SOURCE_TYPE_NONE;
226 SourceGroup = 0;
227 SourceEntry = 0;
228 SourceId = 0;
229 ElseGroup = 0;
230 ConditionType = CONDITION_NONE;
231 ConditionTarget = 0;
232 ConditionValue1 = 0;
233 ConditionValue2 = 0;
234 ConditionValue3 = 0;
235 ReferenceId = 0;
236 ErrorType = 0;
237 ErrorTextId = 0;
238 ScriptId = 0;
239 NegativeCondition = false;
240 }
241
242 bool Meets(ConditionSourceInfo& sourceInfo) const;
243 uint32 GetSearcherTypeMaskForCondition() const;
244 bool isLoaded() const { return ConditionType > CONDITION_NONE || ReferenceId; }
245 uint32 GetMaxAvailableConditionTargets() const;
246
247 std::string ToString(bool ext = false) const;
248};
249
250typedef std::vector<Condition*> ConditionContainer;
251typedef std::unordered_map<uint32 /*SourceEntry*/, ConditionContainer> ConditionsByEntryMap;
252typedef std::array<ConditionsByEntryMap, CONDITION_SOURCE_TYPE_MAX> ConditionEntriesByTypeArray;
253typedef std::unordered_map<uint32, ConditionsByEntryMap> ConditionEntriesByCreatureIdMap;
254typedef std::unordered_map<std::pair<int32, uint32 /*SAI source_type*/>, ConditionsByEntryMap> SmartEventConditionContainer;
255typedef std::unordered_map<uint32, ConditionContainer> ConditionReferenceContainer;//only used for references
256
258{
259 private:
260 ConditionMgr();
262
263 public:
264 static ConditionMgr* instance();
265
266 void LoadConditions(bool isReload = false);
267 bool isConditionTypeValid(Condition* cond) const;
268
269 uint32 GetSearcherTypeMaskForConditionList(ConditionContainer const& conditions) const;
270 bool IsObjectMeetToConditions(WorldObject* object, ConditionContainer const& conditions) const;
271 bool IsObjectMeetToConditions(WorldObject* object1, WorldObject* object2, ConditionContainer const& conditions) const;
272 bool IsObjectMeetToConditions(ConditionSourceInfo& sourceInfo, ConditionContainer const& conditions) const;
273 static bool CanHaveSourceGroupSet(ConditionSourceType sourceType);
274 static bool CanHaveSourceIdSet(ConditionSourceType sourceType);
275 bool IsObjectMeetingNotGroupedConditions(ConditionSourceType sourceType, uint32 entry, ConditionSourceInfo& sourceInfo) const;
276 bool IsObjectMeetingNotGroupedConditions(ConditionSourceType sourceType, uint32 entry, WorldObject* target0, WorldObject* target1 = nullptr, WorldObject* target2 = nullptr) const;
277 bool HasConditionsForNotGroupedEntry(ConditionSourceType sourceType, uint32 entry) const;
278 bool IsObjectMeetingSpellClickConditions(uint32 creatureId, uint32 spellId, WorldObject* clicker, WorldObject* target) const;
279 ConditionContainer const* GetConditionsForSpellClickEvent(uint32 creatureId, uint32 spellId) const;
280 bool IsObjectMeetingVehicleSpellConditions(uint32 creatureId, uint32 spellId, Player* player, Unit* vehicle) const;
281 bool IsObjectMeetingSmartEventConditions(int32 entryOrGuid, uint32 eventId, uint32 sourceType, Unit* unit, WorldObject* baseObject) const;
282 bool IsObjectMeetingVendorItemConditions(uint32 creatureId, uint32 itemId, Player* player, Creature* vendor) const;
283
284 bool IsSpellUsedInSpellClickConditions(uint32 spellId) const;
285
294 static char const* const StaticSourceTypeData[CONDITION_SOURCE_TYPE_MAX];
295 static ConditionTypeInfo const StaticConditionTypeData[CONDITION_MAX];
296
297 private:
298 bool isSourceTypeValid(Condition* cond) const;
299 bool addToLootTemplate(Condition* cond, LootTemplate* loot) const;
300 bool addToGossipMenus(Condition* cond) const;
301 bool addToGossipMenuItems(Condition* cond) const;
302 bool addToSpellImplicitTargetConditions(Condition* cond) const;
303 bool IsObjectMeetToConditionList(ConditionSourceInfo& sourceInfo, ConditionContainer const& conditions) const;
304
305 static void LogUselessConditionValue(Condition const* cond, uint8 index, uint32 value);
306 static void LogUselessConditionValue(Condition const* cond, uint8 index, std::string_view value);
307
308 void Clean(); // free up resources
309 std::vector<Condition*> AllocatedMemoryStore; // some garbage collection :)
310
317
318 std::unordered_set<uint32> SpellsUsedInSpellClickConditions;
319};
320
321#define sConditionMgr ConditionMgr::instance()
322
323#endif
std::unordered_map< uint32, ConditionContainer > ConditionsByEntryMap
std::unordered_map< uint32, ConditionContainer > ConditionReferenceContainer
std::unordered_map< std::pair< int32, uint32 >, ConditionsByEntryMap > SmartEventConditionContainer
ConditionSourceType
@ CONDITION_SOURCE_TYPE_MAX
@ CONDITION_SOURCE_TYPE_CONVERSATION_LINE
@ CONDITION_SOURCE_TYPE_VEHICLE_SPELL
@ CONDITION_SOURCE_TYPE_DISENCHANT_LOOT_TEMPLATE
@ CONDITION_SOURCE_TYPE_REFERENCE_LOOT_TEMPLATE
@ CONDITION_SOURCE_TYPE_TERRAIN_SWAP
@ CONDITION_SOURCE_TYPE_NPC_VENDOR
@ CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION
@ CONDITION_SOURCE_TYPE_SPELL_CLICK_EVENT
@ CONDITION_SOURCE_TYPE_MAIL_LOOT_TEMPLATE
@ CONDITION_SOURCE_TYPE_PHASE
@ CONDITION_SOURCE_TYPE_SPELL_LOOT_TEMPLATE
@ CONDITION_SOURCE_TYPE_SMART_EVENT
@ CONDITION_SOURCE_TYPE_PICKPOCKETING_LOOT_TEMPLATE
@ CONDITION_SOURCE_TYPE_PROSPECTING_LOOT_TEMPLATE
@ CONDITION_SOURCE_TYPE_AREATRIGGER_CLIENT_TRIGGERED
@ CONDITION_SOURCE_TYPE_AREATRIGGER
@ CONDITION_SOURCE_TYPE_SPAWN_GROUP
@ CONDITION_SOURCE_TYPE_SPELL
@ CONDITION_SOURCE_TYPE_FISHING_LOOT_TEMPLATE
@ CONDITION_SOURCE_TYPE_OBJECT_ID_VISIBILITY
@ CONDITION_SOURCE_TYPE_GOSSIP_MENU
@ CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE
@ CONDITION_SOURCE_TYPE_ITEM_LOOT_TEMPLATE
@ CONDITION_SOURCE_TYPE_SPELL_IMPLICIT_TARGET
@ CONDITION_SOURCE_TYPE_GRAVEYARD
@ CONDITION_SOURCE_TYPE_SKINNING_LOOT_TEMPLATE
@ CONDITION_SOURCE_TYPE_TRAINER_SPELL
@ CONDITION_SOURCE_TYPE_CREATURE_LOOT_TEMPLATE
@ CONDITION_SOURCE_TYPE_GAMEOBJECT_LOOT_TEMPLATE
@ CONDITION_SOURCE_TYPE_MILLING_LOOT_TEMPLATE
@ CONDITION_SOURCE_TYPE_SPELL_PROC
@ CONDITION_SOURCE_TYPE_QUEST_AVAILABLE
@ CONDITION_SOURCE_TYPE_NONE
std::array< ConditionsByEntryMap, CONDITION_SOURCE_TYPE_MAX > ConditionEntriesByTypeArray
InstanceInfo
@ INSTANCE_INFO_DATA64
@ INSTANCE_INFO_DATA
@ INSTANCE_INFO_BOSS_STATE
@ INSTANCE_INFO_GUID_DATA
MaxConditionTargets
@ MAX_CONDITION_TARGETS
ConditionTypes
@ CONDITION_TAXI
@ CONDITION_MAPID
@ CONDITION_SKILL
@ CONDITION_RACE
@ CONDITION_STRING_ID
@ CONDITION_REACTION_TO
@ CONDITION_NEAR_GAMEOBJECT
@ CONDITION_QUESTREWARDED
@ CONDITION_REALM_ACHIEVEMENT
@ CONDITION_PHASEMASK
@ CONDITION_QUEST_OBJECTIVE_PROGRESS
@ CONDITION_OBJECT_ENTRY_GUID_MASTER
@ CONDITION_DAILY_QUEST_DONE
@ CONDITION_ACTIVE_EVENT
@ CONDITION_TYPE_MASK_MASTER
@ CONDITION_INSTANCE_INFO
@ CONDITION_RELATION_TO
@ CONDITION_PRIVATE_OBJECT
@ CONDITION_STAND_STATE
@ CONDITION_LABEL
@ CONDITION_DRUNKENSTATE
@ CONDITION_AURA
@ CONDITION_ACHIEVEMENT
@ CONDITION_OBJECT_ENTRY_GUID
@ CONDITION_PET_TYPE
@ CONDITION_DIFFICULTY_ID
@ CONDITION_DISTANCE_TO
@ CONDITION_SCENARIO_STEP
@ CONDITION_HP_VAL
@ CONDITION_BATTLE_PET_COUNT
@ CONDITION_GENDER
@ CONDITION_GAMEMASTER
@ CONDITION_TERRAIN_SWAP
@ CONDITION_REPUTATION_RANK
@ CONDITION_HP_PCT
@ CONDITION_QUEST_COMPLETE
@ CONDITION_MAX
@ CONDITION_SPELL
@ CONDITION_ZONEID
@ CONDITION_CHARMED
@ CONDITION_TYPE_MASK
@ CONDITION_AREAID
@ CONDITION_IN_WATER
@ CONDITION_ITEM
@ CONDITION_WORLD_STATE
@ CONDITION_SPAWNMASK
@ CONDITION_CLASS
@ CONDITION_TEAM
@ CONDITION_NONE
@ CONDITION_QUEST_NONE
@ CONDITION_QUESTSTATE
@ CONDITION_ITEM_EQUIPPED
@ CONDITION_SCENE_IN_PROGRESS
@ CONDITION_LEVEL
@ CONDITION_QUESTTAKEN
@ CONDITION_PLAYER_CONDITION
@ CONDITION_NEAR_CREATURE
@ CONDITION_TITLE
@ CONDITION_ALIVE
@ CONDITION_CREATURE_TYPE
@ CONDITION_UNIT_STATE
std::unordered_map< uint32, ConditionsByEntryMap > ConditionEntriesByCreatureIdMap
std::vector< Condition * > ConditionContainer
RelationType
@ RELATION_IN_PARTY
@ RELATION_IN_RAID_OR_PARTY
@ RELATION_CREATED_BY
@ RELATION_MAX
@ RELATION_SELF
@ RELATION_PASSENGER_OF
@ RELATION_OWNED_BY
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
int32_t int32
Definition Define.h:129
uint32_t uint32
Definition Define.h:133
ConditionEntriesByCreatureIdMap NpcVendorConditionContainerStore
std::unordered_set< uint32 > SpellsUsedInSpellClickConditions
ConditionEntriesByCreatureIdMap VehicleSpellConditionStore
std::vector< Condition * > AllocatedMemoryStore
SmartEventConditionContainer SmartEventConditionStore
ConditionEntriesByTypeArray ConditionStore
ConditionEntriesByCreatureIdMap SpellClickEventConditionStore
ConditionReferenceContainer ConditionReferenceStore
Definition Unit.h:769
Condition const * mLastFailedCondition
ConditionSourceInfo(WorldObject *target0, WorldObject *target1=nullptr, WorldObject *target2=nullptr)
uint32 SourceGroup
ConditionTypes ConditionType
std::string ConditionStringValue1
bool isLoaded() const
uint32 ErrorType
uint32 SourceId
int32 SourceEntry
uint32 ElseGroup
uint32 ScriptId
bool NegativeCondition
ConditionSourceType SourceType
uint32 ConditionValue2
uint8 ConditionTarget
uint32 ReferenceId
uint32 ErrorTextId
uint32 ConditionValue3
uint32 ConditionValue1