mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 13:37:05 +00:00
[c12562] Cleanup Style
This commit is contained in:
parent
d988eb4038
commit
bf5c6b1ddd
19 changed files with 3432 additions and 1071 deletions
|
|
@ -39,7 +39,7 @@ bool CreatureEventAIHolder::UpdateRepeatTimer(Creature* creature, uint32 repeatM
|
|||
Time = urand(repeatMin, repeatMax);
|
||||
else
|
||||
{
|
||||
sLog.outErrorDb("CreatureEventAI: Creature %u using Event %u (Type = %u) has RandomMax < RandomMin. Event repeating disabled.", creature->GetEntry(), Event.event_id, Event.event_type);
|
||||
sLog.outErrorEventAI("Creature %u using Event %u (Type = %u) has RandomMax < RandomMin. Event repeating disabled.", creature->GetEntry(), Event.event_id, Event.event_type);
|
||||
Enabled = false;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -57,10 +57,17 @@ int CreatureEventAI::Permissible(const Creature* creature)
|
|||
void CreatureEventAI::GetAIInformation(ChatHandler& reader)
|
||||
{
|
||||
reader.PSendSysMessage(LANG_NPC_EVENTAI_PHASE, (uint32)m_Phase);
|
||||
reader.PSendSysMessage(LANG_NPC_EVENTAI_MOVE, reader.GetOnOffStr(m_CombatMovementEnabled));
|
||||
reader.PSendSysMessage(LANG_NPC_EVENTAI_MOVE, reader.GetOnOffStr(m_isCombatMovement));
|
||||
reader.PSendSysMessage(LANG_NPC_EVENTAI_COMBAT, reader.GetOnOffStr(m_MeleeEnabled));
|
||||
}
|
||||
|
||||
// For Non Dungeon map only allow non-difficulty flags or EFLAG_DIFFICULTY_0 mode
|
||||
inline bool IsEventFlagsFitForNormalMap(uint8 eFlags)
|
||||
{
|
||||
return !(eFlags & (EFLAG_DIFFICULTY_0 | EFLAG_DIFFICULTY_1 | EFLAG_DIFFICULTY_2 | EFLAG_DIFFICULTY_3)) ||
|
||||
(eFlags & EFLAG_DIFFICULTY_0);
|
||||
}
|
||||
|
||||
CreatureEventAI::CreatureEventAI(Creature* c) : CreatureAI(c)
|
||||
{
|
||||
// Need make copy for filter unneeded steps and safe in case table reload
|
||||
|
|
@ -68,21 +75,21 @@ CreatureEventAI::CreatureEventAI(Creature* c) : CreatureAI(c)
|
|||
if (creatureEventsItr != sEventAIMgr.GetCreatureEventAIMap().end())
|
||||
{
|
||||
uint32 events_count = 0;
|
||||
for (CreatureEventAI_Event_Vec::const_iterator i = (*creatureEventsItr).second.begin(); i != (*creatureEventsItr).second.end(); ++i)
|
||||
for (CreatureEventAI_Event_Vec::const_iterator i = creatureEventsItr->second.begin(); i != creatureEventsItr->second.end(); ++i)
|
||||
{
|
||||
// Debug check
|
||||
#ifndef MANGOS_DEBUG
|
||||
if ((*i).event_flags & EFLAG_DEBUG_ONLY)
|
||||
if (i->event_flags & EFLAG_DEBUG_ONLY)
|
||||
continue;
|
||||
#endif
|
||||
if (m_creature->GetMap()->IsDungeon())
|
||||
{
|
||||
if ((1 << (m_creature->GetMap()->GetSpawnMode() + 1)) & (*i).event_flags)
|
||||
if ((1 << (m_creature->GetMap()->GetSpawnMode() + 1)) & i->event_flags)
|
||||
{
|
||||
++events_count;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (IsEventFlagsFitForNormalMap(i->event_flags))
|
||||
++events_count;
|
||||
}
|
||||
// EventMap had events but they were not added because they must be for instance
|
||||
|
|
@ -91,47 +98,65 @@ CreatureEventAI::CreatureEventAI(Creature* c) : CreatureAI(c)
|
|||
else
|
||||
{
|
||||
m_CreatureEventAIList.reserve(events_count);
|
||||
for (CreatureEventAI_Event_Vec::const_iterator i = (*creatureEventsItr).second.begin(); i != (*creatureEventsItr).second.end(); ++i)
|
||||
for (CreatureEventAI_Event_Vec::const_iterator i = creatureEventsItr->second.begin(); i != creatureEventsItr->second.end(); ++i)
|
||||
{
|
||||
|
||||
// Debug check
|
||||
#ifndef MANGOS_DEBUG
|
||||
if ((*i).event_flags & EFLAG_DEBUG_ONLY)
|
||||
if (i->event_flags & EFLAG_DEBUG_ONLY)
|
||||
continue;
|
||||
#endif
|
||||
if (m_creature->GetMap()->IsDungeon())
|
||||
{
|
||||
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
|
||||
m_CreatureEventAIList.push_back(CreatureEventAIHolder(*i));
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (IsEventFlagsFitForNormalMap(i->event_flags))
|
||||
m_CreatureEventAIList.push_back(CreatureEventAIHolder(*i));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
sLog.outError("CreatureEventAI: EventMap for Creature %u is empty but creature is using CreatureEventAI.", m_creature->GetEntry());
|
||||
sLog.outErrorEventAI("EventMap for Creature %u is empty but creature is using CreatureEventAI.", m_creature->GetEntry());
|
||||
|
||||
m_bEmptyList = m_CreatureEventAIList.empty();
|
||||
m_Phase = 0;
|
||||
m_CombatMovementEnabled = true;
|
||||
m_MeleeEnabled = true;
|
||||
m_AttackDistance = 0.0f;
|
||||
m_AttackAngle = 0.0f;
|
||||
|
||||
m_InvinceabilityHpLevel = 0;
|
||||
|
||||
// Handle Spawned Events
|
||||
if (!m_bEmptyList)
|
||||
// Handle Spawned Events, also calls Reset()
|
||||
JustRespawned();
|
||||
}
|
||||
|
||||
#define LOG_PROCESS_EVENT \
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_EVENT_AI_DEV, "CreatureEventAI: Event type %u (script %u) triggered for %s (invoked by %s)", \
|
||||
pHolder.Event.event_type, pHolder.Event.event_id, m_creature->GetGuidStr().c_str(), pActionInvoker ? pActionInvoker->GetGuidStr().c_str() : "<no invoker>")
|
||||
|
||||
inline bool IsTimerBasedEvent(EventAI_Type type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
|
||||
if (SpawnedEventConditionsCheck((*i).Event))
|
||||
ProcessEvent(*i);
|
||||
case EVENT_T_TIMER_IN_COMBAT:
|
||||
case EVENT_T_TIMER_OOC:
|
||||
case EVENT_T_TIMER_GENERIC:
|
||||
case EVENT_T_MANA:
|
||||
case EVENT_T_HP:
|
||||
case EVENT_T_TARGET_HP:
|
||||
case EVENT_T_TARGET_CASTING:
|
||||
case EVENT_T_FRIENDLY_HP:
|
||||
case EVENT_T_AURA:
|
||||
case EVENT_T_TARGET_AURA:
|
||||
case EVENT_T_MISSING_AURA:
|
||||
case EVENT_T_TARGET_MISSING_AURA:
|
||||
case EVENT_T_RANGE:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
Reset();
|
||||
}
|
||||
|
||||
bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pActionInvoker)
|
||||
|
|
@ -141,17 +166,25 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
|
|||
|
||||
// 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 << m_Phase))
|
||||
{
|
||||
if (!IsTimerBasedEvent(pHolder.Event.event_type))
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_EVENT_AI_DEV, "CreatureEventAI: Event %u skipped because of phasemask %u. Current phase %u", pHolder.Event.event_id, pHolder.Event.event_inverse_phase_mask, m_Phase);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsTimerBasedEvent(pHolder.Event.event_type))
|
||||
LOG_PROCESS_EVENT;
|
||||
|
||||
CreatureEventAI_Event const& event = pHolder.Event;
|
||||
|
||||
// Check event conditions based on the event type, also reset events
|
||||
switch (event.event_type)
|
||||
{
|
||||
case EVENT_T_TIMER:
|
||||
case EVENT_T_TIMER_IN_COMBAT:
|
||||
if (!m_creature->isInCombat())
|
||||
return false;
|
||||
|
||||
LOG_PROCESS_EVENT;
|
||||
// Repeat Timers
|
||||
pHolder.UpdateRepeatTimer(m_creature, event.timer.repeatMin, event.timer.repeatMax);
|
||||
break;
|
||||
|
|
@ -159,6 +192,12 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
|
|||
if (m_creature->isInCombat() || m_creature->IsInEvadeMode())
|
||||
return false;
|
||||
|
||||
LOG_PROCESS_EVENT;
|
||||
// Repeat Timers
|
||||
pHolder.UpdateRepeatTimer(m_creature, event.timer.repeatMin, event.timer.repeatMax);
|
||||
break;
|
||||
case EVENT_T_TIMER_GENERIC:
|
||||
LOG_PROCESS_EVENT;
|
||||
// Repeat Timers
|
||||
pHolder.UpdateRepeatTimer(m_creature, event.timer.repeatMin, event.timer.repeatMax);
|
||||
break;
|
||||
|
|
@ -172,6 +211,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
|
|||
if (perc > event.percent_range.percentMax || perc < event.percent_range.percentMin)
|
||||
return false;
|
||||
|
||||
LOG_PROCESS_EVENT;
|
||||
// Repeat Timers
|
||||
pHolder.UpdateRepeatTimer(m_creature, event.percent_range.repeatMin, event.percent_range.repeatMax);
|
||||
break;
|
||||
|
|
@ -186,6 +226,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
|
|||
if (perc > event.percent_range.percentMax || perc < event.percent_range.percentMin)
|
||||
return false;
|
||||
|
||||
LOG_PROCESS_EVENT;
|
||||
// Repeat Timers
|
||||
pHolder.UpdateRepeatTimer(m_creature, event.percent_range.repeatMin, event.percent_range.repeatMax);
|
||||
break;
|
||||
|
|
@ -225,6 +266,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
|
|||
if (perc > event.percent_range.percentMax || perc < event.percent_range.percentMin)
|
||||
return false;
|
||||
|
||||
LOG_PROCESS_EVENT;
|
||||
// Repeat Timers
|
||||
pHolder.UpdateRepeatTimer(m_creature, event.percent_range.repeatMin, event.percent_range.repeatMax);
|
||||
break;
|
||||
|
|
@ -233,6 +275,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
|
|||
if (!m_creature->isInCombat() || !m_creature->getVictim() || !m_creature->getVictim()->IsNonMeleeSpellCasted(false, false, true))
|
||||
return false;
|
||||
|
||||
LOG_PROCESS_EVENT;
|
||||
// Repeat Timers
|
||||
pHolder.UpdateRepeatTimer(m_creature, event.target_casting.repeatMin, event.target_casting.repeatMax);
|
||||
break;
|
||||
|
|
@ -247,6 +290,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
|
|||
|
||||
pActionInvoker = pUnit;
|
||||
|
||||
LOG_PROCESS_EVENT;
|
||||
// Repeat Timers
|
||||
pHolder.UpdateRepeatTimer(m_creature, event.friendly_hp.repeatMin, event.friendly_hp.repeatMax);
|
||||
break;
|
||||
|
|
@ -325,6 +369,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
|
|||
if (!holder || holder->GetStackAmount() < event.buffed.amount)
|
||||
return false;
|
||||
|
||||
LOG_PROCESS_EVENT;
|
||||
// Repeat Timers
|
||||
pHolder.UpdateRepeatTimer(m_creature, event.buffed.repeatMin, event.buffed.repeatMax);
|
||||
break;
|
||||
|
|
@ -338,6 +383,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
|
|||
if (!holder || holder->GetStackAmount() < event.buffed.amount)
|
||||
return false;
|
||||
|
||||
LOG_PROCESS_EVENT;
|
||||
// Repeat Timers
|
||||
pHolder.UpdateRepeatTimer(m_creature, event.buffed.repeatMin, event.buffed.repeatMax);
|
||||
break;
|
||||
|
|
@ -348,6 +394,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
|
|||
if (holder && holder->GetStackAmount() >= event.buffed.amount)
|
||||
return false;
|
||||
|
||||
LOG_PROCESS_EVENT;
|
||||
// Repeat Timers
|
||||
pHolder.UpdateRepeatTimer(m_creature, event.buffed.repeatMin, event.buffed.repeatMax);
|
||||
break;
|
||||
|
|
@ -361,12 +408,13 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
|
|||
if (holder && holder->GetStackAmount() >= event.buffed.amount)
|
||||
return false;
|
||||
|
||||
LOG_PROCESS_EVENT;
|
||||
// Repeat Timers
|
||||
pHolder.UpdateRepeatTimer(m_creature, event.buffed.repeatMin, event.buffed.repeatMax);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sLog.outErrorDb("CreatureEventAI: Creature %u using Event %u has invalid Event Type(%u), missing from ProcessEvent() Switch.", m_creature->GetEntry(), pHolder.Event.event_id, pHolder.Event.event_type);
|
||||
sLog.outErrorEventAI("Creature %u using Event %u has invalid Event Type(%u), missing from ProcessEvent() Switch.", m_creature->GetEntry(), pHolder.Event.event_id, pHolder.Event.event_type);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -421,6 +469,12 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
|
|||
|
||||
void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 rnd, uint32 EventId, Unit* pActionInvoker)
|
||||
{
|
||||
if (action.type == ACTION_T_NONE)
|
||||
return;
|
||||
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_EVENT_AI_DEV, "CreatureEventAI: Process action %u (script %u) triggered for %s (invoked by %s)",
|
||||
action.type, EventId, m_creature->GetGuidStr().c_str(), pActionInvoker ? pActionInvoker->GetGuidStr().c_str() : "<no invoker>");
|
||||
|
||||
switch (action.type)
|
||||
{
|
||||
case ACTION_T_TEXT:
|
||||
|
|
@ -527,8 +581,15 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
}
|
||||
case ACTION_T_CAST:
|
||||
{
|
||||
Unit* target = GetTargetByType(action.cast.target, pActionInvoker);
|
||||
uint32 selectFlags = 0;
|
||||
uint32 spellId = 0;
|
||||
if (!(action.cast.castFlags & (CAST_TRIGGERED | CAST_FORCE_CAST | CAST_FORCE_TARGET_SELF)))
|
||||
{
|
||||
spellId = action.cast.spellId;
|
||||
selectFlags = SELECT_FLAG_IN_LOS;
|
||||
}
|
||||
|
||||
Unit* target = GetTargetByType(action.cast.target, pActionInvoker, spellId, selectFlags);
|
||||
if (!target)
|
||||
{
|
||||
sLog.outDebug("CreatureEventAI: NULL target for ACTION_T_CAST creature entry %u casting spell id %u", m_creature->GetEntry(), action.cast.spellId);
|
||||
|
|
@ -549,11 +610,11 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
{
|
||||
case CHASE_MOTION_TYPE:
|
||||
case FOLLOW_MOTION_TYPE:
|
||||
m_AttackDistance = 0.0f;
|
||||
m_AttackAngle = 0.0f;
|
||||
m_attackDistance = 0.0f;
|
||||
m_attackAngle = 0.0f;
|
||||
|
||||
m_creature->GetMotionMaster()->Clear(false);
|
||||
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_AttackDistance, m_AttackAngle);
|
||||
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_attackDistance, m_attackAngle);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -574,12 +635,12 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
Creature* pCreature = NULL;
|
||||
|
||||
if (action.summon.duration)
|
||||
pCreature = m_creature->SummonCreature(action.summon.creatureId, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, action.summon.duration);
|
||||
pCreature = m_creature->SummonCreature(action.summon.creatureId, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OOC_OR_DEAD_DESPAWN, action.summon.duration);
|
||||
else
|
||||
pCreature = m_creature->SummonCreature(action.summon.creatureId, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 0);
|
||||
pCreature = m_creature->SummonCreature(action.summon.creatureId, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OOC_DESPAWN, 0);
|
||||
|
||||
if (!pCreature)
|
||||
sLog.outErrorDb("CreatureEventAI: failed to spawn creature %u. Spawn event %d is on creature %d", action.summon.creatureId, EventId, m_creature->GetEntry());
|
||||
sLog.outErrorEventAI("failed to spawn creature %u. Spawn event %d is on creature %d", action.summon.creatureId, EventId, m_creature->GetEntry());
|
||||
else if (action.summon.target != TARGET_T_SELF && target)
|
||||
pCreature->AI()->AttackStart(target);
|
||||
break;
|
||||
|
|
@ -602,7 +663,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
((Player*)target)->AreaExploredOrEventHappens(action.quest_event.questId);
|
||||
break;
|
||||
case ACTION_T_CAST_EVENT:
|
||||
if (Unit* target = GetTargetByType(action.cast_event.target, pActionInvoker))
|
||||
if (Unit* target = GetTargetByType(action.cast_event.target, pActionInvoker, 0, SELECT_FLAG_PLAYER))
|
||||
if (target->GetTypeId() == TYPEID_PLAYER)
|
||||
((Player*)target)->CastedCreatureOrGO(action.cast_event.creatureId, m_creature->GetObjectGuid(), action.cast_event.spellId);
|
||||
break;
|
||||
|
|
@ -632,57 +693,37 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
break;
|
||||
case ACTION_T_COMBAT_MOVEMENT:
|
||||
// ignore no affect case
|
||||
if (m_CombatMovementEnabled == (action.combat_movement.state != 0))
|
||||
if (m_isCombatMovement == (action.combat_movement.state != 0))
|
||||
return;
|
||||
|
||||
m_CombatMovementEnabled = action.combat_movement.state != 0;
|
||||
SetCombatMovement(action.combat_movement.state != 0, true);
|
||||
|
||||
// Allow movement (create new targeted movement gen only if idle)
|
||||
if (m_CombatMovementEnabled)
|
||||
{
|
||||
if (action.combat_movement.melee && m_creature->isInCombat())
|
||||
if (Unit* victim = m_creature->getVictim())
|
||||
m_creature->SendMeleeAttackStart(victim);
|
||||
|
||||
if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == IDLE_MOTION_TYPE)
|
||||
{
|
||||
m_creature->GetMotionMaster()->Clear(false);
|
||||
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_AttackDistance, m_AttackAngle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (action.combat_movement.melee && m_creature->isInCombat())
|
||||
if (Unit* victim = m_creature->getVictim())
|
||||
m_creature->SendMeleeAttackStop(victim);
|
||||
|
||||
if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE)
|
||||
{
|
||||
m_creature->GetMotionMaster()->Clear(false);
|
||||
m_creature->GetMotionMaster()->MoveIdle();
|
||||
m_creature->StopMoving();
|
||||
}
|
||||
}
|
||||
if (m_isCombatMovement && action.combat_movement.melee && m_creature->isInCombat() && m_creature->getVictim())
|
||||
m_creature->SendMeleeAttackStart(m_creature->getVictim());
|
||||
else if (action.combat_movement.melee && m_creature->isInCombat() && m_creature->getVictim())
|
||||
m_creature->SendMeleeAttackStop(m_creature->getVictim());
|
||||
break;
|
||||
case ACTION_T_SET_PHASE:
|
||||
m_Phase = action.set_phase.phase;
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_EVENT_AI_DEV, "CreatureEventAI: ACTION_T_SET_PHASE - script %u for %s, phase is now %u", EventId, m_creature->GetGuidStr().c_str(), m_Phase);
|
||||
break;
|
||||
case ACTION_T_INC_PHASE:
|
||||
{
|
||||
int32 new_phase = int32(m_Phase) + action.set_inc_phase.step;
|
||||
if (new_phase < 0)
|
||||
{
|
||||
sLog.outErrorDb("CreatureEventAI: Event %d decrease Phase under 0. CreatureEntry = %d", EventId, m_creature->GetEntry());
|
||||
sLog.outErrorEventAI("Event %d decrease Phase under 0. CreatureEntry = %d", EventId, m_creature->GetEntry());
|
||||
m_Phase = 0;
|
||||
}
|
||||
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.outErrorEventAI("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());
|
||||
m_Phase = MAX_PHASE - 1;
|
||||
}
|
||||
else
|
||||
m_Phase = new_phase;
|
||||
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_EVENT_AI_DEV, "CreatureEventAI: ACTION_T_INC_PHASE - script %u for %s, phase is now %u", EventId, m_creature->GetGuidStr().c_str(), m_Phase);
|
||||
break;
|
||||
}
|
||||
case ACTION_T_EVADE:
|
||||
|
|
@ -708,27 +749,28 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
target->RemoveAurasDueToSpell(action.remove_aura.spellId);
|
||||
break;
|
||||
case ACTION_T_RANGED_MOVEMENT:
|
||||
m_AttackDistance = (float)action.ranged_movement.distance;
|
||||
m_AttackAngle = action.ranged_movement.angle / 180.0f * M_PI_F;
|
||||
m_attackDistance = (float)action.ranged_movement.distance;
|
||||
m_attackAngle = action.ranged_movement.angle / 180.0f * M_PI_F;
|
||||
|
||||
if (m_CombatMovementEnabled)
|
||||
if (m_isCombatMovement)
|
||||
{
|
||||
if (m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE)
|
||||
{
|
||||
// Drop current movement gen
|
||||
m_creature->GetMotionMaster()->Clear(false);
|
||||
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_AttackDistance, m_AttackAngle);
|
||||
m_creature->GetMotionMaster()->MoveChase(m_creature->getVictim(), m_attackDistance, m_attackAngle);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ACTION_T_RANDOM_PHASE:
|
||||
m_Phase = GetRandActionParam(rnd, action.random_phase.phase1, action.random_phase.phase2, action.random_phase.phase3);
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_EVENT_AI_DEV, "CreatureEventAI: ACTION_T_RANDOM_PHASE - script %u for %s, phase is now %u", EventId, m_creature->GetGuidStr().c_str(), m_Phase);
|
||||
break;
|
||||
case ACTION_T_RANDOM_PHASE_RANGE:
|
||||
if (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
|
||||
sLog.outErrorDb("CreatureEventAI: ACTION_T_RANDOM_PHASE_RANGE cannot have Param2 <= Param1. Divide by Zero. Event = %d. CreatureEntry = %d", EventId, m_creature->GetEntry());
|
||||
sLog.outErrorEventAI("ACTION_T_RANDOM_PHASE_RANGE cannot have Param2 <= Param1. Divide by Zero. Event = %d. CreatureEntry = %d", EventId, m_creature->GetEntry());
|
||||
break;
|
||||
case ACTION_T_SUMMON_ID:
|
||||
{
|
||||
|
|
@ -737,18 +779,18 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
CreatureEventAI_Summon_Map::const_iterator i = sEventAIMgr.GetCreatureEventAISummonMap().find(action.summon_id.spawnId);
|
||||
if (i == sEventAIMgr.GetCreatureEventAISummonMap().end())
|
||||
{
|
||||
sLog.outErrorDb("CreatureEventAI: failed to spawn creature %u. Summon map index %u does not exist. EventID %d. CreatureID %d", action.summon_id.creatureId, action.summon_id.spawnId, EventId, m_creature->GetEntry());
|
||||
sLog.outErrorEventAI("failed to spawn creature %u. Summon map index %u does not exist. EventID %d. CreatureID %d", action.summon_id.creatureId, action.summon_id.spawnId, EventId, m_creature->GetEntry());
|
||||
return;
|
||||
}
|
||||
|
||||
Creature* pCreature = NULL;
|
||||
if ((*i).second.SpawnTimeSecs)
|
||||
pCreature = m_creature->SummonCreature(action.summon_id.creatureId, (*i).second.position_x, (*i).second.position_y, (*i).second.position_z, (*i).second.orientation, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, (*i).second.SpawnTimeSecs);
|
||||
pCreature = m_creature->SummonCreature(action.summon_id.creatureId, (*i).second.position_x, (*i).second.position_y, (*i).second.position_z, (*i).second.orientation, TEMPSUMMON_TIMED_OOC_OR_DEAD_DESPAWN, (*i).second.SpawnTimeSecs);
|
||||
else
|
||||
pCreature = m_creature->SummonCreature(action.summon_id.creatureId, (*i).second.position_x, (*i).second.position_y, (*i).second.position_z, (*i).second.orientation, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 0);
|
||||
pCreature = m_creature->SummonCreature(action.summon_id.creatureId, (*i).second.position_x, (*i).second.position_y, (*i).second.position_z, (*i).second.orientation, TEMPSUMMON_TIMED_OOC_DESPAWN, 0);
|
||||
|
||||
if (!pCreature)
|
||||
sLog.outErrorDb("CreatureEventAI: failed to spawn creature %u. EventId %d.Creature %d", action.summon_id.creatureId, EventId, m_creature->GetEntry());
|
||||
sLog.outErrorEventAI("failed to spawn creature %u. EventId %d.Creature %d", action.summon_id.creatureId, EventId, m_creature->GetEntry());
|
||||
else if (action.summon_id.target != TARGET_T_SELF && target)
|
||||
pCreature->AI()->AttackStart(target);
|
||||
|
||||
|
|
@ -761,7 +803,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
else
|
||||
{
|
||||
// if not available, use pActionInvoker
|
||||
if (Unit* pTarget = GetTargetByType(action.killed_monster.target, pActionInvoker))
|
||||
if (Unit* pTarget = GetTargetByType(action.killed_monster.target, pActionInvoker, 0, SELECT_FLAG_PLAYER))
|
||||
if (Player* pPlayer2 = pTarget->GetCharmerOrOwnerPlayerOrPlayerItself())
|
||||
pPlayer2->RewardPlayerAndGroupAtEvent(action.killed_monster.creatureId, m_creature);
|
||||
}
|
||||
|
|
@ -771,7 +813,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
InstanceData* pInst = m_creature->GetInstanceData();
|
||||
if (!pInst)
|
||||
{
|
||||
sLog.outErrorDb("CreatureEventAI: Event %d attempt to set instance data without instance script. Creature %d", EventId, m_creature->GetEntry());
|
||||
sLog.outErrorEventAI("Event %d attempt to set instance data without instance script. Creature %d", EventId, m_creature->GetEntry());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -783,14 +825,14 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
Unit* target = GetTargetByType(action.set_inst_data64.target, pActionInvoker);
|
||||
if (!target)
|
||||
{
|
||||
sLog.outErrorDb("CreatureEventAI: Event %d attempt to set instance data64 but Target == NULL. Creature %d", EventId, m_creature->GetEntry());
|
||||
sLog.outErrorEventAI("Event %d attempt to set instance data64 but Target == NULL. Creature %d", EventId, m_creature->GetEntry());
|
||||
return;
|
||||
}
|
||||
|
||||
InstanceData* pInst = m_creature->GetInstanceData();
|
||||
if (!pInst)
|
||||
{
|
||||
sLog.outErrorDb("CreatureEventAI: Event %d attempt to set instance data64 without instance script. Creature %d", EventId, m_creature->GetEntry());
|
||||
sLog.outErrorEventAI("Event %d attempt to set instance data64 without instance script. Creature %d", EventId, m_creature->GetEntry());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -801,7 +843,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
if (m_creature->GetEntry() == action.update_template.creatureId)
|
||||
{
|
||||
|
||||
sLog.outErrorDb("CreatureEventAI: Event %d ACTION_T_UPDATE_TEMPLATE call with param1 == current entry. Creature %d", EventId, m_creature->GetEntry());
|
||||
sLog.outErrorEventAI("Event %d ACTION_T_UPDATE_TEMPLATE call with param1 == current entry. Creature %d", EventId, m_creature->GetEntry());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -811,7 +853,7 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
if (m_creature->isDead())
|
||||
{
|
||||
|
||||
sLog.outErrorDb("CreatureEventAI: Event %d ACTION_T_DIE on dead creature. Creature %d", EventId, m_creature->GetEntry());
|
||||
sLog.outErrorEventAI("Event %d ACTION_T_DIE on dead creature. Creature %d", EventId, m_creature->GetEntry());
|
||||
return;
|
||||
}
|
||||
m_creature->DealDamage(m_creature, m_creature->GetMaxHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
|
||||
|
|
@ -869,17 +911,25 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
|
|||
}
|
||||
}
|
||||
|
||||
void CreatureEventAI::JustRespawned()
|
||||
void CreatureEventAI::JustRespawned() // NOTE that this is called from the AI's constructor as well
|
||||
{
|
||||
Reset();
|
||||
|
||||
if (m_bEmptyList)
|
||||
return;
|
||||
|
||||
// Handle Spawned Events
|
||||
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
|
||||
if (SpawnedEventConditionsCheck((*i).Event))
|
||||
{
|
||||
// Reset generic timer
|
||||
if (i->Event.event_type == EVENT_T_TIMER_GENERIC)
|
||||
{
|
||||
if (i->UpdateRepeatTimer(m_creature, i->Event.timer.initialMin, i->Event.timer.initialMax))
|
||||
i->Enabled = true;
|
||||
}
|
||||
// Handle Spawned Events
|
||||
else if (SpawnedEventConditionsCheck((*i).Event))
|
||||
ProcessEvent(*i);
|
||||
}
|
||||
}
|
||||
|
||||
void CreatureEventAI::Reset()
|
||||
|
|
@ -928,7 +978,7 @@ void CreatureEventAI::JustReachedHome()
|
|||
|
||||
void CreatureEventAI::EnterEvadeMode()
|
||||
{
|
||||
m_creature->RemoveAllAuras();
|
||||
m_creature->RemoveAllAurasOnEvade();
|
||||
m_creature->DeleteThreatList();
|
||||
m_creature->CombatStop(true);
|
||||
|
||||
|
|
@ -1036,7 +1086,7 @@ void CreatureEventAI::EnterCombat(Unit* enemy)
|
|||
ProcessEvent(*i, enemy);
|
||||
break;
|
||||
// Reset all in combat timers
|
||||
case EVENT_T_TIMER:
|
||||
case EVENT_T_TIMER_IN_COMBAT:
|
||||
if ((*i).UpdateRepeatTimer(m_creature, event.timer.initialMin, event.timer.initialMax))
|
||||
(*i).Enabled = true;
|
||||
break;
|
||||
|
|
@ -1064,15 +1114,7 @@ void CreatureEventAI::AttackStart(Unit* who)
|
|||
m_creature->SetInCombatWith(who);
|
||||
who->SetInCombatWith(m_creature);
|
||||
|
||||
if (m_CombatMovementEnabled)
|
||||
{
|
||||
m_creature->GetMotionMaster()->MoveChase(who, m_AttackDistance, m_AttackAngle);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_creature->GetMotionMaster()->MoveIdle();
|
||||
m_creature->StopMoving();
|
||||
}
|
||||
HandleMovementOnAttackStart(who);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1177,9 +1219,10 @@ void CreatureEventAI::UpdateAI(const uint32 diff)
|
|||
switch ((*i).Event.event_type)
|
||||
{
|
||||
case EVENT_T_TIMER_OOC:
|
||||
case EVENT_T_TIMER_GENERIC:
|
||||
ProcessEvent(*i);
|
||||
break;
|
||||
case EVENT_T_TIMER:
|
||||
case EVENT_T_TIMER_IN_COMBAT:
|
||||
case EVENT_T_MANA:
|
||||
case EVENT_T_HP:
|
||||
case EVENT_T_TARGET_HP:
|
||||
|
|
@ -1246,7 +1289,7 @@ inline int32 CreatureEventAI::GetRandActionParam(uint32 rnd, int32 param1, int32
|
|||
return 0;
|
||||
}
|
||||
|
||||
inline Unit* CreatureEventAI::GetTargetByType(uint32 Target, Unit* pActionInvoker)
|
||||
inline Unit* CreatureEventAI::GetTargetByType(uint32 Target, Unit* pActionInvoker, uint32 forSpellId, uint32 selectFlags)
|
||||
{
|
||||
switch (Target)
|
||||
{
|
||||
|
|
@ -1255,15 +1298,21 @@ inline Unit* CreatureEventAI::GetTargetByType(uint32 Target, Unit* pActionInvoke
|
|||
case TARGET_T_HOSTILE:
|
||||
return m_creature->getVictim();
|
||||
case TARGET_T_HOSTILE_SECOND_AGGRO:
|
||||
return m_creature->SelectAttackingTarget(ATTACKING_TARGET_TOPAGGRO, 1);
|
||||
return m_creature->SelectAttackingTarget(ATTACKING_TARGET_TOPAGGRO, 1, forSpellId, selectFlags);
|
||||
case TARGET_T_HOSTILE_LAST_AGGRO:
|
||||
return m_creature->SelectAttackingTarget(ATTACKING_TARGET_BOTTOMAGGRO, 0);
|
||||
return m_creature->SelectAttackingTarget(ATTACKING_TARGET_BOTTOMAGGRO, 0, forSpellId, selectFlags);
|
||||
case TARGET_T_HOSTILE_RANDOM:
|
||||
return m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0);
|
||||
return m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0, forSpellId, selectFlags);
|
||||
case TARGET_T_HOSTILE_RANDOM_NOT_TOP:
|
||||
return m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 1);
|
||||
return m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 1, forSpellId, selectFlags);
|
||||
case TARGET_T_HOSTILE_RANDOM_PLAYER:
|
||||
return m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0, forSpellId, SELECT_FLAG_PLAYER | selectFlags);
|
||||
case TARGET_T_HOSTILE_RANDOM_NOT_TOP_PLAYER:
|
||||
return m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 1, forSpellId, SELECT_FLAG_PLAYER | selectFlags);
|
||||
case TARGET_T_ACTION_INVOKER:
|
||||
return pActionInvoker;
|
||||
case TARGET_T_ACTION_INVOKER_OWNER:
|
||||
return pActionInvoker ? pActionInvoker->GetCharmerOrOwnerOrSelf() : NULL;
|
||||
default:
|
||||
return NULL;
|
||||
};
|
||||
|
|
@ -1305,13 +1354,13 @@ void CreatureEventAI::DoScriptText(int32 textEntry, WorldObject* pSource, Unit*
|
|||
{
|
||||
if (!pSource)
|
||||
{
|
||||
sLog.outErrorDb("CreatureEventAI: DoScriptText entry %i, invalid Source pointer.", textEntry);
|
||||
sLog.outErrorEventAI("DoScriptText entry %i, invalid Source pointer.", textEntry);
|
||||
return;
|
||||
}
|
||||
|
||||
if (textEntry >= 0)
|
||||
{
|
||||
sLog.outErrorDb("CreatureEventAI: DoScriptText with source entry %u (TypeId=%u, guid=%u) attempts to process text entry %i, but text entry must be negative.", pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), textEntry);
|
||||
sLog.outErrorEventAI("DoScriptText with source entry %u (TypeId=%u, guid=%u) attempts to process text entry %i, but text entry must be negative.", pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), textEntry);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1319,7 +1368,7 @@ void CreatureEventAI::DoScriptText(int32 textEntry, WorldObject* pSource, Unit*
|
|||
|
||||
if (i == sEventAIMgr.GetCreatureEventAITextMap().end())
|
||||
{
|
||||
sLog.outErrorDb("CreatureEventAI: DoScriptText with source entry %u (TypeId=%u, guid=%u) could not find text entry %i.", pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), textEntry);
|
||||
sLog.outErrorEventAI("DoScriptText with source entry %u (TypeId=%u, guid=%u) could not find text entry %i.", pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), textEntry);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1330,7 +1379,7 @@ void CreatureEventAI::DoScriptText(int32 textEntry, WorldObject* pSource, Unit*
|
|||
if (GetSoundEntriesStore()->LookupEntry((*i).second.SoundId))
|
||||
pSource->PlayDirectSound((*i).second.SoundId);
|
||||
else
|
||||
sLog.outErrorDb("CreatureEventAI: DoScriptText entry %i tried to process invalid sound id %u.", textEntry, (*i).second.SoundId);
|
||||
sLog.outErrorEventAI("DoScriptText entry %i tried to process invalid sound id %u.", textEntry, (*i).second.SoundId);
|
||||
}
|
||||
|
||||
if ((*i).second.Emote)
|
||||
|
|
@ -1340,7 +1389,7 @@ void CreatureEventAI::DoScriptText(int32 textEntry, WorldObject* pSource, Unit*
|
|||
((Unit*)pSource)->HandleEmote((*i).second.Emote);
|
||||
}
|
||||
else
|
||||
sLog.outErrorDb("CreatureEventAI: DoScriptText entry %i tried to process emote for invalid TypeId (%u).", textEntry, pSource->GetTypeId());
|
||||
sLog.outErrorEventAI("DoScriptText entry %i tried to process emote for invalid TypeId (%u).", textEntry, pSource->GetTypeId());
|
||||
}
|
||||
|
||||
switch ((*i).second.Type)
|
||||
|
|
@ -1361,13 +1410,13 @@ void CreatureEventAI::DoScriptText(int32 textEntry, WorldObject* pSource, Unit*
|
|||
{
|
||||
if (target && target->GetTypeId() == TYPEID_PLAYER)
|
||||
pSource->MonsterWhisper(textEntry, target);
|
||||
else sLog.outErrorDb("CreatureEventAI: DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", textEntry);
|
||||
else sLog.outErrorEventAI("DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", textEntry);
|
||||
} break;
|
||||
case CHAT_TYPE_BOSS_WHISPER:
|
||||
{
|
||||
if (target && target->GetTypeId() == TYPEID_PLAYER)
|
||||
pSource->MonsterWhisper(textEntry, target, true);
|
||||
else sLog.outErrorDb("CreatureEventAI: DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", textEntry);
|
||||
else sLog.outErrorEventAI("DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", textEntry);
|
||||
} break;
|
||||
case CHAT_TYPE_ZONE_YELL:
|
||||
pSource->MonsterYellToZone(textEntry, (*i).second.Language, target);
|
||||
|
|
@ -1375,36 +1424,6 @@ void CreatureEventAI::DoScriptText(int32 textEntry, WorldObject* pSource, Unit*
|
|||
}
|
||||
}
|
||||
|
||||
bool CreatureEventAI::CanCast(Unit* Target, SpellEntry const* Spell, bool Triggered)
|
||||
{
|
||||
// No target so we can't cast
|
||||
if (!Target || !Spell)
|
||||
return false;
|
||||
|
||||
// Silenced so we can't cast
|
||||
if (!Triggered && (m_creature->hasUnitState(UNIT_STAT_CAN_NOT_REACT_OR_LOST_CONTROL) ||
|
||||
m_creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED)))
|
||||
return false;
|
||||
|
||||
// Check for power
|
||||
if (!Triggered && m_creature->GetPower((Powers)Spell->powerType) < Spell::CalculatePowerCost(Spell, m_creature))
|
||||
return false;
|
||||
|
||||
SpellRangeEntry const* TempRange = NULL;
|
||||
|
||||
TempRange = GetSpellRangeStore()->LookupEntry(Spell->rangeIndex);
|
||||
|
||||
// Spell has invalid range store so we can't use it
|
||||
if (!TempRange)
|
||||
return false;
|
||||
|
||||
// Unit is out of range of this spell
|
||||
if (!m_creature->IsInRange(Target, TempRange->minRange, TempRange->maxRange))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote)
|
||||
{
|
||||
if (m_bEmptyList)
|
||||
|
|
@ -1418,7 +1437,7 @@ void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote)
|
|||
return;
|
||||
|
||||
PlayerCondition pcon(0, (*itr).Event.receive_emote.condition, (*itr).Event.receive_emote.conditionValue1, (*itr).Event.receive_emote.conditionValue2);
|
||||
if (pcon.Meets(pPlayer))
|
||||
if (pcon.Meets(pPlayer, m_creature->GetMap(), m_creature, CONDITION_FROM_EVENTAI))
|
||||
{
|
||||
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "CreatureEventAI: ReceiveEmote CreatureEventAI: Condition ok, processing");
|
||||
ProcessEvent(*itr, pPlayer);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue