stoneharry

Untitled

Jun 26th, 2013
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.55 KB | None | 0 0
  1. ------------------------------------------------------------------
  2. --[[
  3.  
  4.     SQL Queries used while creating this script:
  5.  
  6.     UPDATE `worldmap_info` SET `viewingDistance` = '900' WHERE `entry` = '631';
  7.  
  8. ]]
  9. ------------------------------------------------------------------
  10.  
  11. -- Variable declaration and generally setting up the script
  12.  
  13. local TirionNPCID = 38995
  14. local LichKingNPCID = 36597
  15.  
  16. -- For 3.3.5a
  17. local OBJECT_END = 0x0006
  18. local UNIT_NPC_FLAGS = OBJECT_END + 0x004C
  19. local UNIT_FIELD_FLAGS = OBJECT_END + 0x0035
  20. local UNIT_FIELD_BYTES_1 = OBJECT_END + 0x0044
  21. local UNIT_FLAG_NOT_SELECTABLE = 0x02000000
  22. local SMSG_INIT_WORLD_STATES = 0x2C2
  23. local SMSG_UPDATE_WORLD_STATE = 0x2C3
  24. local GAMEOBJECT_FLAGS = OBJECT_END + 0x0003
  25.  
  26. -- Unconfigurable Variables
  27.  
  28. ICC = {}
  29. ICC.VAR = {}
  30.  
  31. ------------------------------------------------------------------
  32. -- The gossip used to start the encounter - Tirion ---------------
  33. -- Also set up events etc ----------------------------------------
  34. ------------------------------------------------------------------
  35.  
  36. function ICC.VAR.Tirion_OnGossipTalk(pUnit, Event, player)
  37.     pUnit:GossipCreateMenu(2975252, player, 0)
  38.     pUnit:GossipMenuAddItem(9, "We are prepared, Highlord. Let us battle for the fate of Azeroth! For the light of dawn!", 1, 0)
  39.     pUnit:GossipMenuAddItem(0, "We are not yet prepared, Highlord.", 2, 0)
  40.     pUnit:GossipSendMenu(player)
  41. end
  42.  
  43. function ICC.VAR.Tirion_OnGossipSelect(pUnit, Event, player, id, code)
  44.     if (id == 1) then
  45.         local id = pUnit:GetInstanceID()
  46.         ICC[id] = ICC[id] or {VAR={}}
  47.         ICC[id].VAR.Tirion = pUnit
  48.         ICC[id].VAR.Ready = true
  49.         ICC[id].VAR.Tirion:SetUInt32Value(UNIT_NPC_FLAGS, 2) -- Quest flags disable gossip
  50.         ICC[id].VAR.Tirion:SetUInt32Value(UNIT_FIELD_FLAGS, 2) -- Unattackable, used to prevent LK hitting him instead of players
  51.     end
  52.     player:GossipComplete()
  53. end
  54.  
  55. RegisterUnitGossipEvent(TirionNPCID, 1, "ICC.VAR.Tirion_OnGossipTalk")
  56. RegisterUnitGossipEvent(TirionNPCID, 2, "ICC.VAR.Tirion_OnGossipSelect")
  57.  
  58. function ICC.VAR.OnSpawnHandleStart(pUnit, Event)
  59.     pUnit:SetUInt32Value(UNIT_NPC_FLAGS, 1) -- Gossip Flags, for when the fight resets
  60.     -- This function does not seem to get all the objects required
  61.     --[[for k,objects in pairs(pUnit:GetInRangeObjects()) do
  62.         if objects ~= nil then
  63.             local flags = objects:SetUInt32Value(GAMEOBJECT_FLAGS,0x1)
  64.             if flags ~= nil then
  65.                 if(bit_and(flags,0x1) == 0 or bit_and(flags, 0x2) ~= 0) then
  66.                     objects:SetUInt32Value(GAMEOBJECT_FLAGS,0x1)
  67.                 end
  68.             end
  69.         end
  70.     end]]
  71.     pUnit:RegisterEvent("ICC.VAR.CheckForStart", 2500, 0)
  72. end
  73.  
  74. RegisterUnitEvent(TirionNPCID, 18, "ICC.VAR.OnSpawnHandleStart")
  75.  
  76. function ICC.VAR.OnSpawnHandleDefineAndBytes(pUnit, Event)
  77.     pUnit:RegisterEvent("ICC.VAR.SetBytesAndHandleVariable", 2000, 1)
  78. end
  79.  
  80. function ICC.VAR.SetBytesAndHandleVariable(pUnit)
  81.     local id = pUnit:GetInstanceID()
  82.     ICC[id] = ICC[id] or {VAR={}}
  83.     ICC[id].VAR.Lich = pUnit
  84.     ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_BYTES_1, 1) -- Sit on the throne
  85.     ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_FLAGS, 2) -- Unattackable
  86. end
  87.  
  88. RegisterUnitEvent(LichKingNPCID, 18, "ICC.VAR.OnSpawnHandleDefineAndBytes")
  89.  
  90. ------------------------------------------------------------------
  91. -- Mini-cinematic at the start -----------------------------------
  92. ------------------------------------------------------------------
  93.  
  94. function ICC.VAR.CheckForStart(pUnit)
  95.     local id = pUnit:GetInstanceID()
  96.     ICC[id] = ICC[id] or {VAR={}}
  97.     if (ICC[id].VAR.Ready and ICC[id].VAR.Lich ~= nil) then
  98.         ICC[id].VAR.Ready = false
  99.         ICC[id].VAR.i = 0
  100.         ICC[id].VAR.Tirion:RemoveEvents()
  101.         ICC[id].VAR.Tirion:MoveTo(489.14, -2124.45, 1040.9, 0) -- Closer to LK
  102.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 7500, 1)
  103.     end
  104. end
  105.  
  106. function ICC.VAR.WalkTowardsLichKingThenEmotes(pUnit)
  107.     local id = pUnit:GetInstanceID()
  108.     if (ICC[id].VAR.i == 0) then
  109.         ICC[id].VAR.Tirion:Emote(375, 58500)
  110.         ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_BYTES_1, 0) -- Stand up
  111.         ICC[id].VAR.Tirion:PlaySoundToSet(17349) -- Voice of message - Tirion since players are closer to him
  112.         ICC[id].VAR.Tirion:PlaySoundToSet(17457) -- The music for this point
  113.         ICC[id].VAR.Lich:SendChatMessage(14, 0, "So... the Light's vaunted justice has finally arrived. Shall I lay down Frostmourne and throw myself at your mercy, Fordring?")
  114.         ICC[id].VAR.Lich:StopMovement(0) -- Resets bytes bug
  115.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 4000, 1)
  116.     elseif (ICC[id].VAR.i == 1) then
  117.         ICC[id].VAR.Lich:StopMovement(0) -- Resets bytes bug
  118.         ICC[id].VAR.Lich:MoveTo(457.44, -2123.86, 1041.2, 0) -- Down from throne to floor
  119.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 10000, 1)
  120.     elseif (ICC[id].VAR.i == 2) then
  121.         ICC[id].VAR.Tirion:SendChatMessage(14,0,"We will grant you a swift death, Arthas. More than can be said for the thousands you've tortured and slain.")
  122.         ICC[id].VAR.Tirion:PlaySoundToSet(17390)
  123.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 2000, 1)
  124.     elseif (ICC[id].VAR.i == 3) then
  125.         ICC[id].VAR.Lich:MoveTo(462.01, -2124.146, 1040.9, 0) -- Forwards slightly to correct position
  126.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 8500, 1)
  127.     elseif (ICC[id].VAR.i == 4) then
  128.         ICC[id].VAR.Lich:SendChatMessage(14,0,"You will learn of that first hand. When my work is complete, you will beg for mercy -- and I will deny you. Your anguished cries will be testament to my unbridled power.")
  129.         ICC[id].VAR.Tirion:PlaySoundToSet(17350)
  130.         ICC[id].VAR.Lich:Emote(397, 4000)
  131.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 4500, 1)
  132.     elseif (ICC[id].VAR.i == 5) then
  133.         ICC[id].VAR.Lich:Emote(1, 6000)
  134.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 12000, 1)
  135.     elseif (ICC[id].VAR.i == 6) then
  136.         ICC[id].VAR.Lich:Emote(392, 3500)
  137.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 7500, 1)
  138.     elseif (ICC[id].VAR.i == 7) then
  139.         ICC[id].VAR.Tirion:SendChatMessage(14,0,"So be it. Champions, attack!")
  140.         ICC[id].VAR.Tirion:PlaySoundToSet(17391)
  141.         ICC[id].VAR.Tirion:Emote(397, 2000)
  142.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 2000, 1)
  143.     elseif (ICC[id].VAR.i == 8) then
  144.         ICC[id].VAR.Tirion:SetMovementFlags(1) -- Run
  145.         ICC[id].VAR.Tirion:MoveTo(472.88, -2124.2, 1040.9, 0) -- Run towards LK
  146.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 1000, 1)
  147.     elseif (ICC[id].VAR.i == 9) then
  148.         ICC[id].VAR.Lich:SendChatMessage(14,0,"I'll keep you alive to witness the end, Fordring. I would not want the Light's greatest champion to miss seeing this wretched world remade in my image.")
  149.         ICC[id].VAR.Tirion:PlaySoundToSet(17351)
  150.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 500, 1)
  151.     elseif (ICC[id].VAR.i == 10) then
  152.         ICC[id].VAR.Lich:CastSpellOnTarget(71614, ICC[id].VAR.Tirion) -- Freeze
  153.         ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_FLAGS, 0) -- Attackable
  154.     end
  155.     ICC[id].VAR.i = ICC[id].VAR.i + 1
  156. end
  157.  
  158. ------------------------------------------------------------------
  159. -- The Fight -----------------------------------------------------
  160. ------------------------------------------------------------------
  161.  
  162. function ICC.VAR.OnEnterCombatStuff(pUnit, Event)
  163.     local id = pUnit:GetInstanceID()
  164.     ICC[id] = ICC[id] or {VAR={}}
  165.     if id == nil then id = 0 end
  166.     -- This will only be nil if one enters combat with the lich king in less than 2.5 seconds of spawn
  167.     if ICC[id].VAR.Lich then
  168.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.CheckForFinalPhase", 2500, 0)
  169.     end
  170. end
  171.  
  172. function ICC.VAR.CheckForFinalPhase(pUnit)
  173.     local id = pUnit:GetInstanceID()
  174.     if (ICC[id].VAR.Lich:GetHealthPct() < 11) then
  175.         ICC[id].VAR.Lich:RemoveEvents()
  176.         ICC[id].VAR.Lich:SendChatMessage(14,0,"You gnats actually hurt me! Perhaps I've toyed with you long enough, now taste the vengeance of the grave!")
  177.         ICC[id].VAR.Lich:PlaySoundToSet(17359)
  178.         ICC[id].VAR.Lich:SetMovementFlags(1)
  179.         ICC[id].VAR.Lich:MoveTo(505.212, -2124.35, 1040.95, 0) -- Center of the room
  180.         ICC[id].VAR.Lich:AIDisableCombat(true) -- Requires custom patch to work
  181.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.Lich_KeepMoving", 500, 2) -- Just to make sure he stays on the right tracks, though disabling combat above should work
  182.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.Lich_KillAll", 5005, 1)
  183.     end
  184. end
  185.  
  186. function ICC.VAR.Lich_KeepMoving(pUnit)
  187.     local id = pUnit:GetInstanceID()
  188.     ICC[id].VAR.Lich:MoveTo(505.212, -2124.35, 1040.95, 0) -- Center of the room
  189. end
  190.  
  191. function ICC.VAR.Lich_KillAll(pUnit)
  192.     local id = pUnit:GetInstanceID()
  193.     ICC[id].VAR.Lich:Root()
  194.     ICC[id].VAR.ForceWiped = true
  195.     ICC[id].VAR.Lich:FullCastSpell(70063) -- Wipe the raid - fury of frostmourne
  196.     ICC[id].VAR.i = 0
  197.     ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 10000, 1)
  198. end
  199.  
  200. RegisterUnitEvent(LichKingNPCID, 1, "ICC.VAR.OnEnterCombatStuff")
  201.  
  202. function ICC.VAR.OnWipeEvents(pUnit, Event)
  203.     local id = pUnit:GetInstanceID()
  204.     ICC[id] = ICC[id] or {VAR={}}
  205.     if not ICC[id].VAR.ForceWiped then -- it didn't wipe via fury of frostmourne
  206.         ICC[id].VAR.Lich:RemoveEvents()
  207.         if Event == 2 then
  208.             pUnit:Despawn(2000, 10000)
  209.         elseif Event == 4 then
  210.             -- He died
  211.         end
  212.     end
  213. end
  214.  
  215. RegisterUnitEvent(LichKingNPCID, 2, "ICC.VAR.OnWipeEvents")
  216. RegisterUnitEvent(LichKingNPCID, 4, "ICC.VAR.OnWipeEvents")
  217.  
  218. ------------------------------------------------------------------
  219. -- Death Cinematic -----------------------------------------------
  220. ------------------------------------------------------------------
  221.  
  222. function ICC.VAR.DeathCinematic_Lich(pUnit)
  223.     local id = pUnit:GetInstanceID()
  224.     if (ICC[id].VAR.i == 0) then
  225.         ICC[id].VAR.Tirion:SetUInt32Value(UNIT_FIELD_FLAGS, 2) -- Unattackable, used to prevent Tirion hitting LK during the Dragonball Z moment
  226.         ICC[id].VAR.Tirion:Root() -- Stop stop him resetting position
  227.         ICC[id].VAR.Lich:SendChatMessage(14,0,"No question remains unanswered. No doubts linger. You are Azeroth's greatest champions! You overcame every challenge I laid before you. My mightiest servants have fallen before your relentless onslaught, your unbridled fury...")
  228.         ICC[id].VAR.Lich:PlaySoundToSet(17353)
  229.         ICC[id].VAR.Lich:WipeTargetList() -- reset targets
  230.         ICC[id].VAR.Lich:SetFacing(0.01745329)
  231.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 25000, 1)
  232.     elseif (ICC[id].VAR.i == 1) then
  233.         ICC[id].VAR.Lich:SendChatMessage(14,0,"You trained them well, Fordring. You delivered the greatest fighting force this world has ever known... right into my hands -- exactly as I intended. You shall be rewarded for your unwitting sacrifice.")
  234.         ICC[id].VAR.Lich:PlaySoundToSet(17355) -- text
  235.         ICC[id].VAR.Lich:PlaySoundToSet(17460) -- final music
  236.         ICC[id].VAR.Lich:FullCastSpell(71769) -- visual to raise players
  237.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 24000, 1)
  238.     elseif (ICC[id].VAR.i == 2) then
  239.         ICC[id].VAR.Lich:SendChatMessage(14,0,"Watch now as I raise them from the dead to become masters of the Scourge. They will shroud this world in chaos and destruction. Azeroth's fall will come at their hands -- and you will be the first to die.")
  240.         ICC[id].VAR.Lich:PlaySoundToSet(17356)
  241.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 26000, 1)
  242.     elseif (ICC[id].VAR.i == 3) then
  243.         ICC[id].VAR.Lich:PlaySoundToSet(17357)
  244.         ICC[id].VAR.Lich:SendChatMessage(14,0,"I delight in the irony.", 0)
  245.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 6000, 1)
  246.     elseif (ICC[id].VAR.i == 4) then
  247.         ICC[id].VAR.Tirion:SendChatMessage(14,0,"LIGHT, GRANT ME ONE FINAL BLESSING. GIVE ME THE STRENGTH... TO SHATTER THESE BONDS!")
  248.         ICC[id].VAR.Tirion:PlaySoundToSet(17392)
  249.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 9000, 1)
  250.     elseif (ICC[id].VAR.i == 5) then
  251.         --ICC[id].VAR.Tirion:RemoveAura(71614) -- Ice block
  252.         ICC[id].VAR.Tirion:CastSpell(71797) -- Light visual
  253.         --ICC[id].VAR.Tirion:CastSpell(71614) -- IceBlock visual
  254.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 8000, 1)
  255.     elseif (ICC[id].VAR.i == 6) then
  256.         ICC[id].VAR.Tirion:RemoveAura(71614) -- Ice block
  257.         ICC[id].VAR.Tirion:EquipWeapons(50442, 0, 0) -- Glowing Ashbringer
  258.     end
  259.     ICC[id].VAR.i = ICC[id].VAR.i + 1
  260. end
  261.  
  262.  
  263.  
  264. ------------------------------------------------------------------
  265. -- Misc Stuff ----------------------------------------------------
  266. ------------------------------------------------------------------
  267.  
  268. -- Handle the ICC buffs and when to change worldstates
  269.  
  270. function ICC.VAR.OnZoneChange(event, player, zone, oldzone)
  271.     local race = player:GetPlayerRace()
  272.     if (zone == 4812) then
  273.         UpdateWorldstatesUI(player)
  274.         local id = player:GetInstanceID()
  275.         ICC[id] = ICC[id] or {VAR={}}
  276.         UpdateAttempts(player, id)
  277.         player:CastSpell(69127) -- Chill of the Throne
  278.         player:CastSpell(69127) -- Hack'y way of applying the correct aura types.
  279.         if (race == 1 or race == 3 or race == 4 or race == 7 or race == 11) then
  280.             player:CastSpell(73828) -- Strength of Wyrn
  281.         else
  282.             player:CastSpell(73822) -- Hellscreem's warsong
  283.         end
  284.     elseif (oldzone == 4812) then
  285.         ResetWorldstatesUI(player)
  286.         player:RemoveAura(69127) -- Chill of the Throne
  287.         if (race == 1 or race == 3 or race == 4 or race == 7 or race == 11) then
  288.             player:RemoveAura(73828) -- Strength of Wyrn
  289.         else
  290.             player:RemoveAura(73822) -- Hellscreem's warsong
  291.         end
  292.     end
  293. end
  294.  
  295. RegisterServerHook(15, "ICC.VAR.OnZoneChange")
  296.  
  297. -- Handle the worldstates
  298.  
  299. function UpdateWorldstatesUI(player)
  300.     local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18)
  301.     pack:WriteULong(631) -- Map
  302.     pack:WriteULong(4859) -- Zone
  303.     pack:WriteULong(0)
  304.     pack:WriteUShort(2)
  305.     pack:WriteULong(4940) -- ID
  306.     pack:WriteULong(1) -- Value
  307.     player:SendPacketToPlayer(pack)
  308. end
  309.  
  310. function UpdateAttempts(player, id)
  311.     if ICC[id].VAR.Attempts == nil then
  312.         ICC[id].VAR.Attempts = 20
  313.     end
  314.     local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  315.     pack:WriteULong(4941) -- ID, X/
  316.     pack:WriteULong(ICC[id].VAR.Attempts) -- Value
  317.     player:SendPacketToPlayer(pack)
  318.     local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  319.     pack:WriteULong(4942) -- ID, /X
  320.     pack:WriteULong(ICC[id].VAR.Attempts) -- Value
  321.     player:SendPacketToPlayer(pack)
  322. end
  323.  
  324. function ResetWorldstatesUI(player)
  325.     local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18)
  326.     pack:WriteULong(0) -- Map
  327.     pack:WriteULong(0) -- Zone
  328.     pack:WriteULong(0)
  329.     pack:WriteUShort(0)
  330.     pack:WriteULong(0) -- ID
  331.     pack:WriteULong(0) -- Value
  332.     player:SendPacketToPlayer(pack)
  333. end
  334.  
  335. ------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment