AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
npc_echo_of_medivh Struct Reference
Inheritance diagram for npc_echo_of_medivh:
ScriptedAI CreatureAI UnitAI

Public Member Functions

 npc_echo_of_medivh (Creature *creature)
 
void Reset () override
 
void JustSummoned (Creature *summon) override
 
void SummonedCreatureDespawn (Creature *summon) override
 
void RemoveCheats ()
 
void SetupBoard ()
 
void HandleCellInitialData (uint8 row, uint8 col, Creature *trigger, BoardCell &cell)
 
bool IsMedivhPiece (uint32 entry) const
 
CreatureGetHostileTargetForChangeFacing (Creature *piece, KarazhanChessOrientationType orientation)
 
void HandlePieceJustDied (Creature *piece)
 
int8 HandlePieceRotate (Creature *piece, ObjectGuid const &triggerGUID)
 
int8 HandlePieceMove (Creature *piece, ObjectGuid const &triggerGUID, bool moveByAI)
 
void CastChangeFacing (Creature *piece, Creature *trigger)
 
bool HandlePieceMoveByAI (Creature *piece, KarazhanChessOrientationType orientation)
 
void HandleCheat ()
 
CreatureGetPiece (Creature *sourcePiece, uint8 searchType, float distance, bool hostile, uint32 minHPDiff, bool checkFront)
 
void UpdateAI (uint32 diff) override
 
void sGossipHello (Player *player) override
 
void sGossipSelect (Player *player, uint32, uint32 gossipListId) override
 
- Public Member Functions inherited from ScriptedAI
 ScriptedAI (Creature *creature)
 
 ~ScriptedAI () override
 
void AttackStartNoMove (Unit *target)
 
void DamageTaken (Unit *, uint32 &, DamageEffectType, SpellSchoolMask) override
 
void UpdateAI (uint32 diff) override
 
void JustDied (Unit *) override
 
void KilledUnit (Unit *) override
 
void JustSummoned (Creature *) override
 
void SummonedCreatureDespawn (Creature *) override
 
void SpellHit (Unit *, SpellInfo const *) override
 
void SpellHitTarget (Unit *, SpellInfo const *) override
 
void MovementInform (uint32, uint32) override
 
void OnPossess (bool)
 
bool IsInRoom (const Position *pos, Axis axis, bool above)
 
void Reset () override
 
void JustEngagedWith (Unit *) override
 Called for reaction when initially engaged.
 
void AttackStart (Unit *) override
 
void DoStartMovement (Unit *target, float distance=0.0f, float angle=0.0f)
 
void DoStartNoMovement (Unit *target)
 
void DoStopAttack ()
 
void DoCastSpell (Unit *target, SpellInfo const *spellInfo, bool triggered=false)
 
void DoPlaySoundToSet (WorldObject *source, uint32 soundId)
 
void DoPlayMusic (uint32 soundId, bool zone)
 
void DoAddThreat (Unit *unit, float amount)
 
void DoModifyThreatByPercent (Unit *unit, int32 pct)
 
void DoResetThreat (Unit *unit)
 
void DoResetThreatList ()
 
float DoGetThreat (Unit *unit)
 
void DoTeleportPlayer (Unit *unit, float x, float y, float z, float o)
 
void DoTeleportAll (float x, float y, float z, float o)
 
UnitDoSelectLowestHpFriendly (float range, uint32 minHPDiff=1)
 
std::list< Creature * > DoFindFriendlyCC (float range)
 
std::list< Creature * > DoFindFriendlyMissingBuff (float range, uint32 spellId)
 
PlayerGetPlayerAtMinimumRange (float minRange)
 
CreatureDoSpawnCreature (uint32 entry, float offsetX, float offsetY, float offsetZ, float angle, uint32 type, uint32 despawntime)
 
bool IsUniqueTimedEventDone (uint32 id) const
 
void SetUniqueTimedEventDone (uint32 id)
 
void ResetUniqueTimedEvent (uint32 id)
 
void ClearUniqueTimedEventsDone ()
 
void ScheduleTimedEvent (Milliseconds timerMin, Milliseconds timerMax, std::function< void()> exec, Milliseconds repeatMin, Milliseconds repeatMax=0s, uint32 uniqueId=0)
 
void ScheduleTimedEvent (Milliseconds timerMax, std::function< void()> exec, Milliseconds repeatMin, Milliseconds repeatMax=0s, uint32 uniqueId=0)
 
void ScheduleUniqueTimedEvent (Milliseconds timer, std::function< void()> exec, uint32 uniqueId)
 
bool HealthBelowPct (uint32 pct) const
 
bool HealthAbovePct (uint32 pct) const
 
SpellInfo const * SelectSpell (Unit *target, uint32 school, uint32 mechanic, SelectTargetType targets, uint32 powerCostMin, uint32 powerCostMax, float rangeMin, float rangeMax, SelectEffect effect)
 
void SetEquipmentSlots (bool loadDefault, int32 mainHand=EQUIP_NO_CHANGE, int32 offHand=EQUIP_NO_CHANGE, int32 ranged=EQUIP_NO_CHANGE)
 
void SetCombatMovement (bool allowMovement)
 
bool IsCombatMovementAllowed () const
 
virtual bool CheckEvadeIfOutOfCombatArea () const
 
bool IsHeroic () const
 
Difficulty GetDifficulty () const
 
bool Is25ManRaid () const
 
template<class T >
const T & DUNGEON_MODE (const T &normal5, const T &heroic10) const
 
template<class T >
const T & RAID_MODE (const T &normal10, const T &normal25) const
 
template<class T >
const T & RAID_MODE (const T &normal10, const T &normal25, const T &heroic10, const T &heroic25) const
 
PlayerSelectTargetFromPlayerList (float maxdist, uint32 excludeAura=0, bool mustBeInLOS=false) const
 
- Public Member Functions inherited from CreatureAI
void Talk (uint8 id, WorldObject const *whisperTarget=nullptr, Milliseconds delay=0s)
 Causes the creature to talk/say the text assigned to their entry in the creature_text database table.
 
void Talk (uint8 id, Milliseconds delay)
 
 CreatureAI (Creature *creature)
 
 ~CreatureAI () override
 
void MoveCircleChecks ()
 
void MoveBackwardsChecks ()
 
void MoveInLineOfSight_Safe (Unit *who)
 == Reactions At =================================
 
void TriggerAlert (Unit const *who) const
 
virtual bool CanRespawn ()
 
virtual void EnterEvadeMode (EvadeReason why=EVADE_REASON_OTHER)
 
virtual void JustEngagedWith (Unit *)
 Called for reaction when initially engaged.
 
virtual void JustDied (Unit *)
 
virtual void KilledUnit (Unit *)
 
virtual void JustSummoned (Creature *)
 
virtual void IsSummonedBy (WorldObject *)
 
virtual void SummonedCreatureDespawn (Creature *)
 
virtual void SummonedCreatureDies (Creature *, Unit *)
 
virtual void SummonedCreatureDespawnAll ()
 
virtual void SpellHit (Unit *, SpellInfo const *)
 
virtual void SpellHitTarget (Unit *, SpellInfo const *)
 
virtual void AttackedBy (Unit *)
 
virtual bool IsEscorted ()
 
virtual void JustRespawned ()
 
virtual void MovementInform (uint32, uint32)
 
virtual void PathEndReached (uint32)
 
void OnCharmed (bool apply) override
 
virtual void JustReachedHome ()
 
void DoZoneInCombat (Creature *creature=nullptr, float maxRangeToNearestTarget=250.0f)
 
virtual void ReceiveEmote (Player *, uint32)
 
virtual void OwnerAttackedBy (Unit *)
 
virtual void OwnerAttacked (Unit *)
 
virtual void CorpseRemoved (uint32 &)
 == Triggered Actions Requested ==================
 
virtual void PassengerBoarded (Unit *, int8, bool)
 == Fields =======================================
 
virtual bool BeforeSpellClick (Unit *)
 
virtual void OnSpellClick (Unit *, bool &)
 
virtual bool CanSeeAlways (WorldObject const *)
 
virtual bool CanBeSeen (Player const *)
 
virtual bool CanAlwaysBeDetectable (WorldObject const *)
 
virtual void PetStopAttack ()
 
virtual bool CheckInRoom ()
 
CreatureBoundary const * GetBoundary () const
 
void SetBoundary (CreatureBoundary const *boundary, bool negativeBoundaries=false)
 
bool IsInBoundary (Position const *who=nullptr) const
 
virtual void CalculateThreat (Unit *, float &, SpellInfo const *)
 
virtual bool OnTeleportUnreacheablePlayer (Player *)
 
