diff options
Diffstat (limited to 'src/game/CreatureEventAI.cpp')
-rw-r--r-- | src/game/CreatureEventAI.cpp | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 0393c30e7d3..5c425217844 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -30,6 +30,7 @@ #include "GridNotifiers.h" #include "GridNotifiersImpl.h" #include "InstanceData.h" +#include "SpellMgr.h" bool CreatureEventAIHolder::UpdateRepeatTimer( Creature* creature, uint32 repeatMin, uint32 repeatMax ) { @@ -95,6 +96,8 @@ CreatureEventAI::CreatureEventAI(Creature *c ) : CreatureAI(c) AttackDistance = 0.0f; AttackAngle = 0.0f; + InvinceabilityHpLevel = 0; + //Handle Spawned Events if (!bEmptyList) { @@ -113,13 +116,6 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction if (pHolder.Event.event_inverse_phase_mask & (1 << Phase)) return false; - //Store random here so that all random actions match up - uint32 rnd = rand(); - - //Return if chance for event is not met - if (pHolder.Event.event_chance <= rnd % 100) - return false; - CreatureEventAI_Event const& event = pHolder.Event; //Check event conditions based on the event type, also reset events @@ -331,6 +327,13 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction if (!(pHolder.Event.event_flags & EFLAG_REPEATABLE)) pHolder.Enabled = false; + //Store random here so that all random actions match up + uint32 rnd = rand(); + + //Return if chance for event is not met + if (pHolder.Event.event_chance <= rnd % 100) + return false; + //Process actions for (uint32 j = 0; j < MAX_ACTIONS; j++) ProcessAction(pHolder.Event.action[j], rnd, pHolder.Event.event_id, pActionInvoker); @@ -746,15 +749,10 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 m_creature->DealDamage(m_creature, m_creature->GetMaxHealth(),NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); break; case ACTION_T_ZONE_COMBAT_PULSE: - if (!m_creature->isInCombat() || !m_creature->GetMap()->IsDungeon()) - { - - sLog.outErrorDb("CreatureEventAI: Event %d ACTION_T_ZONE_COMBAT_PULSE on creature out of combat or in non-dungeon map. Creature %d", EventId, m_creature->GetEntry()); - return; - } - - DoZoneInCombat(m_creature); + { + m_creature->SetInCombatWithZone(); break; + } case ACTION_T_CALL_FOR_HELP: { m_creature->CallForHelp(action.call_for_help.radius); @@ -796,6 +794,14 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 m_creature->ForcedDespawn(); break; } + case ACTION_T_SET_INVINCIBILITY_HP_LEVEL: + { + if(action.invincibility_hp_level.is_percent) + InvinceabilityHpLevel = m_creature->GetMaxHealth()*action.invincibility_hp_level.hp_level/100; + else + InvinceabilityHpLevel = action.invincibility_hp_level.hp_level; + break; + } } } @@ -1302,7 +1308,7 @@ bool CreatureEventAI::CanCast(Unit* Target, SpellEntry const *Spell, bool Trigge return false; //Check for power - if (!Triggered && me->GetPower((Powers)Spell->powerType) < Spell->manaCost) + if (!Triggered && me->GetPower((Powers)Spell->powerType) < CalculatePowerCost(Spell, me, GetSpellSchoolMask(Spell))) return false; SpellRangeEntry const *TempRange = NULL; @@ -1342,6 +1348,17 @@ void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote) } } +void CreatureEventAI::DamageTaken( Unit* done_by, uint32& damage ) +{ + if(InvinceabilityHpLevel > 0 && m_creature->GetHealth() < InvinceabilityHpLevel+damage) + { + if(m_creature->GetHealth() <= InvinceabilityHpLevel) + damage = 0; + else + damage = m_creature->GetHealth() - InvinceabilityHpLevel; + } +} + bool CreatureEventAI::SpawnedEventConditionsCheck(CreatureEventAI_Event const& event) { if(event.event_type != EVENT_T_SPAWNED) |