stoneharry

Untitled

Jul 28th, 2013
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 24.94 KB | None | 0 0
  1. --[[
  2. SET @CHESS := 68000;
  3.  
  4. INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `killcredit1`, `killcredit2`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `leader`)
  5. VALUES (@CHESS+0, "Chess Piece - White Pawn", "", '', '0', '10', '0', '0', '0', '0', '3526', '0', '0', '0', '1', '1', '0');
  6. INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`, `summonguard`)
  7. VALUES (@CHESS+0, '1', '1', '35', '1', '1', '0', '1', '0', '100', '0', '0', '0', '0', '0', '0', '0', '60000', '0', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '0', '0', '8.00', '8.00', '8.00', '0', '0', '0', '0', '0', '0', '0', '0');
  8.  
  9. INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `killcredit1`, `killcredit2`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `leader`)
  10. VALUES (@CHESS+1, "Chess Piece - White Tower", "", '', '0', '10', '0', '0', '0', '0', '525', '0', '0', '0', '1', '1', '0');
  11. INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`, `summonguard`)
  12. VALUES (@CHESS+1, '1', '1', '35', '1', '1', '0', '1', '0', '100', '0', '0', '0', '0', '0', '0', '0', '60000', '0', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '0', '0', '8.00', '8.00', '8.00', '0', '0', '0', '0', '0', '0', '0', '0');
  13.  
  14. INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `killcredit1`, `killcredit2`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `leader`)
  15. VALUES (@CHESS+2, "Chess Piece - White Knight", "", '', '0', '10', '0', '0', '0', '0', '3167', '0', '0', '0', '1', '1', '0');
  16. INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`, `summonguard`)
  17. VALUES (@CHESS+2, '1', '1', '35', '1', '1', '0', '1', '0', '100', '0', '0', '0', '0', '0', '0', '0', '60000', '0', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '0', '0', '8.00', '8.00', '8.00', '0', '0', '0', '0', '0', '0', '0', '0');
  18.  
  19. INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `killcredit1`, `killcredit2`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `leader`)
  20. VALUES (@CHESS+3, "Chess Piece - White Bishop", "", '', '0', '10', '0', '0', '0', '0', '5548', '0', '0', '0', '1', '1', '0');
  21. INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`, `summonguard`)
  22. VALUES (@CHESS+3, '1', '1', '35', '1', '1', '0', '1', '0', '100', '0', '0', '0', '0', '0', '0', '0', '60000', '0', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '0', '0', '8.00', '8.00', '8.00', '0', '0', '0', '0', '0', '0', '0', '0');
  23.  
  24. INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `killcredit1`, `killcredit2`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `leader`)
  25. VALUES (@CHESS+4, "Chess Piece - White Queen", "", '', '0', '10', '0', '0', '0', '0', '30863', '0', '0', '0', '1', '1', '0');
  26. INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`, `summonguard`)
  27. VALUES (@CHESS+4, '1', '1', '35', '1', '1', '0', '1', '0', '100', '0', '0', '0', '0', '0', '0', '0', '60000', '0', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '0', '0', '8.00', '8.00', '8.00', '0', '0', '0', '0', '0', '0', '0', '0');
  28.  
  29. INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `killcredit1`, `killcredit2`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `leader`)
  30. VALUES (@CHESS+5, "Chess Piece - White King", "", '', '0', '10', '0', '0', '0', '0', '28127', '0', '0', '0', '1', '1', '0');
  31. INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`, `summonguard`)
  32. VALUES (@CHESS+5, '1', '1', '35', '1', '1', '0', '1', '0', '100', '0', '0', '0', '0', '0', '0', '0', '60000', '0', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '0', '0', '8.00', '8.00', '8.00', '0', '0', '0', '0', '0', '0', '0', '0');
  33.  
  34. INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `killcredit1`, `killcredit2`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `leader`)
  35. VALUES (@CHESS+6, "Chess Piece - Black Pawn", "", '', '0', '10', '0', '0', '0', '0', '2141', '0', '0', '0', '1', '1', '0');
  36. INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`, `summonguard`)
  37. VALUES (@CHESS+6, '1', '1', '35', '1', '1', '0', '1', '0', '100', '0', '0', '0', '0', '0', '0', '0', '60000', '0', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '0', '0', '8.00', '8.00', '8.00', '0', '0', '0', '0', '0', '0', '0', '0');
  38.  
  39. INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `killcredit1`, `killcredit2`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `leader`)
  40. VALUES (@CHESS+7, "Chess Piece - Black Tower", "", '', '0', '10', '0', '0', '0', '0', '1405', '0', '0', '0', '1', '1', '0');
  41. INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`, `summonguard`)
  42. VALUES (@CHESS+7, '1', '1', '35', '1', '1', '0', '1.4', '0', '100', '0', '0', '0', '0', '0', '0', '0', '60000', '0', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '0', '0', '8.00', '8.00', '8.00', '0', '0', '0', '0', '0', '0', '0', '0');
  43.  
  44. INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `killcredit1`, `killcredit2`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `leader`)
  45. VALUES (@CHESS+8, "Chess Piece - Black Knight", "", '', '0', '10', '0', '0', '0', '0', '4602', '0', '0', '0', '1', '1', '0');
  46. INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`, `summonguard`)
  47. VALUES (@CHESS+8, '1', '1', '35', '1', '1', '0', '1', '0', '100', '0', '0', '0', '0', '0', '0', '0', '60000', '0', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '0', '0', '8.00', '8.00', '8.00', '0', '0', '0', '0', '0', '0', '0', '0');
  48.  
  49. INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `killcredit1`, `killcredit2`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `leader`)
  50. VALUES (@CHESS+9, "Chess Piece - Black Bishop", "", '', '0', '10', '0', '0', '0', '0', '17568', '0', '0', '0', '1', '1', '0');
  51. INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`, `summonguard`)
  52. VALUES (@CHESS+9, '1', '1', '35', '1', '1', '0', '1', '0', '100', '0', '0', '0', '0', '0', '0', '0', '60000', '0', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '0', '0', '8.00', '8.00', '8.00', '0', '0', '0', '0', '0', '0', '0', '0');
  53.  
  54. INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `killcredit1`, `killcredit2`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `leader`)
  55. VALUES (@CHESS+10, "Chess Piece - Black Queen", "", '', '0', '10', '0', '0', '0', '0', '28213', '0', '0', '0', '1', '1', '0');
  56. INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`, `summonguard`)
  57. VALUES (@CHESS+10, '1', '1', '35', '1', '1', '0', '1', '0', '100', '0', '0', '0', '0', '0', '0', '0', '60000', '0', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '0', '0', '8.00', '8.00', '8.00', '0', '0', '0', '0', '0', '0', '0', '0');
  58.  
  59. INSERT INTO `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `killcredit1`, `killcredit2`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `leader`)
  60. VALUES (@CHESS+11, "Chess Piece - Black King", "", '', '0', '10', '0', '0', '0', '0', '27744', '0', '0', '0', '1', '1', '0');
  61. INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`, `summonguard`)
  62. VALUES (@CHESS+11, '1', '1', '35', '1', '1', '0', '1', '0', '100', '0', '0', '0', '0', '0', '0', '0', '60000', '0', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '0', '0', '8.00', '8.00', '8.00', '0', '0', '0', '0', '0', '0', '0', '0');
  63. ]]
  64. --------------------------------------------------------
  65. -- Variable setup
  66. --------------------------------------------------------
  67.  
  68. local CHESS_ENTRY_START = 68000
  69. local gameInProgress = false
  70. local grid_npc = {}
  71. local grid_obj = {}
  72. local a_npcs = {}
  73. local h_npcs = {}
  74. local current_npc = nil
  75. local TURN = false
  76. local clock = os.clock()
  77.  
  78. -- Format entry Id's: Castle, Bishop, Knight, King, Queen, Knight, Bishop, Castle, Pawn
  79. local alliance_creatures = {CHESS_ENTRY_START + 1, CHESS_ENTRY_START + 3, CHESS_ENTRY_START + 2,
  80.                             CHESS_ENTRY_START + 5, CHESS_ENTRY_START + 4, CHESS_ENTRY_START + 2,
  81.                             CHESS_ENTRY_START + 3, CHESS_ENTRY_START + 1, CHESS_ENTRY_START}
  82. local horde_creatures = {CHESS_ENTRY_START + 7, CHESS_ENTRY_START + 9, CHESS_ENTRY_START + 8,
  83.                         CHESS_ENTRY_START + 11, CHESS_ENTRY_START + 10, CHESS_ENTRY_START + 8,
  84.                         CHESS_ENTRY_START + 9, CHESS_ENTRY_START + 7, CHESS_ENTRY_START + 6}
  85. -- Creature entry ID's and what they are
  86. local creature_index = {[CHESS_ENTRY_START + 1] = "a_castle",
  87.                         [CHESS_ENTRY_START + 7] = "h_castle",
  88.                         [CHESS_ENTRY_START + 3] = "a_bishop",
  89.                         [CHESS_ENTRY_START + 9] = "h_bishop",
  90.                         [CHESS_ENTRY_START + 2] = "a_knight",
  91.                         [CHESS_ENTRY_START + 8] = "h_knight",
  92.                         [CHESS_ENTRY_START + 4] = "a_queen",
  93.                         [CHESS_ENTRY_START + 10] = "h_queen",
  94.                         [CHESS_ENTRY_START + 5] = "a_king",
  95.                         [CHESS_ENTRY_START + 11] = "h_king",
  96.                         [CHESS_ENTRY_START + 0] = "a_pawn",
  97.                         [CHESS_ENTRY_START + 6] = "h_pawn"}
  98.  
  99. --------------------------------------------------------
  100. -- Event triggering (toggle)
  101. --------------------------------------------------------
  102.  
  103. function chesschat(event, plr, message, mtype, language)
  104.     if message == "#chess" and plr:IsGm() then
  105.         if gameInProgress then
  106.             plr:SendBroadcastMessage("Ending chess.")
  107.             DespawnChess()
  108.         else
  109.             plr:SendBroadcastMessage("Starting chess.")
  110.             SpawnChess(plr)
  111.         end
  112.         return false
  113.     end
  114. end
  115.  
  116. RegisterServerHook(16, "chesschat")
  117.  
  118. --------------------------------------------------------
  119. -- Spawn/Despawn grid
  120. --------------------------------------------------------
  121.  
  122. function SpawnChess(pUnit)
  123.     if not pUnit then
  124.         return
  125.     end
  126.     if gameInProgress then
  127.         pUnit:SendBroadcastMessage("Game is in progress - try again later.")
  128.         return
  129.     end
  130.     gameInProgress = true
  131.     local x = pUnit:GetX()
  132.     local y = pUnit:GetY()
  133.     local z = pUnit:GetZ()
  134.     local i, j
  135.     local a = 0
  136.     local b = 0
  137.     for i=0,35,5 do
  138.         a = a + 1
  139.         table.insert(a_npcs, pUnit:SpawnCreature(alliance_creatures[a], x+i, y, z+0.1, 1.5, 35, 0))
  140.         for j=0,35,5 do
  141.             if j == 5 then
  142.                 table.insert(a_npcs, pUnit:SpawnCreature(alliance_creatures[9], x+i, y+j, z+0.1, 1.5, 35, 0))
  143.             elseif j == 30 then
  144.                 table.insert(h_npcs, pUnit:SpawnCreature(horde_creatures[9], x+i, y+j, z+0.1, 4.7, 35, 0))
  145.             elseif j == 35 then
  146.                 b = b + 1
  147.                 table.insert(h_npcs, pUnit:SpawnCreature(horde_creatures[b], x+i, y+j, z+0.1, 4.7, 35, 0))
  148.             end
  149.             table.insert(grid_npc, pUnit:SpawnCreature(28816, x+i, y+j, z, 0, 35, 0))
  150.             table.insert(grid_obj, pUnit:SpawnGameObject(185301, x+i, y+j, z-0.21, 0, 0, 100))
  151.         end
  152.     end
  153. end
  154.  
  155. function DespawnChess()
  156.     for _,v in ipairs(grid_npc) do
  157.         if v then
  158.             v:Despawn(1,0)
  159.         end
  160.     end
  161.     for _,v in ipairs(grid_obj) do
  162.         if v then
  163.             v:Despawn(1,0)
  164.         end
  165.     end
  166.     for _,v in ipairs(a_npcs) do
  167.         if v then
  168.             v:Despawn(1,0)
  169.         end
  170.     end
  171.     for _,v in ipairs(h_npcs) do
  172.         if v then
  173.             v:Despawn(1,0)
  174.         end
  175.     end
  176.     grid_npc = {}
  177.     grid_obj = {}
  178.     a_npcs = {}
  179.     h_npcs = {}
  180.     gameInProgress = false
  181.     current_npc = nil
  182.     TURN = false
  183. end
  184.  
  185. --------------------------------------------------------
  186. -- Utility
  187. --------------------------------------------------------
  188.  
  189. function IsHordeCreature(entry)
  190.     for _,v in pairs(horde_creatures) do
  191.         if v == entry then
  192.             return true
  193.         end
  194.     end
  195.     return false
  196. end
  197.  
  198. function IsAllianceCreature(entry)
  199.     for _,v in pairs(alliance_creatures) do
  200.         if v == entry then
  201.             return true
  202.         end
  203.     end
  204.     return false
  205. end
  206.  
  207. function checkValidTile(pUnit)
  208.     if pUnit:HasAura(50236) then
  209.         return true
  210.     end
  211.     local u = pUnit:GetClosestFriend()
  212.     if u then
  213.         if u:GetDistanceYards(pUnit) > 2 then
  214.             pUnit:CastSpell(50236) -- light beam
  215.             return true
  216.         end
  217.     end
  218.     return false
  219. end
  220.  
  221. function AttackTile(pUnit, _x, _y, kill)
  222.     local z = pUnit:GetZ()
  223.     local npc = nil
  224.     if (IsAllianceCreature(pUnit:GetEntry())) then
  225.         for _,v in pairs(horde_creatures) do
  226.             npc = pUnit:GetCreatureNearestCoords(_x, _y, z, v)
  227.             if npc and npc:GetDistanceYards(pUnit) < 7 then
  228.                 pUnit:SendChatMessage(12,0,"pUnit = "..pUnit:GetName().." | npc = "..npc:GetName())
  229.                 if kill then
  230.                     pUnit:Kill(npc)
  231.                     break
  232.                 end
  233.                 npc = pUnit:GetCreatureNearestCoords(_x, _y, z, 28816)
  234.                 if npc then
  235.                     npc:CastSpell(62296)
  236.                 end
  237.                 break
  238.             end
  239.         end
  240.         return
  241.     end
  242.     for _,v in pairs(alliance_creatures) do
  243.         npc = pUnit:GetCreatureNearestCoords(_x, _y, z, v)
  244.         if npc and npc:GetDistanceYards(pUnit) < 7 then
  245.             pUnit:SendChatMessage(12,0,"pUnit = "..pUnit:GetName().." | npc = "..npc:GetName())
  246.             if kill then
  247.                 pUnit:Kill(npc)
  248.                 break
  249.             end
  250.             npc = pUnit:GetCreatureNearestCoords(_x, _y, z, 28816)
  251.             if npc then
  252.                 npc:CastSpell(62296)
  253.             end
  254.             break
  255.         end
  256.     end
  257. end
  258.  
  259. --------------------------------------------------------
  260. -- Moving a piece
  261. --------------------------------------------------------
  262.  
  263. function Chess_Piece_Move(pUnit)
  264.     if os.clock() - clock < 5 then
  265.         return
  266.     end
  267.     local plr = pUnit:GetClosestPlayer()
  268.     if not plr then
  269.         return
  270.     end
  271.     if plr:GetDistanceYards(pUnit) > 1.5 then
  272.         return
  273.     end
  274.     if IsAllianceCreature(pUnit:GetEntry()) then
  275.         if TURN then
  276.             plr:SendBroadcastMessage("It isn't your turn.")
  277.             return
  278.         end
  279.     end
  280.     if IsHordeCreature(pUnit:GetEntry()) then
  281.         if not TURN then
  282.             plr:SendBroadcastMessage("It isn't your turn.")
  283.             return
  284.         end
  285.     end
  286.     -- Flags for stationary creatures, instead see the clock replacement
  287.     --[[local _c = pUnit:GetInRangeUnits()
  288.     for _,v in ipairs(_c) do
  289.         if IsAllianceCreature(v:GetEntry()) or IsHordeCreature(v:GetEntry()) then
  290.             if v:IsCreatureMoving() then
  291.                 pUnit:SendChatMessage(12,0,v:GetName().." is moving!")
  292.                 return
  293.             end
  294.         end
  295.     end]]
  296.     if current_npc then
  297.         if current_npc:GetX() ~= pUnit:GetX() then
  298.             current_npc:RemoveAura(50236) -- light beam
  299.             --for _,v in pairs(grid_npc) do
  300.             for _,v in pairs(pUnit:GetInRangeUnits()) do
  301.                 v:RemoveAura(50236)
  302.             end
  303.         end
  304.     end
  305.     current_npc = pUnit
  306.     pUnit:CastSpell(50236) -- light beam visual
  307.     ------------------------------------------------
  308.     -- Handle where this unit can move
  309.     ------------------------------------------------
  310.     local piece = creature_index[pUnit:GetEntry()]
  311.     if not piece then
  312.         pUnit:SendChatMessage(12,0,"ERROR: I am not handled. creature_index{} needs populating.")
  313.         return
  314.     end
  315.     if piece == "h_king" or piece == "a_king" then
  316.         king_move(pUnit)
  317.     elseif piece == "a_pawn" or piece == "h_pawn" then
  318.         pawn_move(pUnit)
  319.     end
  320. end
  321.  
  322. function GridNPCSpawn(pUnit, Event)
  323.     pUnit:SetUInt32Value(0x0006+0x0035, 0x02000000) -- untargetable
  324.     pUnit:RegisterEvent("CheckPlayerComeAtMe", 1000, 0)
  325. end
  326.  
  327. function CheckPlayerComeAtMe(pUnit)
  328.     if not pUnit:HasAura(50236) and not pUnit:HasAura(62296) then
  329.         return
  330.     end
  331.     local plr = pUnit:GetClosestPlayer()
  332.     if not plr then
  333.         return
  334.     end
  335.     if plr:GetDistanceYards(pUnit) > 1.5 then
  336.         return
  337.     end
  338.     if current_npc then
  339.         current_npc:RemoveAura(50236) -- light beam
  340.         current_npc:SetValue("move", 1)
  341.         if pUnit:HasAura(62296) then
  342.             AttackTile(pUnit, pUnit:GetX(), pUnit:GetY(), true)
  343.             current_npc:SetMovementFlags(1)
  344.             pUnit:RemoveAura(62296)
  345.         end
  346.         current_npc:MoveTo(pUnit:GetX(), pUnit:GetY(), pUnit:GetZ(), 0) -- orientation should be handled
  347.         for _,v in pairs(grid_npc) do
  348.             v:RemoveAura(50236)
  349.             v:RemoveAura(62296)
  350.         end
  351.         TURN = not TURN
  352.         clock = os.clock()
  353.     end
  354. end
  355.  
  356. RegisterUnitEvent(28816, 18, "GridNPCSpawn")
  357.  
  358. --------------------------------------------------------
  359. -- Pawn movement
  360. --------------------------------------------------------
  361.  
  362. function pawn_move(pUnit)
  363.     local x, y, z = pUnit:GetX(), pUnit:GetY(), pUnit:GetZ()
  364.     local movetwo = pUnit:GetValue("move")
  365.     local allowed = false
  366.  
  367.     -- Alliance pawn movement
  368.     if IsAllianceCreature(pUnit:GetEntry()) then
  369.         -- Movement
  370.         local n = pUnit:GetCreatureNearestCoords(x, y+5, z, 28816)
  371.         if n then
  372.             allowed = checkValidTile(n)
  373.         end
  374.         if allowed then
  375.             if movetwo == nil then
  376.                 n = pUnit:GetCreatureNearestCoords(x, y+10, z, 28816)
  377.                 if n then
  378.                     checkValidTile(n)
  379.                 end
  380.             end
  381.         end
  382.         current_npc = pUnit
  383.         -- Taking pieces
  384.         AttackTile(pUnit, x+5, y+5, false)
  385.         AttackTile(pUnit, x-5, y+5, false)
  386.         return
  387.     end
  388.     -- Horde pawn movement
  389.     -- Movement
  390.     local n = pUnit:GetCreatureNearestCoords(x, y-5, z, 28816)
  391.     if n then
  392.         allowed = checkValidTile(n)
  393.     end
  394.     if allowed then
  395.         if movetwo == nil then
  396.             n = pUnit:GetCreatureNearestCoords(x, y-10, z, 28816)
  397.             if n then
  398.                 checkValidTile(n)
  399.             end
  400.         end
  401.     end
  402.     current_npc = pUnit
  403.     -- Taking pieces
  404.     AttackTile(pUnit, x+5, y-5, false)
  405.     AttackTile(pUnit, x-5, y-5, false)
  406. end
  407.  
  408. --------------------------------------------------------
  409. -- King movement
  410. --------------------------------------------------------
  411.  
  412. function king_move(pUnit)
  413.     local x, y, z = pUnit:GetX(), pUnit:GetY(), pUnit:GetZ()
  414.     local n = pUnit:GetCreatureNearestCoords(x+5, y, z, 28816)
  415.     if n then
  416.         checkValidTile(n)
  417.     end
  418.     n = pUnit:GetCreatureNearestCoords(x-5, y, z, 28816)
  419.     if n then
  420.         checkValidTile(n)
  421.     end
  422.     n = pUnit:GetCreatureNearestCoords(x, y+5, z, 28816)
  423.     if n then
  424.         checkValidTile(n)
  425.     end
  426.     n = pUnit:GetCreatureNearestCoords(x, y-5, z, 28816)
  427.     if n then
  428.         checkValidTile(n)
  429.     end
  430.     current_npc = pUnit
  431. end
  432.  
  433. --------------------------------------------------------
  434. -- Piece events (spawn)
  435. --------------------------------------------------------
  436.  
  437. function PieceSpawn(pUnit, Event)
  438.     pUnit:RegisterEvent("Chess_Piece_Move", 1000, 0)
  439.     local piece = creature_index[pUnit:GetEntry()]
  440.     if piece == "a_knight" or piece == "h_knight" then
  441.         pUnit:RegisterEvent("MountUpKnight_Piece", 1000, 1)
  442.     end
  443. end
  444.  
  445. function MountUpKnight_Piece(pUnit)
  446.     local piece = creature_index[pUnit:GetEntry()]
  447.     if piece == "a_knight" then
  448.         pUnit:SetMount(14337)
  449.     else
  450.         pUnit:SetMount(14334)
  451.     end
  452. end
  453.  
  454. local m
  455. for m=1,#alliance_creatures do
  456.     RegisterUnitEvent(alliance_creatures[m], 18, "PieceSpawn")
  457. end
  458. for m=1,#horde_creatures do
  459.     RegisterUnitEvent(horde_creatures[m], 18, "PieceSpawn")
  460. end
  461. m = nil
Advertisement
Add Comment
Please, Sign In to add comment