- Public Member Functions inherited from UnitAI
 UnitAI (Unit *unit)
 
virtual ~UnitAI ()
 
virtual bool CanAIAttack (Unit const *) const
 
virtual void AttackStart (Unit *)
 
virtual void UpdateAI (uint32)=0
 
virtual void InitializeAI ()
 
virtual void Reset ()
 
virtual void OnCharmed (bool apply)=0
 
virtual void DoAction (int32)
 
virtual uint32 GetData (uint32) const
 
virtual void SetData (uint32, uint32)
 
virtual void SetGUID (ObjectGuid, int32=0)
 
virtual ObjectGuid GetGUID (int32=0) const
 
UnitSelectTarget (SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
 
template<class PREDICATE >
UnitSelectTarget (SelectTargetMethod targetType, uint32 position, PREDICATE const &predicate)
 
void SelectTargetList (std::list< Unit * > &targetList, uint32 num, SelectTargetMethod targetType, uint32 position=0, float dist=0.0f, bool playerOnly=false, bool withTank=true, int32 aura=0)
 
template<class PREDICATE >
void SelectTargetList (std::list< Unit * > &targetList, uint32 num, SelectTargetMethod targetType, uint32 position, PREDICATE const &predicate)
 
virtual void JustEnteredCombat (Unit *)
 Called when the unit enters combat (NOTE: Creature engage logic should NOT be here, but in JustEngagedWith, which happens once threat is established!)
 
virtual void JustExitedCombat ()
 Called when the unit leaves combat.
 
virtual void DamageDealt (Unit *, uint32 &, DamageEffectType)
 
virtual void DamageTaken (Unit *, uint32 &, DamageEffectType, SpellSchoolMask)
 
virtual void HealReceived (Unit *, uint32 &)
 
virtual void OnPowerUpdate (Powers, int32, int32, uint32)
 
virtual void HealDone (Unit *, uint32 &)
 
virtual void OnCalculateMeleeDamageReceived (uint32 &, Unit *)
 
virtual void OnCalculateSpellDamageReceived (int32 &, Unit *)
 
virtual void OnCalculatePeriodicTickReceived (uint32 &, Unit *)
 
void AttackStartCaster (Unit *victim, float dist)
 
SpellCastResult DoAddAuraToAllHostilePlayers (uint32 spellid)
 
SpellCastResult DoCast (uint32 spellId)
 
SpellCastResult DoCast (Unit *victim, uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastSelf (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastToAllHostilePlayers (uint32 spellid, bool triggered=false)
 
SpellCastResult DoCastVictim (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastAOE (uint32 spellId, bool triggered=false)
 
SpellCastResult DoCastRandomTarget (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false)
 
SpellCastResult DoCastMaxThreat (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false)
 Cast spell on the max threat target, which may not always be the current victim.
 
float DoGetSpellMaxRange (uint32 spellId, bool positive=false)
 
void DoMeleeAttackIfReady ()
 
bool DoSpellAttackIfReady (uint32 spell)
 
void DoSpellAttackToRandomTargetIfReady (uint32 spell, uint32 threatTablePosition=0, float dist=0.f, bool playerOnly=true)
 
virtual void SummonMovementInform (Creature *, uint32, uint32)
 
virtual void sGossipHello (Player *)
 
virtual void sGossipSelect (Player *, uint32, uint32)
 
virtual void sGossipSelectCode (Player *, uint32, uint32, char const *)
 
virtual void sQuestAccept (Player *, Quest const *)
 
virtual void sQuestSelect (Player *, Quest const *)
 
virtual void sQuestComplete (Player *, Quest const *)
 
virtual void sQuestReward (Player *, Quest const *, uint32)
 
virtual void sOnGameEvent (bool, uint16)
 
virtual std::string GetDebugInfo () const
 

Private Attributes

InstanceScript_instance
 
SummonList _summons
 
std::array< std::array< BoardCell, MAX_COL >, MAX_ROW_boards
 
std::array< uint32, 2 > _deadCount
 
uint32 _cheatTimer
 

Additional Inherited Members

- Public Types inherited from ScriptedAI
enum class  Axis {
  AXIS_X ,
  AXIS_Y
}
 
- Public Types inherited from CreatureAI
enum  EvadeReason {
  EVADE_REASON_NO_HOSTILES ,
  EVADE_REASON_BOUNDARY ,
  EVADE_REASON_SEQUENCE_BREAK ,
  EVADE_REASON_NO_PATH ,
  EVADE_REASON_OTHER
}
 
- Static Public Member Functions inherited from CreatureAI
static bool IsInBounds (CreatureBoundary const &boundary, Position const *who)
 
- Static Public Member Functions inherited from UnitAI
static void FillAISpellInfo ()
 
- Public Attributes inherited from ScriptedAI
Creatureme
 
bool IsFleeing
 
- Static Public Attributes inherited from UnitAI
static AISpellInfoTypeAISpellInfo
 
- Protected Member Functions inherited from CreatureAI
bool UpdateVictim ()
 
bool UpdateVictimWithGaze ()
 
void SetGazeOn (Unit *target)
 
CreatureDoSummon (uint32 entry, Position const &pos, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
CreatureDoSummon (uint32 entry, WorldObject *obj, float radius=5.0f, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
CreatureDoSummonFlyer (uint32 entry, WorldObject *obj, float flightZ, float radius=5.0f, uint32 despawnTime=30000, TempSummonType summonType=TEMPSUMMON_CORPSE_TIMED_DESPAWN)
 
virtual void MoveInLineOfSight (Unit *)
 
bool _EnterEvadeMode (EvadeReason why=EVADE_REASON_OTHER)
 
- Protected Attributes inherited from CreatureAI
Creature *const me
 
EventMap events
 
TaskScheduler scheduler
 
CreatureBoundary const * _boundary
 
bool _negateBoundary
 
- Protected Attributes inherited from UnitAI
Unit *const me
 

Detailed Description

Constructor & Destructor Documentation

◆ npc_echo_of_medivh()

npc_echo_of_medivh::npc_echo_of_medivh ( Creature creature)
inline
191 : ScriptedAI(creature), _summons(me)
192 {
193 _instance = creature->GetInstanceScript();
194 }
Definition: ScriptedCreature.h:192
Creature * me
Definition: ScriptedCreature.h:282
InstanceScript * GetInstanceScript() const
Definition: Object.cpp:1192
InstanceScript * _instance
Definition: boss_chess_event.cpp:1414
SummonList _summons
Definition: boss_chess_event.cpp:1415

References _instance, and WorldObject::GetInstanceScript().

Member Function Documentation

◆ CastChangeFacing()

void npc_echo_of_medivh::CastChangeFacing ( Creature piece,
Creature trigger 
)
inline
970 {
971 piece->CastSpell(trigger, SPELL_CHANGE_FACING, true);
972 }
@ SPELL_CHANGE_FACING
Definition: boss_chess_event.cpp:49
SpellCastResult CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=nullptr, AuraEffect const *triggeredByAura=nullptr, ObjectGuid originalCaster=ObjectGuid::Empty)
Definition: Unit.cpp:1169

References Unit::CastSpell(), and SPELL_CHANGE_FACING.

Referenced by HandlePieceMoveByAI().

◆ GetHostileTargetForChangeFacing()

Creature * npc_echo_of_medivh::GetHostileTargetForChangeFacing ( Creature piece,
KarazhanChessOrientationType  orientation 
)
inline
392 {
393 for (uint8 row = 0; row < MAX_ROW; ++row)
394 {
395 for (uint8 col = 0; col < MAX_COL; ++col)
396 {
397 BoardCell const& cell = _boards[row][col];
398 if (cell.pieceGUID == piece->GetGUID())
399 {
400 std::vector<KarazhanChessOrientationType> orientations;
401 switch (orientation)
402 {
403 case ORI_SE:
405 break;
406 case ORI_S:
408 break;
409 case ORI_SW:
411 break;
412 case ORI_W:
414 break;
415 case ORI_NW:
417 break;
418 case ORI_N:
420 break;
421 case ORI_NE:
423 break;
424 case ORI_E:
426 break;
427 default:
428 break;
429 }
430
432 {
433 uint8 newRow = row;
434 uint8 newCol = col;
435 switch (orient)
436 {
437 case ORI_SE:
438 newRow -= 1;
439 break;
440 case ORI_S:
441 newRow -= 1;
442 newCol -= 1;
443 break;
444 case ORI_SW:
445 newCol -= 1;
446 break;
447 case ORI_W:
448 newRow += 1;
449 newCol -= 1;
450 break;
451 case ORI_NW:
452 newRow += 1;
453 break;
454 case ORI_N:
455 newRow += 1;
456 newCol += 1;
457 break;
458 case ORI_NE:
459 newCol += 1;
460 break;
461 case ORI_E:
462 newRow -= 1;
463 newCol += 1;
464 break;
465 default:
466 break;
467 }
468
469 if (Creature* targetPiece = ObjectAccessor::GetCreature(*me, _boards[newRow][newCol].pieceGUID))
470 {
471 if (!IsFriendly(piece, targetPiece))
472 {
473 return targetPiece;
474 }
475 }
476 }
477
478 return nullptr;
479 }
480 }
481 }
482
483 return nullptr;
484 }
std::uint8_t uint8
Definition: Define.h:110
static std::array< float, MAX_ORI > orientations
Definition: boss_chess_event.cpp:176
static constexpr uint8 MAX_ROW
Definition: boss_chess_event.cpp:142
KarazhanChessOrientationType
Definition: boss_chess_event.cpp:73
@ ORI_NE
Definition: boss_chess_event.cpp:80
@ ORI_W
Definition: boss_chess_event.cpp:77
@ ORI_E
Definition: boss_chess_event.cpp:81
@ ORI_S
Definition: boss_chess_event.cpp:75
@ ORI_NW
Definition: boss_chess_event.cpp:78
@ ORI_N
Definition: boss_chess_event.cpp:79
@ ORI_SE
Definition: boss_chess_event.cpp:74
@ ORI_SW
Definition: boss_chess_event.cpp:76
static constexpr uint8 MAX_COL
Definition: boss_chess_event.cpp:143
static bool IsFriendly(Creature *piece, Creature *target)
Definition: boss_chess_event.cpp:178
Creature * GetCreature(WorldObject const &u, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:213
Definition: Creature.h:46
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
Definition: boss_chess_event.cpp:146
ObjectGuid pieceGUID
Definition: boss_chess_event.cpp:150
std::array< std::array< BoardCell, MAX_COL >, MAX_ROW > _boards
Definition: boss_chess_event.cpp:1416

References _boards, ObjectAccessor::GetCreature(), Object::GetGUID(), IsFriendly(), MAX_COL, MAX_ROW, ScriptedAI::me, ORI_E, ORI_N, ORI_NE, ORI_NW, ORI_S, ORI_SE, ORI_SW, ORI_W, orientations, and BoardCell::pieceGUID.

Referenced by HandlePieceMoveByAI().

◆ GetPiece()

Creature * npc_echo_of_medivh::GetPiece ( Creature sourcePiece,
uint8  searchType,
float  distance,
bool  hostile,
uint32  minHPDiff,
bool  checkFront 
)
inline
1270 {
1271 if (!sourcePiece)
1272 {
1273 return nullptr;
1274 }
1275
1276 Creature* target = nullptr;
1277 std::vector<Creature*> targets;
1278
1279 for (uint8 row = 0; row < MAX_ROW; ++row)
1280 {
1281 for (uint8 col = 0; col < MAX_COL; ++col)
1282 {
1283 if (Creature* piece = ObjectAccessor::GetCreature(*me, _boards[row][col].pieceGUID))
1284 {
1285 if (IsFriendly(piece, sourcePiece) == hostile)
1286 {
1287 continue;
1288 }
1289
1290 if (checkFront && !sourcePiece->HasInArc(float(M_PI) / 3.0f, piece))
1291 {
1292 continue;
1293 }
1294
1295 if (minHPDiff)
1296 {
1297 if (piece->GetMaxHealth() - piece->GetHealth() <= minHPDiff)
1298 {
1299 continue;
1300 }
1301
1302 minHPDiff = piece->GetMaxHealth() - piece->GetHealth();
1303 }
1304
1305 float dist = sourcePiece->GetExactDist2d(piece);
1306 if (dist < distance)
1307 {
1308 if (searchType == CHESS_PIECE_SEARCH_TYPE_CLOSEST)
1309 {
1310 distance = dist;
1311 target = piece;
1312 }
1313 else
1314 {
1315 targets.push_back(piece);
1316 }
1317 }
1318 }
1319 }
1320 }
1321
1322 if (!targets.empty())
1323 {
1325 }
1326
1327 return target;
1328 }
@ CHESS_PIECE_SEARCH_TYPE_CLOSEST
Definition: boss_chess_event.cpp:185
auto SelectRandomContainerElement(C const &container) -> typename std::add_const< decltype(*std::begin(container))>::type &
Definition: Containers.h:135
float GetExactDist2d(const float x, const float y) const
Definition: Position.h:166
bool HasInArc(float arcangle, const Position *pos, float targetRadius=0.0f) const
Definition: Position.cpp:140
uint32 GetMaxHealth() const
Definition: Unit.h:1455

References _boards, CHESS_PIECE_SEARCH_TYPE_CLOSEST, ObjectAccessor::GetCreature(), Position::GetExactDist2d(), Unit::GetMaxHealth(), Position::HasInArc(), IsFriendly(), MAX_COL, MAX_ROW, ScriptedAI::me, and Acore::Containers::SelectRandomContainerElement().

◆ HandleCellInitialData()

void npc_echo_of_medivh::HandleCellInitialData ( uint8  row,
uint8  col,
Creature trigger,
BoardCell cell 
)
inline
263 {
264 switch (row)
265 {
266 case 0: // Alliance first row
267 {
268 switch (col)
269 {
270 case 0:
271 case 7: // Rook
272 if (Creature* rook = trigger->FindNearestCreature(NPC_ROOK_A, 4.0f, true))
273 {
274 cell.SetPiece(rook);
275 }
276 break;
277 case 1:
278 case 6: // Knight
279 if (Creature* knight = trigger->FindNearestCreature(NPC_KNIGHT_A, 4.0f, true))
280 {
281 cell.SetPiece(knight);
282 }
283 break;
284 case 2:
285 case 5: // Bishop
286 if (Creature* bishop = trigger->FindNearestCreature(NPC_BISHOP_A, 4.0f, true))
287 {
288 cell.SetPiece(bishop);
289 }
290 break;
291 case 3: // Queen
292 if (Creature* queen = trigger->FindNearestCreature(NPC_QUEEN_A, 4.0f, true))
293 {
294 cell.SetPiece(queen);
295 }
296 break;
297 case 4: // King
298 if (Creature* king = trigger->FindNearestCreature(NPC_KING_A, 4.0f, true))
299 {
300 cell.SetPiece(king);
301 }
302 break;
303 }
304 break;
305 }
306 case 1: // Alliance second row
307 // All pawns
308 if (Creature* pawn = trigger->FindNearestCreature(NPC_PAWN_A, 4.0f, true))
309 {
310 cell.SetPiece(pawn);
311 }
312 break;
313 case 6: // Horde second row
314 // All pawns
315 if (Creature* pawn = trigger->FindNearestCreature(NPC_PAWN_H, 4.0f, true))
316 {
317 cell.SetPiece(pawn);
318 }
319 break;
320 case 7: // Horde first row
321 {
322 switch (col)
323 {
324 case 0:
325 case 7: // Rook
326 if (Creature* rook = trigger->FindNearestCreature(NPC_ROOK_H, 4.0f, true))
327 {
328 cell.SetPiece(rook);
329 }
330 break;
331 case 1:
332 case 6: // Knight
333 if (Creature* knight = trigger->FindNearestCreature(NPC_KNIGHT_H, 4.0f, true))
334 {
335 cell.SetPiece(knight);
336 }
337 break;
338 case 2:
339 case 5: // Bishop
340 if (Creature* bishop = trigger->FindNearestCreature(NPC_BISHOP_H, 4.0f, true))
341 {
342 cell.SetPiece(bishop);
343 }
344 break;
345 case 3: // Queen
346 if (Creature* queen = trigger->FindNearestCreature(NPC_QUEEN_H, 4.0f, true))
347 {
348 cell.SetPiece(queen);
349 }
350 break;
351 case 4: // King
352 if (Creature* king = trigger->FindNearestCreature(NPC_KING_H, 4.0f, true))
353 {
354 cell.SetPiece(king);
355 }
356 break;
357 default:
358 break;
359 }
360 break;
361 }
362 default:
363 cell.Reset();
364 break;
365 }
366 }
@ NPC_QUEEN_H
Definition: karazhan.h:126
@ NPC_ROOK_A
Definition: karazhan.h:131
@ NPC_KNIGHT_H
Definition: karazhan.h:124
@ NPC_KING_A
Definition: karazhan.h:133
@ NPC_PAWN_H
Definition: karazhan.h:122
@ NPC_PAWN_A
Definition: karazhan.h:123
@ NPC_ROOK_H
Definition: karazhan.h:130
@ NPC_KING_H
Definition: karazhan.h:132
@ NPC_QUEEN_A
Definition: karazhan.h:127
@ NPC_BISHOP_H
Definition: karazhan.h:128
@ NPC_BISHOP_A
Definition: karazhan.h:129
@ NPC_KNIGHT_A
Definition: karazhan.h:125
Creature * FindNearestCreature(uint32 entry, float range, bool alive=true) const
Definition: Object.cpp:2434
void Reset()
Definition: boss_chess_event.cpp:162
void SetPiece(Creature *piece)
Definition: boss_chess_event.cpp:168

References WorldObject::FindNearestCreature(), NPC_BISHOP_A, NPC_BISHOP_H, NPC_KING_A, NPC_KING_H, NPC_KNIGHT_A, NPC_KNIGHT_H, NPC_PAWN_A, NPC_PAWN_H, NPC_QUEEN_A, NPC_QUEEN_H, NPC_ROOK_A, NPC_ROOK_H, BoardCell::Reset(), and BoardCell::SetPiece().

Referenced by SetupBoard().

◆ HandleCheat()

void npc_echo_of_medivh::HandleCheat ( )
inline
1175 {
1177
1178 switch (urand(0, 2))
1179 {
1180 case 0: // Heal king
1181 {
1183 {
1184 if (Creature* king = me->FindNearestCreature(NPC_KING_H, 80.0f, true))
1185 {
1186 king->SetHealth(king->GetMaxHealth());
1187 }
1188 }
1190 {
1191 if (Creature* king = me->FindNearestCreature(NPC_KING_A, 80.0f, true))
1192 {
1193 king->SetHealth(king->GetMaxHealth());
1194 }
1195 }
1196
1197 break;
1198 }
1199 case 1: // Fire
1200 {
1201 std::list<Creature*> targetList;
1202 for (uint8 row = 0; row < MAX_ROW; ++row)
1203 {
1204 for (uint8 col = 0; col < MAX_COL; ++col)
1205 {
1206 BoardCell const& cell = _boards[row][col];
1207 if (!cell.pieceGUID || IsMedivhPiece(cell.pieceEntry))
1208 {
1209 continue;
1210 }
1211
1212 if (Creature* trigger = ObjectAccessor::GetCreature(*me, cell.triggerGUID))
1213 {
1214 targetList.push_back(trigger);
1215 }
1216 }
1217 }
1218
1219 if (targetList.size() > 3)
1220 {
1221 Acore::Containers::RandomResize(targetList, 3);
1222 }
1223
1224 for (Creature* target : targetList)
1225 {
1226 DoCast(target, SPELL_FURY_OF_MEDIVH_FIRE, true);
1227 }
1228
1229 break;
1230 }
1231 case 2: // Buff
1232 {
1233 std::list<Creature*> targetList;
1234 for (uint8 row = 0; row < MAX_ROW; ++row)
1235 {
1236 for (uint8 col = 0; col < MAX_COL; ++col)
1237 {
1238 BoardCell const& cell = _boards[row][col];
1239 if (!cell.pieceGUID || !IsMedivhPiece(cell.pieceEntry))
1240 {
1241 continue;
1242 }
1243
1244 if (Creature* piece = ObjectAccessor::GetCreature(*me, cell.pieceGUID))
1245 {
1246 targetList.push_back(piece);
1247 }
1248 }
1249 }
1250
1251 uint8 resizeMax = urand(1, 4);
1252 if (targetList.size() > resizeMax)
1253 {
1254 Acore::Containers::RandomResize(targetList, resizeMax);
1255 }
1256
1257 for (Creature* target : targetList)
1258 {
1259 DoCast(target, SPELL_HAND_OF_MEDIVH, true);
1260 }
1261
1262 break;
1263 }
1264 }
1265
1267 }
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:44
@ TALK_MEDIHV_CHEAT_EMOTE
Definition: boss_chess_event.cpp:122
@ TALK_MEDIHV_CHEAT
Definition: boss_chess_event.cpp:121
@ SPELL_FURY_OF_MEDIVH_FIRE
Definition: boss_chess_event.cpp:55
@ SPELL_HAND_OF_MEDIVH
Definition: karazhan.h:183
@ CHESS_EVENT_TEAM
Definition: karazhan.h:62
Talk
Definition: boss_fathomlord_karathress.cpp:25
@ TEAM_ALLIANCE
Definition: SharedDefines.h:760
@ TEAM_HORDE
Definition: SharedDefines.h:761
void RandomResize(C &container, std::size_t requestedSize)
Definition: Containers.h:81
SpellCastResult DoCast(uint32 spellId)
Definition: UnitAI.cpp:177
virtual uint32 GetData(uint32) const
Definition: ZoneScript.h:52
uint32 pieceEntry
Definition: boss_chess_event.cpp:151
ObjectGuid triggerGUID
Definition: boss_chess_event.cpp:149
bool IsMedivhPiece(uint32 entry) const
Definition: boss_chess_event.cpp:368

References _boards, _instance, CHESS_EVENT_TEAM, UnitAI::DoCast(), WorldObject::FindNearestCreature(), ObjectAccessor::GetCreature(), ZoneScript::GetData(), IsMedivhPiece(), MAX_COL, MAX_ROW, ScriptedAI::me, NPC_KING_A, NPC_KING_H, BoardCell::pieceEntry, BoardCell::pieceGUID, Acore::Containers::RandomResize(), SPELL_FURY_OF_MEDIVH_FIRE, SPELL_HAND_OF_MEDIVH, TALK_MEDIHV_CHEAT, TALK_MEDIHV_CHEAT_EMOTE, TEAM_ALLIANCE, TEAM_HORDE, BoardCell::triggerGUID, and urand().

Referenced by UpdateAI().

◆ HandlePieceJustDied()

void npc_echo_of_medivh::HandlePieceJustDied ( Creature piece)
inline
487 {
488 switch (piece->GetFaction())
489 {
491 {
492 float baseX = -11078.116211f;
493 float baseY = -1908.443115f;
494 float deltaX = 2.148438f;
495 float deltaY = 1.723755f;
496 float extraX = 2.416992f;
497 float extraY = -2.889649f;
498 float offset = 1.3f * (_deadCount[DEAD_ALLIANCE] % MAX_ROW);
499 float finalX = baseX + offset * deltaX + (_deadCount[DEAD_ALLIANCE] >= MAX_ROW ? 1 : 0) * extraX;
500 float finalY = baseY + offset * deltaY + (_deadCount[DEAD_ALLIANCE] >= MAX_ROW ? 1 : 0) * extraY;
501 piece->NearTeleportTo(finalX, finalY, 221.0f, orientations[ORI_SW]);
503
504 piece->CombatStop();
506 piece->setDeathState(DeathState::JustRespawned);
507 piece->SetHealth(piece->GetMaxHealth());
508 break;
509 }
511 {
512 float baseX = -11081.393555f;
513 float baseY = -1844.194092f;
514 float deltaX = -2.148438f;
515 float deltaY = -1.723755f;
516 float extraX = -2.416992f;
517 float extraY = 2.889649f;
518
519 float offset = 1.3f * (_deadCount[DEAD_HORDE] % MAX_ROW);
520
521 float finalX = baseX + offset * deltaX + (_deadCount[DEAD_HORDE] >= MAX_ROW ? 1 : 0) * extraX;
522 float finalY = baseY + offset * deltaY + (_deadCount[DEAD_HORDE] >= MAX_ROW ? 1 : 0) * extraY;
523 piece->NearTeleportTo(finalX, finalY, 221.0f, orientations[ORI_NE]);
525
526 piece->CombatStop();
528 piece->setDeathState(DeathState::JustRespawned);
529 piece->SetHealth(piece->GetMaxHealth());
530 break;
531 }
532 }
533
534 for (uint8 row = 0; row < MAX_ROW; ++row)
535 {
536 for (uint8 col = 0; col < MAX_COL; ++col)
537 {
538 if (_boards[row][col].pieceGUID == piece->GetGUID())
539 {
540 _boards[row][col].Reset();
541 }
542 }
543 }
544
546 {
547 bool ended = false;
548 switch (piece->GetEntry())
549 {
550 case NPC_KING_H:
554 break;
555 case NPC_KING_A:
557 {
563 ended = true;
565 }
567 {
571 ended = true;
573 }
574 break;
575 default:
576 break;
577 }
578
579 if (!ended)
580 {
581 uint8 talkIndex = TALK_PLAYER_LOOSE_PAWN;
582 if (piece->GetFaction() == CHESS_FACTION_ALLIANCE)
583 {
584 talkIndex = TALK_MEDIVH_LOOSE_PAWN;
585 }
586
587 switch (piece->GetEntry())
588 {
589 case NPC_ROOK_A:
590 case NPC_ROOK_H:
591 talkIndex += 1;
592 break;
593 case NPC_KNIGHT_A:
594 case NPC_KNIGHT_H:
595 talkIndex += 2;
596 break;
597 case NPC_BISHOP_A:
598 case NPC_BISHOP_H:
599 talkIndex += 3;
600 break;
601 case NPC_QUEEN_A:
602 case NPC_QUEEN_H:
603 talkIndex += 4;
604 break;
605 case NPC_KING_H:
606 case NPC_KING_A:
607 talkIndex += 5;
608 break;
609 }
610
611 Talk(talkIndex);
612 }
613 }
615 {
616 bool ended = false;
617 switch (piece->GetEntry())
618 {
619 case NPC_KING_A:
623 break;
624 case NPC_KING_H:
626 {
632 ended = true;
634 }
636 {
641 ended = true;
642 }
643 break;
644 default:
645 break;
646 }
647
648 if (!ended)
649 {
650 uint8 talkIndex = TALK_PLAYER_LOOSE_PAWN;
651 if (piece->GetFaction() == CHESS_FACTION_HORDE)
652 {
653 talkIndex = TALK_MEDIVH_LOOSE_PAWN;
654 }
655
656 switch (piece->GetEntry())
657 {
658 case NPC_ROOK_A:
659 case NPC_ROOK_H:
660 talkIndex += 1;
661 break;
662 case NPC_KNIGHT_A:
663 case NPC_KNIGHT_H:
664 talkIndex += 2;
665 break;
666 case NPC_BISHOP_A:
667 case NPC_BISHOP_H:
668 talkIndex += 3;
669 break;
670 case NPC_QUEEN_A:
671 case NPC_QUEEN_H:
672 talkIndex += 4;
673 break;
674 case NPC_KING_H:
675 case NPC_KING_A:
676 talkIndex += 5;
677 break;
678 }
679
680 Talk(talkIndex);
681 }
682 }
683 else
684 {
685 switch (piece->GetEntry())
686 {
687 case NPC_KING_H:
688 case NPC_KING_A:
693 break;
694 }
695
696 uint8 talkIndex = TALK_PLAYER_LOOSE_PAWN;
697 if (piece->GetFaction() == CHESS_FACTION_HORDE)
698 {
699 talkIndex = TALK_MEDIVH_LOOSE_PAWN;
700 }
701
702 switch (piece->GetEntry())
703 {
704 case NPC_ROOK_A:
705 case NPC_ROOK_H:
706 talkIndex += 1;
707 break;
708 case NPC_KNIGHT_A:
709 case NPC_KNIGHT_H:
710 talkIndex += 2;
711 break;
712 case NPC_BISHOP_A:
713 case NPC_BISHOP_H:
714 talkIndex += 3;
715 break;
716 case NPC_QUEEN_A:
717 case NPC_QUEEN_H:
718 talkIndex += 4;
719 break;
720 case NPC_KING_H:
721 case NPC_KING_A:
722 talkIndex += 5;
723 break;
724 }
725
726 Talk(talkIndex);
727 }
728 }
constexpr auto DAY
Definition: Common.h:51
@ UNIT_FLAG_NOT_SELECTABLE
Definition: Unit.h:473
@ IN_PROGRESS
Definition: InstanceScript.h:58
@ DONE
Definition: InstanceScript.h:60
@ SPECIAL
Definition: InstanceScript.h:61
@ NOT_STARTED
Definition: InstanceScript.h:57
@ TALK_EVENT_ENDED
Definition: boss_chess_event.cpp:139
@ TALK_MEDIVH_LOOSE_PAWN
Definition: boss_chess_event.cpp:131
@ TALK_PLAYER_LOOSE_PAWN
Definition: boss_chess_event.cpp:124
@ DEAD_ALLIANCE
Definition: boss_chess_event.cpp:68
@ DEAD_HORDE
Definition: boss_chess_event.cpp:69
@ CHESS_FACTION_HORDE
Definition: karazhan.h:200
@ CHESS_FACTION_ALLIANCE
Definition: karazhan.h:201
@ CHESS_PHASE_NOT_STARTED
Definition: karazhan.h:189
@ CHESS_PHASE_PVE_FINISHED
Definition: karazhan.h:193
@ SPELL_GAME_IN_SESSION
Definition: karazhan.h:182
@ DATA_CHESS_GAME_PHASE
Definition: karazhan.h:64
@ DATA_DUST_COVERED_CHEST
Definition: karazhan.h:66
@ DATA_CHESS_EVENT
Definition: karazhan.h:39
@ DATA_CHESS_REINIT_PIECES
Definition: karazhan.h:63
void setDeathState(DeathState s, bool despawn=false) override
Definition: Creature.cpp:1903
uint32 GetEntry() const
Definition: Object.h:109
void CombatStop(bool includingCast=false)
Definition: Unit.cpp:10440
void SetHealth(uint32 val)
Definition: Unit.cpp:15464
uint32 GetFaction() const
Definition: Unit.h:1509
void NearTeleportTo(Position &pos, bool casting=false, bool vehicleTeleport=false, bool withPet=false, bool removeTransport=false)
Definition: Unit.cpp:20250
void SetUnitFlag(UnitFlags flags)
Definition: Unit.h:1495
ObjectGuid GetGuidData(uint32 type) const override
Definition: InstanceScript.cpp:94
void DoRemoveAurasDueToSpellOnPlayers(uint32 spell)
Definition: InstanceScript.cpp:638
void DoRespawnGameObject(ObjectGuid guid, uint32 timeToDespawn=MINUTE)
Definition: InstanceScript.cpp:534
virtual void SetData(uint32, uint32)
Definition: ZoneScript.h:53
std::array< uint32, 2 > _deadCount
Definition: boss_chess_event.cpp:1417

References _boards, _deadCount, _instance, CHESS_EVENT_TEAM, CHESS_FACTION_ALLIANCE, CHESS_FACTION_HORDE, CHESS_PHASE_NOT_STARTED, CHESS_PHASE_PVE_FINISHED, Unit::CombatStop(), DATA_CHESS_EVENT, DATA_CHESS_GAME_PHASE, DATA_CHESS_REINIT_PIECES, DATA_DUST_COVERED_CHEST, DAY, DEAD_ALLIANCE, DEAD_HORDE, DONE, InstanceScript::DoRemoveAurasDueToSpellOnPlayers(), InstanceScript::DoRespawnGameObject(), ZoneScript::GetData(), Object::GetEntry(), Unit::GetFaction(), Object::GetGUID(), InstanceScript::GetGuidData(), Unit::GetMaxHealth(), IN_PROGRESS, MAX_COL, MAX_ROW, Unit::NearTeleportTo(), NOT_STARTED, NPC_BISHOP_A, NPC_BISHOP_H, NPC_KING_A, NPC_KING_H, NPC_KNIGHT_A, NPC_KNIGHT_H, NPC_QUEEN_A, NPC_QUEEN_H, NPC_ROOK_A, NPC_ROOK_H, ORI_NE, ORI_SW, orientations, ZoneScript::SetData(), Creature::setDeathState(), Unit::SetHealth(), Unit::SetUnitFlag(), SPECIAL, SPELL_GAME_IN_SESSION, TALK_EVENT_ENDED, TALK_MEDIVH_LOOSE_PAWN, TALK_PLAYER_LOOSE_PAWN, TEAM_ALLIANCE, TEAM_HORDE, and UNIT_FLAG_NOT_SELECTABLE.

◆ HandlePieceMove()

int8 npc_echo_of_medivh::HandlePieceMove ( Creature piece,
ObjectGuid const &  triggerGUID,
bool  moveByAI 
)
inline
852 {
853 bool foundProperCell = false;
854 bool foundOld = false;
855 bool foundNew = false;
856 int8 oldRow = MAX_ROW;
857 int8 oldCol = MAX_COL;
858 int8 newRow = -1;
859 int8 newCol = -1;
860
861 for (uint8 row = 0; row < MAX_ROW; ++row)
862 {
863 for (uint8 col = 0; col < MAX_COL; ++col)
864 {
865 BoardCell const& cell = _boards[row][col];
866 if (!foundNew)
867 {
868 if (cell.triggerGUID == triggerGUID)
869 {
870 //is there already a piece on this cell ?
871 if (cell.pieceGUID)
872 {
873 return -1;
874 }
875
876 newCol = col;
877 newRow = row;
878 foundProperCell = true;
879 foundNew = true;
880 }
881 }
882
883 if (!foundOld)
884 {
885 if (cell.pieceGUID == piece->GetGUID())
886 {
887 oldCol = col;
888 oldRow = row;
889 foundOld = true;
890 }
891 }
892
893 if (foundNew && foundOld)
894 {
895 break;
896 }
897 }
898
899 if (foundNew && foundOld)
900 {
901 break;
902 }
903 }
904
905 if (newCol == -1 || newRow == -1)
906 {
907 return -1;
908 }
909
910 if (!moveByAI && foundProperCell)
911 {
912 uint8 deltaRow = abs(oldRow - newRow);
913 uint8 deltaCol = abs(oldCol - newCol);
914
915 switch (piece->GetEntry())
916 {
917 case NPC_PAWN_H:
918 case NPC_PAWN_A:
919 case NPC_BISHOP_H:
920 case NPC_BISHOP_A:
921 case NPC_ROOK_H:
922 case NPC_ROOK_A:
923 case NPC_KING_H:
924 case NPC_KING_A:
925 if (deltaRow > 1 || deltaCol > 1)
926 {
927 foundProperCell = false;
928 }
929 break;
930 case NPC_QUEEN_H:
931 case NPC_QUEEN_A:
932 if (deltaRow > 3 || deltaCol > 3)
933 {
934 foundProperCell = false;
935 }
936 break;
937 case NPC_KNIGHT_H:
938 case NPC_KNIGHT_A:
939 if (deltaRow > 2 || deltaCol > 2)
940 {
941 foundProperCell = false;
942 }
943 break;
944 default:
945 break;
946 }
947 }
948
949 if (foundProperCell || moveByAI)
950 {
951 int8 orientation = HandlePieceRotate(piece, triggerGUID);
952 if (orientation != -1)
953 {
954 _boards[newRow][newCol].triggerGUID = triggerGUID;
955 _boards[newRow][newCol].SetPiece(piece);
956
957 if (oldRow != MAX_ROW && oldCol != MAX_COL)
958 {
959 _boards[oldRow][oldCol].Reset();
960 }
961 }
962
963 return orientation;
964 }
965
966 return -1;
967 }
std::int8_t int8
Definition: Define.h:106
int8 HandlePieceRotate(Creature *piece, ObjectGuid const &triggerGUID)
Definition: boss_chess_event.cpp:730

References _boards, Object::GetEntry(), Object::GetGUID(), HandlePieceRotate(), MAX_COL, MAX_ROW, NPC_BISHOP_A, NPC_BISHOP_H, NPC_KING_A, NPC_KING_H, NPC_KNIGHT_A, NPC_KNIGHT_H, NPC_PAWN_A, NPC_PAWN_H, NPC_QUEEN_A, NPC_QUEEN_H, NPC_ROOK_A, NPC_ROOK_H, BoardCell::pieceGUID, and BoardCell::triggerGUID.

◆ HandlePieceMoveByAI()

bool npc_echo_of_medivh::HandlePieceMoveByAI ( Creature piece,
KarazhanChessOrientationType  orientation 
)
inline

Change orientation at edges

Here we shouldn't be facing the edges of the board, check in the 4 first if statements

975 {
976 uint8 pieceRow = 0;
977 uint8 pieceCol = 0;
978 bool found = false;
979
980 for (uint8 row = 0; row < MAX_ROW; ++row)
981 {
982 for (uint8 col = 0; col < MAX_COL; ++col)
983 {
984 if (_boards[row][col].pieceGUID == piece->GetGUID())
985 {
986 pieceRow = row;
987 pieceCol = col;
988 found = true;
989 break;
990 }
991 }
992
993 if (found)
994 {
995 break;
996 }
997 }
998
1000 if (orientation == ORI_SE && pieceRow == 0)
1001 {
1002 if (Creature* trigger = ObjectAccessor::GetCreature(*me, _boards[pieceRow + 1][pieceCol].triggerGUID))
1003 {
1004 CastChangeFacing(piece, trigger);
1005 }
1006
1007 return true;
1008 }
1009 else if (orientation == ORI_NW && pieceRow == 7)
1010 {
1011 if (Creature* trigger = ObjectAccessor::GetCreature(*me, _boards[pieceRow - 1][pieceCol].triggerGUID))
1012 {
1013 CastChangeFacing(piece, trigger);
1014 }
1015
1016 return true;
1017 }
1018 else if (orientation == ORI_SW && pieceCol == 0)
1019 {
1020 if (Creature* trigger = ObjectAccessor::GetCreature(*me, _boards[pieceRow][pieceCol + 1].triggerGUID))
1021 {
1022 CastChangeFacing(piece, trigger);
1023 }
1024
1025 return true;
1026 }
1027 else if (orientation == ORI_NE && pieceCol == 7)
1028 {
1029 if (Creature* trigger = ObjectAccessor::GetCreature(*me, _boards[pieceRow][pieceCol - 1].triggerGUID))
1030 {
1031 CastChangeFacing(piece, trigger);
1032 }
1033
1034 return true;
1035 }
1036 else if (urand(0, 1)) // 50% chance to check for nearby enemies
1037 {
1038 if (Creature* target = GetHostileTargetForChangeFacing(piece, orientation))
1039 {
1040 CastChangeFacing(me, target);
1041 return true;
1042 }
1043 }
1044
1045 switch (orientation)
1046 {
1047 case ORI_W:
1048 case ORI_N:
1049 orientation = ORI_NW;
1050 break;
1051 case ORI_S:
1052 case ORI_E:
1053 orientation = ORI_SE;
1054 break;
1055 default:
1056 break;
1057 }
1058
1059 switch (orientation)
1060 {
1061 case ORI_SE:
1062 case ORI_NW:
1063 {
1064 int32 randomRow = (orientation == ORI_SE) ? pieceRow - 1 : pieceRow + 1;
1065 int32 randomCol = pieceCol;
1066 switch (urand(0, 2))
1067 {
1068 case 0:
1069 if ((me->GetEntry() == NPC_QUEEN_A || me->GetEntry() == NPC_QUEEN_H))
1070 {
1071 randomCol -= irand(1, 2);
1072 }
1073 else
1074 {
1075 randomCol -= 1;
1076 }
1077 break;
1078 case 1:
1079 if ((me->GetEntry() == NPC_QUEEN_A || me->GetEntry() == NPC_QUEEN_H))
1080 {
1081 randomCol += irand(1, 2);
1082 }
1083 else
1084 {
1085 randomCol += 1;
1086 }
1087 break;
1088 case 2:
1089 if ((me->GetEntry() == NPC_QUEEN_A || me->GetEntry() == NPC_QUEEN_H))
1090 {
1091 randomRow += (orientation == ORI_SE) ? irand(-2, 0) : irand(0, 2);
1092 }
1093 else if ((me->GetEntry() == NPC_KNIGHT_A || me->GetEntry() == NPC_KNIGHT_H) && urand(0, 1))
1094 {
1095 randomRow += (orientation == ORI_SE) ? -1 : 1;
1096 }
1097 break;
1098 }
1099
1100 randomRow = RoundToInterval(randomRow, 0, 7);
1101 randomCol = RoundToInterval(randomCol, 0, 7);
1102
1103 BoardCell const& cell = _boards[randomRow][randomCol];
1104 if (Creature* trigger = ObjectAccessor::GetCreature(*me, cell.triggerGUID))
1105 {
1106 if (!cell.pieceGUID)
1107 {
1108 piece->CastSpell(trigger, SPELL_MOVE_GENERIC, false);
1109 return true;
1110 }
1111 }
1112 break;
1113 }
1114 case ORI_SW:
1115 case ORI_NE:
1116 {
1117 int32 randomRow = pieceRow;
1118 int32 randomCol = orientation == ORI_SW ? pieceCol - 1 : pieceCol + 1;
1119 switch (urand(0, 2))
1120 {
1121 case 0:
1122 if ((me->GetEntry() == NPC_QUEEN_A || me->GetEntry() == NPC_QUEEN_H))
1123 {
1124 randomRow -= irand(1, 2);
1125 }
1126 else
1127 {
1128 randomRow -= 1;
1129 }
1130 break;
1131 case 1:
1132 if ((me->GetEntry() == NPC_QUEEN_A || me->GetEntry() == NPC_QUEEN_H))
1133 {
1134 randomRow += irand(1, 2);
1135 }
1136 else
1137 {
1138 randomRow += 1;
1139 }
1140 break;
1141 case 2:
1142 if ((me->GetEntry() == NPC_QUEEN_A || me->GetEntry() == NPC_QUEEN_H))
1143 {
1144 randomCol += (orientation == ORI_SW) ? irand(-2, 0) : irand(0, 2);
1145 }
1146 else if ((me->GetEntry() == NPC_KNIGHT_A || me->GetEntry() == NPC_KNIGHT_H) && urand(0, 1))
1147 {
1148 randomCol += (orientation == ORI_SW) ? -1 : 1;
1149 }
1150 break;
1151 }
1152
1153 randomRow = RoundToInterval(randomRow, 0, 7);
1154 randomCol = RoundToInterval(randomCol, 0, 7);
1155
1156 BoardCell const& cell = _boards[randomRow][randomCol];
1157 if (Creature* trigger = ObjectAccessor::GetCreature(*me, cell.triggerGUID))
1158 {
1159 if (!cell.pieceGUID)
1160 {
1161 piece->CastSpell(trigger, SPELL_MOVE_GENERIC, false);
1162 return true;
1163 }
1164 }
1165 break;
1166 }
1167 default:
1168 break;
1169 }
1170
1171 return false;
1172 }
std::int32_t int32
Definition: Define.h:104
int32 irand(int32 min, int32 max)
Definition: Random.cpp:37
T RoundToInterval(T &num, T floor, T ceil)
Definition: Util.h:79
@ SPELL_MOVE_GENERIC
Definition: boss_chess_event.cpp:47
void CastChangeFacing(Creature *piece, Creature *trigger)
Definition: boss_chess_event.cpp:969
Creature * GetHostileTargetForChangeFacing(Creature *piece, KarazhanChessOrientationType orientation)
Definition: boss_chess_event.cpp:391

References _boards, CastChangeFacing(), Unit::CastSpell(), ObjectAccessor::GetCreature(), Object::GetEntry(), Object::GetGUID(), GetHostileTargetForChangeFacing(), irand(), MAX_COL, MAX_ROW, ScriptedAI::me, NPC_KNIGHT_A, NPC_KNIGHT_H, NPC_QUEEN_A, NPC_QUEEN_H, ORI_E, ORI_N, ORI_NE, ORI_NW, ORI_S, ORI_SE, ORI_SW, ORI_W, BoardCell::pieceGUID, RoundToInterval(), SPELL_MOVE_GENERIC, BoardCell::triggerGUID, and urand().

◆ HandlePieceRotate()

int8 npc_echo_of_medivh::HandlePieceRotate ( Creature piece,
ObjectGuid const &  triggerGUID 
)
inline
731 {
732 bool foundOld = false;
733 bool foundNew = false;
734 int8 pieceRow = MAX_ROW;
735 int8 pieceCol = MAX_COL;
736 int8 targetRow = -1;
737 int8 targetCol = -1;
738
739 for (uint8 row = 0; row < MAX_ROW; ++row)
740 {
741 for (uint8 col = 0; col < MAX_COL; ++col)
742 {
743 BoardCell const& cell = _boards[row][col];
744 if (!foundNew && cell.triggerGUID == triggerGUID)
745 {
746 targetRow = row;
747 targetCol = col;
748 foundNew = true;
749 }
750
751 if (!foundOld && cell.pieceGUID == piece->GetGUID())
752 {
753 pieceRow = row;
754 pieceCol = col;
755 foundOld = true;
756 }
757
758 if (foundNew && foundOld)
759 {
760 break;
761 }
762 }
763
764 if (foundNew && foundOld)
765 {
766 break;
767 }
768 }
769
770 if (targetRow == -1 || targetCol == -1)
771 {
772 return -1;
773 }
774
775 int8 deltaRow = targetRow - pieceRow;
776 int8 deltaCol = targetCol - pieceCol;
777
778 if (!deltaRow && !deltaCol)
779 {
780 return -1;
781 }
782
783 switch (deltaRow)
784 {
785 case -3:
786 case -2:
787 case -1:
788 {
789 switch (deltaCol)
790 {
791 case -3:
792 case -2:
793 case -1:
794 return ORI_S;
795 case 0:
796 return ORI_SE;
797 case 1:
798 case 2:
799 case 3:
800 return ORI_E;
801 default:
802 break;
803 }
804 break;
805 }
806 case 0:
807 {
808 switch (deltaCol)
809 {
810 case -3:
811 case -2:
812 case -1:
813 return ORI_SW;
814 case 1:
815 case 2:
816 case 3:
817 return ORI_NE;
818 default:
819 break;
820 }
821 break;
822 }
823 case 1:
824 case 2:
825 case 3:
826 {
827 switch (deltaCol)
828 {
829 case -3:
830 case -2:
831 case -1:
832 return ORI_W;
833 case 0:
834 return ORI_NW;
835 case 1:
836 case 2:
837 case 3:
838 return ORI_N;
839 default:
840 break;
841 }
842 break;
843 }
844 default:
845 break;
846 }
847
848 return -1;
849 }

References _boards, Object::GetGUID(), MAX_COL, MAX_ROW, ORI_E, ORI_N, ORI_NE, ORI_NW, ORI_S, ORI_SE, ORI_SW, ORI_W, BoardCell::pieceGUID, and BoardCell::triggerGUID.

Referenced by HandlePieceMove().

◆ IsMedivhPiece()

bool npc_echo_of_medivh::IsMedivhPiece ( uint32  entry) const
inline
369 {
370 switch (entry)
371 {
372 case NPC_PAWN_H:
373 case NPC_KNIGHT_H:
374 case NPC_QUEEN_H:
375 case NPC_BISHOP_H:
376 case NPC_ROOK_H:
377 case NPC_KING_H:
379 case NPC_PAWN_A:
380 case NPC_KNIGHT_A:
381 case NPC_QUEEN_A:
382 case NPC_BISHOP_A:
383 case NPC_ROOK_A:
384 case NPC_KING_A:
386 }
387
388 return false;
389 }

References _instance, CHESS_EVENT_TEAM, ZoneScript::GetData(), NPC_BISHOP_A, NPC_BISHOP_H, NPC_KING_A, NPC_KING_H, NPC_KNIGHT_A, NPC_KNIGHT_H, NPC_PAWN_A, NPC_PAWN_H, NPC_QUEEN_A, NPC_QUEEN_H, NPC_ROOK_A, NPC_ROOK_H, TEAM_ALLIANCE, and TEAM_HORDE.

Referenced by HandleCheat().

◆ JustSummoned()

void npc_echo_of_medivh::JustSummoned ( Creature summon)
inlineoverridevirtual

Reimplemented from ScriptedAI.

212 {
213 _summons.Summon(summon);
214 }
void Summon(Creature const *summon)
Definition: ScriptedCreature.h:90

References _summons, and SummonList::Summon().

◆ RemoveCheats()

void npc_echo_of_medivh::RemoveCheats ( )
inline
222 {
223 // Buffs
224 for (uint8 row = 0; row < MAX_ROW; ++row)
225 {
226 for (uint8 col = 0; col < MAX_COL; ++col)
227 {
228 if (ObjectGuid guid = _boards[row][col].pieceGUID)
229 {
230 if (Creature* piece = ObjectAccessor::GetCreature(*me, guid))
231 {
232 piece->RemoveAurasDueToSpell(SPELL_HAND_OF_MEDIVH);
233 }
234 }
235 }
236 }
237 }
Definition: ObjectGuid.h:120

References _boards, ObjectAccessor::GetCreature(), MAX_COL, MAX_ROW, ScriptedAI::me, and SPELL_HAND_OF_MEDIVH.

◆ Reset()

void npc_echo_of_medivh::Reset ( )
inlineoverridevirtual

Reimplemented from ScriptedAI.

197 {
198 for (uint8 row = 0; row < MAX_ROW; ++row)
199 {
200 for (uint8 col = 0; col < MAX_COL; ++col)
201 {
202 _boards[row][col].Reset();
203 }
204 }
205
207
209 }
constexpr auto IN_MILLISECONDS
Definition: Common.h:55
void DespawnAll(uint32 delay=0)
Definition: ScriptedCreature.cpp:71
uint32 _cheatTimer
Definition: boss_chess_event.cpp:1418

References _boards, _cheatTimer, _summons, SummonList::DespawnAll(), IN_MILLISECONDS, MAX_COL, MAX_ROW, and urand().

◆ SetupBoard()

void npc_echo_of_medivh::SetupBoard ( )
inline
240 {
242
244
245 for (uint8 row = 0; row < MAX_ROW; ++row)
246 {
247 for (uint8 col = 0; col < MAX_COL; ++col)
248 {
249 BoardCell& cell = _boards[row][col];
250
251 if (Creature* trigger = me->SummonCreature(NPC_CHESS_MOVE_TRIGGER, (-11108.099609f + (3.49f * col) + (4.4f * row)), (-1872.910034f - (4.4f * col) + (3.45f * row)), 220.667f, 0, TEMPSUMMON_MANUAL_DESPAWN, 0))
252 {
253 cell.SetData(trigger->GetGUID(), row, col);
254 HandleCellInitialData(row, col, trigger, cell);
255 }
256 }
257 }
258
259 _deadCount.fill(0);
260 }
@ TEMPSUMMON_MANUAL_DESPAWN
Definition: Object.h:49
@ NPC_CHESS_MOVE_TRIGGER
Definition: boss_chess_event.cpp:63
TempSummon * SummonCreature(uint32 id, const Position &pos, TempSummonType spwtype=TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0, uint32 vehId=0, SummonPropertiesEntry const *properties=nullptr, bool visibleBySummonerOnly=false) const
Definition: Object.cpp:2343
void SetData(ObjectGuid _triggerGUID, uint8 _row, uint8 _col)
Definition: boss_chess_event.cpp:155
void HandleCellInitialData(uint8 row, uint8 col, Creature *trigger, BoardCell &cell)
Definition: boss_chess_event.cpp:262

References _boards, _deadCount, _instance, _summons, DATA_CHESS_REINIT_PIECES, SummonList::DespawnAll(), HandleCellInitialData(), MAX_COL, MAX_ROW, ScriptedAI::me, NPC_CHESS_MOVE_TRIGGER, BoardCell::SetData(), ZoneScript::SetData(), WorldObject::SummonCreature(), and TEMPSUMMON_MANUAL_DESPAWN.

Referenced by sGossipSelect().

◆ sGossipHello()

void npc_echo_of_medivh::sGossipHello ( Player player)
inlineoverridevirtual

Reimplemented from UnitAI.

1351 {
1353 switch (chessPhase)
1354 {
1356 AddGossipItemFor(player, GOSSIP_ICON_CHAT, "We want to play a game against you!", GOSSIP_SENDER_MAIN, MEDIVH_GOSSIP_START_PVE);
1357 break;
1360 AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Restart", GOSSIP_SENDER_MAIN, MEDIVH_GOSSIP_RESTART); // We want to player another game against you
1361 break;
1363 AddGossipItemFor(player, GOSSIP_ICON_CHAT, "PvP", GOSSIP_SENDER_MAIN, MEDIVH_GOSSIP_START_PVP); // We'd like to fight each other
1364 break;
1365 }
1366
1367 SendGossipMenuFor(player, player->GetGossipTextId(me), me->GetGUID());
1368 }
std::uint32_t uint32
Definition: Define.h:108
void SendGossipMenuFor(Player *player, uint32 npcTextID, ObjectGuid const guid)
Definition: ScriptedGossip.cpp:45
void AddGossipItemFor(Player *player, uint32 icon, std::string const &text, uint32 sender, uint32 action)
Definition: ScriptedGossip.cpp:28
@ GOSSIP_SENDER_MAIN
Definition: ScriptedGossip.h:70
@ GOSSIP_ICON_CHAT
Definition: GossipDef.h:60
@ MEDIVH_GOSSIP_RESTART
Definition: boss_chess_event.cpp:34
@ MEDIVH_GOSSIP_START_PVP
Definition: boss_chess_event.cpp:35
@ MEDIVH_GOSSIP_START_PVE
Definition: boss_chess_event.cpp:33
@ CHESS_PHASE_INPROGRESS_PVP
Definition: karazhan.h:195
@ CHESS_PHASE_INPROGRESS_PVE
Definition: karazhan.h:191
uint32 GetGossipTextId(uint32 menuId, WorldObject *source)
Definition: PlayerGossip.cpp:403

References _instance, AddGossipItemFor(), CHESS_PHASE_INPROGRESS_PVE, CHESS_PHASE_INPROGRESS_PVP, CHESS_PHASE_NOT_STARTED, CHESS_PHASE_PVE_FINISHED, DATA_CHESS_GAME_PHASE, ZoneScript::GetData(), Player::GetGossipTextId(), Object::GetGUID(), GOSSIP_ICON_CHAT, GOSSIP_SENDER_MAIN, ScriptedAI::me, MEDIVH_GOSSIP_RESTART, MEDIVH_GOSSIP_START_PVE, MEDIVH_GOSSIP_START_PVP, and SendGossipMenuFor().

◆ sGossipSelect()

void npc_echo_of_medivh::sGossipSelect ( Player player,
uint32  ,
uint32  gossipListId 
)
inlineoverridevirtual

Reimplemented from UnitAI.

1371 {
1373 _instance->SetData(CHESS_EVENT_TEAM, chessPhase < CHESS_PHASE_PVE_FINISHED ? player->GetTeamId() : TEAM_NEUTRAL);
1374
1375 CloseGossipMenuFor(player);
1376
1377 uint32 const action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);
1378 switch (action)
1379 {
1382 SetupBoard();
1385 break;
1389 _deadCount.fill(0);
1391 {
1394 }
1396 {
1399 }
1401 break;
1404 SetupBoard();
1407 break;
1408 default:
1409 break;
1410 }
1411 }
void CloseGossipMenuFor(Player *player)
Definition: ScriptedGossip.cpp:56
@ TALK_EVENT_BEGIN
Definition: boss_chess_event.cpp:119
@ CHESS_PHASE_FAILED
Definition: karazhan.h:192
@ CHESS_PHASE_PVE_WARMUP
Definition: karazhan.h:190
@ CHESS_PHASE_PVP_WARMUP
Definition: karazhan.h:194
TeamId GetTeamId(PvPTeamId teamId)
Definition: SharedDefines.h:3462
@ TEAM_NEUTRAL
Definition: SharedDefines.h:762
uint32 GetGossipOptionAction(uint32 selection) const
Definition: GossipDef.h:270
PlayerMenu * PlayerTalkClass
Definition: Player.h:2201
void SetupBoard()
Definition: boss_chess_event.cpp:239

References _deadCount, _instance, CHESS_EVENT_TEAM, CHESS_PHASE_FAILED, CHESS_PHASE_NOT_STARTED, CHESS_PHASE_PVE_FINISHED, CHESS_PHASE_PVE_WARMUP, CHESS_PHASE_PVP_WARMUP, CloseGossipMenuFor(), DATA_CHESS_EVENT, DATA_CHESS_GAME_PHASE, DATA_CHESS_REINIT_PIECES, DONE, InstanceScript::DoRemoveAurasDueToSpellOnPlayers(), ZoneScript::GetData(), PlayerMenu::GetGossipOptionAction(), GetTeamId(), IN_PROGRESS, MEDIVH_GOSSIP_RESTART, MEDIVH_GOSSIP_START_PVE, MEDIVH_GOSSIP_START_PVP, NOT_STARTED, Player::PlayerTalkClass, ZoneScript::SetData(), SetupBoard(), SPECIAL, SPELL_GAME_IN_SESSION, TALK_EVENT_BEGIN, and TEAM_NEUTRAL.

◆ SummonedCreatureDespawn()

void npc_echo_of_medivh::SummonedCreatureDespawn ( Creature summon)
inlineoverridevirtual

Reimplemented from ScriptedAI.

217 {
218 _summons.Despawn(summon);
219 }
void Despawn(Creature const *summon)
Definition: ScriptedCreature.h:91

References _summons, and SummonList::Despawn().

◆ UpdateAI()

void npc_echo_of_medivh::UpdateAI ( uint32  diff)
inlineoverridevirtual

Reimplemented from ScriptedAI.

1331 {
1333 if (chessPhase != CHESS_PHASE_INPROGRESS_PVE && chessPhase != CHESS_PHASE_INPROGRESS_PVP)
1334 return;
1335
1336 if (chessPhase == CHESS_PHASE_INPROGRESS_PVE)
1337 {
1338 if (_cheatTimer <= diff)
1339 {
1340 HandleCheat();
1341 _cheatTimer = urand(45000, 100000);
1342 }
1343 else
1344 {
1345 _cheatTimer -= diff;
1346 }
1347 }
1348 }
void HandleCheat()
Definition: boss_chess_event.cpp:1174

References _cheatTimer, _instance, CHESS_PHASE_INPROGRESS_PVE, CHESS_PHASE_INPROGRESS_PVP, DATA_CHESS_GAME_PHASE, ZoneScript::GetData(), HandleCheat(), and urand().

Member Data Documentation

◆ _boards

◆ _cheatTimer

uint32 npc_echo_of_medivh::_cheatTimer
private

Referenced by Reset(), and UpdateAI().

◆ _deadCount

std::array<uint32, 2> npc_echo_of_medivh::_deadCount
private

◆ _instance

◆ _summons

SummonList npc_echo_of_medivh::_summons
private