Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --initialise variables
- function vars()
- --essence storage
- tank = peripheral.wrap("industrialforegoing:black_hole_tank_tile_6")
- --mob tool storage
- chestName = "projecte:alchemical_chest_1094"
- chest = peripheral.wrap(chestName)
- --main monitor display
- monitor = peripheral.wrap("top")
- monX,monY = monitor.getSize()
- monX = monX-2
- monY = monY-2
- mon = window.create(monitor,2,2,monX,monY,true)
- --modem for wither turtle
- modem = peripheral.wrap("left")
- --block name for spawners
- blockName = "industrialforegoing:mob_duplicator_tile_"
- --spawner IDs, split into rings
- spawners = {
- -- Ring 1
- {
- "8",
- "11",
- "5",
- "29",
- "9",
- "32",
- "10",
- "31"
- },
- -- Ring 2
- {
- "14",
- "17",
- "7",
- "30",
- "15",
- "18",
- "16",
- "20"
- },
- -- Ring 3
- {
- "21",
- "25",
- "23",
- "26",
- "22",
- "28",
- "24",
- "27"
- }
- }
- --add block name to spawner IDs
- for ring,group in pairs(spawners) do
- for spawner,id in pairs(group) do
- spawners[ring][spawner] = blockName..id
- end
- end
- --wave counter
- wave = 0
- --mob counter table
- mobs = {
- ["Zombie"] = 0,
- ["ZombieVillager"] = 0,
- ["quark:dweller"] = 0,
- ["Husk"] = 0,
- ["PigZombie"] = 0,
- ["Skeleton"] = 0,
- ["Stray"] = 0,
- ["quark:ashen"] = 0,
- ["WitherSkeleton"] = 0,
- ["quark:foxhound"] = 0,
- ["Blaze"] = 0,
- ["Ghast"] = 0,
- ["Witch"] = 0,
- ["VindicationIllager"] = 0,
- ["EvocationIllager"] = 0,
- }
- --sensor table
- sensors = {
- "manipulator_15",
- "manipulator_16",
- "manipulator_17",
- "manipulator_18"
- }
- --living mob table
- alive = {}
- --queue table
- queue = {}
- mobQueued = nil
- --set initial flags
- running = true
- isAlive = false
- waveOver = false
- mobExists = false
- lastCheck = ""
- end
- --initialise on startup
- vars()
- --use given spawner for given mob
- function spawn(r,s,m)
- --wrap current spawner
- spawner = peripheral.wrap(spawners[r][s])
- --check essence amount
- if not spawner.getTanks()[1].amount or (spawner.getTanks()[1].amount < 8000) then
- --give essence if needed
- --print(string.format("Giving essence to %s:%s",r,s))
- tank.pushFluid(spawners[r][s],8000,"essence")
- end
- --find mob
- item = 0
- for slot,_ in pairs(chest.list()) do
- --print("Checking slot "..slot)
- if string.match(chest.getItem(slot).getMetadata().displayName,m) then
- item = slot
- --print("Item found in slot "..item)
- break
- end
- end
- if not (item == 0) then
- --give mob to spawner
- spawner.pullItems(chestName,item)
- sleep(0.2)
- --return mob to chest
- spawner.pushItems(chestName,7)
- --else print("Mob not found!")
- end
- end
- function initWave()
- --increment wave
- wave = wave + 1
- --tell progressBar wave started
- modem.transmit(wave,100,"")
- --display wave on monitor
- line = "Wave "..wave
- mon.setCursorPos((monX-#line)/2,1)
- mon.clearLine()
- mon.write(line)
- --mob changes per wave
- if wave < 3 then mobs["ZombieVillager"] = 4 * wave end
- if wave == 3 then mobs["Witch"] = 2 end
- if wave == 3 then mobs["Witch"] = 4 end
- if wave == 5 then mobs["VindicationIllager"] = 2 end
- if wave == 6 then mobs["VindicationIllager"] = 4 end
- if wave == 7 then mobs["EvocationIllager"] = 2 end
- if wave == 8 then mobs["EvocationIllager"] = 4 end
- if wave == 9 then
- mobs["WitherSkeleton"] = 2
- mobs["ZombieVillager"] = 6
- mobs["Husk"] = 2
- end
- if wave == 10 then
- mobs["ZombieVillager"] = 4
- mobs["quark:dweller"] = 2
- mobs["Stray"] = 1
- mobs["quark:ashen"] = 1
- running = false
- end
- --queue all mobs for current wave
- for mob,count in pairs(mobs) do
- if count > 0 then
- for i = 1,count do
- table.insert(queue,mob)
- if not alive[mob] then
- alive[mob] = {}
- end
- end
- end
- end
- end
- function checkSpawned(mobQueued)
- for _,sensorID in pairs(sensors) do
- sensor = peripheral.wrap(sensorID)
- for _,found in pairs(sensor.sense()) do
- if found.name == mobQueued then
- --print(found.name,found.id)
- if #alive[mobQueued] > 0 then
- for _,mobID in pairs(alive[mobQueued]) do
- if found.id == mobID then
- mobExists = true
- --break
- end
- end
- end
- if not mobExists then
- table.insert(alive[mobQueued],found.id)
- end
- end
- if mobExists then mobExists = false end
- end
- end
- end
- function checkAlive(totalCount)
- isAlive = false
- for m,ids in pairs(alive) do
- for n,id in pairs(ids) do
- for i,sensor in pairs(sensors) do
- if peripheral.wrap(sensor).getMetaByID(id) then
- isAlive = true
- end
- end
- if not isAlive then
- table.remove(alive[m],n)
- else
- isAlive = false
- end
- end
- if (#alive[m] + #queue) == 0 then
- alive[m] = nil
- end
- numAlive = 0
- for _,ids in pairs(alive) do numAlive = numAlive + #ids end
- waveProg = math.floor(((numAlive+#queue)/totalCount)*100)
- if waveProg ~= lastCheck then
- modem.transmit(wave,waveProg,"")
- lastCheck = waveProg
- end
- if (numAlive + #queue) == 0 then waveOver = true end
- end
- return waveOver
- end
- function displayWave()
- currentY = 2
- for mob,count in pairs(mobs) do
- if count > 0 then
- if alive[mob] then live = #alive[mob] else live = 0 end
- for _,m in pairs(queue) do
- if m == mob then live = live + 1 end
- end
- line = string.format("%s: %s/%s",mob,live,count)
- currentY = currentY + 1
- mon.setCursorPos((monX-#line)/2,currentY)
- mon.clearLine()
- mon.write(line)
- end
- end
- end
- function main()
- while running do
- --initialise next wave
- initWave()
- --reset ring/spawner flag
- cRing = 1
- cSpwner = 0
- --list all mobs in wave on monitor
- currentY = 2
- totalCount = 0
- for mob,count in pairs(mobs) do
- if count > 0 then
- line = string.format("%s: %s/%s",mob,count,count)
- currentY = currentY + 1
- mon.setCursorPos((monX-#line)/2,currentY)
- mon.write(line)
- end
- totalCount = totalCount + count
- end
- --for each mob queued
- while #queue > 0 do
- mobQueued = queue[#queue]
- --if ring full
- if cSpwner == #spawners[cRing] then
- --increment ring
- cRing = cRing + 1
- --reset spawner to start
- cSpwner = 1
- else
- --otherwise increment spawner
- cSpwner = cSpwner + 1
- end
- --spawn next mob in queue
- --print(string.format("%s:%s %s",cRing,cSpwner,mobQueued))
- spawn(cRing,cSpwner,mobQueued)
- --find spawned mob
- checkSpawned(mobQueued)
- --check mobs still alive
- checkAlive(totalCount)
- --remove item from queue
- table.remove(queue,#queue)
- --update monitor display
- displayWave()
- end
- --check alive mobs until none
- while not waveOver do
- waveOver = checkAlive(totalCount)
- displayWave()
- end
- waveOver=false
- waveProg = ""
- currentX,currentY = mon.getCursorPos()
- line = "Wave Cleared!"
- mon.setCursorPos((monX-#line)/2,currentY+2)
- --if trial still in progress
- if running then
- --pause 3 seconds before next wave
- sleep(3)
- end
- mon.clear()
- end
- end
- --run main function
- print("Beginning Trial...")
- main()
- modem.transmit(11,1,"")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement