stoneharry

Untitled

Apr 30th, 2011
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.63 KB | None | 0 0
  1. -- Variable declaration and generally setting up the script
  2. --?!MAP= 631
  3.  
  4. local TirionNPCID = 38995
  5. local LichKingNPCID = 36597
  6.  
  7. -- For 3.3.5a
  8. local OBJECT_END = 0x0006
  9. local UNIT_NPC_FLAGS = OBJECT_END + 0x004C
  10. local UNIT_FIELD_FLAGS = OBJECT_END + 0x0035
  11. local UNIT_FIELD_BYTES_1 = OBJECT_END + 0x0044
  12. local UNIT_FLAG_NOT_SELECTABLE = 0x02000000
  13. local SMSG_INIT_WORLD_STATES = 0x2C2
  14. local SMSG_UPDATE_WORLD_STATE = 0x2C3
  15.  
  16. -- Unconfigurable Variables
  17.  
  18. local CheckForStart
  19. local WalkTowardsLichKingThenEmotes
  20. local SetBytesAndHandleVariable
  21. local KeepMoving
  22. local KillAll
  23. local CheckForFinalPhase
  24.  
  25. ICC = {}
  26. ICC.VAR = {}
  27.  
  28. ------------------------------------------------------------------
  29. -- The gossip used to start the encounter - Tirion ---------------
  30. -- Also set up events etc ----------------------------------------
  31. ------------------------------------------------------------------
  32.  
  33. local function OnGossipTalk(pUnit, Event, player)
  34.     local menu = GossipMenu(pUnit, 2975252, 1)
  35.     menu:AddItem(9, "We are prepared, Highlord. Let us battle for the fate of Azeroth! For the light of dawn!", 1, false)
  36.     menu:AddItem(0, "We are not yet prepared, Highlord.", 2, false)
  37.     menu:Send(player)
  38. end
  39.  
  40. local function OnGossipSelect(pUnit, Event, player, id, code)
  41.     if (id == 1) then
  42.         local id = MapMgr:GetInstanceID()
  43.         ICC[id] = ICC[id] or {VAR={}}
  44.         ICC[id].VAR.Tirion = pUnit
  45.         ICC[id].VAR.Ready = true
  46.         ICC[id].VAR.Tirion:SetUInt32Value(UNIT_NPC_FLAGS, 2) -- Quest flags disable gossip
  47.         ICC[id].VAR.Tirion:SetUInt32Value(UNIT_FIELD_FLAGS, 2) -- Unattackable, used to prevent LK hitting him instead of players
  48.         -- Gossip complete
  49.     elseif (id == 2) then
  50.         -- Gossip complete
  51.     end
  52. end
  53.  
  54. RegisterUnitGossipEvent(TirionNPCID, 1, OnGossipTalk)
  55. RegisterUnitGossipEvent(TirionNPCID, 2, OnGossipSelect)
  56.  
  57. local function OnSpawnHandleStart(pUnit, Event)
  58.     pUnit:SetUInt32Value(UNIT_NPC_FLAGS, 1) -- Gossip Flags, for when the fight resets
  59.     pUnit:RegisterEvent(CheckForStart, 2500, 1) -- Setting repeat to 0 only calls once for some reason
  60. end
  61.  
  62. RegisterUnitEvent(TirionNPCID, 18, OnSpawnHandleStart)
  63.  
  64. local function OnSpawnHandleDefineAndBytes(pUnit, Event)
  65.     pUnit:RegisterEvent(SetBytesAndHandleVariable, 2000, 1)
  66. end
  67.  
  68. function SetBytesAndHandleVariable(pUnit)
  69.     local id = MapMgr:GetInstanceID()
  70.     ICC[id] = ICC[id] or {VAR={}}
  71.     ICC[id].VAR.Lich = pUnit
  72.     ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_BYTES_1, 1) -- Sit on the throne
  73.     ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_FLAGS, 2) -- Unattackable
  74. end
  75.  
  76. RegisterUnitEvent(LichKingNPCID, 18, OnSpawnHandleDefineAndBytes)
  77.  
  78. ------------------------------------------------------------------
  79. -- Mini-cinematic at the start -----------------------------------
  80. ------------------------------------------------------------------
  81.  
  82. function CheckForStart(pUnit)
  83.     local id = MapMgr:GetInstanceID()
  84.     ICC[id] = ICC[id] or {VAR={}}
  85.     if (ICC[id].VAR.Ready and ICC[id].VAR.Lich ~= nil) then
  86.         ICC[id].VAR.Ready = false
  87.         ICC[id].VAR.i = 0
  88.         ICC[id].VAR.Tirion:GetAIInterface():MoveTo(489.14, -2124.45, 1040.9, 0) -- Closer to LK
  89.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 7500, 1)
  90.     else
  91.         pUnit:RegisterEvent(CheckForStart, 2500, 1)
  92.     end
  93. end
  94.  
  95. function WalkTowardsLichKingThenEmotes(pUnit)
  96.     local id = MapMgr:GetInstanceID()
  97.     if (ICC[id].VAR.i == 0) then
  98.         ICC[id].VAR.Tirion:EventAddEmote(375, 58500)
  99.         ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_BYTES_1, 0) -- Stand up
  100.         PlaySoundToSet(ICC[id].VAR.Tirion, 17349) -- Voice of message - Tirion since players are closer to him
  101.         PlaySoundToSet(ICC[id].VAR.Tirion, 17457) -- The music for this point
  102.         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?", 0)
  103.         ICC[id].VAR.Lich:GetAIInterface():StopMovement(0) -- Resets bytes bug
  104.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 4000, 1)
  105.     elseif (ICC[id].VAR.i == 1) then
  106.         ICC[id].VAR.Lich:GetAIInterface():StopMovement(0) -- Resets bytes bug
  107.         ICC[id].VAR.Lich:GetAIInterface():MoveTo(457.44, -2123.86, 1041.2, 0) -- Down from throne to floor
  108.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 10000, 1)
  109.     elseif (ICC[id].VAR.i == 2) then
  110.         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.", 0)
  111.         PlaySoundToSet(ICC[id].VAR.Tirion, 17390)
  112.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 2000, 1)
  113.     elseif (ICC[id].VAR.i == 3) then
  114.         ICC[id].VAR.Lich:GetAIInterface():MoveTo(462.01, -2124.146, 1040.9, 0) -- Forwards slightly to correct position
  115.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 8500, 1)
  116.     elseif (ICC[id].VAR.i == 4) then
  117.         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.", 0)
  118.         PlaySoundToSet(ICC[id].VAR.Tirion, 17350)
  119.         ICC[id].VAR.Lich:EventAddEmote(397, 4000)
  120.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 4500, 1)
  121.     elseif (ICC[id].VAR.i == 5) then
  122.         ICC[id].VAR.Lich:EventAddEmote(1, 6000)
  123.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 12000, 1)
  124.     elseif (ICC[id].VAR.i == 6) then
  125.         ICC[id].VAR.Lich:EventAddEmote(392, 3500)
  126.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 7500, 1)
  127.     elseif (ICC[id].VAR.i == 7) then
  128.         ICC[id].VAR.Tirion:SendChatMessage(14,0,"So be it. Champions, attack!", 0)
  129.         PlaySoundToSet(ICC[id].VAR.Tirion, 17391)
  130.         ICC[id].VAR.Tirion:EventAddEmote(397, 2000)
  131.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 2000, 1)
  132.     elseif (ICC[id].VAR.i == 8) then
  133.         ICC[id].VAR.Tirion:GetAIInterface():setMoveRunFlag(true)
  134.         ICC[id].VAR.Tirion:GetAIInterface():MoveTo(472.88, -2124.2, 1040.9, 0) -- Run towards LK
  135.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 1000, 1)
  136.     elseif (ICC[id].VAR.i == 9) then
  137.         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.", 0)
  138.         PlaySoundToSet(ICC[id].VAR.Tirion, 17351)
  139.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 500, 1)
  140.     elseif (ICC[id].VAR.i == 10) then
  141.         ICC[id].VAR.Lich:CastSpell(ICC[id].VAR.Tirion, 71614, false) -- Freeze
  142.         ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_FLAGS, 0) -- Attackable
  143.     end
  144.     ICC[id].VAR.i = ICC[id].VAR.i + 1
  145. end
  146.  
  147. ------------------------------------------------------------------
  148. -- The Fight -----------------------------------------------------
  149. ------------------------------------------------------------------
  150.  
  151. local function OnEnterCombatStuff(pUnit, Event)
  152.     local id = MapMgr:GetInstanceID()
  153.     -- This will only be nil if one enters combat with the lich king in less than 2.5 seconds of spawn
  154.     ICC[id].VAR.Lich:RegisterEvent(CheckForFinalPhase, 2500, 1) -- Repeat 0 only checks once for some reason
  155. end
  156.  
  157. function CheckForFinalPhase(pUnit)
  158.     local id = MapMgr:GetInstanceID()
  159.     if (ICC[id].VAR.Lich:GetHealthPct() < 11) then
  160.         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!", 0)
  161.         PlaySoundToSet(ICC[id].VAR.Lich, 17359)
  162.         ICC[id].VAR.Lich:GetAIInterface():setMoveRunFlag(true)
  163.         ICC[id].VAR.Lich:GetAIInterface():MoveTo(505.212, -2124.35, 1040.95, 0) -- Center of the room
  164.         ICC[id].VAR.Lich:RegisterEvent(KeepMoving, 250, 20)
  165.         ICC[id].VAR.Lich:RegisterEvent(KillAll, 5005, 1)
  166.     else
  167.         ICC[id].VAR.Lich:RegisterEvent(CheckForFinalPhase, 2500, 1)
  168.     end
  169. end
  170.  
  171. function KeepMoving(pUnit)
  172.     local id = MapMgr:GetInstanceID()
  173.     ICC[id].VAR.Lich:GetAIInterface():MoveTo(505.212, -2124.35, 1040.95, 0) -- Center of the room
  174. end
  175.  
  176. function KillAll(pUnit)
  177.     local id = MapMgr:GetInstanceID()
  178.     ICC[id].VAR.Lich:GetAIInterface():StopMovement(120000)
  179.     ICC[id].VAR.Lich:CastSpell(ICC[id].VAR.Lich, 70063, false) -- Wipe the raid - fury of frostmourne
  180. end
  181.  
  182. RegisterUnitEvent(LichKingNPCID, 1, OnEnterCombatStuff)
  183.  
  184. ------------------------------------------------------------------
  185. -- Misc Stuff ----------------------------------------------------
  186. ------------------------------------------------------------------
  187.  
  188. -- Handle the ICC buffs and when to change worldstates
  189.  
  190. local function OnZoneChange(event, player, zone, oldzone)
  191.     local race = player:getRace()
  192.     if (zone == 4812) then
  193.         UpdateWorldstatesUI(player)
  194.         local id = MapMgr:GetInstanceID()
  195.         ICC[id] = ICC[id] or {VAR={}}
  196.         UpdateAttempts(player, id)
  197.         player:CastSpell(player, 69127, true) -- Chill of the Throne
  198.         player:CastSpell(player, 69127, true) -- Hack'y way of applying the correct aura types.
  199.         if (race == 1 or race == 3 or race == 4 or race == 7 or race == 11) then
  200.             player:CastSpell(player, 73828, true) -- Strength of Wyrn
  201.         else
  202.             player:CastSpell(player, 73822, true) -- Hellscreem's warsong
  203.         end
  204.     elseif (oldzone == 4812) then
  205.         ResetWorldstatesUI(player)
  206.         player:RemoveAura(69127) -- Chill of the Throne
  207.         if (race == 1 or race == 3 or race == 4 or race == 7 or race == 11) then
  208.             player:RemoveAura(73828) -- Strength of Wyrn
  209.         else
  210.             player:RemoveAura(73822) -- Hellscreem's warsong
  211.         end
  212.     end
  213. end
  214.  
  215. RegisterServerHook(15, OnZoneChange)
  216.  
  217. -- Playing sounds to set
  218.  
  219. function PlaySoundToSet(object, ID)
  220.     local pack = LuaPacket(722, 4)
  221.     pack:WriteUint32(ID)
  222.     object:SendMessageToSet(pack, true)
  223. end
  224.  
  225. -- Handle the worldstates
  226.  
  227. function UpdateWorldstatesUI(player)
  228.     local pack = LuaPacket(SMSG_INIT_WORLD_STATES, 18)
  229.     pack:WriteUint32(631) -- Map
  230.     pack:WriteUint32(4859) -- Zone
  231.     pack:WriteUint32(0)
  232.     pack:WriteUInt16(2)
  233.     pack:WriteUint32(4940) -- ID
  234.     pack:WriteUint32(1) -- Value
  235.     TO_PLAYER(player):SendPacket(pack)
  236. end
  237.  
  238. function UpdateAttempts(player, id)
  239.     if ICC[id].VAR.Attempts == nil then
  240.         ICC[id].VAR.Attempts = 20
  241.     end
  242.     local pack = LuaPacket(SMSG_UPDATE_WORLD_STATE, 8)
  243.     pack:WriteUint32(4941) -- ID, X/
  244.     pack:WriteUint32(ICC[id].VAR.Attempts) -- Value
  245.     player:SendPacket(pack)
  246.     local pack = LuaPacket(SMSG_UPDATE_WORLD_STATE, 8)
  247.     pack:WriteUint32(4942) -- ID, /X
  248.     pack:WriteUint32(ICC[id].VAR.Attempts) -- Value
  249.     TO_PLAYER(player):SendPacket(pack)
  250. end
  251.  
  252. function ResetWorldstatesUI(player)
  253.     local pack = LuaPacket(SMSG_INIT_WORLD_STATES, 18)
  254.     pack:WriteUint32(0) -- Map
  255.     pack:WriteUint32(0) -- Zone
  256.     pack:WriteUint32(0)
  257.     pack:WriteUint16(0)
  258.     pack:WriteUint32(0) -- ID
  259.     pack:WriteUint32(0) -- Value
  260.     TO_PLAYER(player):SendPacket(pack)
  261. end
  262.  
  263. ------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment