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
 Use to start attacking a target. Called just before JustEngagedWith() More...
 
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
 Called at any Damage from any attacker (before damage apply) More...
 
void UpdateAI (uint32 diff) override
 Use to start attacking a target. Called just before JustEngagedWith() More...
 
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. More...
 
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 DoTeleportPlayer (Unit *unit, Position pos)
 
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)
 
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
 
void SetInvincibility (bool apply)
 
bool IsInvincible () const
 
void SetAutoAttackAllowed (bool allow)
 
bool IsAutoAttackAllowed () 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. More...
 
void Talk (uint8 id, Milliseconds delay)
 
WorldObjectGetSummoner () const
 Returns the summoner creature/object, if the creature is a temporary summon. More...
 
 CreatureAI (Creature *creature)
 
 ~CreatureAI () override
 
void MoveCircleChecks ()
 
void MoveBackwardsChecks ()
 
void MoveInLineOfSight_Safe (Unit *who)
 == Reactions At ================================= More...
 
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. More...
 
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 SummonedCreatureEvade (Creature *)
 
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
 Called when unit is charmed. More...
 
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 ================== More...
 
virtual void PassengerBoarded (Unit *, int8, bool)
 == Fields ======================================= More...
 
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 *)
 
virtual void OnAuraRemove (AuraApplication *, AuraRemoveMode)
 
- 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
 Use to start attacking a target. Called just before JustEngagedWith() More...
 
virtual void InitializeAI ()
 
virtual void Reset ()
 
virtual void OnCharmed (bool apply)=0
 Called when unit is charmed. More...
 
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)
 Select the best (up to) <num> targets (in <targetType> order) from the threat list that fulfill the following: More...
 
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. More...
 
virtual void JustExitedCombat ()
 Called when the unit leaves combat. More...
 
virtual void DamageDealt (Unit *, uint32 &, DamageEffectType)
 Called at any Damage to any victim (before damage apply) More...
 
virtual void DamageTaken (Unit *, uint32 &, DamageEffectType, SpellSchoolMask)
 Called at any Damage from any attacker (before damage apply) More...
 
virtual void HealReceived (Unit *, uint32 &)
 Called when the creature receives heal. More...
 
virtual void OnPowerUpdate (Powers, int32, int32, uint32)
 Called when the creature power updates. More...
 
virtual void HealDone (Unit *, uint32 &)
 Called when the unit heals. More...
 
virtual void OnCalculateMeleeDamageReceived (uint32 &, Unit *)
 Called during damage calculations. More...
 
virtual void OnCalculateSpellDamageReceived (int32 &, Unit *)
 
virtual void OnCalculatePeriodicTickReceived (uint32 &, Unit *)
 Called during calculation when receiving periodic healing or damage (DoT or HoT) More...
 
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)
 To specify the caster as target if the spell is self-cast. More...
 
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, bool withTank=true)
 Cast the spell on a random unit from the threat list. More...
 
SpellCastResult DoCastMaxThreat (uint32 spellId, uint32 threatTablePosition=0, float dist=0.0f, bool playerOnly=true, bool triggered=false)
 Cast spell on the top threat target, which may not be the current victim. More...
 
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)
 Called when a summon reaches a waypoint or point movement finished. More...
 
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
 
- 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
193 : ScriptedAI(creature), _summons(me)
194 {
195 _instance = creature->GetInstanceScript();
196 }
Definition: ScriptedCreature.h:190
Creature * me
Definition: ScriptedCreature.h:280
InstanceScript * GetInstanceScript() const
Definition: Object.cpp:1203
InstanceScript * _instance
Definition: boss_chess_event.cpp:1413
SummonList _summons
Definition: boss_chess_event.cpp:1414

References _instance, and WorldObject::GetInstanceScript().

Member Function Documentation

◆ CastChangeFacing()

void npc_echo_of_medivh::CastChangeFacing ( Creature piece,
Creature trigger 
)
inline
969 {
970 piece->CastSpell(trigger, SPELL_CHANGE_FACING, true);
971 }
@ SPELL_CHANGE_FACING
Definition: boss_chess_event.cpp:51
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:1167

References Unit::CastSpell(), and SPELL_CHANGE_FACING.

Referenced by HandlePieceMoveByAI().

