EnzzoCaaue

arenaSvargrondQuest.lua

Feb 4th, 2015
21,702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.65 KB | None | 0 0
  1. --[[
  2.     TODO
  3.         - Include PITS and ARENA table in SvargrondArena -> SvargrondArena.arenas / SvargrondArena.pits
  4.         - Restructure PITS and ARENA table (reward.storage does not seem to be used)
  5. ]]
  6.  
  7. SvargrondArena = {
  8.     -- action ids have to be equal to action id of reward doors
  9.     actionGreenhorn = 26100,
  10.     actionScrapper = 27100,
  11.     actionWarlord = 28100,
  12.  
  13.     -- kick time in seconds (10 minutes)
  14.     kickTime = 600,
  15.     kickPosition = Position(32251, 31098, 6),
  16.     rewardPosition = Position(32222, 31080, 6),
  17.  
  18.     -- used to store event ids
  19.     kickEvents = {},
  20.     timerEvents = {},
  21.     effectPositionCache = {},
  22.  
  23.     -- item ids used by the script
  24.     itemTimer = 10288,
  25.     itemPillar = 1354,
  26.     itemTeleport = 5023,
  27.     itemsNotErasable = {10288, 1354, 1543, 1544, 1545},
  28. }
  29.  
  30. -- Script automatically derives other pit positions from this one
  31. local firstPit = {
  32.     fromPos = {x = 32205, y = 31094, z = 7},
  33.     toPos = {x = 32214, y = 31103, z = 7},
  34.     center = {x = 32210, y = 31098, z = 7},
  35.     pillar = {x = 32204, y = 31098, z = 7},
  36.     tp = {x = 32204, y = 31098, z = 7},
  37.     summon = {x = 32210, y = 31100, z = 7}
  38. }
  39.  
  40. PITS = {
  41.     [1] = {
  42.         fromPos = firstPit.fromPos,
  43.         toPos = firstPit.toPos,
  44.         center = firstPit.center,
  45.         pillar = firstPit.pillar,
  46.         tp = firstPit.tp,
  47.         summon = firstPit.summon
  48.     },
  49.     [2] = {
  50.         fromPos = {x = firstPit.fromPos.x - 14, y = firstPit.fromPos.y, z = firstPit.fromPos.z},
  51.         toPos = {x = firstPit.toPos.x - 14, y = firstPit.toPos.y, z = firstPit.toPos.z},
  52.         center = {x = firstPit.center.x - 14, y = firstPit.center.y, z = firstPit.center.z},
  53.         pillar = {x = firstPit.pillar.x - 14, y = firstPit.pillar.y, z = firstPit.pillar.z},
  54.         tp = {x = firstPit.tp.x - 14, y = firstPit.tp.y, z = firstPit.tp.z},
  55.         summon = {x = firstPit.summon.x - 14, y = firstPit.summon.y, z = firstPit.summon.z}
  56.     },
  57.     [3] = {
  58.         fromPos = {x = firstPit.fromPos.x - 28, y = firstPit.fromPos.y, z = firstPit.fromPos.z},
  59.         toPos = {x = firstPit.toPos.x - 28, y = firstPit.toPos.y, z = firstPit.toPos.z},
  60.         center = {x = firstPit.center.x - 28, y = firstPit.center.y, z = firstPit.center.z},
  61.         pillar = {x = firstPit.pillar.x - 28, y = firstPit.pillar.y, z = firstPit.pillar.z},
  62.         tp = {x = firstPit.tp.x - 28, y = firstPit.tp.y, z = firstPit.tp.z},
  63.         summon = {x = firstPit.summon.x - 28, y = firstPit.summon.y, z = firstPit.summon.z}
  64.     },
  65.     [4] = {
  66.         fromPos = {x = firstPit.fromPos.x - 42, y = firstPit.fromPos.y, z = firstPit.fromPos.z},
  67.         toPos = {x = firstPit.toPos.x - 42, y = firstPit.toPos.y, z = firstPit.toPos.z},
  68.         center = {x = firstPit.center.x - 42, y = firstPit.center.y, z = firstPit.center.z},
  69.         pillar = {x = firstPit.pillar.x - 42, y = firstPit.pillar.y, z = firstPit.pillar.z},
  70.         tp = {x = firstPit.tp.x - 42, y = firstPit.tp.y, z = firstPit.tp.z},
  71.         summon = {x = firstPit.summon.x - 42, y = firstPit.summon.y, z = firstPit.summon.z}
  72.     },
  73.     [5] = {
  74.         fromPos = {x = firstPit.fromPos.x - 35, y = firstPit.fromPos.y - 14, z = firstPit.fromPos.z},
  75.         toPos = {x = firstPit.toPos.x - 35, y = firstPit.toPos.y - 14, z = firstPit.toPos.z},
  76.         center = {x = firstPit.center.x - 35, y = firstPit.center.y - 14, z = firstPit.center.z},
  77.         pillar = {x = firstPit.pillar.x - 35, y = firstPit.pillar.y - 14, z = firstPit.pillar.z},
  78.         tp = {x = firstPit.tp.x - 35, y = firstPit.tp.y - 14, z = firstPit.tp.z},
  79.         summon = {x = firstPit.summon.x - 35, y = firstPit.summon.y - 14, z = firstPit.summon.z}
  80.     },
  81.     [6] = {
  82.         fromPos = {x = firstPit.fromPos.x - 21, y = firstPit.fromPos.y - 14, z = firstPit.fromPos.z},
  83.         toPos = {x = firstPit.toPos.x - 21, y = firstPit.toPos.y - 14, z = firstPit.toPos.z},
  84.         center = {x = firstPit.center.x - 21, y = firstPit.center.y - 14, z = firstPit.center.z},
  85.         pillar = {x = firstPit.pillar.x - 21, y = firstPit.pillar.y - 14, z = firstPit.pillar.z},
  86.         tp = {x = firstPit.tp.x - 21, y = firstPit.tp.y - 14, z = firstPit.tp.z},
  87.         summon = {x = firstPit.summon.x - 21, y = firstPit.summon.y - 14, z = firstPit.summon.z}
  88.     },
  89.     [7] = {
  90.         fromPos = {x = firstPit.fromPos.x - 7, y = firstPit.fromPos.y - 14, z = firstPit.fromPos.z},
  91.         toPos = {x = firstPit.toPos.x - 7, y = firstPit.toPos.y - 14, z = firstPit.toPos.z},
  92.         center = {x = firstPit.center.x - 7, y = firstPit.center.y - 14, z = firstPit.center.z},
  93.         pillar = {x = firstPit.pillar.x - 7, y = firstPit.pillar.y - 14, z = firstPit.pillar.z},
  94.         tp = {x = firstPit.tp.x - 7, y = firstPit.tp.y - 14, z = firstPit.tp.z},
  95.         summon = {x = firstPit.summon.x - 7, y = firstPit.summon.y - 14, z = firstPit.summon.z}
  96.     },
  97.     [8] = {
  98.         fromPos = {x = firstPit.fromPos.x - 14, y = firstPit.fromPos.y - 28, z = firstPit.fromPos.z},
  99.         toPos = {x = firstPit.toPos.x - 14, y = firstPit.toPos.y - 28, z = firstPit.toPos.z},
  100.         center = {x = firstPit.center.x - 14, y = firstPit.center.y - 28, z = firstPit.center.z},
  101.         pillar = {x = firstPit.pillar.x - 14, y = firstPit.pillar.y - 28, z = firstPit.pillar.z},
  102.         tp = {x = firstPit.tp.x - 14, y = firstPit.tp.y - 28, z = firstPit.tp.z},
  103.         summon = {x = firstPit.summon.x - 14, y = firstPit.summon.y - 28, z = firstPit.summon.z}
  104.     },
  105.     [9] = {
  106.         fromPos = {x = firstPit.fromPos.x - 28, y = firstPit.fromPos.y - 28, z = firstPit.fromPos.z},
  107.         toPos = {x = firstPit.toPos.x - 28, y = firstPit.toPos.y - 28, z = firstPit.toPos.z},
  108.         center = {x = firstPit.center.x - 28, y = firstPit.center.y - 28, z = firstPit.center.z},
  109.         pillar = {x = firstPit.pillar.x - 28, y = firstPit.pillar.y - 28, z = firstPit.pillar.z},
  110.         tp = {x = firstPit.tp.x - 28, y = firstPit.tp.y - 28, z = firstPit.tp.z},
  111.         summon = {x = firstPit.summon.x - 28, y = firstPit.summon.y - 28, z = firstPit.summon.z}
  112.     },
  113.     [10] = {
  114.         fromPos = {x = firstPit.fromPos.x - 21, y = firstPit.fromPos.y - 42, z = firstPit.fromPos.z},
  115.         toPos = {x = firstPit.toPos.x - 21, y = firstPit.toPos.y - 42, z = firstPit.toPos.z},
  116.         center = {x = firstPit.center.x - 21, y = firstPit.center.y - 41, z = firstPit.center.z},
  117.         pillar = {x = firstPit.pillar.x - 21, y = firstPit.pillar.y - 41, z = firstPit.pillar.z},
  118.         tp = {x = firstPit.tp.x - 21, y = firstPit.tp.y - 41, z = firstPit.tp.z},
  119.         summon = {x = firstPit.summon.x - 21, y = firstPit.summon.y - 41, z = firstPit.summon.z}
  120.     }
  121. }
  122.  
  123. ARENA = {
  124.     [1] = {
  125.         name = 'Greenhorn',
  126.         price = 1000,
  127.         questLog = 50140,
  128.         achievement = 'Greenhorn',
  129.         creatures = {
  130.             [1] = 'frostfur',
  131.             [2] = 'bloodpaw',
  132.             [3] = 'bovinus',
  133.             [4] = 'achad',
  134.             [5] = 'colerian the barbarian',
  135.             [6] = 'the hairy one',
  136.             [7] = 'axeitus headbanger',
  137.             [8] = 'rocky',
  138.             [9] = 'cursed gladiator',
  139.             [10] = 'orcus the cruel'
  140.         },
  141.         reward = {
  142.             storage = 1102,
  143.             trophy = 5807,
  144.             trophyStorage = 1103,
  145.             desc = 'A brave warrior that finished the Greenhorn mode. Awarded to %s.',
  146.             [26300] = {
  147.                 container = true,
  148.                 id = 1990,
  149.                 inside = {
  150.                     {2114, 1},
  151.                     {9570, 1},
  152.                     {6574, 1},
  153.                     {2688, 10},
  154.                     {7372, 1}
  155.                 }
  156.             },
  157.             [26400] = {
  158.                 container = true,
  159.                 id = 7342,
  160.                 inside = {
  161.                     {7364, 100},
  162.                     {7365, 100}
  163.                 },
  164.             },
  165.             [26500] = {
  166.                 id = {7406, 1}
  167.             },
  168.             [26600] = {
  169.                 id = {7380, 1}
  170.             },
  171.             [26700] = {
  172.                 id = {7392, 1}
  173.             }
  174.         }
  175.     },
  176.     [2] = {
  177.         name = 'Scrapper',
  178.         price = 5000,
  179.         questLog = 50141,
  180.         achievement = 'Scrapper',
  181.         creatures = {
  182.             [1] = 'avalanche',
  183.             [2] = 'kreebosh the exile',
  184.             [3] = 'the dark dancer',
  185.             [4] = 'the hag',
  186.             [5] = 'slim',
  187.             [6] = 'grimgor guteater',
  188.             [7] = 'drasilla',
  189.             [8] = 'spirit of earth',
  190.             [9] = 'spirit of water',
  191.             [10] = 'spirit of fire'
  192.         },
  193.         reward = {
  194.             storage = 1104,
  195.             trophy = 5806,
  196.             trophyStorage = 1105,
  197.             desc = 'A brave warrior that finished the Scrapper mode. Awarded to %s.',
  198.             [27300] = {
  199.                 container = true,
  200.                 id = 1990,
  201.                 inside = {
  202.                     {7183, 1},
  203.                     {6574, 1},
  204.                     {7373, 1},
  205.                     {2688, 10}
  206.                 }
  207.             },
  208.             [27400] = {
  209.                 container = true,
  210.                 id = 7342,
  211.                 inside = {
  212.                     {2304, 50},
  213.                     {2311, 50},
  214.                     {2547, 200},
  215.                     {7365, 100}
  216.                 },
  217.             },
  218.             [27500] = {
  219.                 id = {7384, 1}
  220.             },
  221.             [27600] = {
  222.                 id = {7389, 1}
  223.             },
  224.             [27700] = {
  225.                 id = {7415, 1}
  226.             }
  227.         }
  228.     },
  229.     [3] = {
  230.         name = 'Warlord',
  231.         price = 10000,
  232.         questLog = 50142,
  233.         achievement = 'Warlord of Svargrond',
  234.         creatures = {
  235.             [1] = 'webster',
  236.             [2] = 'darakan the executioner',
  237.             [3] = 'norgle glacierbeard',
  238.             [4] = 'the pit lord',
  239.             [5] = 'svoren the mad',
  240.             [6] = 'the masked marauder',
  241.             [7] = 'gnorre chyllson',
  242.             [8] = 'fallen mooh\'tah master ghar',
  243.             [9] = 'deathbringer',
  244.             [10] = 'the obliverator'
  245.         },
  246.         reward = {
  247.             storage = 1006,
  248.             trophy = 5805,
  249.             trophyStorage = 1007,
  250.             desc = 'A brave warrior that finished the Warlord mode. Awarded to %s.',
  251.             [28300] = {
  252.                 container = true,
  253.                 id = 1990,
  254.                 inside = {
  255.                     {6568, 1},
  256.                     {6574, 1},
  257.                     {7374, 1},
  258.                     {2688, 10}
  259.                 }
  260.             },
  261.             [28400] = {
  262.                 container = true,
  263.                 id = 7342,
  264.                 inside = {
  265.                     {6529, 100},
  266.                     {7440, 1},
  267.                     {7443, 1},
  268.                     {2268, 50},
  269.                     {2273, 50}
  270.                 },
  271.             },
  272.             [28500] = {
  273.                 id = {7390, 1}
  274.             },
  275.             [28600] = {
  276.                 id = {7434, 1}
  277.             },
  278.             [28700] = {
  279.                 id = {7429, 1}
  280.             }
  281.         }
  282.     }
  283. }
  284.  
  285. function SvargrondArena.getActionIdByArena(arenaId)
  286.     if arenaId == 1 then
  287.         return SvargrondArena.actionGreenhorn
  288.     elseif arenaId == 2 then
  289.         return SvargrondArena.actionScrapper
  290.     elseif arenaId == 3 then
  291.         return SvargrondArena.actionWarlord
  292.     else
  293.         print('SvargronArena::getActionIdByArena invalid arenaId')
  294.     end
  295. end
  296.  
  297. function SvargrondArena.getPitCreatures(pitId)
  298.     if not PITS[pitId] then
  299.         return {}
  300.     end
  301.  
  302.     local ret = {}
  303.     local specs = Game.getSpectators(PITS[pitId].center, false, false, 5, 5, 5, 5)
  304.     for i = 1, #specs do
  305.         ret[#ret+1] = specs[i]
  306.     end
  307.  
  308.     return ret
  309. end
  310.  
  311. function SvargrondArena.resetPit(pitId)
  312.     if not PITS[pitId] then
  313.         return
  314.     end
  315.  
  316.     for x = PITS[pitId].fromPos.x, PITS[pitId].toPos.x do
  317.         for y = PITS[pitId].fromPos.y, PITS[pitId].toPos.y do
  318.             for z = PITS[pitId].fromPos.z, PITS[pitId].toPos.z do
  319.                 local tile = Tile({x=x, y=y, z=z})
  320.                 if tile then
  321.                     local moveableItem = tile:getThing(STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE)
  322.                     if moveableItem and moveableItem:isItem() then
  323.                         local itemType = ItemType(moveableItem:getId())
  324.                         if itemType and itemType:isMovable() and not isInArray(SvargrondArena.itemsNotErasable, moveableItem:getId()) then
  325.                             moveableItem:remove()
  326.                         end
  327.                     end
  328.  
  329.                     local creature = tile:getTopCreature()
  330.                     if creature and creature:isMonster() then
  331.                         creature:remove()
  332.                     end
  333.                 end
  334.             end
  335.         end
  336.     end
  337.  
  338.     local pillarTile = Tile(PITS[pitId].pillar)
  339.     if pillarTile then
  340.         local teleportItem = pillarTile:getItemById(SvargrondArena.itemTeleport)
  341.         if teleportItem then
  342.             teleportItem:remove()
  343.         end
  344.  
  345.         local pillarItem = pillarTile:getItemById(SvargrondArena.itemPillar)
  346.         if not pillarItem then
  347.             Game.createItem(SvargrondArena.itemPillar, 1, PITS[pitId].pillar)
  348.         end
  349.     end
  350. end
  351.  
  352. function SvargrondArena.getPitOccupant(pitId, ignorePlayer)
  353.     local creatures = SvargrondArena.getPitCreatures(pitId)
  354.     for i = 1, #creatures do
  355.         if creatures[i]:isPlayer() and creatures[i]:getId() ~= ignorePlayer:getId() then
  356.             return creatures[i]
  357.         end
  358.     end
  359.  
  360.     return nil
  361. end
  362.  
  363. function SvargrondArena.kickPlayer(cid, hideMessage)
  364.     SvargrondArena.cancelEvents(cid)
  365.     local player = Player(cid)
  366.     if not player then
  367.         return
  368.     end
  369.  
  370.     if player:getStorageValue(Storage.SvargrondArena.Pit) > 0 then
  371.         player:teleportTo(SvargrondArena.kickPosition)
  372.         SvargrondArena.kickPosition:sendMagicEffect(CONST_ME_TELEPORT)
  373.         player:setStorageValue(Storage.SvargrondArena.Pit, 0)
  374.         if not hideMessage then
  375.             player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Your time ran out!')
  376.         end
  377.     end
  378. end
  379.  
  380. function SvargrondArena.cancelEvents(cid)
  381.     local kickEvent = SvargrondArena.kickEvents[cid]
  382.     if kickEvent then
  383.         SvargrondArena.removeTimer(kickEvent.pitId)
  384.         stopEvent(kickEvent.eventId)
  385.     end
  386.     SvargrondArena.kickEvents[cid] = nil
  387. end
  388.  
  389. function SvargrondArena.scheduleKickPlayer(cid, pitId)
  390.     SvargrondArena.cancelEvents(cid)
  391.     SvargrondArena.startTimer(pitId)
  392.     local eventId = addEvent(SvargrondArena.kickPlayer, SvargrondArena.kickTime * 1000, cid)
  393.     SvargrondArena.kickEvents[cid] = {eventId = eventId, pitId = pitId}
  394. end
  395.  
  396. function SvargrondArena.startTimer(pitId)
  397.     local tile = Tile(PITS[pitId].fromPos)
  398.     if not tile then
  399.         return
  400.     end
  401.  
  402.     local timerItem = tile:getItemById(SvargrondArena.itemTimer)
  403.     if timerItem then
  404.         timerItem:remove()
  405.     end
  406.  
  407.     timerItem = Game.createItem(SvargrondArena.itemTimer, 1, PITS[pitId].fromPos)
  408.     if timerItem then
  409.         timerItem:decay()
  410.     end
  411.  
  412.     if SvargrondArena.timerEvents[pitId] then
  413.         stopEvent(SvargrondArena.timerEvents[pitId])
  414.     end
  415.     SvargrondArena.timerEvents[pitId] = addEvent(SvargrondArena.removeTimer, SvargrondArena.kickTime * 1000, pitId)
  416. end
  417.  
  418. function SvargrondArena.removeTimer(pitId)
  419.     local tile = Tile(PITS[pitId].fromPos)
  420.     if not tile then
  421.         return
  422.     end
  423.  
  424.     local timerItem = tile:getItemById(SvargrondArena.itemTimer)
  425.     if timerItem then
  426.         timerItem:remove()
  427.     end
  428.     SvargrondArena.timerEvents[pitId] = nil
  429. end
  430.  
  431. function SvargrondArena.sendPillarEffect(pitId)
  432.     local positions = SvargrondArena.effectPositionCache[pitId]
  433.     if not positions then
  434.         local position = PITS[pitId].pillar
  435.         local effectPositions = {
  436.                 Position(position.x - 1, position.y,     position.z),
  437.                 Position(position.x + 1, position.y,     position.z),
  438.                 Position(position.x + 1, position.y - 1, position.z),
  439.                 Position(position.x + 1, position.y + 1, position.z),
  440.                 Position(position.x,     position.y,     position.z)
  441.         }
  442.         SvargrondArena.effectPositionCache[pitId] = effectPositions
  443.         positions = effectPositions
  444.     end
  445.  
  446.     for _, position in ipairs(positions) do
  447.         position:sendMagicEffect(CONST_ME_MAGIC_BLUE)
  448.     end
  449. end
Advertisement
Add Comment
Please, Sign In to add comment