Permalink
Browse files

Core: Logical fixes and improvements in EventMap

  • Loading branch information...
Gacko committed Jan 23, 2013
1 parent 5a74336 commit dbecf05e39204ff46621ce46bf5dd181e6450eeb
@@ -336,21 +336,35 @@ class EventMap
// Sets event phase, must be in range 1 - 8
void SetPhase(uint32 phase)
{
- if (phase && phase < 8)
- _phase = (1 << (phase + 24));
+ if (phase && phase <= 8)
+ _phase = (1 << (phase + 23));
else if (!phase)
_phase = 0;
}
+ // Activates event phase, must be in range 1 - 8
+ void AddPhase(uint32 phase)
+ {
+ if (phase && phase <= 8)
+ _phase |= (1 << (phase + 23));
+ }
+
+ // Deactivates event phase, must be in range 1 - 8
+ void RemovePhase(uint32 phase)
+ {
+ if (phase && phase <= 8)
+ _phase &= ~(1 << (phase + 23));
+ }
+
// Creates new event entry in map with given id, time, group if given (1 - 8) and phase if given (1 - 8)
// 0 for group/phase means it belongs to no group or runs in all phases
void ScheduleEvent(uint32 eventId, uint32 time, uint32 groupId = 0, uint32 phase = 0)
{
time += _time;
if (groupId && groupId < 9)
- eventId |= (1 << (groupId + 16));
+ eventId |= (1 << (groupId + 15));
if (phase && phase < 8)
- eventId |= (1 << (phase + 24));
+ eventId |= (1 << (phase + 23));
StorageType::const_iterator itr = _eventMap.find(time);
while (itr != _eventMap.end())
{
@@ -443,8 +457,12 @@ class EventMap
// Delay all events having the specified Group
void DelayEvents(uint32 delay, uint32 groupId)
{
+ if (!groupId || groupId > 8)
+ return;
+
uint32 nextTime = _time + delay;
- uint32 groupMask = (1 << (groupId + 16));
+ uint32 groupMask = (1 << (groupId + 15));
+
for (StorageType::iterator itr = _eventMap.begin(); itr != _eventMap.end() && itr->first < nextTime;)
{
if (itr->second & groupMask)
@@ -476,7 +494,10 @@ class EventMap
// Cancel events belonging to specified group
void CancelEventGroup(uint32 groupId)
{
- uint32 groupMask = (1 << (groupId + 16));
+ if (!groupId || groupId > 8)
+ return;
+
+ uint32 groupMask = (1 << (groupId + 15));
for (StorageType::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
{
@@ -501,6 +522,12 @@ class EventMap
return 0;
}
+ // Returns wether the eventmap is in the given phase or not.
+ bool IsInPhase(uint32 phase)
+ {
+ return phase <= 8 && (!phase || _phase & (1 << phase + 23));
+ }
+
private:
uint32 _time;
uint32 _phase;
@@ -232,7 +232,7 @@ class boss_thekal : public CreatureScript
if (me->IsFullHealth() && WasDead)
WasDead = false;
- if ((events.GetPhaseMask() == PHASE_ONE) && !WasDead && !HealthAbovePct(5))
+ if ((events.IsInPhase(PHASE_ONE)) && !WasDead && !HealthAbovePct(5))
{
me->RemoveAurasByType(SPELL_AURA_PERIODIC_DAMAGE_PERCENT);
me->RemoveAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
@@ -61,9 +61,7 @@ enum Phases
{
PHASE_ALL = 0,
PHASE_INTRO = 1,
- PHASE_COMBAT = 2,
-
- PHASE_INTRO_MASK = 1 << PHASE_INTRO,
+ PHASE_COMBAT = 2
};
class boss_baltharus_the_warborn : public CreatureScript
@@ -166,15 +164,16 @@ class boss_baltharus_the_warborn : public CreatureScript
void UpdateAI(uint32 const diff)
{
- if (!UpdateVictim() && !(events.GetPhaseMask() & PHASE_INTRO_MASK))
+ bool introPhase = events.IsInPhase(PHASE_INTRO);
+ if (!UpdateVictim() && !introPhase)
return;
- if (!(events.GetPhaseMask() & PHASE_INTRO_MASK))
+ if (!introPhase)
me->SetHealth(instance->GetData(DATA_BALTHARUS_SHARED_HEALTH));
events.Update(diff);
- if (me->HasUnitState(UNIT_STATE_CASTING) && !(events.GetPhaseMask() & PHASE_INTRO_MASK))
+ if (me->HasUnitState(UNIT_STATE_CASTING) && !introPhase)
return;
while (uint32 eventId = events.ExecuteEvent())
@@ -165,12 +165,7 @@ enum Phases
PHASE_INTRO = 1,
PHASE_ONE = 2,
PHASE_TWO = 3,
- PHASE_THREE = 4,
-
- PHASE_INTRO_MASK = 1 << PHASE_INTRO,
- PHASE_ONE_MASK = 1 << PHASE_ONE,
- PHASE_TWO_MASK = 1 << PHASE_TWO,
- PHASE_THREE_MASK = 1 << PHASE_THREE
+ PHASE_THREE = 4
};
enum Misc
@@ -325,7 +320,7 @@ class boss_halion : public CreatureScript
void EnterEvadeMode()
{
// Phase 1: We always can evade. Phase 2 & 3: We can evade if and only if the controller tells us to.
- if ((events.GetPhaseMask() & PHASE_ONE_MASK) || _canEvade)
+ if (events.IsInPhase(PHASE_ONE) || _canEvade)
generic_halionAI::EnterEvadeMode();
}
@@ -369,7 +364,7 @@ class boss_halion : public CreatureScript
void DamageTaken(Unit* attacker, uint32& damage)
{
- if (me->HealthBelowPctDamaged(75, damage) && (events.GetPhaseMask() & PHASE_ONE_MASK))
+ if (me->HealthBelowPctDamaged(75, damage) && events.IsInPhase(PHASE_ONE))
{
events.SetPhase(PHASE_TWO);
Talk(SAY_PHASE_TWO);
@@ -383,7 +378,7 @@ class boss_halion : public CreatureScript
return;
}
- if (events.GetPhaseMask() & PHASE_THREE_MASK)
+ if (events.IsInPhase(PHASE_THREE))
{
// Don't consider copied damage.
if (!me->InSamePhase(attacker))
@@ -396,7 +391,7 @@ class boss_halion : public CreatureScript
void UpdateAI(uint32 const diff)
{
- if (events.GetPhaseMask() & PHASE_TWO_MASK)
+ if (events.IsInPhase(PHASE_TWO))
return;
generic_halionAI::UpdateAI(diff);
@@ -528,7 +523,7 @@ class boss_twilight_halion : public CreatureScript
void DamageTaken(Unit* attacker, uint32& damage)
{
- if (me->HealthBelowPctDamaged(50, damage) && (events.GetPhaseMask() & PHASE_TWO_MASK))
+ if (me->HealthBelowPctDamaged(50, damage) && events.IsInPhase(PHASE_TWO))
{
events.SetPhase(PHASE_THREE);
me->CastStop();
@@ -537,7 +532,7 @@ class boss_twilight_halion : public CreatureScript
return;
}
- if (events.GetPhaseMask() & PHASE_THREE_MASK)
+ if (events.IsInPhase(PHASE_THREE))
{
// Don't consider copied damage.
if (!me->InSamePhase(attacker))
@@ -693,7 +688,7 @@ class npc_halion_controller : public CreatureScript
// The isInCombat() check is needed because that check should be false when Halion is
// not engaged, while it would return true without as UpdateVictim() checks for
// combat state.
- if (!(_events.GetPhaseMask() & PHASE_INTRO_MASK) && me->isInCombat() && !UpdateVictim())
+ if (!(_events.IsInPhase(PHASE_INTRO)) && me->isInCombat() && !UpdateVictim())
{
EnterEvadeMode();
return;
@@ -154,9 +154,7 @@ enum Phases
{
// Anub'arak
PHASE_MELEE = 1,
- PHASE_SUBMERGED = 2,
-
- PHASE_MASK_MELEE = 1 << PHASE_MELEE
+ PHASE_SUBMERGED = 2
};
class boss_anubarak_trial : public CreatureScript
@@ -403,15 +401,15 @@ class boss_anubarak_trial : public CreatureScript
}
- if (HealthBelowPct(30) && events.GetPhaseMask() & PHASE_MASK_MELEE && !_reachedPhase3)
+ if (HealthBelowPct(30) && events.IsInPhase(PHASE_MELEE) && !_reachedPhase3)
{
_reachedPhase3 = true;
DoCastAOE(SPELL_LEECHING_SWARM);
Talk(EMOTE_LEECHING_SWARM);
Talk(SAY_LEECHING_SWARM);
}
- if (events.GetPhaseMask() & PHASE_MASK_MELEE)
+ if (events.IsInPhase(PHASE_MELEE))
DoMeleeAttackIfReady();
}
@@ -146,10 +146,7 @@ enum Phases
{
PHASE_MOBILE = 1,
PHASE_STATIONARY = 2,
- PHASE_SUBMERGED = 3,
-
- PHASE_MASK_MOBILE = 1 << PHASE_MOBILE,
- PHASE_MASK_STATIONARY = 1 << PHASE_STATIONARY
+ PHASE_SUBMERGED = 3
};
class boss_gormok : public CreatureScript
@@ -624,9 +621,9 @@ struct boss_jormungarAI : public BossAI
return;
}
}
- if (events.GetPhaseMask() & PHASE_MASK_MOBILE)
+ if (events.IsInPhase(PHASE_MOBILE))
DoMeleeAttackIfReady();
- if (events.GetPhaseMask() & PHASE_MASK_STATIONARY)
+ if (events.IsInPhase(PHASE_STATIONARY))
DoSpellAttackIfReady(SpitSpell);
}
@@ -118,7 +118,7 @@ class boss_bronjahm : public CreatureScript
void DamageTaken(Unit* /*attacker*/, uint32& /*damage*/)
{
- if (events.GetPhaseMask() & (1 << PHASE_1) && !HealthAbovePct(30))
+ if (events.IsInPhase(PHASE_1) && !HealthAbovePct(30))
{
events.SetPhase(PHASE_2);
DoCast(me, SPELL_TELEPORT);
@@ -52,11 +52,7 @@ enum Phases
{
PHASE_ONE = 1,
PHASE_TWO = 2,
- PHASE_THREE = 3,
-
- PHASE_ONE_MASK = 1 << PHASE_ONE,
- PHASE_TWO_MASK = 1 << PHASE_TWO,
- PHASE_THREE_MASK = 1 << PHASE_THREE,
+ PHASE_THREE = 3
};
enum MiscData
@@ -136,7 +132,7 @@ enum Events
void DamageTaken(Unit* /*attacker*/, uint32& /*uiDamage*/)
{
- if (events.GetPhaseMask() & PHASE_ONE_MASK && !HealthAbovePct(66))
+ if (events.IsInPhase(PHASE_ONE) && !HealthAbovePct(66))
{
events.SetPhase(PHASE_TWO);
Talk(SAY_PHASE2);
@@ -146,7 +142,7 @@ enum Events
return;
}
- if (events.GetPhaseMask() & PHASE_TWO_MASK && !HealthAbovePct(33))
+ if (events.IsInPhase(PHASE_TWO) && !HealthAbovePct(33))
{
events.SetPhase(PHASE_THREE);
Talk(SAY_PHASE3);
@@ -162,12 +158,12 @@ enum Events
if (type != EFFECT_MOTION_TYPE || id != POINT_FORGE)
return;
- if (events.GetPhaseMask() & PHASE_TWO_MASK)
+ if (events.IsInPhase(PHASE_TWO))
{
DoCast(me, SPELL_FORGE_BLADE);
SetEquipmentSlots(false, EQUIP_ID_SWORD);
}
- if (events.GetPhaseMask() & PHASE_THREE_MASK)
+ if (events.IsInPhase(PHASE_THREE))
{
me->RemoveAurasDueToSpell(SPELL_FORGE_BLADE_HELPER);
DoCast(me, SPELL_FORGE_MACE);
@@ -226,15 +222,15 @@ enum Events
break;
case EVENT_JUMP:
me->AttackStop();
- if (events.GetPhaseMask() & PHASE_TWO_MASK)
+ if (events.IsInPhase(PHASE_TWO))
me->GetMotionMaster()->MoveJump(northForgePos.GetPositionX(), northForgePos.GetPositionY(), northForgePos.GetPositionZ(), 25.0f, 15.0f);
- else if (events.GetPhaseMask() & PHASE_THREE_MASK)
+ else if (events.IsInPhase(PHASE_THREE))
me->GetMotionMaster()->MoveJump(southForgePos.GetPositionX(), southForgePos.GetPositionY(), southForgePos.GetPositionZ(), 25.0f, 15.0f);
break;
case EVENT_RESUME_ATTACK:
- if (events.GetPhaseMask() & PHASE_TWO_MASK)
+ if (events.IsInPhase(PHASE_THREE))
events.ScheduleEvent(EVENT_CHILLING_WAVE, 5000, 0, PHASE_TWO);
- else if (events.GetPhaseMask() & PHASE_THREE_MASK)
+ else if (events.IsInPhase(PHASE_THREE))
events.ScheduleEvent(EVENT_DEEP_FREEZE, 10000, 0, PHASE_THREE);
AttackStart(me->getVictim());
break;
@@ -94,7 +94,7 @@ enum Phases
PHASE_NONE = 0,
PHASE_INTRO = 1,
PHASE_COMBAT = 2,
- PHASE_OUTRO = 3,
+ PHASE_OUTRO = 3
};
enum Actions
@@ -168,7 +168,7 @@ class boss_tyrannus : public CreatureScript
if (me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE))
return;
- if (victim && me->Attack(victim, true) && !(events.GetPhaseMask() & (1 << PHASE_INTRO)))
+ if (victim && me->Attack(victim, true) && !events.IsInPhase(PHASE_INTRO))
me->GetMotionMaster()->MoveChase(victim);
}
@@ -217,7 +217,7 @@ class boss_tyrannus : public CreatureScript
void UpdateAI(const uint32 diff)
{
- if (!UpdateVictim() && !(events.GetPhaseMask() & (1 << PHASE_INTRO)))
+ if (!UpdateVictim() && !events.IsInPhase(PHASE_INTRO))
return;
events.Update(diff);
@@ -337,7 +337,7 @@ class boss_rimefang : public CreatureScript
void UpdateAI(const uint32 diff)
{
- if (!UpdateVictim() && !(_events.GetPhaseMask() & (1 << PHASE_COMBAT)))
+ if (!UpdateVictim() && !_events.IsInPhase(PHASE_COMBAT))
return;
_events.Update(diff);
@@ -185,9 +185,7 @@ enum Phases
{
PHASE_INTRO_A = 1,
PHASE_INTRO_H = 2,
- PHASE_COMBAT = 3,
-
- PHASE_INTRO_MASK = (1 << PHASE_INTRO_A) | (1 << PHASE_INTRO_H),
+ PHASE_COMBAT = 3
};
enum Actions
@@ -424,7 +422,7 @@ class boss_deathbringer_saurfang : public CreatureScript
void UpdateAI(uint32 const diff)
{
- if (!UpdateVictim() && !(events.GetPhaseMask() & PHASE_INTRO_MASK))
+ if ((!UpdateVictim() && !events.IsInPhase(PHASE_INTRO_A)) || events.IsInPhase(PHASE_INTRO_H))

This comment has been minimized.

Show comment Hide comment
@Destalker

Destalker Jan 30, 2013

This looks strange....

@Destalker

Destalker Jan 30, 2013

This looks strange....

return;
events.Update(diff);
@@ -612,7 +610,7 @@ class npc_high_overlord_saurfang_icc : public CreatureScript
case ACTION_START_EVENT:
{
// Prevent crashes
- if (_events.GetPhaseMask() & PHASE_INTRO_MASK)
+ if (_events.IsInPhase(PHASE_INTRO_A) || _events.IsInPhase(PHASE_INTRO_H))
return;
GetCreatureListWithEntryInGrid(_guardList, me, NPC_SE_KOR_KRON_REAVER, 20.0f);
@@ -821,7 +819,7 @@ class npc_muradin_bronzebeard_icc : public CreatureScript
case ACTION_START_EVENT:
{
// Prevent crashes
- if (_events.GetPhaseMask() & PHASE_INTRO_MASK)
+ if (_events.IsInPhase(PHASE_INTRO_A) || _events.IsInPhase(PHASE_INTRO_H))
return;
_events.SetPhase(PHASE_INTRO_A);
Oops, something went wrong.

3 comments on commit dbecf05

@Gacko

This comment has been minimized.

Show comment Hide comment
@Gacko

Gacko Jan 30, 2013

Member
@Norfik

This comment has been minimized.

Show comment Hide comment
@Norfik

Norfik Jan 30, 2013

Contributor

Gacko: "See http://www.trinitycore.org/f/topic/7821-eventmap-system for details."

The page you are looking for cannot be found.

Thx Aokromes xD Me bad hahaha....

Contributor

Norfik replied Jan 30, 2013

Gacko: "See http://www.trinitycore.org/f/topic/7821-eventmap-system for details."

The page you are looking for cannot be found.

Thx Aokromes xD Me bad hahaha....

@Aokromes

This comment has been minimized.

Show comment Hide comment
@Aokromes

Aokromes Jan 30, 2013

Member

You need to be logged in forum to see it.

Member

Aokromes replied Jan 30, 2013

You need to be logged in forum to see it.

Please sign in to comment.