◆ GetHostileTargetForChangeFacing()

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

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

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

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

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
486 {
487 switch (piece->GetFaction())
488 {
490 {
491 float baseX = -11078.116211f;
492 float baseY = -1908.443115f;
493 float deltaX = 2.148438f;
494 float deltaY = 1.723755f;
495 float extraX = 2.416992f;
496 float extraY = -2.889649f;
497 float offset = 1.3f * (_deadCount[DEAD_ALLIANCE] % MAX_ROW);
498 float finalX = baseX + offset * deltaX + (_deadCount[DEAD_ALLIANCE] >= MAX_ROW ? 1 : 0) * extraX;
499 float finalY = baseY + offset * deltaY + (_deadCount[DEAD_ALLIANCE] >= MAX_ROW ? 1 : 0) * extraY;
500 piece->NearTeleportTo(finalX, finalY, 221.0f, orientations[ORI_SW]);
502
503 piece->CombatStop();
505 piece->setDeathState(DeathState::JustRespawned);
506 piece->SetHealth(piece->GetMaxHealth());
507 break;
508 }
510 {
511 float baseX = -11081.393555f;
512 float baseY = -1844.194092f;
513 float deltaX = -2.148438f;
514 float deltaY = -1.723755f;
515 float extraX = -2.416992f;
516 float extraY = 2.889649f;
517
518 float offset = 1.3f * (_deadCount[DEAD_HORDE] % MAX_ROW);
519
520 float finalX = baseX + offset * deltaX + (_deadCount[DEAD_HORDE] >= MAX_ROW ? 1 : 0) * extraX;
521 float finalY = baseY + offset * deltaY + (_deadCount[DEAD_HORDE] >= MAX_ROW ? 1 : 0) * extraY;
522 piece->NearTeleportTo(finalX, finalY, 221.0f, orientations[ORI_NE]);
524
525 piece->CombatStop();
527 piece->setDeathState(DeathState::JustRespawned);
528 piece->SetHealth(piece->GetMaxHealth());
529 break;
530 }
531 }
532
533 for (uint8 row = 0; row < MAX_ROW; ++row)
534 {
535 for (uint8 col = 0; col < MAX_COL; ++col)
536 {
537 if (_boards[row][col].pieceGUID == piece->GetGUID())
538 {
539 _boards[row][col].Reset();
540 }
541 }
542 }
543
545 {
546 bool ended = false;
547 switch (piece->GetEntry())
548 {
549 case NPC_KING_H:
553 break;
554 case NPC_KING_A:
556 {
562 ended = true;
564 }
566 {
570 ended = true;
572 }
573 break;
574 default:
575 break;
576 }
577
578 if (!ended)
579 {
580 uint8 talkIndex = TALK_PLAYER_LOOSE_PAWN;
581 if (piece->GetFaction() == CHESS_FACTION_ALLIANCE)
582 {
583 talkIndex = TALK_MEDIVH_LOOSE_PAWN;
584 }
585
586 switch (piece->GetEntry())
587 {
588 case NPC_ROOK_A:
589 case NPC_ROOK_H:
590 talkIndex += 1;
591 break;
592 case NPC_KNIGHT_A:
593 case NPC_KNIGHT_H:
594 talkIndex += 2;
595 break;
596 case NPC_BISHOP_A:
597 case NPC_BISHOP_H:
598 talkIndex += 3;
599 break;
600 case NPC_QUEEN_A:
601 case NPC_QUEEN_H:
602 talkIndex += 4;
603 break;
604 case NPC_KING_H:
605 case NPC_KING_A:
606 talkIndex += 5;
607 break;
608 }
609
610 Talk(talkIndex);
611 }
612 }
614 {
615 bool ended = false;
616 switch (piece->GetEntry())
617 {
618 case NPC_KING_A:
622 break;
623 case NPC_KING_H:
625 {
631 ended = true;
633 }
635 {
640 ended = true;
641 }
642 break;
643 default:
644 break;
645 }
646
647 if (!ended)
648 {
649 uint8 talkIndex = TALK_PLAYER_LOOSE_PAWN;
650 if (piece->GetFaction() == CHESS_FACTION_HORDE)
651 {
652 talkIndex = TALK_MEDIVH_LOOSE_PAWN;
653 }
654
655 switch (piece->GetEntry())
656 {
657 case NPC_ROOK_A:
658 case NPC_ROOK_H:
659 talkIndex += 1;
660 break;
661 case NPC_KNIGHT_A:
662 case NPC_KNIGHT_H:
663 talkIndex += 2;
664 break;
665 case NPC_BISHOP_A:
666 case NPC_BISHOP_H:
667 talkIndex += 3;
668 break;
669 case NPC_QUEEN_A:
670 case NPC_QUEEN_H:
671 talkIndex += 4;
672 break;
673 case NPC_KING_H:
674 case NPC_KING_A:
675 talkIndex += 5;
676 break;
677 }
678
679 Talk(talkIndex);
680 }
681 }
682 else
683 {
684 switch (piece->GetEntry())
685 {
686 case NPC_KING_H:
687 case NPC_KING_A:
692 break;
693 }
694
695 uint8 talkIndex = TALK_PLAYER_LOOSE_PAWN;
696 if (piece->GetFaction() == CHESS_FACTION_HORDE)
697 {
698 talkIndex = TALK_MEDIVH_LOOSE_PAWN;
699 }
700
701 switch (piece->GetEntry())
702 {
703 case NPC_ROOK_A:
704 case NPC_ROOK_H:
705 talkIndex += 1;
706 break;
707 case NPC_KNIGHT_A:
708 case NPC_KNIGHT_H:
709 talkIndex += 2;
710 break;
711 case NPC_BISHOP_A:
712 case NPC_BISHOP_H:
713 talkIndex += 3;
714 break;
715 case NPC_QUEEN_A:
716 case NPC_QUEEN_H:
717 talkIndex += 4;
718 break;
719 case NPC_KING_H:
720 case NPC_KING_A:
721 talkIndex += 5;
722 break;
723 }
724
725 Talk(talkIndex);
726 }
727 }
constexpr auto DAY
Definition: Common.h:49
@ TALK_EVENT_ENDED
Definition: boss_chess_event.cpp:141
@ TALK_MEDIVH_LOOSE_PAWN
Definition: boss_chess_event.cpp:133
@ TALK_PLAYER_LOOSE_PAWN
Definition: boss_chess_event.cpp:126
@ DEAD_ALLIANCE
Definition: boss_chess_event.cpp:70
@ DEAD_HORDE
Definition: boss_chess_event.cpp:71
@ 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
@ IN_PROGRESS
Definition: InstanceScript.h:58
@ DONE
Definition: InstanceScript.h:60
@ SPECIAL
Definition: InstanceScript.h:61
@ NOT_STARTED
Definition: InstanceScript.h:57
@ UNIT_FLAG_NOT_SELECTABLE
Definition: UnitDefines.h:254
void setDeathState(DeathState s, bool despawn=false) override
A creature can be in 4 different states: Alive, JustDied, Corpse, and JustRespawned....
Definition: Creature.cpp:1965
uint32 GetEntry() const
Definition: Object.h:115
void CombatStop(bool includingCast=false)
Definition: Unit.cpp:10436
void SetHealth(uint32 val)
Definition: Unit.cpp:15478
uint32 GetFaction() const
Definition: Unit.h:808
void NearTeleportTo(Position &pos, bool casting=false, bool vehicleTeleport=false, bool withPet=false, bool removeTransport=false)
Definition: Unit.cpp:19979
void SetUnitFlag(UnitFlags flags)
UnitFlags available in UnitDefines.h.
Definition: Unit.h:713
ObjectGuid GetGuidData(uint32 type) const override
Definition: InstanceScript.cpp:98
void DoRemoveAurasDueToSpellOnPlayers(uint32 spell)
Definition: InstanceScript.cpp:665
void DoRespawnGameObject(ObjectGuid guid, uint32 timeToDespawn=MINUTE)
Definition: InstanceScript.cpp:561
virtual void SetData(uint32, uint32)
Definition: ZoneScript.h:52
std::array< uint32, 2 > _deadCount
Definition: boss_chess_event.cpp:1416

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

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

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

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

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
371 {
372 switch (entry)
373 {
374 case NPC_PAWN_H:
375 case NPC_KNIGHT_H:
376 case NPC_QUEEN_H:
377 case NPC_BISHOP_H:
378 case NPC_ROOK_H:
379 case NPC_KING_H:
381 case NPC_PAWN_A:
382 case NPC_KNIGHT_A:
383 case NPC_QUEEN_A:
384 case NPC_BISHOP_A:
385 case NPC_ROOK_A:
386 case NPC_KING_A:
388 }
389
390 return false;
391 }

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.

