Advertisement
Larvix

waveManager

Nov 13th, 2024 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.10 KB | None | 0 0
  1. --initialise variables
  2. function vars()
  3. --essence storage
  4. tank = peripheral.wrap("industrialforegoing:black_hole_tank_tile_6")
  5. --mob tool storage
  6. chestName = "projecte:alchemical_chest_1094"
  7. chest = peripheral.wrap(chestName)
  8. --main monitor display
  9. monitor = peripheral.wrap("top")
  10. monX,monY = monitor.getSize()
  11. monX = monX-2
  12. monY = monY-2
  13. mon = window.create(monitor,2,2,monX,monY,true)
  14. --modem for wither turtle
  15. modem = peripheral.wrap("left")
  16. --block name for spawners
  17. blockName = "industrialforegoing:mob_duplicator_tile_"
  18. --spawner IDs, split into rings
  19. spawners = {
  20. -- Ring 1
  21.     {
  22.         "8",
  23.         "11",
  24.         "5",
  25.         "29",
  26.         "9",
  27.         "32",
  28.         "10",
  29.         "31"
  30.     },
  31. -- Ring 2
  32.     {
  33.         "14",
  34.         "17",
  35.         "7",
  36.         "30",
  37.         "15",
  38.         "18",
  39.         "16",
  40.         "20"
  41.     },
  42. -- Ring 3
  43.     {
  44.         "21",
  45.         "25",
  46.         "23",
  47.         "26",
  48.         "22",
  49.         "28",
  50.         "24",
  51.         "27"
  52.     }
  53. }
  54. --add block name to spawner IDs
  55. for ring,group in pairs(spawners) do
  56.     for spawner,id in pairs(group) do
  57.         spawners[ring][spawner] = blockName..id
  58.     end
  59. end
  60.  
  61. --wave counter
  62. wave = 0
  63. --mob counter table
  64. mobs = {
  65. ["Zombie"] = 0,
  66. ["ZombieVillager"] = 0,
  67. ["quark:dweller"] = 0,
  68. ["Husk"] = 0,
  69. ["PigZombie"] = 0,
  70. ["Skeleton"] = 0,
  71. ["Stray"] = 0,
  72. ["quark:ashen"] = 0,
  73. ["WitherSkeleton"] = 0,
  74. ["quark:foxhound"] = 0,
  75. ["Blaze"] = 0,
  76. ["Ghast"] = 0,
  77. ["Witch"] = 0,
  78. ["VindicationIllager"] = 0,
  79. ["EvocationIllager"] = 0,
  80. }
  81. --sensor table
  82. sensors = {
  83. "manipulator_15",
  84. "manipulator_16",
  85. "manipulator_17",
  86. "manipulator_18"
  87. }
  88. --living mob table
  89. alive = {}
  90. --queue table
  91. queue = {}
  92. mobQueued = nil
  93. --set initial flags
  94. running = true
  95. isAlive = false
  96. waveOver = false
  97. mobExists = false
  98. lastCheck = ""
  99. end
  100. --initialise on startup
  101. vars()
  102.  
  103. --use given spawner for given mob
  104. function spawn(r,s,m)
  105. --wrap current spawner
  106.     spawner = peripheral.wrap(spawners[r][s])
  107. --check essence amount
  108.     if not spawner.getTanks()[1].amount or (spawner.getTanks()[1].amount < 8000) then
  109. --give essence if needed
  110.         --print(string.format("Giving essence to %s:%s",r,s))
  111.         tank.pushFluid(spawners[r][s],8000,"essence")
  112.     end
  113. --find mob
  114.     item = 0
  115.     for slot,_ in pairs(chest.list()) do
  116.         --print("Checking slot "..slot)
  117.         if string.match(chest.getItem(slot).getMetadata().displayName,m) then
  118.             item = slot
  119.             --print("Item found in slot "..item)
  120.             break
  121.         end
  122.     end
  123.     if not (item == 0) then
  124. --give mob to spawner
  125.     spawner.pullItems(chestName,item)
  126.     sleep(0.2)
  127. --return mob to chest
  128.     spawner.pushItems(chestName,7)
  129.     --else print("Mob not found!")
  130.     end
  131. end
  132.  
  133. function initWave()
  134.     --increment wave
  135.     wave = wave + 1
  136.     --tell progressBar wave started
  137.     modem.transmit(wave,100,"")
  138.     --display wave on monitor
  139.     line = "Wave "..wave
  140.     mon.setCursorPos((monX-#line)/2,1)
  141.     mon.clearLine()
  142.     mon.write(line)
  143.     --mob changes per wave
  144.     if wave < 3 then mobs["ZombieVillager"] = 4 * wave end
  145.     if wave == 3 then mobs["Witch"] = 2 end
  146.     if wave == 3 then mobs["Witch"] = 4 end
  147.     if wave == 5 then mobs["VindicationIllager"] = 2 end
  148.     if wave == 6 then mobs["VindicationIllager"] = 4 end
  149.     if wave == 7 then mobs["EvocationIllager"] = 2 end
  150.     if wave == 8 then mobs["EvocationIllager"] = 4 end
  151.     if wave == 9 then
  152.         mobs["WitherSkeleton"] = 2
  153.         mobs["ZombieVillager"] = 6
  154.         mobs["Husk"] = 2
  155.     end
  156.     if wave == 10 then
  157.         mobs["ZombieVillager"] = 4
  158.         mobs["quark:dweller"] = 2
  159.         mobs["Stray"] = 1
  160.         mobs["quark:ashen"] = 1
  161.         running = false
  162.     end
  163.     --queue all mobs for current wave
  164.     for mob,count in pairs(mobs) do
  165.         if count > 0 then
  166.             for i = 1,count do
  167.                 table.insert(queue,mob)
  168.                 if not alive[mob] then
  169.                     alive[mob] = {}
  170.                 end
  171.             end
  172.         end
  173.     end
  174. end
  175.  
  176. function checkSpawned(mobQueued)
  177.         for _,sensorID in pairs(sensors) do
  178.             sensor = peripheral.wrap(sensorID)
  179.             for _,found in pairs(sensor.sense()) do
  180.                 if found.name == mobQueued then
  181.                     --print(found.name,found.id)
  182.                     if #alive[mobQueued] > 0 then
  183.                     for _,mobID in pairs(alive[mobQueued]) do
  184.                         if found.id == mobID then
  185.                             mobExists = true
  186.                             --break
  187.                         end
  188.                     end
  189.                     end
  190.                     if not mobExists then
  191.                         table.insert(alive[mobQueued],found.id)
  192.                     end
  193.                 end
  194.                 if mobExists then mobExists = false end
  195.             end
  196.         end
  197. end
  198.  
  199. function checkAlive(totalCount)
  200.     isAlive = false
  201.         for m,ids in pairs(alive) do
  202.             for n,id in pairs(ids) do
  203.                 for i,sensor in pairs(sensors) do
  204.                     if peripheral.wrap(sensor).getMetaByID(id) then
  205.                         isAlive = true
  206.                     end
  207.                 end
  208.                 if not isAlive then
  209.                     table.remove(alive[m],n)
  210.                 else
  211.                     isAlive = false
  212.                 end
  213.             end
  214.             if (#alive[m] + #queue) == 0 then
  215.                 alive[m] = nil
  216.             end
  217.             numAlive = 0
  218.             for _,ids in pairs(alive) do numAlive = numAlive + #ids end
  219.             waveProg = math.floor(((numAlive+#queue)/totalCount)*100)
  220.             if waveProg ~= lastCheck then
  221.                 modem.transmit(wave,waveProg,"")
  222.                 lastCheck = waveProg
  223.             end
  224.             if (numAlive + #queue) == 0 then waveOver = true end
  225.      end
  226.     return waveOver
  227. end
  228.  
  229. function displayWave()
  230.         currentY = 2
  231.         for mob,count in pairs(mobs) do
  232.             if count > 0 then
  233.                 if alive[mob] then live = #alive[mob] else live = 0 end
  234.                 for _,m in pairs(queue) do
  235.                     if m == mob then live = live + 1 end
  236.                 end
  237.                 line = string.format("%s: %s/%s",mob,live,count)
  238.                 currentY = currentY + 1
  239.                 mon.setCursorPos((monX-#line)/2,currentY)
  240.                 mon.clearLine()
  241.                 mon.write(line)
  242.             end
  243.         end
  244. end
  245.  
  246. function main()
  247.     while running do
  248.     --initialise next wave
  249.     initWave()
  250.     --reset ring/spawner flag
  251.     cRing = 1
  252.     cSpwner = 0
  253.     --list all mobs in wave on monitor
  254.     currentY = 2
  255.     totalCount = 0
  256.     for mob,count in pairs(mobs) do
  257.         if count > 0 then
  258.             line = string.format("%s: %s/%s",mob,count,count)
  259.             currentY = currentY + 1
  260.             mon.setCursorPos((monX-#line)/2,currentY)
  261.             mon.write(line)
  262.         end
  263.         totalCount = totalCount + count
  264.     end
  265.     --for each mob queued
  266.     while #queue > 0 do
  267.     mobQueued = queue[#queue]
  268.     --if ring full
  269.         if cSpwner == #spawners[cRing] then
  270.     --increment ring
  271.             cRing = cRing + 1
  272.     --reset spawner to start
  273.             cSpwner = 1
  274.         else
  275.     --otherwise increment spawner
  276.             cSpwner = cSpwner + 1
  277.         end
  278.     --spawn next mob in queue
  279.         --print(string.format("%s:%s %s",cRing,cSpwner,mobQueued))
  280.         spawn(cRing,cSpwner,mobQueued)
  281.         --find spawned mob
  282.         checkSpawned(mobQueued)
  283.         --check mobs still alive
  284.         checkAlive(totalCount)
  285.         --remove item from queue
  286.         table.remove(queue,#queue)
  287.         --update monitor display
  288.         displayWave()
  289.     end
  290.     --check alive mobs until none
  291.     while not waveOver do
  292.         waveOver = checkAlive(totalCount)
  293.         displayWave()
  294.     end
  295.     waveOver=false
  296.     waveProg = ""
  297.     currentX,currentY = mon.getCursorPos()
  298.     line = "Wave Cleared!"
  299.     mon.setCursorPos((monX-#line)/2,currentY+2)
  300.     --if trial still in progress
  301.     if running then
  302.     --pause 3 seconds before next wave
  303.         sleep(3)
  304.     end
  305.     mon.clear()
  306.     end
  307. end
  308.  
  309. --run main function
  310. print("Beginning Trial...")
  311. main()
  312. modem.transmit(11,1,"")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement