Cleanup in CreatureEventAI code (based on changes by SilverIce and VladimirMangos)
--HG-- branch : trunk
This commit is contained in:
@@ -77,32 +77,32 @@ CreatureEventAI::CreatureEventAI(Creature *c) : CreatureAI(c)
|
|||||||
if ((1 << (me->GetMap()->GetSpawnMode()+1)) & (*i).event_flags)
|
if ((1 << (me->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;
|
continue;
|
||||||
}
|
}
|
||||||
CreatureEventAIList.push_back(CreatureEventAIHolder(*i));
|
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.", me->GetEntry());
|
sLog.outError("CreatureEventAI: Creature %u has events but no events added to list because of instance flags.", me->GetEntry());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sLog.outError("CreatureEventAI: EventMap for Creature %u is empty but creature is using CreatureEventAI.", me->GetEntry());
|
sLog.outError("CreatureEventAI: EventMap for Creature %u is empty but creature is using CreatureEventAI.", me->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::list<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);
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,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;
|
||||||
@@ -481,10 +481,10 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||||||
{
|
{
|
||||||
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == TARGETED_MOTION_TYPE)
|
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == TARGETED_MOTION_TYPE)
|
||||||
{
|
{
|
||||||
AttackDistance = 0.0f;
|
m_AttackDistance = 0.0f;
|
||||||
AttackAngle = 0.0f;
|
m_AttackAngle = 0.0f;
|
||||||
|
|
||||||
me->GetMotionMaster()->MoveChase(me->getVictim(), AttackDistance, AttackAngle);
|
me->GetMotionMaster()->MoveChase(me->getVictim(), m_AttackDistance, m_AttackAngle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,17 +565,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)
|
||||||
{
|
{
|
||||||
Unit* victim = me->getVictim();
|
Unit* victim = me->getVictim();
|
||||||
if (me->isInCombat() && victim)
|
if (me->isInCombat() && victim)
|
||||||
@@ -586,7 +586,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||||||
me->SendMeleeAttackStart(victim);
|
me->SendMeleeAttackStart(victim);
|
||||||
}
|
}
|
||||||
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == IDLE_MOTION_TYPE)
|
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == IDLE_MOTION_TYPE)
|
||||||
me->GetMotionMaster()->MoveChase(victim, AttackDistance, AttackAngle); // Targeted movement generator will start melee automatically, no need to send it explicitly
|
me->GetMotionMaster()->MoveChase(victim, m_AttackDistance, m_AttackAngle); // Targeted movement generator will start melee automatically, no need to send it explicitly
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -605,23 +605,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, me->GetEntry());
|
sLog.outErrorDb("CreatureEventAI: Event %d decrease m_Phase under 0. CreatureEntry = %d", EventId, me->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, me->GetEntry());
|
sLog.outErrorDb("CreatureEventAI: Event %d incremented m_Phase above %u. m_Phase mask cannot be used with phases past %u. CreatureEntry = %d", EventId, MAX_PHASE-1, MAX_PHASE-1, me->GetEntry());
|
||||||
Phase = MAX_PHASE-1;
|
m_Phase = MAX_PHASE-1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Phase = new_phase;
|
m_Phase = new_phase;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -653,20 +653,20 @@ 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;
|
m_AttackAngle = action.ranged_movement.angle/180.0f*M_PI;
|
||||||
|
|
||||||
if (CombatMovementEnabled)
|
if (m_CombatMovementEnabled)
|
||||||
{
|
{
|
||||||
me->GetMotionMaster()->MoveChase(me->getVictim(), AttackDistance, AttackAngle);
|
me->GetMotionMaster()->MoveChase(me->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.phaseMin <= action.random_phase_range.phaseMax)
|
if (action.random_phase_range.phaseMin <= action.random_phase_range.phaseMax)
|
||||||
Phase = urand(action.random_phase_range.phaseMin, action.random_phase_range.phaseMax);
|
m_Phase = urand(action.random_phase_range.phaseMin, action.random_phase_range.phaseMax);
|
||||||
else
|
else
|
||||||
sLog.outErrorDb("CreatureEventAI: ACTION_T_RANDOM_PHASE_RANGE cannot have Param2 < Param1. Event = %d. CreatureEntry = %d", EventId, me->GetEntry());
|
sLog.outErrorDb("CreatureEventAI: ACTION_T_RANDOM_PHASE_RANGE cannot have Param2 < Param1. Event = %d. CreatureEntry = %d", EventId, me->GetEntry());
|
||||||
break;
|
break;
|
||||||
@@ -821,9 +821,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 = me->GetMaxHealth()*action.invincibility_hp_level.hp_level/100;
|
m_InvinceabilityHpLevel = me->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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -833,25 +833,25 @@ void CreatureEventAI::JustRespawned()
|
|||||||
{
|
{
|
||||||
Reset();
|
Reset();
|
||||||
|
|
||||||
if (bEmptyList)
|
if (m_bEmptyList)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Handle Spawned Events
|
//Handle Spawned Events
|
||||||
for (std::list<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;
|
||||||
|
|
||||||
|
|
||||||
for (std::list<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_RESET)
|
if ((*i).Event.event_type == EVENT_T_RESET)
|
||||||
ProcessEvent(*i);
|
ProcessEvent(*i);
|
||||||
@@ -859,7 +859,7 @@ void CreatureEventAI::Reset()
|
|||||||
|
|
||||||
|
|
||||||
//Reset all events to enabled
|
//Reset all events to enabled
|
||||||
for (std::list<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)
|
||||||
@@ -884,9 +884,9 @@ void CreatureEventAI::JustReachedHome()
|
|||||||
{
|
{
|
||||||
me->LoadCreaturesAddon();
|
me->LoadCreaturesAddon();
|
||||||
|
|
||||||
if (!bEmptyList)
|
if (!m_bEmptyList)
|
||||||
{
|
{
|
||||||
for (std::list<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);
|
||||||
@@ -900,11 +900,11 @@ void CreatureEventAI::EnterEvadeMode()
|
|||||||
{
|
{
|
||||||
CreatureAI::EnterEvadeMode();
|
CreatureAI::EnterEvadeMode();
|
||||||
|
|
||||||
if (bEmptyList)
|
if (m_bEmptyList)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Handle Evade events
|
//Handle Evade events
|
||||||
for (std::list<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);
|
||||||
@@ -915,26 +915,26 @@ void CreatureEventAI::JustDied(Unit* killer)
|
|||||||
{
|
{
|
||||||
Reset();
|
Reset();
|
||||||
|
|
||||||
if (bEmptyList)
|
if (m_bEmptyList)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Handle Evade events
|
//Handle Evade events
|
||||||
for (std::list<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::list<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);
|
||||||
@@ -943,10 +943,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::list<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);
|
||||||
@@ -956,9 +956,9 @@ void CreatureEventAI::JustSummoned(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::list<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)
|
||||||
@@ -981,8 +981,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)
|
||||||
@@ -990,11 +990,11 @@ void CreatureEventAI::AttackStart(Unit *who)
|
|||||||
if (!who)
|
if (!who)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (me->Attack(who, MeleeEnabled))
|
if (me->Attack(who, m_MeleeEnabled))
|
||||||
{
|
{
|
||||||
if (CombatMovementEnabled)
|
if (m_CombatMovementEnabled)
|
||||||
{
|
{
|
||||||
me->GetMotionMaster()->MoveChase(who, AttackDistance, AttackAngle);
|
me->GetMotionMaster()->MoveChase(who, m_AttackDistance, m_AttackAngle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1009,9 +1009,9 @@ void CreatureEventAI::MoveInLineOfSight(Unit *who)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
//Check for OOC LOS Event
|
//Check for OOC LOS Event
|
||||||
if (!bEmptyList)
|
if (!m_bEmptyList)
|
||||||
{
|
{
|
||||||
for (std::list<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)
|
||||||
{
|
{
|
||||||
@@ -1036,10 +1036,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::list<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)
|
||||||
@@ -1052,24 +1052,24 @@ void CreatureEventAI::UpdateAI(const uint32 diff)
|
|||||||
//Check if we are in combat (also updates calls threat update code)
|
//Check if we are in combat (also updates calls threat update code)
|
||||||
bool Combat = UpdateVictim();
|
bool Combat = UpdateVictim();
|
||||||
|
|
||||||
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::list<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 (EventDiff <= (*i).Time)
|
if (m_EventDiff <= (*i).Time)
|
||||||
{
|
{
|
||||||
//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;
|
||||||
@@ -1101,18 +1101,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1321,10 +1321,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::list<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)
|
||||||
{
|
{
|
||||||
@@ -1347,12 +1347,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 && me->GetHealth() < InvinceabilityHpLevel+damage)
|
if (m_InvinceabilityHpLevel > 0 && me->GetHealth() < m_InvinceabilityHpLevel+damage)
|
||||||
{
|
{
|
||||||
if (me->GetHealth() <= InvinceabilityHpLevel)
|
if (me->GetHealth() <= m_InvinceabilityHpLevel)
|
||||||
damage = 0;
|
damage = 0;
|
||||||
else
|
else
|
||||||
damage = me->GetHealth() - InvinceabilityHpLevel;
|
damage = me->GetHealth() - m_InvinceabilityHpLevel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -587,7 +587,7 @@ class 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();
|
||||||
@@ -620,18 +620,19 @@ class 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::list<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
|
typedef std::vector<CreatureEventAIHolder> CreatureEventAIList;
|
||||||
uint8 Phase; // Current phase, max 32 phases
|
CreatureEventAIList m_CreatureEventAIList; // Holder for events (stores enabled, time, and eventid)
|
||||||
bool CombatMovementEnabled; // If we allow targeted movment gen (movement twoards top threat)
|
// Variables used by Events themselves
|
||||||
bool MeleeEnabled; // If we allow melee auto attack
|
uint8 m_Phase; // Current phase, max 32 phases
|
||||||
float AttackDistance; // Distance to attack from
|
bool m_CombatMovementEnabled; // If we allow targeted movment gen (movement twoards top threat)
|
||||||
float AttackAngle; // Angle of attack
|
bool m_MeleeEnabled; // If we allow melee auto attack
|
||||||
uint32 InvinceabilityHpLevel; // Minimal health level allowed at damage apply
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user