214 {
215 _summons.Summon(summon);
216 }
void Summon(Creature const *summon)
Definition: ScriptedCreature.h:88

References _summons, and SummonList::Summon().

◆ RemoveCheats()

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

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.

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

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

◆ SetupBoard()

void npc_echo_of_medivh::SetupBoard ( )
inline
242 {
244
246
247 for (uint8 row = 0; row < MAX_ROW; ++row)
248 {
249 for (uint8 col = 0; col < MAX_COL; ++col)
250 {
251 BoardCell& cell = _boards[row][col];
252
253 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))
254 {
255 cell.SetData(trigger->GetGUID(), row, col);
256 HandleCellInitialData(row, col, trigger, cell);
257 }
258 }
259 }
260
261 _deadCount.fill(0);
262 }
@ NPC_CHESS_MOVE_TRIGGER
Definition: boss_chess_event.cpp:65
@ TEMPSUMMON_MANUAL_DESPAWN
Definition: Object.h:53
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:2366
void SetData(ObjectGuid _triggerGUID, uint8 _row, uint8 _col)
Definition: boss_chess_event.cpp:157
void HandleCellInitialData(uint8 row, uint8 col, Creature *trigger, BoardCell &cell)
Definition: boss_chess_event.cpp:264

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.

1350 {
1352 switch (chessPhase)
1353 {
1355 AddGossipItemFor(player, GOSSIP_ICON_CHAT, "We want to play a game against you!", GOSSIP_SENDER_MAIN, MEDIVH_GOSSIP_START_PVE);
1356 break;
1359 AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Restart", GOSSIP_SENDER_MAIN, MEDIVH_GOSSIP_RESTART); // We want to player another game against you
1360 break;
1362 AddGossipItemFor(player, GOSSIP_ICON_CHAT, "PvP", GOSSIP_SENDER_MAIN, MEDIVH_GOSSIP_START_PVP); // We'd like to fight each other
1363 break;
1364 }
1365
1366 SendGossipMenuFor(player, player->GetGossipTextId(me), me->GetGUID());
1367 }
std::uint32_t uint32
Definition: Define.h:107
@ MEDIVH_GOSSIP_RESTART
Definition: boss_chess_event.cpp:36
@ MEDIVH_GOSSIP_START_PVP
Definition: boss_chess_event.cpp:37
@ MEDIVH_GOSSIP_START_PVE
Definition: boss_chess_event.cpp:35
@ CHESS_PHASE_INPROGRESS_PVP
Definition: karazhan.h:195
@ CHESS_PHASE_INPROGRESS_PVE
Definition: karazhan.h:191
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:61
uint32 GetGossipTextId(uint32 menuId, WorldObject *source)
Definition: PlayerGossip.cpp:404

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.

