[10277] Use typedef CreatureEventAIList, some other code style cleanups in EventAI code.

This commit is contained in:
VladimirMangos 2010-07-27 12:19:05 +04:00
parent 8827c72a79
commit 61d076442f
3 changed files with 103 additions and 101 deletions

View file

@ -55,11 +55,10 @@ int CreatureEventAI::Permissible(const Creature *creature)
CreatureEventAI::CreatureEventAI(Creature *c ) : CreatureAI(c) CreatureEventAI::CreatureEventAI(Creature *c ) : CreatureAI(c)
{ {
// Need make copy for filter unneeded steps and safe in case table reload // Need make copy for filter unneeded steps and safe in case table reload
CreatureEventAI_Event_Map::const_iterator CreatureEvents = sEventAIMgr.GetCreatureEventAIMap().find(m_creature->GetEntry()); CreatureEventAI_Event_Map::const_iterator creatureEventsItr = sEventAIMgr.GetCreatureEventAIMap().find(m_creature->GetEntry());
if (CreatureEvents != sEventAIMgr.GetCreatureEventAIMap().end()) if (creatureEventsItr != sEventAIMgr.GetCreatureEventAIMap().end())
{ {
std::vector<CreatureEventAI_Event>::const_iterator i; for (CreatureEventAI_Event_Vec::const_iterator i = (*creatureEventsItr).second.begin(); i != (*creatureEventsItr).second.end(); ++i)
for (i = (*CreatureEvents).second.begin(); i != (*CreatureEvents).second.end(); ++i)
{ {
//Debug check //Debug check
@ -72,32 +71,32 @@ CreatureEventAI::CreatureEventAI(Creature *c ) : CreatureAI(c)
if ((1 << (m_creature->GetMap()->GetSpawnMode()+1)) & (*i).event_flags) if ((1 << (m_creature->GetMap()->GetSpawnMode()+1)) & (*i).event_flags)
{ {
//event flagged for instance mode //event flagged for instance mode
CreatureEventAIList.push_back(CreatureEventAIHolder(*i)); m_CreatureEventAIList.push_back(CreatureEventAIHolder(*i));
} }
continue;
} }
CreatureEventAIList.push_back(CreatureEventAIHolder(*i)); else
m_CreatureEventAIList.push_back(CreatureEventAIHolder(*i));
} }
//EventMap had events but they were not added because they must be for instance //EventMap had events but they were not added because they must be for instance
if (CreatureEventAIList.empty()) if (m_CreatureEventAIList.empty())
sLog.outError("CreatureEventAI: Creature %u has events but no events added to list because of instance flags.", m_creature->GetEntry()); sLog.outError("CreatureEventAI: Creature %u has events but no events added to list because of instance flags.", m_creature->GetEntry());
} }
else else
sLog.outError("CreatureEventAI: EventMap for Creature %u is empty but creature is using CreatureEventAI.", m_creature->GetEntry()); sLog.outError("CreatureEventAI: EventMap for Creature %u is empty but creature is using CreatureEventAI.", m_creature->GetEntry());
bEmptyList = CreatureEventAIList.empty(); m_bEmptyList = m_CreatureEventAIList.empty();
Phase = 0; m_Phase = 0;
CombatMovementEnabled = true; m_CombatMovementEnabled = true;
MeleeEnabled = true; m_MeleeEnabled = true;
AttackDistance = 0.0f; m_AttackDistance = 0.0f;
AttackAngle = 0.0f; m_AttackAngle = 0.0f;
InvinceabilityHpLevel = 0; m_InvinceabilityHpLevel = 0;
//Handle Spawned Events //Handle Spawned Events
if (!bEmptyList) if (!m_bEmptyList)
{ {
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
if (SpawnedEventConditionsCheck((*i).Event)) if (SpawnedEventConditionsCheck((*i).Event))
ProcessEvent(*i); ProcessEvent(*i);
} }
@ -110,7 +109,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
return false; return false;
//Check the inverse phase mask (event doesn't trigger if current phase bit is set in mask) //Check the inverse phase mask (event doesn't trigger if current phase bit is set in mask)
if (pHolder.Event.event_inverse_phase_mask & (1 << Phase)) if (pHolder.Event.event_inverse_phase_mask & (1 << m_Phase))
return false; return false;
CreatureEventAI_Event const& event = pHolder.Event; CreatureEventAI_Event const& event = pHolder.Event;
@ -476,11 +475,11 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
{ {
case CHASE_MOTION_TYPE: case CHASE_MOTION_TYPE:
case FOLLOW_MOTION_TYPE: case FOLLOW_MOTION_TYPE:
AttackDistance = 0.0f; m_AttackDistance = 0.0f;
AttackAngle = 0.0f; m_AttackAngle = 0.0f;
m_creature->GetMotionMaster()->Clear(false); m_creature->GetMotionMaster()->Clear(false);
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), AttackDistance, AttackAngle); m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_AttackDistance, m_AttackAngle);
break; break;
} }
} }
@ -562,17 +561,17 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
target->RemoveFlag(UNIT_FIELD_FLAGS, action.unit_flag.value); target->RemoveFlag(UNIT_FIELD_FLAGS, action.unit_flag.value);
break; break;
case ACTION_T_AUTO_ATTACK: case ACTION_T_AUTO_ATTACK:
MeleeEnabled = action.auto_attack.state != 0; m_MeleeEnabled = action.auto_attack.state != 0;
break; break;
case ACTION_T_COMBAT_MOVEMENT: case ACTION_T_COMBAT_MOVEMENT:
// ignore no affect case // ignore no affect case
if(CombatMovementEnabled==(action.combat_movement.state!=0)) if(m_CombatMovementEnabled==(action.combat_movement.state!=0))
return; return;
CombatMovementEnabled = action.combat_movement.state != 0; m_CombatMovementEnabled = action.combat_movement.state != 0;
//Allow movement (create new targeted movement gen only if idle) //Allow movement (create new targeted movement gen only if idle)
if (CombatMovementEnabled) if (m_CombatMovementEnabled)
{ {
if(action.combat_movement.melee && m_creature->isInCombat()) if(action.combat_movement.melee && m_creature->isInCombat())
if(Unit* victim = m_creature->getVictim()) if(Unit* victim = m_creature->getVictim())
@ -581,7 +580,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == IDLE_MOTION_TYPE) if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == IDLE_MOTION_TYPE)
{ {
m_creature->GetMotionMaster()->Clear(false); m_creature->GetMotionMaster()->Clear(false);
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), AttackDistance, AttackAngle); m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_AttackDistance, m_AttackAngle);
} }
} }
else else
@ -599,23 +598,23 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
} }
break; break;
case ACTION_T_SET_PHASE: case ACTION_T_SET_PHASE:
Phase = action.set_phase.phase; m_Phase = action.set_phase.phase;
break; break;
case ACTION_T_INC_PHASE: case ACTION_T_INC_PHASE:
{ {
int32 new_phase = int32(Phase)+action.set_inc_phase.step; int32 new_phase = int32(m_Phase)+action.set_inc_phase.step;
if (new_phase < 0) if (new_phase < 0)
{ {
sLog.outErrorDb( "CreatureEventAI: Event %d decrease Phase under 0. CreatureEntry = %d", EventId, m_creature->GetEntry()); sLog.outErrorDb( "CreatureEventAI: Event %d decrease Phase under 0. CreatureEntry = %d", EventId, m_creature->GetEntry());
Phase = 0; m_Phase = 0;
} }
else if (new_phase >= MAX_PHASE) else if (new_phase >= MAX_PHASE)
{ {
sLog.outErrorDb( "CreatureEventAI: Event %d incremented Phase above %u. Phase mask cannot be used with phases past %u. CreatureEntry = %d", EventId, MAX_PHASE-1, MAX_PHASE-1, m_creature->GetEntry()); sLog.outErrorDb( "CreatureEventAI: Event %d incremented Phase above %u. Phase mask cannot be used with phases past %u. CreatureEntry = %d", EventId, MAX_PHASE-1, MAX_PHASE-1, m_creature->GetEntry());
Phase = MAX_PHASE-1; m_Phase = MAX_PHASE-1;
} }
else else
Phase = new_phase; m_Phase = new_phase;
break; break;
} }
@ -647,25 +646,25 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
target->RemoveAurasDueToSpell(action.remove_aura.spellId); target->RemoveAurasDueToSpell(action.remove_aura.spellId);
break; break;
case ACTION_T_RANGED_MOVEMENT: case ACTION_T_RANGED_MOVEMENT:
AttackDistance = (float)action.ranged_movement.distance; m_AttackDistance = (float)action.ranged_movement.distance;
AttackAngle = action.ranged_movement.angle/180.0f*M_PI_F; m_AttackAngle = action.ranged_movement.angle/180.0f*M_PI_F;
if (CombatMovementEnabled) if (m_CombatMovementEnabled)
{ {
if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE) if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE)
{ {
//Drop current movement gen //Drop current movement gen
m_creature->GetMotionMaster()->Clear(false); m_creature->GetMotionMaster()->Clear(false);
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), AttackDistance, AttackAngle); m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_AttackDistance, m_AttackAngle);
} }
} }
break; break;
case ACTION_T_RANDOM_PHASE: case ACTION_T_RANDOM_PHASE:
Phase = GetRandActionParam(rnd, action.random_phase.phase1, action.random_phase.phase2, action.random_phase.phase3); m_Phase = GetRandActionParam(rnd, action.random_phase.phase1, action.random_phase.phase2, action.random_phase.phase3);
break; break;
case ACTION_T_RANDOM_PHASE_RANGE: case ACTION_T_RANDOM_PHASE_RANGE:
if (action.random_phase_range.phaseMax > action.random_phase_range.phaseMin) if (action.random_phase_range.phaseMax > action.random_phase_range.phaseMin)
Phase = action.random_phase_range.phaseMin + (rnd % (action.random_phase_range.phaseMax - action.random_phase_range.phaseMin)); m_Phase = action.random_phase_range.phaseMin + (rnd % (action.random_phase_range.phaseMax - action.random_phase_range.phaseMin));
else else
sLog.outErrorDb( "CreatureEventAI: ACTION_T_RANDOM_PHASE_RANGE cannot have Param2 <= Param1. Divide by Zero. Event = %d. CreatureEntry = %d", EventId, m_creature->GetEntry()); sLog.outErrorDb( "CreatureEventAI: ACTION_T_RANDOM_PHASE_RANGE cannot have Param2 <= Param1. Divide by Zero. Event = %d. CreatureEntry = %d", EventId, m_creature->GetEntry());
break; break;
@ -778,9 +777,9 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
case ACTION_T_SET_INVINCIBILITY_HP_LEVEL: case ACTION_T_SET_INVINCIBILITY_HP_LEVEL:
{ {
if(action.invincibility_hp_level.is_percent) if(action.invincibility_hp_level.is_percent)
InvinceabilityHpLevel = m_creature->GetMaxHealth()*action.invincibility_hp_level.hp_level/100; m_InvinceabilityHpLevel = m_creature->GetMaxHealth()*action.invincibility_hp_level.hp_level/100;
else else
InvinceabilityHpLevel = action.invincibility_hp_level.hp_level; m_InvinceabilityHpLevel = action.invincibility_hp_level.hp_level;
break; break;
} }
} }
@ -790,25 +789,25 @@ void CreatureEventAI::JustRespawned()
{ {
Reset(); Reset();
if (bEmptyList) if (m_bEmptyList)
return; return;
//Handle Spawned Events //Handle Spawned Events
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
if (SpawnedEventConditionsCheck((*i).Event)) if (SpawnedEventConditionsCheck((*i).Event))
ProcessEvent(*i); ProcessEvent(*i);
} }
void CreatureEventAI::Reset() void CreatureEventAI::Reset()
{ {
EventUpdateTime = EVENT_UPDATE_TIME; m_EventUpdateTime = EVENT_UPDATE_TIME;
EventDiff = 0; m_EventDiff = 0;
if (bEmptyList) if (m_bEmptyList)
return; return;
//Reset all events to enabled //Reset all events to enabled
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{ {
CreatureEventAI_Event const& event = (*i).Event; CreatureEventAI_Event const& event = (*i).Event;
switch (event.event_type) switch (event.event_type)
@ -833,9 +832,9 @@ void CreatureEventAI::JustReachedHome()
{ {
m_creature->LoadCreaturesAddon(); m_creature->LoadCreaturesAddon();
if (!bEmptyList) if (!m_bEmptyList)
{ {
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{ {
if ((*i).Event.event_type == EVENT_T_REACHED_HOME) if ((*i).Event.event_type == EVENT_T_REACHED_HOME)
ProcessEvent(*i); ProcessEvent(*i);
@ -856,11 +855,11 @@ void CreatureEventAI::EnterEvadeMode()
m_creature->SetLootRecipient(NULL); m_creature->SetLootRecipient(NULL);
if (bEmptyList) if (m_bEmptyList)
return; return;
//Handle Evade events //Handle Evade events
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{ {
if ((*i).Event.event_type == EVENT_T_EVADE) if ((*i).Event.event_type == EVENT_T_EVADE)
ProcessEvent(*i); ProcessEvent(*i);
@ -878,26 +877,26 @@ void CreatureEventAI::JustDied(Unit* killer)
m_creature->SendZoneUnderAttackMessage(pKiller); m_creature->SendZoneUnderAttackMessage(pKiller);
} }
if (bEmptyList) if (m_bEmptyList)
return; return;
//Handle Evade events //Handle Evade events
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{ {
if ((*i).Event.event_type == EVENT_T_DEATH) if ((*i).Event.event_type == EVENT_T_DEATH)
ProcessEvent(*i, killer); ProcessEvent(*i, killer);
} }
// reset phase after any death state events // reset phase after any death state events
Phase = 0; m_Phase = 0;
} }
void CreatureEventAI::KilledUnit(Unit* victim) void CreatureEventAI::KilledUnit(Unit* victim)
{ {
if (bEmptyList || victim->GetTypeId() != TYPEID_PLAYER) if (m_bEmptyList || victim->GetTypeId() != TYPEID_PLAYER)
return; return;
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{ {
if ((*i).Event.event_type == EVENT_T_KILL) if ((*i).Event.event_type == EVENT_T_KILL)
ProcessEvent(*i, victim); ProcessEvent(*i, victim);
@ -906,10 +905,10 @@ void CreatureEventAI::KilledUnit(Unit* victim)
void CreatureEventAI::JustSummoned(Creature* pUnit) void CreatureEventAI::JustSummoned(Creature* pUnit)
{ {
if (bEmptyList || !pUnit) if (m_bEmptyList || !pUnit)
return; return;
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{ {
if ((*i).Event.event_type == EVENT_T_SUMMONED_UNIT) if ((*i).Event.event_type == EVENT_T_SUMMONED_UNIT)
ProcessEvent(*i, pUnit); ProcessEvent(*i, pUnit);
@ -918,10 +917,10 @@ void CreatureEventAI::JustSummoned(Creature* pUnit)
void CreatureEventAI::SummonedCreatureJustDied(Creature* pUnit) void CreatureEventAI::SummonedCreatureJustDied(Creature* pUnit)
{ {
if (bEmptyList || !pUnit) if (m_bEmptyList || !pUnit)
return; return;
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{ {
if ((*i).Event.event_type == EVENT_T_SUMMONED_JUST_DIED) if ((*i).Event.event_type == EVENT_T_SUMMONED_JUST_DIED)
ProcessEvent(*i, pUnit); ProcessEvent(*i, pUnit);
@ -930,10 +929,10 @@ void CreatureEventAI::SummonedCreatureJustDied(Creature* pUnit)
void CreatureEventAI::SummonedCreatureDespawn(Creature* pUnit) void CreatureEventAI::SummonedCreatureDespawn(Creature* pUnit)
{ {
if (bEmptyList || !pUnit) if (m_bEmptyList || !pUnit)
return; return;
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{ {
if ((*i).Event.event_type == EVENT_T_SUMMONED_JUST_DESPAWN) if ((*i).Event.event_type == EVENT_T_SUMMONED_JUST_DESPAWN)
ProcessEvent(*i, pUnit); ProcessEvent(*i, pUnit);
@ -943,9 +942,9 @@ void CreatureEventAI::SummonedCreatureDespawn(Creature* pUnit)
void CreatureEventAI::EnterCombat(Unit *enemy) void CreatureEventAI::EnterCombat(Unit *enemy)
{ {
//Check for on combat start events //Check for on combat start events
if (!bEmptyList) if (!m_bEmptyList)
{ {
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{ {
CreatureEventAI_Event const& event = (*i).Event; CreatureEventAI_Event const& event = (*i).Event;
switch (event.event_type) switch (event.event_type)
@ -968,8 +967,8 @@ void CreatureEventAI::EnterCombat(Unit *enemy)
} }
} }
EventUpdateTime = EVENT_UPDATE_TIME; m_EventUpdateTime = EVENT_UPDATE_TIME;
EventDiff = 0; m_EventDiff = 0;
} }
void CreatureEventAI::AttackStart(Unit *who) void CreatureEventAI::AttackStart(Unit *who)
@ -977,15 +976,15 @@ void CreatureEventAI::AttackStart(Unit *who)
if (!who) if (!who)
return; return;
if (m_creature->Attack(who, MeleeEnabled)) if (m_creature->Attack(who, m_MeleeEnabled))
{ {
m_creature->AddThreat(who); m_creature->AddThreat(who);
m_creature->SetInCombatWith(who); m_creature->SetInCombatWith(who);
who->SetInCombatWith(m_creature); who->SetInCombatWith(m_creature);
if (CombatMovementEnabled) if (m_CombatMovementEnabled)
{ {
m_creature->GetMotionMaster()->MoveChase(who, AttackDistance, AttackAngle); m_creature->GetMotionMaster()->MoveChase(who, m_AttackDistance, m_AttackAngle);
} }
else else
{ {
@ -1001,9 +1000,9 @@ void CreatureEventAI::MoveInLineOfSight(Unit *who)
return; return;
//Check for OOC LOS Event //Check for OOC LOS Event
if (!bEmptyList && !m_creature->getVictim()) if (!m_bEmptyList && !m_creature->getVictim())
{ {
for (std::vector<CreatureEventAIHolder>::iterator itr = CreatureEventAIList.begin(); itr != CreatureEventAIList.end(); ++itr) for (CreatureEventAIList::iterator itr = m_CreatureEventAIList.begin(); itr != m_CreatureEventAIList.end(); ++itr)
{ {
if ((*itr).Event.event_type == EVENT_T_OOC_LOS) if ((*itr).Event.event_type == EVENT_T_OOC_LOS)
{ {
@ -1051,10 +1050,10 @@ void CreatureEventAI::MoveInLineOfSight(Unit *who)
void CreatureEventAI::SpellHit(Unit* pUnit, const SpellEntry* pSpell) void CreatureEventAI::SpellHit(Unit* pUnit, const SpellEntry* pSpell)
{ {
if (bEmptyList) if (m_bEmptyList)
return; return;
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
if ((*i).Event.event_type == EVENT_T_SPELLHIT) if ((*i).Event.event_type == EVENT_T_SPELLHIT)
//If spell id matches (or no spell id) & if spell school matches (or no spell school) //If spell id matches (or no spell id) & if spell school matches (or no spell school)
if (!(*i).Event.spell_hit.spellId || pSpell->Id == (*i).Event.spell_hit.spellId) if (!(*i).Event.spell_hit.spellId || pSpell->Id == (*i).Event.spell_hit.spellId)
@ -1071,24 +1070,24 @@ void CreatureEventAI::UpdateAI(const uint32 diff)
if (!m_creature->isAlive()) if (!m_creature->isAlive())
return; return;
if (!bEmptyList) if (!m_bEmptyList)
{ {
//Events are only updated once every EVENT_UPDATE_TIME ms to prevent lag with large amount of events //Events are only updated once every EVENT_UPDATE_TIME ms to prevent lag with large amount of events
if (EventUpdateTime < diff) if (m_EventUpdateTime < diff)
{ {
EventDiff += diff; m_EventDiff += diff;
//Check for time based events //Check for time based events
for (std::vector<CreatureEventAIHolder>::iterator i = CreatureEventAIList.begin(); i != CreatureEventAIList.end(); ++i) for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{ {
//Decrement Timers //Decrement Timers
if ((*i).Time) if ((*i).Time)
{ {
if ((*i).Time > EventDiff) if ((*i).Time > m_EventDiff)
{ {
//Do not decrement timers if event cannot trigger in this phase //Do not decrement timers if event cannot trigger in this phase
if (!((*i).Event.event_inverse_phase_mask & (1 << Phase))) if (!((*i).Event.event_inverse_phase_mask & (1 << m_Phase)))
(*i).Time -= EventDiff; (*i).Time -= m_EventDiff;
//Skip processing of events that have time remaining //Skip processing of events that have time remaining
continue; continue;
@ -1122,18 +1121,18 @@ void CreatureEventAI::UpdateAI(const uint32 diff)
} }
} }
EventDiff = 0; m_EventDiff = 0;
EventUpdateTime = EVENT_UPDATE_TIME; m_EventUpdateTime = EVENT_UPDATE_TIME;
} }
else else
{ {
EventDiff += diff; m_EventDiff += diff;
EventUpdateTime -= diff; m_EventUpdateTime -= diff;
} }
} }
//Melee Auto-Attack //Melee Auto-Attack
if (Combat && MeleeEnabled) if (Combat && m_MeleeEnabled)
DoMeleeAttackIfReady(); DoMeleeAttackIfReady();
} }
@ -1340,10 +1339,10 @@ bool CreatureEventAI::CanCast(Unit* Target, SpellEntry const *Spell, bool Trigge
void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote) void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote)
{ {
if (bEmptyList) if (m_bEmptyList)
return; return;
for (std::vector<CreatureEventAIHolder>::iterator itr = CreatureEventAIList.begin(); itr != CreatureEventAIList.end(); ++itr) for (CreatureEventAIList::iterator itr = m_CreatureEventAIList.begin(); itr != m_CreatureEventAIList.end(); ++itr)
{ {
if ((*itr).Event.event_type == EVENT_T_RECEIVE_EMOTE) if ((*itr).Event.event_type == EVENT_T_RECEIVE_EMOTE)
{ {
@ -1362,12 +1361,12 @@ void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote)
void CreatureEventAI::DamageTaken( Unit* /*done_by*/, uint32& damage ) void CreatureEventAI::DamageTaken( Unit* /*done_by*/, uint32& damage )
{ {
if(InvinceabilityHpLevel > 0 && m_creature->GetHealth() < InvinceabilityHpLevel+damage) if(m_InvinceabilityHpLevel > 0 && m_creature->GetHealth() < m_InvinceabilityHpLevel+damage)
{ {
if(m_creature->GetHealth() <= InvinceabilityHpLevel) if(m_creature->GetHealth() <= m_InvinceabilityHpLevel)
damage = 0; damage = 0;
else else
damage = m_creature->GetHealth() - InvinceabilityHpLevel; damage = m_creature->GetHealth() - m_InvinceabilityHpLevel;
} }
} }

View file

@ -569,7 +569,7 @@ class MANGOS_DLL_SPEC CreatureEventAI : public CreatureAI
explicit CreatureEventAI(Creature *c); explicit CreatureEventAI(Creature *c);
~CreatureEventAI() ~CreatureEventAI()
{ {
CreatureEventAIList.clear(); m_CreatureEventAIList.clear();
} }
void JustRespawned(); void JustRespawned();
void Reset(); void Reset();
@ -607,18 +607,21 @@ class MANGOS_DLL_SPEC CreatureEventAI : public CreatureAI
void DoFindFriendlyMissingBuff(std::list<Creature*>& _list, float range, uint32 spellid); void DoFindFriendlyMissingBuff(std::list<Creature*>& _list, float range, uint32 spellid);
void DoFindFriendlyCC(std::list<Creature*>& _list, float range); void DoFindFriendlyCC(std::list<Creature*>& _list, float range);
//Holder for events (stores enabled, time, and eventid) protected:
std::vector<CreatureEventAIHolder> CreatureEventAIList; uint32 m_EventUpdateTime; //Time between event updates
uint32 EventUpdateTime; //Time between event updates uint32 m_EventDiff; //Time between the last event call
uint32 EventDiff; //Time between the last event call bool m_bEmptyList;
bool bEmptyList;
//Variables used by Events themselves //Variables used by Events themselves
uint8 Phase; // Current phase, max 32 phases typedef std::vector<CreatureEventAIHolder> CreatureEventAIList;
bool CombatMovementEnabled; // If we allow targeted movment gen (movement twoards top threat) CreatureEventAIList m_CreatureEventAIList; //Holder for events (stores enabled, time, and eventid)
bool MeleeEnabled; // If we allow melee auto attack
float AttackDistance; // Distance to attack from uint8 m_Phase; // Current phase, max 32 phases
float AttackAngle; // Angle of attack bool m_CombatMovementEnabled; // If we allow targeted movment gen (movement twoards top threat)
uint32 InvinceabilityHpLevel; // Minimal health level allowed at damage apply bool m_MeleeEnabled; // If we allow melee auto attack
float m_AttackDistance; // Distance to attack from
float m_AttackAngle; // Angle of attack
uint32 m_InvinceabilityHpLevel; // Minimal health level allowed at damage apply
}; };
#endif #endif

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10276" #define REVISION_NR "10277"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__