Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
example_creature.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
/* ScriptData
7
SDName: Example_Creature
8
SD%Complete: 100
9
SDComment: Short custom scripting example
10
SDCategory: Script Examples
11
EndScriptData */
12
13
#include "
ScriptMgr.h
"
14
#include "
ScriptedCreature.h
"
15
#include "
ScriptedGossip.h
"
16
#include "
Player.h
"
17
18
// **** This script is designed as an example for others to build on ****
19
// **** Please modify whatever you'd like to as this script is only for developement ****
20
21
// **** Script Info* ***
22
// This script is written in a way that it can be used for both friendly and hostile monsters
23
// Its primary purpose is to show just how much you can really do with scripts
24
// I recommend trying it out on both an agressive NPC and on friendly npc
25
26
// **** Quick Info* ***
27
// Functions with Handled Function marked above them are functions that are called automatically by the core
28
// Functions that are marked Custom Function are functions I've created to simplify code
29
30
enum
Yells
31
{
32
//List of text id's. The text is stored in database, also in a localized version
33
//(if translation not exist for the textId, default english text will be used)
34
//Not required to define in this way, but simplify if changes are needed.
35
//These texts must be added to the creature texts of the npc for which the script is assigned.
36
SAY_AGGRO
= 0,
// "Let the games begin."
37
SAY_RANDOM
= 1,
// "I see endless suffering. I see torment. I see rage. I see everything.",
38
// "Muahahahaha",
39
// "These mortal infedels my lord, they have invaded your sanctum and seek to steal your secrets.",
40
// "You are already dead.",
41
// "Where to go? What to do? So many choices that all end in pain, end in death."
42
SAY_BERSERK
= 2,
// "$N, I sentance you to death!"
43
SAY_PHASE
= 3,
// "The suffering has just begun!"
44
SAY_DANCE
= 4,
// "I always thought I was a good dancer."
45
SAY_SALUTE
= 5,
// "Move out Soldier!"
46
SAY_EVADE
= 6
// "Help $N! I'm under attack!"
47
};
48
49
enum
Spells
50
{
51
// List of spells.
52
// Not required to define them in this way, but will make it easier to maintain in case spellId change
53
SPELL_BUFF
= 25661,
54
SPELL_ONE
= 12555,
55
SPELL_ONE_ALT
= 24099,
56
SPELL_TWO
= 10017,
57
SPELL_THREE
= 26027,
58
SPELL_FRENZY
= 23537,
59
SPELL_BERSERK
= 32965,
60
};
61
62
enum
Factions
63
{
64
// any other constants
65
FACTION_WORGEN
= 24
66
};
67
68
//List of gossip item texts. Items will appear in the gossip window.
69
#define GOSSIP_ITEM "I'm looking for a fight"
70
71
class
example_creature
:
public
CreatureScript
72
{
73
public
:
74
example_creature
() :
CreatureScript
(
"example_creature"
) { }
75
76
struct
example_creatureAI
:
public
ScriptedAI
77
{
78
// *** HANDLED FUNCTION ***
79
//This is the constructor, called only once when the Creature is first created
80
example_creatureAI
(
Creature
* creature) :
ScriptedAI
(creature) { }
81
82
// *** CUSTOM VARIABLES ****
83
//These variables are for use only by this individual script.
84
//Nothing else will ever call them but us.
85
86
uint32
m_uiSayTimer
;
// Timer for random chat
87
uint32
m_uiRebuffTimer
;
// Timer for rebuffing
88
uint32
m_uiSpell1Timer
;
// Timer for spell 1 when in combat
89
uint32
m_uiSpell2Timer
;
// Timer for spell 1 when in combat
90
uint32
m_uiSpell3Timer
;
// Timer for spell 1 when in combat
91
uint32
m_uiBeserkTimer
;
// Timer until we go into Beserk (enraged) mode
92
uint32
m_uiPhase
;
// The current battle phase we are in
93
uint32
m_uiPhaseTimer
;
// Timer until phase transition
94
95
// *** HANDLED FUNCTION ***
96
//This is called after spawn and whenever the core decides we need to evade
97
void
Reset
()
OVERRIDE
98
{
99
m_uiPhase
= 1;
// Start in phase 1
100
m_uiPhaseTimer
= 60000;
// 60 seconds
101
m_uiSpell1Timer
= 5000;
// 5 seconds
102
m_uiSpell2Timer
= urand(10000, 20000);
// between 10 and 20 seconds
103
m_uiSpell3Timer
= 19000;
// 19 seconds
104
m_uiBeserkTimer
= 120000;
// 2 minutes
105
106
me
->RestoreFaction();
107
}
108
109
// *** HANDLED FUNCTION ***
110
// Enter Combat called once per combat
111
void
EnterCombat
(
Unit
* who)
OVERRIDE
112
{
113
//Say some stuff
114
Talk
(
SAY_AGGRO
, who);
115
}
116
117
// *** HANDLED FUNCTION ***
118
// Attack Start is called when victim change (including at start of combat)
119
// By default, attack who and start movement toward the victim.
120
//void AttackStart(Unit* who) OVERRIDE
121
//{
122
// ScriptedAI::AttackStart(who);
123
//}
124
125
// *** HANDLED FUNCTION ***
126
// Called when going out of combat. Reset is called just after.
127
void
EnterEvadeMode
()
OVERRIDE
128
{
129
Talk
(
SAY_EVADE
);
130
}
131
132
// *** HANDLED FUNCTION ***
133
//Our Receive emote function
134
void
ReceiveEmote
(
Player
*
/*player*/
,
uint32
uiTextEmote)
OVERRIDE
135
{
136
me
->HandleEmoteCommand(uiTextEmote);
137
138
switch
(uiTextEmote)
139
{
140
case
TEXT_EMOTE_DANCE
:
141
Talk
(
SAY_DANCE
);
142
break
;
143
case
TEXT_EMOTE_SALUTE
:
144
Talk
(
SAY_SALUTE
);
145
break
;
146
}
147
}
148
149
// *** HANDLED FUNCTION ***
150
//Update AI is called Every single map update (roughly once every 50ms if a player is within the grid)
151
void
UpdateAI
(
uint32
uiDiff)
OVERRIDE
152
{
153
//Out of combat timers
154
if
(!
me
->GetVictim())
155
{
156
//Random Say timer
157
if
(
m_uiSayTimer
<= uiDiff)
158
{
159
//Random switch between 5 outcomes
160
Talk
(
SAY_RANDOM
);
161
162
m_uiSayTimer
= 45000;
//Say something agian in 45 seconds
163
}
164
else
165
m_uiSayTimer
-= uiDiff;
166
167
//Rebuff timer
168
if
(
m_uiRebuffTimer
<= uiDiff)
169
{
170
DoCast
(
me
,
SPELL_BUFF
);
171
m_uiRebuffTimer
= 900000;
//Rebuff agian in 15 minutes
172
}
173
else
174
m_uiRebuffTimer
-= uiDiff;
175
}
176
177
//Return since we have no target
178
if
(!
UpdateVictim
())
179
return
;
180
181
//Spell 1 timer
182
if
(
m_uiSpell1Timer
<= uiDiff)
183
{
184
//Cast spell one on our current target.
185
if
(rand()%50 > 10)
186
DoCastVictim
(
SPELL_ONE_ALT
);
187
else
if
(
me
->IsWithinDist(
me
->GetVictim(), 25.0f))
188
DoCastVictim
(
SPELL_ONE
);
189
190
m_uiSpell1Timer
= 5000;
191
}
192
else
193
m_uiSpell1Timer
-= uiDiff;
194
195
//Spell 2 timer
196
if
(
m_uiSpell2Timer
<= uiDiff)
197
{
198
//Cast spell two on our current target.
199
DoCastVictim
(
SPELL_TWO
);
200
m_uiSpell2Timer
= 37000;
201
}
202
else
203
m_uiSpell2Timer
-= uiDiff;
204
205
//Beserk timer
206
if
(
m_uiPhase
> 1)
207
{
208
//Spell 3 timer
209
if
(
m_uiSpell3Timer
<= uiDiff)
210
{
211
//Cast spell one on our current target.
212
DoCastVictim
(
SPELL_THREE
);
213
214
m_uiSpell3Timer
= 19000;
215
}
216
else
217
m_uiSpell3Timer
-= uiDiff;
218
219
if
(
m_uiBeserkTimer
<= uiDiff)
220
{
221
//Say our line then cast uber death spell
222
Talk
(
SAY_BERSERK
,
me
->GetVictim());
223
DoCastVictim
(
SPELL_BERSERK
);
224
225
//Cast our beserk spell agian in 12 seconds if we didn't kill everyone
226
m_uiBeserkTimer
= 12000;
227
}
228
else
229
m_uiBeserkTimer
-= uiDiff;
230
}
231
else
if
(
m_uiPhase
== 1)
//Phase timer
232
{
233
if
(
m_uiPhaseTimer
<= uiDiff)
234
{
235
//Go to next phase
236
++
m_uiPhase
;
237
Talk
(
SAY_PHASE
);
238
DoCast
(
me
,
SPELL_FRENZY
);
239
}
240
else
241
m_uiPhaseTimer
-= uiDiff;
242
}
243
244
DoMeleeAttackIfReady
();
245
}
246
};
247
248
CreatureAI
*
GetAI
(
Creature
* creature)
const
OVERRIDE
249
{
250
return
new
example_creatureAI
(creature);
251
}
252
253
bool
OnGossipHello
(
Player
* player,
Creature
* creature)
OVERRIDE
254
{
255
player->ADD_GOSSIP_ITEM(
GOSSIP_ICON_CHAT
,
GOSSIP_ITEM
,
GOSSIP_SENDER_MAIN
,
GOSSIP_ACTION_INFO_DEF
+ 1);
256
player->SEND_GOSSIP_MENU(907, creature->GetGUID());
257
258
return
true
;
259
}
260
261
bool
OnGossipSelect
(
Player
* player,
Creature
* creature,
uint32
/*sender*/
,
uint32
action)
OVERRIDE
262
{
263
player->PlayerTalkClass->ClearMenus();
264
if
(action ==
GOSSIP_ACTION_INFO_DEF
+1)
265
{
266
player->CLOSE_GOSSIP_MENU();
267
//Set our faction to hostile towards all
268
creature->setFaction(
FACTION_WORGEN
);
269
creature->AI()->AttackStart(player);
270
}
271
272
return
true
;
273
}
274
};
275
276
//This is the actual function called only once durring InitScripts()
277
//It must define all handled functions that are to be run in this script
278
void
AddSC_example_creature
()
279
{
280
new
example_creature
();
281
}
Spells
Spells
Definition
BattlegroundIC.h:645
uint32
std::uint32_t uint32
Definition
Define.h:77
OVERRIDE
#define OVERRIDE
Definition
Define.h:60
GOSSIP_ICON_CHAT
@ GOSSIP_ICON_CHAT
Definition
GossipDef.h:46
Player.h
ScriptMgr.h
ScriptedCreature.h
ScriptedGossip.h
GOSSIP_SENDER_MAIN
@ GOSSIP_SENDER_MAIN
Definition
ScriptedGossip.h:58
GOSSIP_ACTION_INFO_DEF
@ GOSSIP_ACTION_INFO_DEF
Definition
ScriptedGossip.h:56
TEXT_EMOTE_DANCE
@ TEXT_EMOTE_DANCE
Definition
SharedDefines.h:1905
TEXT_EMOTE_SALUTE
@ TEXT_EMOTE_SALUTE
Definition
SharedDefines.h:1949
SAY_BERSERK
@ SAY_BERSERK
Definition
boss_akilzon.cpp:17
SAY_AGGRO
#define SAY_AGGRO
Definition
boss_commander_kolurg.cpp:28
SPELL_FRENZY
@ SPELL_FRENZY
Definition
boss_drekthar.cpp:14
SPELL_BERSERK
#define SPELL_BERSERK
Definition
boss_four_horsemen.cpp:62
SAY_RANDOM
@ SAY_RANDOM
Definition
boss_nefarian.cpp:48
CreatureAI
Definition
CreatureAI.h:54
CreatureAI::Talk
void Talk(uint8 id, WorldObject const *whisperTarget=NULL)
Definition
CreatureAI.cpp:28
CreatureAI::UpdateVictim
bool UpdateVictim()
Definition
CreatureAI.cpp:192
Creature
Definition
Creature.h:427
CreatureScript::CreatureScript
CreatureScript(const char *name)
Definition
ScriptMgr.cpp:1436
Player
Definition
Player.h:1289
UnitAI::DoMeleeAttackIfReady
void DoMeleeAttackIfReady()
Definition
UnitAI.cpp:28
UnitAI::DoCast
void DoCast(uint32 spellId)
Definition
UnitAI.cpp:110
UnitAI::DoCastVictim
void DoCastVictim(uint32 spellId, bool triggered=false)
Definition
UnitAI.cpp:168
Unit
Definition
Unit.h:1367
example_creature
Definition
example_creature.cpp:72
example_creature::OnGossipSelect
bool OnGossipSelect(Player *player, Creature *creature, uint32, uint32 action) OVERRIDE
Definition
example_creature.cpp:261
example_creature::example_creature
example_creature()
Definition
example_creature.cpp:74
example_creature::OnGossipHello
bool OnGossipHello(Player *player, Creature *creature) OVERRIDE
Definition
example_creature.cpp:253
example_creature::GetAI
CreatureAI * GetAI(Creature *creature) const OVERRIDE
Definition
example_creature.cpp:248
AddSC_example_creature
void AddSC_example_creature()
Definition
example_creature.cpp:278
SAY_AGGRO
@ SAY_AGGRO
Definition
example_creature.cpp:36
SAY_SALUTE
@ SAY_SALUTE
Definition
example_creature.cpp:45
SAY_EVADE
@ SAY_EVADE
Definition
example_creature.cpp:46
SAY_RANDOM
@ SAY_RANDOM
Definition
example_creature.cpp:37
SAY_BERSERK
@ SAY_BERSERK
Definition
example_creature.cpp:42
SAY_DANCE
@ SAY_DANCE
Definition
example_creature.cpp:44
SAY_PHASE
@ SAY_PHASE
Definition
example_creature.cpp:43
SPELL_ONE_ALT
@ SPELL_ONE_ALT
Definition
example_creature.cpp:55
SPELL_ONE
@ SPELL_ONE
Definition
example_creature.cpp:54
SPELL_THREE
@ SPELL_THREE
Definition
example_creature.cpp:57
SPELL_TWO
@ SPELL_TWO
Definition
example_creature.cpp:56
SPELL_BUFF
@ SPELL_BUFF
Definition
example_creature.cpp:53
SPELL_FRENZY
@ SPELL_FRENZY
Definition
example_creature.cpp:58
SPELL_BERSERK
@ SPELL_BERSERK
Definition
example_creature.cpp:59
GOSSIP_ITEM
#define GOSSIP_ITEM
Definition
example_creature.cpp:69
Factions
Factions
Definition
example_creature.cpp:63
FACTION_WORGEN
@ FACTION_WORGEN
Definition
example_creature.cpp:65
ScriptedAI::me
Creature * me
Definition
ScriptedCreature.h:182
ScriptedAI::ScriptedAI
ScriptedAI(Creature *creature)
Definition
ScriptedCreature.cpp:85
Yells
Definition
boss_illidan.cpp:256
example_creature::example_creatureAI
Definition
example_creature.cpp:77
example_creature::example_creatureAI::m_uiPhaseTimer
uint32 m_uiPhaseTimer
Definition
example_creature.cpp:93
example_creature::example_creatureAI::m_uiBeserkTimer
uint32 m_uiBeserkTimer
Definition
example_creature.cpp:91
example_creature::example_creatureAI::m_uiSpell3Timer
uint32 m_uiSpell3Timer
Definition
example_creature.cpp:90
example_creature::example_creatureAI::m_uiSpell2Timer
uint32 m_uiSpell2Timer
Definition
example_creature.cpp:89
example_creature::example_creatureAI::EnterEvadeMode
void EnterEvadeMode() OVERRIDE
Definition
example_creature.cpp:127
example_creature::example_creatureAI::ReceiveEmote
void ReceiveEmote(Player *, uint32 uiTextEmote) OVERRIDE
Definition
example_creature.cpp:134
example_creature::example_creatureAI::Reset
void Reset() OVERRIDE
Definition
example_creature.cpp:97
example_creature::example_creatureAI::example_creatureAI
example_creatureAI(Creature *creature)
Definition
example_creature.cpp:80
example_creature::example_creatureAI::EnterCombat
void EnterCombat(Unit *who) OVERRIDE
Definition
example_creature.cpp:111
example_creature::example_creatureAI::m_uiPhase
uint32 m_uiPhase
Definition
example_creature.cpp:92
example_creature::example_creatureAI::m_uiSayTimer
uint32 m_uiSayTimer
Definition
example_creature.cpp:86
example_creature::example_creatureAI::m_uiSpell1Timer
uint32 m_uiSpell1Timer
Definition
example_creature.cpp:88
example_creature::example_creatureAI::UpdateAI
void UpdateAI(uint32 uiDiff) OVERRIDE
== Triggered Actions Requested ==================
Definition
example_creature.cpp:151
example_creature::example_creatureAI::m_uiRebuffTimer
uint32 m_uiRebuffTimer
Definition
example_creature.cpp:87
src
server
scripts
Examples
example_creature.cpp
Generated on
for Project SkyFire Core by
1.17.0