1370 {
1372 _instance->SetData(CHESS_EVENT_TEAM, chessPhase < CHESS_PHASE_PVE_FINISHED ? player->GetTeamId() : TEAM_NEUTRAL);
1373
1374 CloseGossipMenuFor(player);
1375
1376 uint32 const action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);
1377 switch (action)
1378 {
1381 SetupBoard();
1384 break;
1388 _deadCount.fill(0);
1390 {
1393 }
1395 {
1398 }
1400 break;
1403 SetupBoard();
1406 break;
1407 default:
1408 break;
1409 }
1410 }
@ TALK_EVENT_BEGIN
Definition: boss_chess_event.cpp:121
@ 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
void CloseGossipMenuFor(Player *player)
Definition: ScriptedGossip.cpp:56
uint32 GetGossipOptionAction(uint32 selection) const
Definition: GossipDef.h:271
PlayerMenu * PlayerTalkClass
Definition: Player.h:2239
void SetupBoard()
Definition: boss_chess_event.cpp:241

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.

219 {
220 _summons.Despawn(summon);
221 }
void Despawn(Creature const *summon)
Definition: ScriptedCreature.h:89

References _summons, and SummonList::Despawn().

◆ UpdateAI()

void npc_echo_of_medivh::UpdateAI ( uint32  )
inlineoverridevirtual

Use to start attacking a target. Called just before JustEngagedWith()

Reimplemented from ScriptedAI.

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

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