Advertisement
Guest User

Untitled

a guest
Oct 7th, 2014
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.67 KB | None | 0 0
  1. local npcId = 70000;
  2. local minionId = 70001;
  3. local minion2Id = 70002;
  4. local portalId = 70005;
  5.  
  6. local CREATURE_EVENT_ON_ENTER_COMBAT            = 1;
  7. local CREATURE_EVENT_ON_LEAVE_COMBAT            = 2;
  8. local CREATURE_EVENT_ON_DIED                    = 4;
  9. local CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE  = 19;
  10. local CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED  = 21;
  11. local CREATURE_EVENT_ON_SUMMONED                = 22;
  12. local CREATURE_EVENT_ON_RESET                   = 23;
  13.  
  14. local ACTION_MOVE_HOME                          = 1;
  15. local ACTION_SPAWN_LIGHT_ZONE                   = 2;
  16. local ACTION_ZONE_EXPLOSION                     = 3;
  17. local ACTION_SPAWN_LIGHT_MINION                 = 4;
  18. local ACTION_PREPARE_DARK_ZONE                  = 5;
  19. local ACTION_DESTROY_DARK_ZONE                  = 6;
  20.  
  21. local VOID_ZONE_LIGHT                           = 40670;
  22. local VOID_ZONE_DARK                            = 40672;
  23. local VOID_ZONE_LIGHT_VISUAL                    = 74629;
  24. local VOID_ZONE_DARK_VISUAL                     = 74803;
  25. local VOID_ZONE_DARK_DAMAGE                     = 75874;
  26.  
  27. local SPELL_BEAM_OF_LIGHT                       = 46822;
  28. local SPELL_ROOT                                = 38505;
  29. local SPELL_SHADOW_AURA                         = 72523;
  30. local SPELL_SHROUD_OF_SORROW                    = 70985;
  31. local SPELL_SHADOW_EXPLOSION                    = 74799;
  32. local SPELL_HOLY_NOVA                           = 35740;
  33.  
  34. local DISPLAY_ID_SHADOW_FORM                    = 25452;
  35.  
  36. local OBJECT_END                                = 0x0006;
  37. local UNIT_FIELD_FLAGS                          = OBJECT_END + 0x0035;
  38. local UNIT_FLAG_NOT_SELECTABLE                  = 0x02000000;
  39. --local UNIT_FLAG_NOT_ATTACKABLE                    = 0x00000002;
  40.  
  41. local creatureSpells = {
  42.     -- Light phase
  43.     ["SMITE"] = {id = 71778, cooldown = 12},
  44.     ["HOLY_FIRE"] = {id = 66538, cooldown = 15},
  45.     ["DISARM"] = {id = 27581, cooldown = 20},
  46.    
  47.     -- Dark phase
  48.     ["SHADOW_CLEAVE"] = {id = 70670, cooldown = 3},
  49.     ["SHADOW_STRIKE"] = {id = 40685, cooldown = 18},
  50.     ["DEATH_AND_DECAY"] = {id = 61603, cooldown = 15},
  51.     ["DARK_SHELL"] = {id = 38759, cooldown = 30},
  52.     ["SHADOW_BOLT"] = {id = 55851, cooldown = 10}
  53. };
  54.    
  55.  
  56. local arthura = {};
  57. local function getClass(pUnit, AIFunc)
  58.     local guid = pUnit:GetGUIDLow();
  59.     if arthura[guid] == nil then
  60.         arthura[guid] = AIFunc(pUnit);
  61.     end
  62.     return arthura[guid];
  63. end
  64.  
  65. local function tableFind(tbl, value)
  66.     for _, v in pairs(tbl) do
  67.         if tostring(v) == tostring(value) then
  68.             return true;
  69.         end
  70.     end
  71.     return false;
  72. end
  73.  
  74. -- Creature class ( sort of .. )
  75. local function arthuraAI(pUnit)
  76.     -- Private
  77.     local phase = 1;
  78.     local eventTimer = 0;
  79.     local actionInProgress = false;
  80.    
  81.     local darkMinion;
  82.  
  83.     local cooldown = {};   
  84.     local function hasCooldown(name)
  85.         if not cooldown[name] then
  86.             return false;
  87.         end
  88.         if os.time() > cooldown[name] then
  89.             return false;
  90.         end
  91.         return true;
  92.     end
  93.     local function setCooldown(name)
  94.         cooldown[name] = os.time() + creatureSpells[name].cooldown;
  95.     end
  96.    
  97.     local function getEntry(name)
  98.         return creatureSpells[name].id;
  99.     end
  100.    
  101.     local function getRandomPlayer()
  102.         local targetList = pUnit:GetPlayersInRange();
  103.         return targetList[math.random(#targetList)];
  104.     end
  105.    
  106.     -- public
  107.     local self = {};
  108.    
  109.     function self.onReset()
  110.         phase = 1;
  111.         actionInProgress = false;
  112.         eventTimer = 0;
  113.  
  114.         pUnit:RemoveEvents();
  115.     end
  116.    
  117.     function self.onCombatStart()
  118.         pUnit:SendUnitYell("You were fools to come here, you will never walk out of here alive!", 0);
  119.         pUnit:RegisterEvent(self.onAIUpdate, 1000, 0);
  120.     end
  121.    
  122.     function self.onLeaveCombat()
  123.         local unitDarkMinion = getClass(darkMinion, darkMinionAI);
  124.         unitDarkMinion.onDestroy();
  125.        
  126.         local portal = pUnit:GetNearObject(50, 0, portalId)
  127.         local voidZone = pUnit:GetNearObject(50, 0, VOID_ZONE_DARK)
  128.         if portal then
  129.             portal:DespawnOrUnsummon();
  130.         end
  131.         if voidZone then
  132.             voidZone:DespawnOrUnsummon();
  133.         end
  134.     end
  135.    
  136.     function self.onJustDied(pKiller)
  137.         pUnit:SendUnitYell("You beaten the combination of shadow and light! How?", 0)
  138.     end
  139.    
  140.     function self.onJustSummoned(_, pSummoned)
  141.         darkMinion = pSummoned;
  142.     end
  143.  
  144.     function self.onAIUpdate()
  145.         eventTimer = eventTimer + 1;
  146.         -- :MoveTo() roots the boss, so I had to come up
  147.         -- with something.
  148.         if not actionInProgress then
  149.             pUnit:MoveChase(pUnit:GetVictim(), 0, 0);
  150.         end
  151.        
  152.         local healthPct = pUnit:GetHealthPct();
  153.         if phase == 1 then
  154.             if not pUnit:IsFullHealth() then
  155.                 pUnit:SetHealth(pUnit:GetHealth() + (pUnit:GetMaxHealth() * 0.001)); -- about 10000 a second.
  156.             end
  157.            
  158.             if eventTimer % 30 == 0 and not actionInProgress then
  159.                 self.doAction(ACTION_MOVE_HOME);
  160.             elseif actionInProgress and not pUnit:GetNearObject(50, 0, VOID_ZONE_LIGHT) then
  161.                 local x, y = pUnit:GetHomePosition();
  162.                 if pUnit:GetX() == x and pUnit:GetY() == y then
  163.                     self.doAction(ACTION_SPAWN_LIGHT_ZONE);
  164.                     CreateLuaEvent(function() self.doAction(ACTION_ZONE_EXPLOSION); end, 10000, 1);
  165.                 end
  166.             end
  167.            
  168.             if eventTimer % 20 == 0 and not pUnit:GetNearObject(50, 0, minionId) then
  169.                 self.doAction(ACTION_SPAWN_LIGHT_MINION);
  170.             end
  171.            
  172.             if not actionInProgress and not pUnit:GetCurrentSpell(1) then
  173.                 if not hasCooldown("SMITE") then
  174.                     local target = getRandomPlayer();
  175.                    
  176.                     pUnit:CastSpell(target, getEntry("SMITE"));
  177.                     setCooldown("SMITE");
  178.                 elseif not hasCooldown("HOLY_FIRE") then
  179.                     local targets = {};
  180.                     local targetList = pUnit:GetPlayersInRange();
  181.                     while #targets < 3 do
  182.                         local target = targetList[math.random(#targetList)];
  183.                         if not tableFind(targets, target) then
  184.                             table.insert(targets, target);
  185.                         end
  186.                        
  187.                         if #targetList == #targets then break; end -- In case of < 3 targets.
  188.                     end
  189.                    
  190.                     for _, v in pairs(targets) do
  191.                         pUnit:CastSpell(v, getEntry("HOLY_FIRE"), true);
  192.                     end
  193.                     setCooldown("HOLY_FIRE");
  194.                 elseif not hasCooldown("DISARM") then
  195.                     pUnit:CastSpell(pUnit:GetVictim(), getEntry("DISARM"));
  196.                     setCooldown("DISARM");
  197.                 end
  198.             end
  199.            
  200.             if not actionInProgress and healthPct <= 50then
  201.                 pUnit:SendUnitYell("Weak is the light, I cannot ... control ... ARRGGGH!", 0);
  202.                 pUnit:CastSpell(pUnit, SPELL_SHADOW_EXPLOSION );
  203.                 pUnit:SetDisplayId(DISPLAY_ID_SHADOW_FORM);
  204.                
  205.                 phase = 2;
  206.             end
  207.            
  208.         elseif phase == 2 then
  209.        
  210.             if eventTimer % 5 == 0 then
  211.                 pUnit:CastSpell(pUnit, SPELL_SHROUD_OF_SORROW);
  212.             end
  213.            
  214.             if eventTimer % 30 == 0 and not actionInProgress then
  215.                 self.doAction(ACTION_PREPARE_DARK_ZONE);
  216.             end
  217.            
  218.             if not pUnit:GetCurrentSpell(1) then
  219.                 if not hasCooldown("SHADOW_CLEAVE") then
  220.                     pUnit:CastSpell(pUnit:GetVictim(), getEntry("SHADOW_CLEAVE"));
  221.                     setCooldown("SHADOW_CLEAVE");
  222.                 elseif not hasCooldown("SHADOW_STRIKE") then
  223.                     pUnit:CastSpell(pUnit:GetVictim(), getEntry("SHADOW_STRIKE"));
  224.                     setCooldown("SHADOW_STRIKE");
  225.                 elseif not hasCooldown("DEATH_AND_DECAY") then
  226.                     local target = getRandomPlayer();
  227.                    
  228.                     pUnit:CastSpell(target, getEntry("DEATH_AND_DECAY"));
  229.                     setCooldown("DEATH_AND_DECAY");
  230.                 elseif not hasCooldown("DARK_SHELL") then
  231.                     if not pUnit:HasAura(getEntry("DARK_SHELL")) then
  232.                         pUnit:CastSpell(pUnit, getEntry("DARK_SHELL"))
  233.                     end
  234.                     setCooldown("DARK_SHELL");
  235.                 elseif not hasCooldown("SHADOW_BOLT") then
  236.                     pUnit:CastSpell(pUnit, getEntry("SHADOW_BOLT"));
  237.                     setCooldown("SHADOW_BOLT");                
  238.                 end
  239.             end
  240.         end
  241.     end
  242.    
  243.     function self.doAction(action)
  244.         local function getRandomCoords()
  245.             local x, y, z = pUnit:GetHomePosition();
  246.             x = math.random(2) == 1 and x-25 or x+25;
  247.             y = y + math.random(-25, 25);
  248.            
  249.             return x, y, z;
  250.         end
  251.            
  252.         if action == ACTION_MOVE_HOME then
  253.             local x, y, z = pUnit:GetHomePosition();
  254.             pUnit:MoveTo(1, x, y, z, false);
  255.            
  256.             actionInProgress = true;
  257.         elseif action == ACTION_SPAWN_LIGHT_ZONE then
  258.             local x, y, z = pUnit:GetHomePosition();   
  259.             pUnit:SpawnCreature(VOID_ZONE_LIGHT, x+20, y+20, z, 0, 1, 20000);
  260.             pUnit:SpawnCreature(VOID_ZONE_LIGHT, x-20, y-20, z, 0, 1, 20000);
  261.            
  262.             pUnit:SendUnitYell("Prepare for the true power of light!", 0)
  263.         elseif action == ACTION_ZONE_EXPLOSION then
  264.             pUnit:CastSpell(pUnit, SPELL_BEAM_OF_LIGHT);
  265.             CreateLuaEvent(function() pUnit:RemoveAura(SPELL_BEAM_OF_LIGHT); end, 1000, 1);
  266.            
  267.             local targets = {};
  268.             for _, v in pairs(pUnit:GetNearObjects(40, 0, VOID_ZONE_LIGHT)) do
  269.                 for _, target in pairs(pUnit:GetPlayersInRange()) do
  270.                     local inTable = tableFind(targets, target);
  271.                     if v:GetDistance(target) > 3 and inTable then
  272.                         pUnit:Kill(target);
  273.                     elseif v:GetDistance(target) > 3 and not inTable then
  274.                         table.insert(targets, target);
  275.                     end
  276.                 end
  277.             end
  278.            
  279.             eventTimer = 0;
  280.             actionInProgress = false;
  281.         elseif action == ACTION_SPAWN_LIGHT_MINION then
  282.             local x, y, z = getRandomCoords();
  283.             pUnit:SpawnCreature(minionId, x, y, z, 0, 1, 20000);
  284.         elseif action == ACTION_PREPARE_DARK_ZONE then
  285.             local target = getRandomPlayer();
  286.             pUnit:SpawnCreature(VOID_ZONE_DARK, target:GetX(), target:GetY(), target:GetZ(), 0, 1, 200000);
  287.            
  288.             local x, y, z = getRandomCoords();
  289.             pUnit:SpawnCreature(portalId, x, y, z, 0, 1, 200000);
  290.            
  291.             x, y, z = pUnit:GetHomePosition();
  292.             pUnit:SpawnCreature(minion2Id, x, y, z, 0, 1, 200000);
  293.            
  294.             actionInProgress = true;
  295.         elseif action == ACTION_DESTROY_DARK_ZONE then
  296.             local darkZone = pUnit:GetNearObject(50, 0, VOID_ZONE_DARK)
  297.             if darkZone then
  298.                 darkZone:DespawnOrUnsummon();
  299.             end
  300.            
  301.             eventTimer = 0;
  302.             actionInProgress = false;
  303.         end
  304.     end
  305.        
  306.     return self;
  307. end
  308.  
  309. local function handleArthuraAI(event, pUnit, ...)
  310.     local self = getClass(pUnit, arthuraAI);
  311.     if event == CREATURE_EVENT_ON_ENTER_COMBAT then
  312.         self.onCombatStart();
  313.     elseif event == CREATURE_EVENT_ON_LEAVE_COMBAT then
  314.         self.onLeaveCombat();
  315.     elseif event == CREATURE_EVENT_ON_DIED then
  316.         local pKiller = select(1, ...);
  317.         self.onJustDied(pKiller);
  318.     elseif event == CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE then
  319.         local pSummoned = select(1, ...);
  320.         self.onJustSummoned(pUnit, pSummoned);
  321.     elseif event == CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED then
  322.         local pSummoned = select(1, ...);
  323.         local pKiller = select(2, ...);
  324.         self.onSummonedCreatureDied(pUnit, pSummoned, pKiller);
  325.     elseif event == CREATURE_EVENT_ON_RESET then
  326.         self.onReset();
  327.     end
  328. end
  329.  
  330. RegisterCreatureEvent(npcId, CREATURE_EVENT_ON_ENTER_COMBAT, handleArthuraAI);
  331. RegisterCreatureEvent(npcId, CREATURE_EVENT_ON_LEAVE_COMBAT, handleArthuraAI);
  332. RegisterCreatureEvent(npcId, CREATURE_EVENT_ON_DIED, handleArthuraAI);
  333. RegisterCreatureEvent(npcId, CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE, handleArthuraAI);
  334. --RegisterCreatureEvent(npcId, CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED, handleArthuraAI);
  335. RegisterCreatureEvent(npcId, CREATURE_EVENT_ON_RESET, handleArthuraAI);
  336.  
  337. local function lightZoneAI(pUnit)
  338.     -- private
  339.     local summoner;
  340.    
  341.     local function getDamage()
  342.         local damage = 50000;
  343.         local vZone = pUnit:GetNearObject(60, 0, VOID_ZONE_LIGHT)
  344.         for _, v in pairs(vZone:GetPlayersInRange()) do
  345.             if vZone:GetDistance(v) <= 3 then
  346.                 return damage;
  347.             end
  348.         end
  349.         return damage * 5;
  350.     end
  351.    
  352.     local function handleVoidZone()
  353.         if not summoner:IsAlive() then
  354.             return pUnit:DespawnOrUnsummon();
  355.         end
  356.    
  357.         local players = {}
  358.         for _, v in pairs(pUnit:GetPlayersInRange()) do
  359.             if pUnit:GetDistance(v) <= 3 then
  360.                 table.insert(players, v);
  361.             end
  362.         end
  363.                
  364.         local damage = getDamage() / #players;
  365.         for _, v in pairs(players) do
  366.             pUnit:DealDamage(v, damage);
  367.         end
  368.        
  369.         pUnit:DespawnOrUnsummon(2000);
  370.     end
  371.        
  372.     -- public
  373.     local self = {};
  374.    
  375.     function self.onJustSummoned(pSummoner)
  376.         summoner = pSummoner;
  377.        
  378.         pUnit:SetFaction(35);      
  379.         pUnit:CastSpell(pUnit, VOID_ZONE_LIGHT_VISUAL);
  380.         pUnit:SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
  381.        
  382.         pUnit:RegisterEvent(handleVoidZone, 10000, 1);
  383.     end
  384.    
  385.     return self;
  386. end
  387.  
  388. local function handleLightZoneAI(event, pUnit, ...)
  389.     local self = getClass(pUnit, lightZoneAI);
  390.     if event == CREATURE_EVENT_ON_SUMMONED then
  391.         local pSummoner = select(1, ...);
  392.         self.onJustSummoned(pSummoner);
  393.     end
  394. end
  395.  
  396. RegisterCreatureEvent(VOID_ZONE_LIGHT, CREATURE_EVENT_ON_SUMMONED, handleLightZoneAI);
  397.  
  398. local function lightMinionAI(pUnit)
  399.     -- private
  400.     local summoner;
  401.    
  402.     -- public
  403.     local self = {};
  404.    
  405.     function self.onJustSummoned(pSummoner)
  406.         summoner = pSummoner;
  407.         pUnit:RegisterEvent(self.onAIUpdate, 1000, 0);
  408.     end
  409.    
  410.     function self.onJustDied(pKiller)
  411.         pUnit:DespawnOrUnsummon();
  412.     end
  413.    
  414.     function self.onAIUpdate()
  415.         pUnit:MoveChase(summoner, 0, 0);
  416.         if pUnit:GetDistance(summoner) <= 2 then
  417.             local maxHealth = summoner:GetMaxHealth();
  418.             local mMaxHealth = summoner:GetHealth()+(maxHealth/20);
  419.             if mMaxHealth > maxHealth then
  420.                 summoner:SetHealth(maxHealth);
  421.             else
  422.                 summoner:SetHealth(mMaxHealth);
  423.             end
  424.            
  425.             summoner:CastSpell(summoner, SPELL_HOLY_NOVA);
  426.             pUnit:DespawnOrUnsummon(); 
  427.         end
  428.     end
  429.    
  430.     return self;
  431. end
  432.  
  433. local function handleLightMinionAI(event, pUnit, ...)
  434.     local self = getClass(pUnit, lightMinionAI);
  435.     if event == CREATURE_EVENT_ON_SUMMONED then
  436.         local pSummoner = select(1, ...);
  437.         self.onJustSummoned(pSummoner);
  438.     elseif event == CREATURE_EVENT_ON_DIED then
  439.         local pKiller = select(1, ...);
  440.         self.onJustDied(pKiller);
  441.     end
  442. end
  443.  
  444. RegisterCreatureEvent(minionId, CREATURE_EVENT_ON_SUMMONED, handleLightMinionAI);
  445. RegisterCreatureEvent(minionId, CREATURE_EVENT_ON_DIED, handleLightMinionAI);
  446.  
  447. local function darkZoneAI(pUnit)
  448.     -- private
  449.     local summoner;
  450.     local scale = 1;
  451.    
  452.     local function onDamageTick()
  453.         local unitArthura = pUnit:GetNearObject(50, 0, npcId)
  454.         if not unitArthura then return; end
  455.        
  456.         for _, v in pairs(pUnit:GetPlayersInRange()) do
  457.             if pUnit:GetDistance(v) <= scale*3 then
  458.                 unitArthura:CastSpell(v, VOID_ZONE_DARK_DAMAGE);
  459.             end
  460.         end
  461.     end
  462.    
  463.     -- public
  464.     local self = {};
  465.    
  466.     function self.onJustSummoned(pSummoner)
  467.         summoner = pSummoner;
  468.        
  469.         pUnit:SetFaction(35);
  470.         pUnit:CastSpell(pUnit, VOID_ZONE_DARK_VISUAL);
  471.         pUnit:SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
  472.        
  473.         pUnit:RegisterEvent(self.onAIUpdate, 100, 0);
  474.         pUnit:RegisterEvent(onDamageTick, 1000, 0);
  475.     end
  476.    
  477.     function self.onAIUpdate()
  478.         if not summoner:IsAlive() then
  479.             return pUnit:DespawnOrUnsummon();
  480.         end
  481.        
  482.         scale = scale + 0.02;
  483.         pUnit:SetScale(scale);
  484.        
  485.         if scale >= 10 then
  486.             pUnit:DespawnOrUnsummon();
  487.         end
  488.     end
  489.    
  490.     return self;
  491. end
  492.  
  493. local function handleDarkZoneAI(event, pUnit, ...)
  494.     local self = getClass(pUnit, darkZoneAI);
  495.     if event == CREATURE_EVENT_ON_SUMMONED then
  496.         local pSummoner = select(1, ...);
  497.         self.onJustSummoned(pSummoner);
  498.     end
  499. end
  500.  
  501. RegisterCreatureEvent(VOID_ZONE_DARK, CREATURE_EVENT_ON_SUMMONED, handleDarkZoneAI);
  502.  
  503. local function portalAI(pUnit)
  504.     -- private
  505.     local summoner;
  506.    
  507.     -- public.
  508.     local self = {};
  509.    
  510.     function self.onJustSummoned(pSummoner)
  511.         summoner = pSummoner;
  512.        
  513.         pUnit:SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
  514.         pUnit:RegisterEvent(self.onAIUpdate, 1000, 0);
  515.     end
  516.    
  517.     function self.onAIUpdate()
  518.         if not summoner:IsAlive() then
  519.             return pUnit:DespawnOrUnsummon();
  520.         end
  521.        
  522.         for _, v in pairs(pUnit:GetPlayersInRange()) do
  523.             if pUnit:GetDistance(v) <= 3 then
  524.                 v:SetPhaseMask(4);
  525.                 return pUnit:DespawnOrUnsummon();
  526.             end
  527.         end
  528.     end
  529.    
  530.     return self;
  531. end
  532.  
  533. local function handlePortalAI(event, pUnit, ...)
  534.     local self = getClass(pUnit, portalAI);
  535.     if event == CREATURE_EVENT_ON_SUMMONED then
  536.         local pSummoner = select(1, ...);
  537.         self.onJustSummoned(pSummoner);
  538.     end
  539. end
  540.  
  541. RegisterCreatureEvent(portalId, CREATURE_EVENT_ON_SUMMONED, handlePortalAI);
  542.  
  543. local function darkMinionAI(pUnit)
  544.     -- private
  545.     local summoner;
  546.    
  547.     -- public
  548.     local self = {};
  549.    
  550.     function self.onJustSummoned(pSummoner)
  551.         summoner = pSummoner;
  552.         pUnit:SetPhaseMask(4);
  553.         pUnit:RegisterEvent(self.onAIUpdate, 1000, 0);
  554.     end
  555.    
  556.     function self.onJustDied(pKiller)
  557.         pKiller:SetPhaseMask(1);
  558.        
  559.         local unitArthura = getClass(summoner, arthuraAI);
  560.         unitArthura.doAction(ACTION_DESTROY_DARK_ZONE);
  561.        
  562.         pUnit:DespawnOrUnsummon();
  563.     end
  564.    
  565.     function self.onAIUpdate()
  566.         if not summoner:IsAlive() then
  567.             for _, v in pairs(pUnit:GetPlayersInRange()) do
  568.                 v:SetPhaseMask(1);
  569.             end
  570.            
  571.             return pUnit:DespawnOrUnsummon();
  572.         end
  573.        
  574.         if not pUnit:HasSpell(SPELL_ROOT) then
  575.             pUnit:CastSpell(pUnit, SPELL_ROOT); pUnit:CastSpell(pUnit, SPELL_SHADOW_AURA);
  576.         end
  577.     end
  578.    
  579.     function self.onDestroy()
  580.         for _, v in pairs(pUnit:GetPlayersInRange()) do
  581.             v:SetPhaseMask(1);
  582.         end
  583.            
  584.         pUnit:DespawnOrUnsummon();
  585.     end
  586.    
  587.     return self;
  588. end
  589.  
  590. local function handleDarkMinionAI(event, pUnit, ...)
  591.     local self = getClass(pUnit, darkMinionAI);
  592.     if event == CREATURE_EVENT_ON_SUMMONED then
  593.         local pSummoner = select(1, ...);
  594.         self.onJustSummoned(pSummoner);
  595.     elseif event == CREATURE_EVENT_ON_DIED then
  596.         local pKiller = select(1, ...);
  597.         self.onJustDied(pKiller);
  598.     end
  599. end
  600.  
  601. RegisterCreatureEvent(minion2Id, CREATURE_EVENT_ON_SUMMONED, handleDarkMinionAI);
  602. RegisterCreatureEvent(minion2Id, CREATURE_EVENT_ON_DIED, handleDarkMinionAI);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement