Core/Spells: fixed Mage Mirror Image and Glyph of Mirror Image

* removed loads of hacks from the core
This commit is contained in:
Ovahlord committed 2018-07-23 12:17:18 +02:00
1 parent daf6cfca70
commit 7b56a074bd
8 files changed
+237 -238

No files matched your search

+108 -212
View File
@@ -28,233 +28,129 @@
#include "PetAI.h"
#include "ScriptedCreature.h"
enum MageSpells
enum Spells
{
SPELL_MAGE_CLONE_ME = 45204,
SPELL_MAGE_MASTERS_THREAT_LIST = 58838,
SPELL_MAGE_FROST_BOLT = 59638,
SPELL_MAGE_FIRE_BLAST = 59637
SPELL_INHERIT_MASTERS_THREAT_LIST = 58838,
SPELL_PET_HEALTH_SCALING = 61679,
SPELL_CLONE_ME = 45204,
SPELL_COPY_OFFHAND_WEAPON = 45206,
SPELL_COPY_WEAPON = 41055,
SPELL_INITIALIZE_IMAGES = 58836,
SPELL_FIREBALL = 88082,
SPELL_FROST_BOLT = 59638,
SPELL_ARCANE_BLAST = 88084
};
enum MirrorImageTimers
enum CreatureIds
{
TIMER_MIRROR_IMAGE_INIT = 0,
TIMER_MIRROR_IMAGE_FROST_BOLT = 4000,
TIMER_MIRROR_IMAGE_FIRE_BLAST = 6000
NPC_MIRROR_IMAGE_FIRE = 47244,
NPC_MIRROR_IMAGE_ARCANE = 47243,
NPC_MIRROR_IMAGE_FROST = 31216
};
class npc_pet_mage_mirror_image : public CreatureScript
enum Events
{
public:
npc_pet_mage_mirror_image() : CreatureScript("npc_pet_mage_mirror_image") { }
EVENT_CAST_ABILITY = 1
};
struct npc_pet_mage_mirror_imageAI : CasterAI
struct npc_pet_mage_mirror_image : ScriptedAI
{
npc_pet_mage_mirror_image(Creature* creature) : ScriptedAI(creature)
{
Initialize();
}
void Initialize()
{
_angle = 0.0f;
}
void AttackStart(Unit* who) override
{
AttackStartCaster(who, 20.0f);
}
void EnterEvadeMode(EvadeReason /*why*/) override
{
if (Unit* summoner = me->ToTempSummon()->GetSummoner())
me->GetMotionMaster()->MoveFollow(summoner, PET_FOLLOW_DIST, _angle);
}
void IsSummonedBy(Unit* summoner) override
{
DoCastAOE(SPELL_INHERIT_MASTERS_THREAT_LIST);
DoCastSelf(SPELL_PET_HEALTH_SCALING);
summoner->CastSpell(me, SPELL_CLONE_ME, true);
DoCast(summoner, SPELL_COPY_OFFHAND_WEAPON);
DoCast(summoner, SPELL_COPY_WEAPON);
_angle = summoner->GetAngle(me);
me->GetMotionMaster()->MoveFollow(summoner, PET_FOLLOW_DIST, _angle);
}
void SpellHitTarget(Unit* target, SpellInfo const* spell) override
{
if (spell->Id == SPELL_INHERIT_MASTERS_THREAT_LIST)
{
npc_pet_mage_mirror_imageAI(Creature* creature) : CasterAI(creature) { }
Unit* summoner = me->ToTempSummon()->GetSummoner();
if (!summoner)
return;
void Init()
if (target->IsInCombatWith(summoner))
{
Unit* owner = me->GetCharmerOrOwner();
std::list<Unit*> targets;
Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(me, me, 30.0f);
Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(me, targets, u_check);
Cell::VisitAllObjects(me, searcher, 40.0f);
Unit* highestThreatUnit = nullptr;
float highestThreat = 0.0f;
Unit* nearestPlayer = nullptr;
for (std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter)
{
// Consider only units without CC
if (!(*iter)->HasBreakableByDamageCrowdControlAura((*iter)))
{
// Take first found unit
if (!highestThreatUnit && (*iter)->GetTypeId() != TYPEID_PLAYER)
{
highestThreatUnit = (*iter);
continue;
}
if (!nearestPlayer && ((*iter)->GetTypeId() == TYPEID_PLAYER))
{
nearestPlayer = (*iter);
continue;
}
// else compare best fit unit with current unit
ThreatContainer::StorageType triggers = (*iter)->getThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator trig_citr = triggers.begin(); trig_citr != triggers.end(); ++trig_citr)
{
// Try to find threat referenced to owner
if ((*trig_citr)->getTarget() == owner)
{
// Check if best fit hostile unit hs lower threat than this current unit
if (highestThreat < (*trig_citr)->getThreat())
{
// If so, update best fit unit
highestThreat = (*trig_citr)->getThreat();
highestThreatUnit = (*iter);
break;
}
}
}
// In case no unit with threat was found so far, always check for nearest unit (only for players)
if ((*iter)->GetTypeId() == TYPEID_PLAYER)
{
// If this player is closer than the previous one, update it
if (me->GetDistance((*iter)->GetPosition()) < me->GetDistance(nearestPlayer->GetPosition()))
nearestPlayer = (*iter);
}
}
}
// Prioritize units with threat referenced to owner
if (highestThreat > 0.0f && highestThreatUnit)
me->Attack(highestThreatUnit, false);
// If there is no such target, try to attack nearest hostile unit if such exists
else if (nearestPlayer)
me->Attack(nearestPlayer, false);
target->AddThreat(me, target->getThreatManager().getThreat(summoner));
me->SetInCombatWith(target);
}
bool IsInThreatList(Unit* target)
{
Unit* owner = me->GetCharmerOrOwner();
std::list<Unit*> targets;
Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(me, me, 30.0f);
Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(me, targets, u_check);
Cell::VisitAllObjects(me, searcher, 40.0f);
for (std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter)
{
if ((*iter) == target)
{
// Consider only units without CC
if (!(*iter)->HasBreakableByDamageCrowdControlAura((*iter)))
{
ThreatContainer::StorageType triggers = (*iter)->getThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator trig_citr = triggers.begin(); trig_citr != triggers.end(); ++trig_citr)
{
// Try to find threat referenced to owner
if ((*trig_citr)->getTarget() == owner)
return true;
}
}
}
}
return false;
}
void InitializeAI() override
{
CasterAI::InitializeAI();
Unit* owner = me->GetOwner();
if (!owner)
return;
// here mirror image casts on summoner spell (not present in client dbc) 49866
// here should be auras (not present in client dbc): 35657, 35658, 35659, 35660 selfcast by mirror images (stats related?)
// Clone Me!
owner->CastSpell(me, SPELL_MAGE_CLONE_ME, false);
}
void JustEngagedWith(Unit* who) override
{
if (me->GetVictim() && !me->GetVictim()->HasBreakableByDamageCrowdControlAura(me))
{
me->CastSpell(who, SPELL_MAGE_FIRE_BLAST, false);
events.ScheduleEvent(SPELL_MAGE_FROST_BOLT, TIMER_MIRROR_IMAGE_INIT);
events.ScheduleEvent(SPELL_MAGE_FIRE_BLAST, TIMER_MIRROR_IMAGE_FIRE_BLAST);
}
else
EnterEvadeMode(EVADE_REASON_OTHER);
}
void Reset() override
{
events.Reset();
}
void UpdateAI(uint32 diff) override
{
Unit* owner = me->GetCharmerOrOwner();
if (!owner)
return;
Unit* target = owner->getAttackerForHelper();
events.Update(diff);
// prevent CC interrupts by images
if (me->GetVictim() && me->EnsureVictim()->HasBreakableByDamageCrowdControlAura(me))
{
me->InterruptNonMeleeSpells(false);
return;
}
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
// assign target if image doesnt have any or the target is not actual
if (!target || me->GetVictim() != target)
{
Unit* ownerTarget = nullptr;
if (Player* playerOwner = me->GetCharmerOrOwner()->ToPlayer())
ownerTarget = playerOwner->GetSelectedUnit();
// recognize which victim will be choosen
if (ownerTarget && ownerTarget->GetTypeId() == TYPEID_PLAYER)
{
if (!ownerTarget->HasBreakableByDamageCrowdControlAura(ownerTarget))
me->Attack(ownerTarget, false);
}
else if (ownerTarget && (ownerTarget->GetTypeId() != TYPEID_PLAYER) && IsInThreatList(ownerTarget))
{
if (!ownerTarget->HasBreakableByDamageCrowdControlAura(ownerTarget))
me->Attack(ownerTarget, false);
}
else
Init();
}
if (uint32 spellId = events.ExecuteEvent())
{
if (spellId == SPELL_MAGE_FROST_BOLT)
{
events.ScheduleEvent(SPELL_MAGE_FROST_BOLT, TIMER_MIRROR_IMAGE_FROST_BOLT);
DoCastVictim(spellId);
}
else if (spellId == SPELL_MAGE_FIRE_BLAST)
{
DoCastVictim(spellId);
events.ScheduleEvent(SPELL_MAGE_FIRE_BLAST, TIMER_MIRROR_IMAGE_FIRE_BLAST);
}
}
}
// Do not reload Creature templates on evade mode enter - prevent visual lost
void EnterEvadeMode(EvadeReason /*why*/) override
{
if (me->IsInEvadeMode() || !me->IsAlive())
return;
Unit* owner = me->GetCharmerOrOwner();
me->CombatStop(true);
if (owner && !me->HasUnitState(UNIT_STATE_FOLLOW))
{
me->GetMotionMaster()->Clear(false);
me->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, me->GetFollowAngle(), MOTION_SLOT_ACTIVE);
}
Init();
}
};
CreatureAI* GetAI(Creature* creature) const override
{
return new npc_pet_mage_mirror_imageAI(creature);
}
}
void SpellHit(Unit* caster, SpellInfo const* spell) override
{
if (spell->Id == SPELL_INITIALIZE_IMAGES)
{
_events.ScheduleEvent(EVENT_CAST_ABILITY, 500ms);
if (Unit* target = me->SelectVictim())
AttackStart(target);
}
}
void UpdateAI(uint32 diff) override
{
if (!UpdateVictim())
return;
_events.Update(diff);
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
while (uint32 eventId = _events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_CAST_ABILITY:
if (me->GetEntry() == NPC_MIRROR_IMAGE_FROST)
DoCastVictim(SPELL_FROST_BOLT);
if (me->GetEntry() == NPC_MIRROR_IMAGE_FIRE)
DoCastVictim(SPELL_FIREBALL);
else if (me->GetEntry() == NPC_MIRROR_IMAGE_ARCANE)
DoCastVictim(SPELL_ARCANE_BLAST);
_events.Repeat(3s);
break;
default:
break;
}
}
}
private:
EventMap _events;
float _angle;
};
void AddSC_mage_pet_scripts()
{
new npc_pet_mage_mirror_image();
RegisterCreatureAI(npc_pet_mage_mirror_image);
}
+98 -1
View File
@@ -84,6 +84,9 @@ enum MageSpells
SPELL_MAGE_INCANTERS_ABSORBTION_KNOCKBACK = 86261,
SPELL_MAGE_IGNITE = 12654,
SPELL_MAGE_MASTER_OF_ELEMENTS_ENERGIZE = 29077,
SPELL_MAGE_MIRROR_IMAGE_TRIGGERED_FIRE = 88092,
SPELL_MAGE_MIRROR_IMAGE_TRIGGERED_ARCANE = 88091,
SPELL_MAGE_MIRROR_IMAGE_TRIGGERED_FROST = 58832,
SPELL_MAGE_PERMAFROST = 91394,
SPELL_MAGE_PYROBLAST = 11366,
SPELL_MAGE_SCORCH = 2948,
@@ -134,7 +137,8 @@ enum MageIcons
ICON_MAGE_IMPROVED_MANA_GEM = 1036,
ICON_MAGE_EARLY_FROST_SKILL = 189,
ICON_MAGE_EARLY_FROST = 2114,
SPELL_ICON_MAGE_LIVING_BOMB = 3000
ICON_MAGE_GLYPH_OF_MIRROR_IMAGE = 331,
SPELL_ICON_MAGE_LIVING_BOMB = 3000,
};
enum MiscSpells
@@ -2012,6 +2016,97 @@ class spell_mage_pyroblast : public SpellScriptLoader
}
};
// 55342 - Mirror Image
class spell_mage_mirror_image : public SpellScript
{
PrepareSpellScript(spell_mage_mirror_image);
bool Validate(SpellInfo const* /*spellInfo*/) override
{
return ValidateSpellInfo(
{
SPELL_MAGE_MIRROR_IMAGE_TRIGGERED_FIRE,
SPELL_MAGE_MIRROR_IMAGE_TRIGGERED_ARCANE,
SPELL_MAGE_MIRROR_IMAGE_TRIGGERED_FROST
});
}
void HandleDummyEffect(SpellEffIndex /*effIndex*/)
{
Player* player = GetHitPlayer();
if (!player)
return;
uint32 spellId = SPELL_MAGE_MIRROR_IMAGE_TRIGGERED_FROST;
if (player->GetDummyAuraEffect(SPELLFAMILY_MAGE, ICON_MAGE_GLYPH_OF_MIRROR_IMAGE, EFFECT_0))
{
if (player->GetPrimaryTalentTree(player->GetActiveSpec()) == TALENT_TREE_MAGE_FIRE)
spellId = SPELL_MAGE_MIRROR_IMAGE_TRIGGERED_FIRE;
else if (player->GetPrimaryTalentTree(player->GetActiveSpec()) == TALENT_TREE_MAGE_ARCANE)
spellId = SPELL_MAGE_MIRROR_IMAGE_TRIGGERED_ARCANE;
}
player->CastSpell(player, spellId, true);
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_mage_mirror_image::HandleDummyEffect, EFFECT_1, SPELL_EFFECT_DUMMY);
}
};
class spell_mage_mirror_image_AurasScript : public AuraScript
{
PrepareAuraScript(spell_mage_mirror_image_AurasScript);
void HandleEffectPeriodic(AuraEffect const* aurEff)
{
if (aurEff->GetTickNumber() == 1)
GetTarget()->CastSpell(GetTarget(), GetSpellInfo()->Effects[aurEff->GetEffIndex()].TriggerSpell, true);
}
void Register() override
{
OnEffectPeriodic += AuraEffectPeriodicFn(spell_mage_mirror_image_AurasScript::HandleEffectPeriodic, EFFECT_2, SPELL_AURA_PERIODIC_DUMMY);
}
};
class SummonerCheck
{
public:
SummonerCheck(Unit* _summoner) : summoner(_summoner) { }
bool operator()(WorldObject* object)
{
if (Unit* unit = object->ToUnit())
if (TempSummon* summon = unit->ToTempSummon())
return (summon->GetSummoner() && summon->GetSummoner() != summoner);
return false;
}
private:
Unit* summoner;
};
class spell_initialize_images : public SpellScript
{
PrepareSpellScript(spell_initialize_images);
void FilterTargets(std::list<WorldObject*>& targets)
{
if (targets.empty())
return;
targets.remove_if(SummonerCheck(GetCaster()));
}
void Register() override
{
OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(spell_initialize_images::FilterTargets, EFFECT_0, TARGET_UNIT_SRC_AREA_ENTRY);
}
};
void AddSC_mage_spell_scripts()
{
new spell_mage_arcane_potency();
@@ -2032,6 +2127,7 @@ void AddSC_mage_spell_scripts()
new spell_mage_ice_barrier();
new spell_mage_ignite();
new spell_mage_improved_hot_streak();
RegisterSpellScript(spell_initialize_images);
new spell_mage_glyph_of_ice_block();
new spell_mage_glyph_of_icy_veins();
new spell_mage_glyph_of_polymorph();
@@ -2039,6 +2135,7 @@ void AddSC_mage_spell_scripts()
new spell_mage_mage_ward();
new spell_mage_mana_shield();
new spell_mage_master_of_elements();
RegisterSpellAndAuraScriptPair(spell_mage_mirror_image, spell_mage_mirror_image_AurasScript);
new spell_mage_nether_vortex();
new spell_mage_permafrost();
new spell_mage_polymorph();