-
Notifications
You must be signed in to change notification settings - Fork 294
/
ScriptDevAIMgr.h
180 lines (150 loc) · 7.82 KB
/
ScriptDevAIMgr.h
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
/* This file is part of the ScriptDev2 Project. See AUTHORS file for Copyright information
* This program is free software licensed under GPL version 2
* Please see the included DOCS/LICENSE.TXT for more information */
#ifndef SC_SCRIPTMGR_H
#define SC_SCRIPTMGR_H
#include "Common.h"
#include "Server/DBCStructure.h"
#include "Server/SQLStorages.h"
class Player;
class Creature;
class CreatureAI;
class InstanceData;
class Quest;
class Item;
class GameObject;
class SpellCastTargets;
class Map;
class Unit;
class WorldObject;
class Aura;
class Object;
class ObjectGuid;
class GameObjectAI;
// *********************************************************
// ************** Some defines used globally ***************
// Basic defines
#define VISIBLE_RANGE (166.0f) // MAX visible range (size of grid)
#define DEFAULT_TEXT "<ScriptDev2 Text Entry Missing!>"
/* Escort Factions
* TODO: find better namings and definitions.
* N=Neutral, A=Alliance, H=Horde.
* NEUTRAL or FRIEND = Hostility to player surroundings (not a good definition)
* ACTIVE or PASSIVE = Hostility to environment surroundings.
*/
enum EscortFaction
{
FACTION_ESCORT_A_NEUTRAL_PASSIVE = 10,
FACTION_ESCORT_H_NEUTRAL_PASSIVE = 33,
FACTION_ESCORT_N_NEUTRAL_PASSIVE = 113,
FACTION_ESCORT_A_NEUTRAL_ACTIVE = 231,
FACTION_ESCORT_H_NEUTRAL_ACTIVE = 232,
FACTION_ESCORT_N_NEUTRAL_ACTIVE = 250,
FACTION_ESCORT_N_FRIEND_PASSIVE = 290,
FACTION_ESCORT_N_FRIEND_ACTIVE = 495,
FACTION_ESCORT_A_PASSIVE = 774,
FACTION_ESCORT_H_PASSIVE = 775,
FACTION_ESCORT_N_ACTIVE = 1986,
FACTION_ESCORT_H_ACTIVE = 2046
};
// *********************************************************
// ************* Some structures used globally *************
struct Script
{
Script() :
pGossipHello(nullptr), pGossipHelloGO(nullptr), pGossipSelect(nullptr), pGossipSelectGO(nullptr),
pGossipSelectWithCode(nullptr), pGossipSelectGOWithCode(nullptr),
pDialogStatusNPC(nullptr), pDialogStatusGO(nullptr),
pQuestAcceptNPC(nullptr), pQuestAcceptGO(nullptr), pQuestAcceptItem(nullptr),
pQuestRewardedNPC(nullptr), pQuestRewardedGO(nullptr),
pGOUse(nullptr), pItemUse(nullptr), pAreaTrigger(nullptr), pNpcSpellClick(nullptr), pProcessEventId(nullptr),
pEffectDummyNPC(nullptr), pEffectDummyGO(nullptr), pEffectDummyItem(nullptr), pEffectScriptEffectNPC(nullptr),
pEffectAuraDummy(nullptr), GetGameObjectAI(nullptr), GetAI(nullptr), GetInstanceData(nullptr)
{}
std::string Name;
bool (*pGossipHello)(Player*, Creature*);
bool (*pGossipHelloGO)(Player*, GameObject*);
bool (*pGossipSelect)(Player*, Creature*, uint32, uint32);
bool (*pGossipSelectGO)(Player*, GameObject*, uint32, uint32);
bool (*pGossipSelectWithCode)(Player*, Creature*, uint32, uint32, const char*);
bool (*pGossipSelectGOWithCode)(Player*, GameObject*, uint32, uint32, const char*);
uint32(*pDialogStatusNPC)(const Player*, const Creature*);
uint32(*pDialogStatusGO)(const Player*, const GameObject*);
bool (*pQuestAcceptNPC)(Player*, Creature*, Quest const*);
bool (*pQuestAcceptGO)(Player*, GameObject*, Quest const*);
bool (*pQuestAcceptItem)(Player*, Item*, Quest const*);
bool (*pQuestRewardedNPC)(Player*, Creature*, Quest const*);
bool (*pQuestRewardedGO)(Player*, GameObject*, Quest const*);
bool (*pGOUse)(Player*, GameObject*);
bool (*pItemUse)(Player*, Item*, SpellCastTargets const&);
bool (*pAreaTrigger)(Player*, AreaTriggerEntry const*);
bool (*pNpcSpellClick)(Player*, Creature*, uint32);
bool (*pProcessEventId)(uint32, Object*, Object*, bool);
bool (*pEffectDummyNPC)(Unit*, uint32, SpellEffectIndex, Creature*, ObjectGuid);
bool (*pEffectDummyGO)(Unit*, uint32, SpellEffectIndex, GameObject*, ObjectGuid);
bool (*pEffectDummyItem)(Unit*, uint32, SpellEffectIndex, Item*, ObjectGuid);
bool (*pEffectScriptEffectNPC)(Unit*, uint32, SpellEffectIndex, Creature*, ObjectGuid);
bool (*pEffectAuraDummy)(const Aura*, bool);
GameObjectAI* (*GetGameObjectAI)(GameObject*);
CreatureAI* (*GetAI)(Creature*);
InstanceData* (*GetInstanceData)(Map*);
void RegisterSelf(bool bReportError = true);
};
class ScriptDevAIMgr
{
public:
ScriptDevAIMgr() : num_sc_scripts(0) {}
~ScriptDevAIMgr();
void Initialize();
void LoadScriptNames();
void LoadAreaTriggerScripts();
void LoadEventIdScripts();
bool OnGossipHello(Player* pPlayer, Creature* pCreature);
bool OnGossipHello(Player* pPlayer, GameObject* pGameObject);
bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code);
bool OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code);
bool OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest);
bool OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest);
bool OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest);
bool OnQuestRewarded(Player* pPlayer, Creature* pCreature, Quest const* pQuest);
bool OnQuestRewarded(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest);
uint32 GetDialogStatus(const Player* pPlayer, const Creature* pCreature) const;
uint32 GetDialogStatus(const Player* pPlayer, const GameObject* pGameObject) const;
bool OnGameObjectUse(Player* pPlayer, GameObject* pGameObject);
bool OnItemUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets);
bool OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* atEntry);
bool OnProcessEvent(uint32 eventId, Object* pSource, Object* pTarget, bool isStart);
bool OnEffectDummy(Unit* pCaster, uint32 spellId, SpellEffectIndex effIndex, Creature* pTarget, ObjectGuid originalCasterGuid);
bool OnEffectDummy(Unit* pCaster, uint32 spellId, SpellEffectIndex effIndex, GameObject* pTarget, ObjectGuid originalCasterGuid);
bool OnEffectDummy(Unit* pCaster, uint32 spellId, SpellEffectIndex effIndex, Item* pTarget, ObjectGuid originalCasterGuid);
bool OnEffectScriptEffect(Unit* pCaster, uint32 spellId, SpellEffectIndex effIndex, Creature* pTarget, ObjectGuid originalCasterGuid);
bool OnAuraDummy(Aura const* pAura, bool apply);
bool OnNpcSpellClick(Player* pPlayer, Creature* pClickedCreature, uint32 spellId);
void AddScript(uint32 id, Script* script);
Script* GetScript(uint32 id) const;
const char* GetScriptName(uint32 id) const { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
uint32 GetScriptId(const char* name) const;
uint32 GetScriptIdsCount() const { return m_scriptNames.size(); }
CreatureAI* GetCreatureAI(Creature* creature);
GameObjectAI* GetGameObjectAI(GameObject* gameobject);
InstanceData* CreateInstanceData(Map* pMap);
uint32 GetAreaTriggerScriptId(uint32 triggerId) const;
uint32 GetEventIdScriptId(uint32 eventId) const;
private:
typedef std::vector<Script*> SDScriptVec;
typedef std::vector<std::string> ScriptNameMap;
typedef std::unordered_map<uint32, uint32> AreaTriggerScriptMap;
typedef std::unordered_map<uint32, uint32> EventIdScriptMap;
int num_sc_scripts;
SDScriptVec m_scripts;
AreaTriggerScriptMap m_AreaTriggerScripts;
EventIdScriptMap m_EventIdScripts;
ScriptNameMap m_scriptNames;
};
// *********************************************************
// ************* Some functions used globally **************
// Generic scripting text function
void DoScriptText(int32 iTextEntry, WorldObject* pSource, Unit* pTarget = nullptr);
void DoOrSimulateScriptTextForMap(int32 iTextEntry, uint32 uiCreatureEntry, Map* pMap, Creature* pCreatureSource = nullptr, Unit* pTarget = nullptr);
#define sScriptDevAIMgr MaNGOS::Singleton<ScriptDevAIMgr>::Instance()
#endif