Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
example_escort.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
7SDName: Example_Escort
8SD%Complete: 100
9SDComment: Script used for testing escortAI
10SDCategory: Script Examples
11EndScriptData */
12
13#include "ScriptMgr.h"
14#include "ScriptedCreature.h"
15#include "ScriptedGossip.h"
16#include "ScriptedEscortAI.h"
17#include "Player.h"
18#include "CreatureTextMgr.h"
19
35
42
44{
46};
47
48#define GOSSIP_ITEM_1 "Click to Test Escort(Attack, Run)"
49#define GOSSIP_ITEM_2 "Click to Test Escort(NoAttack, Walk)"
50#define GOSSIP_ITEM_3 "Click to Test Escort(NoAttack, Run)"
51
53{
54 public:
55 example_escort() : CreatureScript("example_escort") { }
56
58 {
59 // CreatureAI functions
60 example_escortAI(Creature* creature) : npc_escortAI(creature) { }
61
64
66 {
67 summoned->AI()->AttackStart(me);
68 }
69
70 // Pure Virtual Functions (Have to be implemented)
72 {
73 switch (waypointId)
74 {
75 case 1:
77 break;
78 case 3:
80 me->SummonCreature(NPC_FELBOAR, me->GetPositionX()+5.0f, me->GetPositionY()+7.0f, me->GetPositionZ(), 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 3000);
81 break;
82 case 4:
83 if (Player* player = GetPlayerForEscort())
84 {
85 //pTmpPlayer is the target of the text
86 Talk(SAY_WP_3, player);
87 //pTmpPlayer is the source of the text
89 }
90 break;
91 }
92 }
93
94 void EnterCombat(Unit* /*who*/) OVERRIDE
95 {
97 {
98 if (Player* player = GetPlayerForEscort())
99 Talk(SAY_AGGRO1, player);
100 }
101 else
103 }
104
106 {
107 m_uiDeathCoilTimer = 4000;
108 m_uiChatTimer = 4000;
109 }
110
111 void JustDied(Unit* killer) OVERRIDE
112 {
114 {
115 if (Player* player = GetPlayerForEscort())
116 {
117 // not a likely case, code here for the sake of example
118 if (killer == me)
119 Talk(SAY_DEATH_1, player);
120 else
121 Talk(SAY_DEATH_2, player);
122 }
123 }
124 else
126 }
127
129 {
130 //Must update npc_escortAI
132
133 //Combat check
134 if (me->GetVictim())
135 {
136 if (m_uiDeathCoilTimer <= uiDiff)
137 {
140 m_uiDeathCoilTimer = 4000;
141 }
142 else
143 m_uiDeathCoilTimer -= uiDiff;
144 }
145 else
146 {
147 //Out of combat but being escorted
149 {
150 if (m_uiChatTimer <= uiDiff)
151 {
152 if (me->HasAura(SPELL_ELIXIR_OF_FORTITUDE, 0))
153 {
156 }
157 else
158 {
161 }
162
163 m_uiChatTimer = 12000;
164 }
165 else
166 m_uiChatTimer -= uiDiff;
167 }
168 }
169 }
170 };
171
173 {
174 return new example_escortAI(creature);
175 }
176
177 bool OnGossipHello(Player* player, Creature* creature) OVERRIDE
178 {
179 player->TalkedToCreature(creature->GetEntry(), creature->GetGUID());
180 player->PrepareGossipMenu(creature, 0);
181
185
186 player->SendPreparedGossip(creature);
187
188 return true;
189 }
190
191 bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 action) OVERRIDE
192 {
193 player->PlayerTalkClass->ClearMenus();
194 npc_escortAI* pEscortAI = CAST_AI(example_escort::example_escortAI, creature->AI());
195
196 switch (action)
197 {
199 player->CLOSE_GOSSIP_MENU();
200
201 if (pEscortAI)
202 pEscortAI->Start(true, true, player->GetGUID());
203 break;
205 player->CLOSE_GOSSIP_MENU();
206
207 if (pEscortAI)
208 pEscortAI->Start(false, false, player->GetGUID());
209 break;
211 player->CLOSE_GOSSIP_MENU();
212
213 if (pEscortAI)
214 pEscortAI->Start(false, true, player->GetGUID());
215 break;
216 default:
217 return false; // nothing defined -> trinity core handling
218 }
219
220 return true; // no default handling -> prevent trinity core handling
221 }
222};
223
225{
226 new example_escort();
227}
#define sCreatureTextMgr
@ TEXT_RANGE_NORMAL
std::uint32_t uint32
Definition Define.h:77
#define OVERRIDE
Definition Define.h:60
static constexpr TempSummonType TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT
@ GOSSIP_ICON_CHAT
Definition GossipDef.h:46
#define CAST_AI(a, b)
@ STATE_ESCORT_ESCORTING
@ GOSSIP_SENDER_MAIN
@ GOSSIP_ACTION_INFO_DEF
@ TEAM_OTHER
Creatures
@ SPELL_DEATH_COIL
Definition chapter1.cpp:34
void Talk(uint8 id, WorldObject const *whisperTarget=NULL)
CreatureScript(const char *name)
void DoCast(uint32 spellId)
Definition UnitAI.cpp:110
void DoCastVictim(uint32 spellId, bool triggered=false)
Definition UnitAI.cpp:168
Definition Unit.h:1367
CreatureAI * GetAI(Creature *creature) const OVERRIDE
bool OnGossipSelect(Player *player, Creature *creature, uint32, uint32 action) OVERRIDE
bool OnGossipHello(Player *player, Creature *creature) OVERRIDE
@ NPC_FELBOAR
#define GOSSIP_ITEM_3
#define GOSSIP_ITEM_2
@ SAY_RAND_2
@ SAY_AGGRO1
@ SAY_WP_3
@ SAY_DEATH_2
@ SAY_WP_2
@ SAY_WP_4
@ SAY_DEATH_3
@ SAY_RAND_1
@ SAY_SPELL
@ SAY_DEATH_1
@ SAY_AGGRO2
@ SAY_WP_1
#define GOSSIP_ITEM_1
@ SPELL_DEATH_COIL
@ SPELL_BLUE_FIREWORK
@ SPELL_ELIXIR_OF_FORTITUDE
void AddSC_example_escort()
Creature * me
void UpdateAI(uint32 uiDiff) OVERRIDE
== Triggered Actions Requested ==================
void EnterCombat(Unit *) OVERRIDE
void JustDied(Unit *killer) OVERRIDE
void JustSummoned(Creature *summoned) OVERRIDE
void WaypointReached(uint32 waypointId) OVERRIDE
void UpdateAI(uint32 diff) OVERRIDE
== Triggered Actions Requested ==================
Player * GetPlayerForEscort()
bool HasEscortState(uint32 escortState) const
npc_escortAI(Creature *creature)
void Start(bool isActiveAttacker=true, bool run=false, uint64 playerGUID=0, Quest const *quest=NULL, bool instantRespawn=false, bool canLoopPath=false, bool resetWaypoints=true)