1 | /* |
---|
2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
3 | * |
---|
4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef SCRIPTMGR_H |
---|
22 | #define SCRIPTMGR_H |
---|
23 | |
---|
24 | //Only required includes |
---|
25 | #include "../../game/CreatureAI.h" |
---|
26 | #include "../../game/Creature.h" |
---|
27 | #include "../../game/InstanceData.h" |
---|
28 | |
---|
29 | class Player; |
---|
30 | class Creature; |
---|
31 | class Quest; |
---|
32 | class Item; |
---|
33 | class GameObject; |
---|
34 | class SpellCastTargets; |
---|
35 | class Map; |
---|
36 | |
---|
37 | #define MAX_SCRIPTS 1000 |
---|
38 | #define MAX_INSTANCE_SCRIPTS 1000 |
---|
39 | |
---|
40 | struct Script |
---|
41 | { |
---|
42 | Script() : |
---|
43 | pGossipHello(NULL), pQuestAccept(NULL), pGossipSelect(NULL), pGossipSelectWithCode(NULL), |
---|
44 | pQuestSelect(NULL), pQuestComplete(NULL), pNPCDialogStatus(NULL), pGODialogStatus(NULL), pChooseReward(NULL), |
---|
45 | pItemHello(NULL), pGOHello(NULL), pAreaTrigger(NULL), pItemQuestAccept(NULL), pGOQuestAccept(NULL), |
---|
46 | pGOChooseReward(NULL), pReceiveEmote(NULL), pItemUse(NULL), GetAI(NULL) |
---|
47 | {} |
---|
48 | |
---|
49 | std::string Name; |
---|
50 | |
---|
51 | // -- Quest/gossip Methods to be scripted -- |
---|
52 | bool (*pGossipHello )(Player *player, Creature *_Creature); |
---|
53 | bool (*pQuestAccept )(Player *player, Creature *_Creature, Quest const*_Quest ); |
---|
54 | bool (*pGossipSelect )(Player *player, Creature *_Creature, uint32 sender, uint32 action ); |
---|
55 | bool (*pGossipSelectWithCode)(Player *player, Creature *_Creature, uint32 sender, uint32 action, const char* sCode ); |
---|
56 | bool (*pQuestSelect )(Player *player, Creature *_Creature, Quest const*_Quest ); |
---|
57 | bool (*pQuestComplete )(Player *player, Creature *_Creature, Quest const*_Quest ); |
---|
58 | uint32 (*pNPCDialogStatus )(Player *player, Creature *_Creature ); |
---|
59 | uint32 (*pGODialogStatus )(Player *player, GameObject * _GO ); |
---|
60 | bool (*pChooseReward )(Player *player, Creature *_Creature, Quest const*_Quest, uint32 opt ); |
---|
61 | bool (*pItemHello )(Player *player, Item *_Item, Quest const*_Quest ); |
---|
62 | bool (*pGOHello )(Player *player, GameObject *_GO ); |
---|
63 | bool (*pAreaTrigger )(Player *player, AreaTriggerEntry* at); |
---|
64 | bool (*pItemQuestAccept )(Player *player, Item *_Item, Quest const*_Quest ); |
---|
65 | bool (*pGOQuestAccept )(Player *player, GameObject *_GO, Quest const*_Quest ); |
---|
66 | bool (*pGOChooseReward )(Player *player, GameObject *_GO, Quest const*_Quest, uint32 opt ); |
---|
67 | bool (*pReceiveEmote )(Player *player, Creature *_Creature, uint32 emote ); |
---|
68 | bool (*pItemUse )(Player *player, Item* _Item, SpellCastTargets const& targets); |
---|
69 | |
---|
70 | CreatureAI* (*GetAI)(Creature *_Creature); |
---|
71 | // ----------------------------------------- |
---|
72 | |
---|
73 | }; |
---|
74 | |
---|
75 | class InstanceDataScript |
---|
76 | { |
---|
77 | public: |
---|
78 | InstanceDataScript() : GetInstanceData(NULL) {}; |
---|
79 | |
---|
80 | std::string name; |
---|
81 | InstanceData* (*GetInstanceData)(Map *_Map); |
---|
82 | }; |
---|
83 | |
---|
84 | extern int nrscripts; |
---|
85 | extern Script *m_scripts[MAX_SCRIPTS]; |
---|
86 | extern InstanceDataScript *m_instance_scripts[MAX_INSTANCE_SCRIPTS]; |
---|
87 | extern int num_inst_scripts; |
---|
88 | |
---|
89 | #define VISIBLE_RANGE (50.0f) |
---|
90 | |
---|
91 | struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI |
---|
92 | { |
---|
93 | ScriptedAI(Creature* creature) : m_creature(creature) {} |
---|
94 | ~ScriptedAI() {} |
---|
95 | |
---|
96 | // Called if IsVisible(Unit *who) is true at each *who move |
---|
97 | void MoveInLineOfSight(Unit *) {} |
---|
98 | |
---|
99 | // Called at each attack of m_creature by any victim |
---|
100 | void AttackStart(Unit *) {} |
---|
101 | |
---|
102 | // Called at stopping attack by any attacker |
---|
103 | void EnterEvadeMode(); |
---|
104 | |
---|
105 | // Called at any heal cast/item used (call non implemented) |
---|
106 | void HealBy(Unit* /*healer*/, uint32 /*amount_healed*/) {} |
---|
107 | |
---|
108 | // Called at any Damage to any victim (before damage apply) |
---|
109 | void DamageDeal(Unit* /*done_to*/, uint32& /*damage*/) {} |
---|
110 | |
---|
111 | // Called at any Damage from any attacker (before damage apply) |
---|
112 | void DamageTaken(Unit* /*done_by*/, uint32& /*damage*/) {} |
---|
113 | |
---|
114 | // Is unit visible for MoveInLineOfSight |
---|
115 | bool IsVisible(Unit* who) const |
---|
116 | { |
---|
117 | return !who->HasStealthAura() && m_creature->GetDistance(who) <= VISIBLE_RANGE; |
---|
118 | } |
---|
119 | |
---|
120 | // Called at World update tick |
---|
121 | void UpdateAI(const uint32); |
---|
122 | |
---|
123 | // Called when the creature is killed |
---|
124 | void JustDied(Unit *){} |
---|
125 | |
---|
126 | // Called when the creature kills a unit |
---|
127 | void KilledUnit(Unit *){} |
---|
128 | |
---|
129 | // Called when hit by a spell |
---|
130 | void SpellHit(Unit *, const SpellEntry*){} |
---|
131 | |
---|
132 | Creature* m_creature; |
---|
133 | |
---|
134 | //= Some useful helpers ========================= |
---|
135 | |
---|
136 | // Start attack of victim and go to him |
---|
137 | void DoStartAttack(Unit* victim); |
---|
138 | |
---|
139 | // Stop attack of current victim |
---|
140 | void DoStopAttack(); |
---|
141 | |
---|
142 | // Cast spell |
---|
143 | void DoCast(Unit* victim, uint32 spelId) |
---|
144 | { |
---|
145 | m_creature->CastSpell(victim,spelId,true); |
---|
146 | } |
---|
147 | |
---|
148 | void DoCastSpell(Unit* who,SpellEntry *spellInfo) |
---|
149 | { |
---|
150 | m_creature->CastSpell(who,spellInfo,true); |
---|
151 | } |
---|
152 | |
---|
153 | void DoSay(char const* text, uint32 language) |
---|
154 | { |
---|
155 | m_creature->Say(text,language,0); |
---|
156 | } |
---|
157 | |
---|
158 | void DoGoHome(); |
---|
159 | }; |
---|
160 | |
---|
161 | #endif |
---|