TrinityCore
zone_the_wandering_isle.cpp
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#include "CellImpl.h"
19#include "Containers.h"
20#include "GridNotifiersImpl.h"
21#include "MotionMaster.h"
22#include "ObjectAccessor.h"
23#include "Player.h"
24#include "ScriptedCreature.h"
25#include "ScriptMgr.h"
26#include "TaskScheduler.h"
27
29{
31
33
35
37
42};
43
45 { 1465.3872f, 3283.8604f, 137.69096f },
46 { 1431.401f, 3264.001f, 136.02579f },
47 { 1397.2067f, 3276.5618f, 133.84508f },
48 { 1441.566f, 3232.8013f, 135.01802f },
49 { 1403.632f, 3229.1094f, 132.14877f },
50 { 1347.1927f, 3286.5842f, 131.94803f },
51 { 1365.1865f, 3338.9502f, 128.57233f },
52 { 1349.6024f, 3315.0574f, 130.97443f },
53 { 1335.4618f, 3344.019f, 130.42047f },
54 { 1360.1198f, 3378.02f, 127.34183f },
55 { 1435.8524f, 3355.6423f, 173.77744f },
56 { 1432.7031f, 3385.1572f, 184.4187f },
57 { 1452.6094f, 3373.3315f, 187.0402f },
58 { 1426.7778f, 3364.7517f, 184.39569f },
59 { 1450.3646f, 3361.264f, 184.42484f },
60};
61
62Emote constexpr TraineeEmotes[5] =
63{
69};
70
71// 54586 - Huojin Trainee
72// 65470 - Huojin Trainee
73// 54587 - Tushui Trainee
74// 65471 - Tushui Trainee
76{
77 npc_tushui_huojin_trainee(Creature* creature) : ScriptedAI(creature), _defeated(false) { }
78
80 {
82 me->HandleEmoteCommand(emote);
83 return emote;
84 }
85
86 void DamageTaken(Unit* attacker, uint32& damage, DamageEffectType /*damageType*/, SpellInfo const* /*spellInfo = nullptr*/) override
87 {
88 if (me->HealthBelowPctDamaged(20, damage))
89 {
90 damage = 0;
91 if (_defeated)
92 return;
93
94 _defeated = true;
95 if (attacker)
96 {
97 if (Player* player = attacker->ToPlayer())
98 player->KilledMonsterCredit(QUEST_29524_KILLCREDIT);
99 }
100
103 me->CombatStop();
104
105 _scheduler.Schedule(Seconds(1), [this](TaskContext /*task*/)
106 {
108 });
109
110 _scheduler.Schedule(Seconds(3), [this](TaskContext /*task*/)
111 {
112 Position currentPosition;
113 float currentDist = 1000.0f;
114 for (Position const& pos : TraineeEndpoints)
115 {
116 float dist = pos.GetExactDist(me);
117 if (dist >= currentDist)
118 continue;
119
120 currentPosition = pos;
121 currentDist = dist;
122 }
123 me->GetMotionMaster()->MovePoint(POINT_DESPAWN, currentPosition);
124 });
125 }
126 }
127
128 void MovementInform(uint32 type, uint32 id) override
129 {
130 if (type != POINT_MOTION_TYPE)
131 return;
132
133 if (id != POINT_DESPAWN)
134 return;
135
137 }
138
139 void JustEngagedWith(Unit* /*attacker*/) override
140 {
141 _scheduler.Schedule(Seconds(4), [this](TaskContext task)
142 {
143 if (me->GetVictim())
145
146 task.Repeat(Seconds(8));
147 });
148 }
149
150 void UpdateAI(uint32 diff) override
151 {
152 _scheduler.Update(diff);
153
154 if (!UpdateVictim())
155 return;
156 }
157
158 void EnterEvadeMode(EvadeReason why) override
159 {
160 if (!_defeated)
162 }
163
164protected:
167};
168
170{
172};
173
175{
176public:
177 HuojinTraineePartnerSearch(Creature* partner) : _partner(partner), _minDist(10.0f) { }
178
179 bool operator()(Creature const* target)
180 {
182 return false;
183 if (target == _partner)
184 return false;
185 if (target->IsInCombat())
186 return false;
187 if (target->IsInEvadeMode())
188 return false;
189 if (target->isDead())
190 return false;
191
192 float dist = target->GetDistance(_partner);
193 if (dist >= _minDist)
194 return false;
195
196 _minDist = dist;
197 return true;
198 }
199
200private:
202 float _minDist;
203};
204
205// 54586 - Huojin Trainee
206// 65470 - Huojin Trainee
208{
210
211 void JustEngagedWith(Unit* attacker) override
212 {
215
217 if (!partner)
218 return;
219
220 if (partner->AI())
222 }
223
224 void DoAction(int32 action) override
225 {
226 if (action == ACTION_PARTNER_ENTERED_COMBAT)
227 {
229
231 _scheduler.Schedule(Seconds(1), [this](TaskContext /*task*/ )
232 {
234 });
235 }
236 }
237
239 {
240 _partnerGuid = guid;
243
244 _scheduler.Schedule(Seconds(1), [this](TaskContext /*task*/)
245 {
247 });
248
249 _scheduler.Schedule(Seconds(4), [this](TaskContext task)
250 {
252 task.Repeat(Seconds(4));
253 });
254 }
255
257 {
258 Creature* partner = nullptr;
261 Cell::VisitGridObjects(me, searcher, 10.0f);
262 return partner;
263 }
264
266 {
267 _partnerGuid = partnerGuid;
268 _scheduler.Schedule(Seconds(1), [this, partnerGuid](TaskContext /*task*/)
269 {
270 BeginSparring(partnerGuid);
271 });
272 }
273
275 {
276 Creature* partner = GetNewPartner();
277
278 if (!partner)
279 return;
280
281 BeginSparring(partner->GetGUID());
283 {
284 if (npc_huojin_trainee* ai = CAST_AI(npc_huojin_trainee, partner->GetAI()))
285 ai->BeginSparringDelayed(me->GetGUID());
286 }
287 }
288
289 void JustReachedHome() override
290 {
292 }
293
294 void JustAppeared() override
295 {
296 // partner is already assigned, sparring start is delayed
299 }
300private:
302};
303
305{
306public:
307 TushuiTraineeSearch(Creature* leader, float maxDist) : _leader(leader), _maxDist(maxDist) { }
308
309 bool operator()(Creature const* target) const
310 {
312 return false;
313 if (target->IsInCombat())
314 return false;
315 if (target->IsInEvadeMode())
316 return false;
317 if (target->GetDistance(_leader) >= _maxDist)
318 return false;
319 if (target->isDead())
320 return false;
321
322 return true;
323 }
324
325private:
327 float _maxDist;
328};
329
331{
332 std::list<Creature*> traineeList;
333 TushuiTraineeSearch check(leader, 10.0f);
334 Trinity::CreatureListSearcher<TushuiTraineeSearch> searcher(leader, traineeList, check);
335 Cell::VisitGridObjects(leader, searcher, 10.0f);
336
337 for (Creature* trainee : traineeList)
338 trainee->HandleEmoteCommand(emote);
339}
340
341// 54587 - Tushui Trainee
342// 65471 - Tushui Trainee
344{
346
348 {
349 _scheduler.Schedule(Seconds(1), [this](TaskContext task)
350 {
351 Emote emote = PlayRandomEmote();
353 task.Repeat(Seconds(6));
354 });
355 }
356
357 void JustReachedHome() override
358 {
360 }
361
362 void JustAppeared() override
363 {
365 }
366
367 void JustEngagedWith(Unit* attacker) override
368 {
371 }
372};
373
374// 61411 - Instructor Zhi
376{
377 npc_instructor_zhi(Creature* creature) : ScriptedAI(creature) { }
378
379 void JustAppeared() override
380 {
381 _scheduler.Schedule(Seconds(6), [this](TaskContext task)
382 {
384 me->HandleEmoteCommand(emote);
385
386 task.Schedule(Seconds(1), [this, emote](TaskContext /*task*/)
387 {
389 });
390 task.Repeat(Seconds(6));
391 });
392 }
393
394 void UpdateAI(uint32 diff) override
395 {
396 _scheduler.Update(diff);
397 }
398
399private:
401};
402
404{
409}
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition: Duration.h:32
@ POINT_MOTION_TYPE
#define RegisterCreatureAI(ai_name)
Definition: ScriptMgr.h:1380
Emote
@ EMOTE_ONESHOT_MONKOFFENSE_ATTACKUNARMEDOFF
@ EMOTE_ONESHOT_MONKOFFENSE_PARRYUNARMED
@ EMOTE_ONESHOT_PALMSTRIKE
@ EMOTE_ONESHOT_BOW
@ EMOTE_STATE_MONKOFFENSE_READYUNARMED
@ EMOTE_ONESHOT_MONKOFFENSE_SPECIALUNARMED
@ EMOTE_ONESHOT_NONE
@ EMOTE_ONESHOT_MONKOFFENSE_ATTACKUNARMED
EvadeReason
Definition: UnitAICommon.h:30
#define CAST_AI(a, b)
Definition: UnitAI.h:28
DamageEffectType
Definition: UnitDefines.h:131
@ UNIT_FLAG_IMMUNE_TO_PC
Definition: UnitDefines.h:152
virtual void EnterEvadeMode(EvadeReason why=EvadeReason::Other)
Definition: CreatureAI.cpp:219
void Talk(uint8 id, WorldObject const *whisperTarget=nullptr)
Definition: CreatureAI.cpp:56
bool UpdateVictim()
Definition: CreatureAI.cpp:245
Creature *const me
Definition: CreatureAI.h:61
void DespawnOrUnsummon(Milliseconds timeToDespawn=0s, Seconds forceRespawnTime=0s)
Definition: Creature.cpp:2415
bool IsInEvadeMode() const
Definition: Creature.h:203
CreatureAI * AI() const
Definition: Creature.h:214
HuojinTraineePartnerSearch(Creature *partner)
bool operator()(Creature const *target)
void MovePoint(uint32 id, Position const &pos, bool generatePath=true, Optional< float > finalOrient={}, Optional< float > speed={}, MovementWalkRunSpeedSelectionMode speedSelectionMode=MovementWalkRunSpeedSelectionMode::Default, Optional< float > closeEnoughDistance={})
uint32 GetEntry() const
Definition: Object.h:161
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:159
static Player * ToPlayer(Object *o)
Definition: Object.h:213
TaskContext & Schedule(std::chrono::duration< Rep, Period > time, TaskScheduler::task_handler_t task)
TaskContext & Repeat(std::chrono::duration< Rep, Period > duration)
TaskScheduler & CancelAll()
TaskScheduler & Schedule(std::chrono::duration< Rep, Period > time, task_handler_t task)
TaskScheduler & Update(success_t const &callback=nullptr)
TushuiTraineeSearch(Creature *leader, float maxDist)
bool operator()(Creature const *target) const
virtual void DoAction(int32)
Definition: UnitAI.h:72
SpellCastResult DoCastVictim(uint32 spellId, CastSpellExtraArgs const &args={})
Definition: UnitAI.cpp:180
Definition: Unit.h:627
void CombatStop(bool includingCast=false, bool mutualPvP=true, bool(*unitFilter)(Unit const *otherUnit)=nullptr)
Definition: Unit.cpp:5827
MotionMaster * GetMotionMaster()
Definition: Unit.h:1652
UnitAI * GetAI() const
Definition: Unit.h:660
void SetEmoteState(Emote emote)
Definition: Unit.h:852
Unit * GetVictim() const
Definition: Unit.h:715
void HandleEmoteCommand(Emote emoteId, Player *target=nullptr, Trinity::IteratorPair< int32 const * > spellVisualKitIds={}, int32 sequenceVariation=0)
Definition: Unit.cpp:1598
bool HealthBelowPctDamaged(int32 pct, uint32 damage) const
Definition: Unit.h:781
void SetUnitFlag(UnitFlags flags)
Definition: Unit.h:833
bool IsInCombat() const
Definition: Unit.h:1043
bool isDead() const
Definition: Unit.h:1166
float GetDistance(WorldObject const *obj) const
Definition: Object.cpp:1078
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
auto SelectRandomContainerElement(C const &container) -> typename std::add_const< decltype(*std::begin(container))>::type &
Definition: Containers.h:109
static void VisitGridObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition: CellImpl.h:179
float GetExactDist(float x, float y, float z) const
Definition: Position.h:118
void JustEngagedWith(Unit *attacker) override
npc_huojin_trainee(Creature *creature)
void BeginSparring(ObjectGuid guid)
void DoAction(int32 action) override
Creature * GetNewPartner() const
void BeginSparringDelayed(ObjectGuid partnerGuid)
npc_instructor_zhi(Creature *creature)
void UpdateAI(uint32 diff) override
void EnterEvadeMode(EvadeReason why) override
void UpdateAI(uint32 diff) override
void JustEngagedWith(Unit *) override
void MovementInform(uint32 type, uint32 id) override
void DamageTaken(Unit *attacker, uint32 &damage, DamageEffectType, SpellInfo const *) override
npc_tushui_huojin_trainee(Creature *creature)
void JustEngagedWith(Unit *attacker) override
npc_tushui_leading_trainee(Creature *creature)
Emote constexpr TraineeEmotes[5]
@ SPELL_BLACKOUT_KICK
@ QUEST_29524_KILLCREDIT
@ NPC_TUSHUI_TRAINEE_FEMALE
@ NPC_HUOJIN_TRAINEE_FEMALE
@ NPC_HUOJIN_TRAINEE_MALE
@ NPC_TUSHUI_TRAINEE_MALE
void HandleEmoteNearbyTushuiTrainees(Creature *leader, Emote emote)
void AddSC_zone_the_wandering_isle()
@ ACTION_PARTNER_ENTERED_COMBAT
Position const TraineeEndpoints[]