Many, many cmangos Cata commits applied

The following commits were either applied or found not to be applicable:
This commit is contained in:
Charles A Edwards 2016-08-27 18:42:03 +01:00 committed by Antz
parent 32a26f44c7
commit a800f3b1ad
100 changed files with 2385 additions and 1305 deletions

View file

@ -182,6 +182,7 @@ inline bool IsTimerBasedEvent(EventAI_Type type)
case EVENT_T_MISSING_AURA:
case EVENT_T_TARGET_MISSING_AURA:
case EVENT_T_RANGE:
case EVENT_T_ENERGY:
return true;
default:
return false;
@ -276,6 +277,13 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
pHolder.UpdateRepeatTimer(m_creature, event.spell_hit.repeatMin, event.spell_hit.repeatMax);
break;
case EVENT_T_RANGE:
if (!m_creature->IsInCombat() || !m_creature->getVictim() || !m_creature->IsInMap(m_creature->getVictim()))
return false;
// DISCUSS TODO - Likely replace IsInRange check with CombatReach checks (as used rather for such checks)
if (!m_creature->IsInRange(m_creature->getVictim(), (float)event.range.minDist, (float)event.range.maxDist))
return false;
// Repeat Timers
pHolder.UpdateRepeatTimer(m_creature, event.range.repeatMin, event.range.repeatMax);
break;
@ -394,6 +402,9 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
break;
case EVENT_T_AURA:
{
if (!m_creature->IsInCombat())
return false;
SpellAuraHolder* holder = m_creature->GetSpellAuraHolder(event.buffed.spellId);
if (!holder || holder->GetStackAmount() < event.buffed.amount)
return false;
@ -419,6 +430,9 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
}
case EVENT_T_MISSING_AURA:
{
if (!m_creature->IsInCombat())
return false;
SpellAuraHolder* holder = m_creature->GetSpellAuraHolder(event.buffed.spellId);
if (holder && holder->GetStackAmount() >= event.buffed.amount)
return false;
@ -444,6 +458,21 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
}
case EVENT_T_RECEIVE_AI_EVENT:
break;
case EVENT_T_ENERGY:
{
if (!m_creature->IsInCombat() || !m_creature->GetMaxPower(POWER_ENERGY))
return false;
uint32 perc = (m_creature->GetPower(POWER_ENERGY) * 100) / m_creature->GetMaxPower(POWER_ENERGY);
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;
}
default:
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;
@ -478,7 +507,7 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction
if (count)
{
// select action number from found amount
uint32 idx = urand(0, count - 1);
uint32 idx = rnd % count;
// find selected action, skipping not used
uint32 j = 0;
@ -520,17 +549,17 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
if (action.type == ACTION_T_TEXT)
{
if (action.text.TextId[1] && action.text.TextId[2])
textId = action.text.TextId[urand(0, 2)];
else if (action.text.TextId[1] && urand(0, 1))
textId = action.text.TextId[rnd % 3];
else if (action.text.TextId[1] && (rnd % 2))
textId = action.text.TextId[1];
else
textId = action.text.TextId[0];
}
// ACTION_T_CHANCED_TEXT, chance hits
else if (urand(0, 99) < action.chanced_text.chance)
else if ((rnd % 100) < action.chanced_text.chance)
{
if (action.chanced_text.TextId[0] && action.chanced_text.TextId[1])
textId = action.chanced_text.TextId[urand(0, 1)];
textId = action.chanced_text.TextId[rnd % 2];
else
textId = action.chanced_text.TextId[0];
}
@ -839,9 +868,9 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
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_OOC_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_OOC_DESPAWN, 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.outErrorEventAI("failed to spawn creature %u. EventId %d.Creature %d", action.summon_id.creatureId, EventId, m_creature->GetEntry());
@ -1035,29 +1064,26 @@ void CreatureEventAI::Reset()
{
m_EventUpdateTime = EVENT_UPDATE_TIME;
m_EventDiff = 0;
m_throwAIEventStep = 0;
// Reset all events to enabled
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)
{
// Reset all out of combat timers
// Reset all out of combat timers
case EVENT_T_TIMER_OOC:
{
if ((*i).UpdateRepeatTimer(m_creature, event.timer.initialMin, event.timer.initialMax))
(*i).Enabled = true;
if (i->UpdateRepeatTimer(m_creature, event.timer.initialMin, event.timer.initialMax))
i->Enabled = true;
break;
}
default:
// TODO: enable below code line / verify this is correct to enable events previously disabled (ex. aggro yell), instead of enable this in void Aggro()
//i->Enabled = true;
//i->Time = 0;
break;
// default:
// TODO: enable below code line / verify this is correct to enable events previously disabled (ex. aggro yell), instead of enable this in void Aggro()
//(*i).Enabled = true;
//(*i).Time = 0;
// break;
}
}
}
@ -1066,7 +1092,7 @@ void CreatureEventAI::JustReachedHome()
{
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);
}
@ -1079,18 +1105,16 @@ void CreatureEventAI::EnterEvadeMode()
m_creature->DeleteThreatList();
m_creature->CombatStop(true);
if (m_creature->IsAlive())
// only alive creatures that are not on transport can return to home position
if (m_creature->IsAlive() && !m_creature->IsBoarded())
m_creature->GetMotionMaster()->MoveTargetedHome();
m_creature->SetLootRecipient(NULL);
if (m_bEmptyList)
return;
m_creature->SetLootRecipient(nullptr);
// Handle Evade events
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);
}
}
@ -1112,7 +1136,7 @@ void CreatureEventAI::JustDied(Unit* killer)
// Handle On Death events
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);
}
@ -1127,7 +1151,7 @@ void CreatureEventAI::KilledUnit(Unit* victim)
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);
}
}
@ -1136,7 +1160,7 @@ void CreatureEventAI::JustSummoned(Creature* pUnit)
{
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);
}
}
@ -1145,7 +1169,7 @@ void CreatureEventAI::SummonedCreatureJustDied(Creature* pUnit)
{
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);
}
}
@ -1154,12 +1178,12 @@ void CreatureEventAI::SummonedCreatureDespawn(Creature* pUnit)
{
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);
}
}
void CreatureEventAI::ReceiveAIEvent(AIEventType eventType, Creature* pSender, Unit* pInvoker, uint32 miscValue)
void CreatureEventAI::ReceiveAIEvent(AIEventType eventType, Creature* pSender, Unit* pInvoker, uint32 /*miscValue*/)
{
MANGOS_ASSERT(pSender);
@ -1169,29 +1193,29 @@ void CreatureEventAI::ReceiveAIEvent(AIEventType eventType, Creature* pSender, U
itr->Event.receiveAIEvent.eventType == eventType && (!itr->Event.receiveAIEvent.senderEntry || itr->Event.receiveAIEvent.senderEntry == pSender->GetEntry()))
ProcessEvent(*itr, pInvoker, pSender);
}
}
}
void CreatureEventAI::EnterCombat(Unit* enemy)
{
// Check for on combat start events
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)
{
case EVENT_T_AGGRO:
(*i).Enabled = true;
i->Enabled = true;
ProcessEvent(*i, enemy);
break;
// Reset all in combat timers
// Reset all in combat timers
case EVENT_T_TIMER_IN_COMBAT:
if ((*i).UpdateRepeatTimer(m_creature, event.timer.initialMin, event.timer.initialMax))
(*i).Enabled = true;
if (i->UpdateRepeatTimer(m_creature, event.timer.initialMin, event.timer.initialMax))
i->Enabled = true;
break;
// All normal events need to be re-enabled and their time set to 0
// All normal events need to be re-enabled and their time set to 0
default:
(*i).Enabled = true;
(*i).Time = 0;
i->Enabled = true;
i->Time = 0;
break;
}
}
@ -1221,21 +1245,21 @@ void CreatureEventAI::MoveInLineOfSight(Unit* who)
return;
// Check for OOC LOS Event
if (!m_creature->getVictim())
if (m_HasOOCLoSEvent && !m_creature->getVictim())
{
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)
{
// can trigger if closer than fMaxAllowedRange
float fMaxAllowedRange = (float)(*itr).Event.ooc_los.maxRange;
float fMaxAllowedRange = (float)itr->Event.ooc_los.maxRange;
// if range is ok and we are actually in LOS
if (m_creature->IsWithinDistInMap(who, fMaxAllowedRange) && m_creature->IsWithinLOSInMap(who))
// if friendly event && who is not hostile OR hostile event && who is hostile
if ((itr->Event.ooc_los.noHostile && !m_creature->IsHostileTo(who)) ||
((!itr->Event.ooc_los.noHostile) && m_creature->IsHostileTo(who)))
{
// if friendly event&&who is not hostile OR hostile event&&who is hostile
if (((*itr).Event.ooc_los.noHostile && !m_creature->IsHostileTo(who)) ||
((!(*itr).Event.ooc_los.noHostile) && m_creature->IsHostileTo(who)))
// if range is ok and we are actually in LOS
if (m_creature->IsWithinDistInMap(who, fMaxAllowedRange) && m_creature->IsWithinLOSInMap(who))
ProcessEvent(*itr, who);
}
}
@ -1246,7 +1270,7 @@ void CreatureEventAI::MoveInLineOfSight(Unit* who)
return;
if (m_creature->CanInitiateAttack() && who->IsTargetableForAttack() &&
m_creature->IsHostileTo(who) && who->isInAccessablePlaceFor(m_creature))
m_creature->IsHostileTo(who) && who->IsInAccessablePlaceFor(m_creature))
{
if (!m_creature->CanFly() && m_creature->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE)
return;
@ -1271,10 +1295,10 @@ void CreatureEventAI::MoveInLineOfSight(Unit* who)
void CreatureEventAI::SpellHit(Unit* pUnit, const SpellEntry* pSpell)
{
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 (!(*i).Event.spell_hit.spellId || pSpell->Id == (*i).Event.spell_hit.spellId)
if (pSpell->SchoolMask & (*i).Event.spell_hit.schoolMask)
if (!i->Event.spell_hit.spellId || pSpell->Id == i->Event.spell_hit.spellId)
if (pSpell->SchoolMask & i->Event.spell_hit.schoolMask)
ProcessEvent(*i, pUnit);
}
@ -1292,55 +1316,28 @@ void CreatureEventAI::UpdateAI(const uint32 diff)
for (CreatureEventAIList::iterator i = m_CreatureEventAIList.begin(); i != m_CreatureEventAIList.end(); ++i)
{
// Decrement Timers
if ((*i).Time)
if (i->Time)
{
if ((*i).Time > m_EventDiff)
if (i->Time > m_EventDiff)
{
// Do not decrement timers if event cannot trigger in this phase
if (!((*i).Event.event_inverse_phase_mask & (1 << m_Phase)))
(*i).Time -= m_EventDiff;
// Skip processing of events that have time remaining
continue;
if (!(i->Event.event_inverse_phase_mask & (1 << m_Phase)))
i->Time -= m_EventDiff;
}
else (*i).Time = 0;
else
i->Time = 0;
}
// Events that are updated every EVENT_UPDATE_TIME
switch ((*i).Event.event_type)
{
case EVENT_T_TIMER_OOC:
case EVENT_T_TIMER_GENERIC:
ProcessEvent(*i);
break;
case EVENT_T_TIMER_IN_COMBAT:
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:
if (Combat)
ProcessEvent(*i);
break;
case EVENT_T_RANGE:
if (Combat)
{
if (m_creature->getVictim() && m_creature->IsInMap(m_creature->getVictim()))
if (m_creature->IsInRange(m_creature->getVictim(), (float)(*i).Event.range.minDist, (float)(*i).Event.range.maxDist))
ProcessEvent(*i);
}
break;
default:
break;
}
// Skip processing of events that have time remaining or are disabled
if (!(i->Enabled) || i->Time)
continue;
m_EventDiff = 0;
m_EventUpdateTime = EVENT_UPDATE_TIME;
if (IsTimerBasedEvent(i->Event.event_type))
ProcessEvent(*i);
}
m_EventDiff = 0;
m_EventUpdateTime = EVENT_UPDATE_TIME;
}
else
{
@ -1348,9 +1345,23 @@ void CreatureEventAI::UpdateAI(const uint32 diff)
m_EventUpdateTime -= diff;
}
// Melee Auto-Attack (recheck m_creature->getVictim in case of combat state was changed while processing events)
if (Combat && m_MeleeEnabled && m_creature->getVictim())
DoMeleeAttackIfReady();
// Melee Auto-Attack (getVictim might be nullptr as result of timer based events and actions)
if (Combat && m_creature->getVictim())
{
// Update creature dynamic movement position before doing anything else
if (m_DynamicMovement)
{
if (!m_creature->hasUnitState(UNIT_STAT_CAN_NOT_REACT) && !m_creature->IsNonMeleeSpellCasted(false))
{
if (m_LastSpellMaxRange && m_creature->IsInRange(m_creature->getVictim(), 0, (m_LastSpellMaxRange / 1.5f)))
SetCombatMovement(false, true);
else
SetCombatMovement(true, true);
}
}
else if (m_MeleeEnabled)
DoMeleeAttackIfReady();
}
}
bool CreatureEventAI::IsVisible(Unit* pl) const
@ -1478,12 +1489,12 @@ void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote)
{
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)
{
if ((*itr).Event.receive_emote.emoteId != text_emote)
return;
if (itr->Event.receive_emote.emoteId != text_emote)
continue;
PlayerCondition pcon(0, (*itr).Event.receive_emote.condition, (*itr).Event.receive_emote.conditionValue1, (*itr).Event.receive_emote.conditionValue2);
PlayerCondition pcon(0, itr->Event.receive_emote.condition, itr->Event.receive_emote.conditionValue1, itr->Event.receive_emote.conditionValue2);
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");