Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chestStorage = "minecraft:chest_44"
- local roundTime = 15
- local RED = 0xCE3232
- local LIGHT_BLUE = 0x6EA5F0
- local CYAN = 0x406CAB
- local BLUE = 0x1E385D
- local LIGHT_GRAY = 0x487EC9
- local GRAY = 0x6099EA
- local all_food_file = fs.open("/cooking/allFoods.dat","r")
- local all_foods_raw = all_food_file.readAll()
- local all_foods = {}
- local made_foods = {}
- local made_names = {}
- for line in all_foods_raw:gmatch("[^\r\n]+") do table.insert(all_foods,line) end
- all_food_file.close()
- local stations_file = fs.open("/cooking/stations.dat","r")
- local stations_data = stations_file.readAll()
- local stations = textutils.unserialize(stations_data)
- stations_file.close()
- for i,s in pairs(stations) do
- local mp = peripheral.wrap(s.monitor)
- mp.setPaletteColor(colors.red,RED)
- mp.setPaletteColor(colors.lightBlue,LIGHT_BLUE)
- mp.setPaletteColor(colors.blue,BLUE)
- mp.setPaletteColor(colors.cyan,CYAN)
- mp.setPaletteColor(colors.gray,GRAY)
- mp.setPaletteColor(colors.lightGray,LIGHT_GRAY)
- end
- function fillBottom(m_p,color,i)
- stations[i].bottom_c = color
- local old_c = m_p.getBackgroundColor()
- m_p.setBackgroundColor(color)
- m_p.setCursorPos(1,8)
- m_p.write(string.rep(" ",8))
- m_p.setCursorPos(13,8)
- m_p.write(string.rep(" ",8))
- m_p.setBackgroundColor(old_c)
- end
- function setTime(m_p,seconds,i)
- local old_bgc = m_p.getBackgroundColor()
- m_p.setBackgroundColor(stations[i].bottom_c)
- local s = math.max(0,seconds)
- m_p.setCursorPos(9,8)
- if s < 10 then
- m_p.write(string.format("%04.2f", s))
- else
- m_p.write(string.format("%04.1f", s))
- end
- m_p.setBackgroundColor(old_bgc)
- end
- function setFoods(m_p,foods)
- m_p.setCursorPos(17,2)
- m_p.write(string.format("%03d", math.floor(foods)))
- end
- function setPlayersRemaining(m_p,people)
- m_p.setCursorPos(2,2)
- m_p.write(string.format("%02d", math.floor(people)))
- end
- for i,s in pairs(stations) do
- local m = s.monitor
- local mp = peripheral.wrap(m)
- mp.setBackgroundColor(colors.lightBlue)
- mp.setTextColor(colors.black)
- mp.clear()
- mp.setTextScale(1.5)
- mp.setCursorPos(1,1)
- mp.setBackgroundColor(colors.white)
- mp.clearLine()
- mp.write(" Chef "..i)
- mp.setBackgroundColor(colors.lightBlue)
- mp.setCursorPos(1,2)
- mp.write(string.char(2)..string.format("%02d", #stations).."/"..string.format("%02d",#stations))
- mp.setCursorPos(14,2)
- mp.write("FDs")
- mp.setCursorPos(7,4)
- mp.setBackgroundColor(colors.red)
- mp.clearLine()
- mp.write("NOT READY")
- mp.setBackgroundColor(colors.lightBlue)
- stations[i].ready = false
- stations[i].alive = true
- stations[i].primed = false
- stations[i].bottom_c = colors.lightBlue
- setPlayersRemaining(mp,#stations)
- setFoods(mp,0)
- fillBottom(mp,colors.yellow,i)
- setTime(mp,roundTime,i)
- end
- function anyUnready()
- local allReady = true
- for i,s in pairs(stations) do
- if (not s.ready) then
- allReady = false
- end
- end
- return not allReady
- end
- for i,s in pairs(stations) do
- local mp = peripheral.wrap(s.monitor)
- mp.setBackgroundColor(colors.red)
- mp.setCursorPos(17,1)
- mp.write("RMV")
- mp.setBackgroundColor(colors.lightBlue)
- end
- while anyUnready() do
- local event, side, x, y = os.pullEvent("monitor_touch")
- for i,s in pairs(stations) do
- local mp = peripheral.wrap(s.monitor)
- if s.monitor == side then
- if x > 11 and y == 1 then
- mp.setBackgroundColor(colors.black)
- mp.clear()
- stations[i] = nil
- s.ready = false
- s.alive = false
- else
- s.ready = true
- end
- end
- if s.ready then
- mp.setCursorPos(8,4)
- mp.clearLine()
- mp.setTextColor(colors.green)
- mp.write("READY!")
- mp.setTextColor(colors.black)
- fillBottom(mp,colors.green,i)
- setTime(mp,roundTime,i)
- end
- end
- end
- function getAmountAlive()
- local num_alive = 0
- for i,s in pairs(stations) do
- if s.alive then
- num_alive = num_alive + 1
- end
- end
- return num_alive
- end
- for i,s in pairs(stations) do
- local mp = peripheral.wrap(s.monitor)
- mp.setCursorPos(1,4)
- mp.clearLine()
- mp.setCursorPos(17,1)
- mp.setBackgroundColor(colors.white)
- mp.write(" ")
- mp.setBackgroundColor(colors.lightBlue)
- setPlayersRemaining(mp,getAmountAlive())
- mp.setCursorPos(6,2)
- mp.write(getAmountAlive())
- end
- function contains(table,E)
- for _,e in pairs(table) do if e == E then return true end end
- return false
- end
- function kill(i)
- local s = stations[i]
- s.alive = false
- local mp = peripheral.wrap(s.monitor)
- fillBottom(mp,colors.red,i)
- setTime(mp,0,i)
- mp.setCursorPos(1,3)
- mp.clearLine()
- mp.setCursorPos(1,4)
- mp.clearLine()
- mp.setCursorPos(1,5)
- mp.clearLine()
- mp.setCursorPos(1,6)
- mp.clearLine()
- mp.setCursorPos(1,7)
- mp.clearLine()
- end
- function center_text(t, width)
- local text = t
- if not t then text = "" end
- local padding = math.floor((width - #text) / 2)
- return string.rep(" ", padding) .. text .. string.rep(" ", padding+1)
- end
- local t1 = os.epoch("utc")/1000
- while getAmountAlive() > 1 do
- local t2 = os.epoch("utc")/1000
- for i,s in pairs(stations) do
- local mp = peripheral.wrap(s.monitor)
- setFoods(mp,#made_foods)
- if s.alive then
- if s.primed then
- fillBottom(mp,colors.green,i)
- setTime(mp,roundTime+t1-t2,i)
- else
- fillBottom(mp,colors.yellow,i)
- setTime(mp,roundTime+t1-t2,i)
- end
- setPlayersRemaining(mp,getAmountAlive())
- local bp = peripheral.wrap(s.barrel)
- local submission = bp.getItemDetail(1)
- local fd5 = made_names[#made_names-4]
- local fd4 = made_names[#made_names-3]
- local fd3 = made_names[#made_names-2]
- local fd2 = made_names[#made_names-1]
- local fd1 = made_names[#made_names]
- mp.setCursorPos(1,3)
- mp.setTextColor(colors.gray)
- mp.write(center_text(fd5,19))
- mp.setCursorPos(1,4)
- mp.setTextColor(colors.lightGray)
- mp.write(center_text(fd4,19))
- mp.setCursorPos(1,5)
- mp.setTextColor(colors.cyan)
- mp.write(center_text(fd3,19))
- mp.setCursorPos(1,6)
- mp.setTextColor(colors.blue)
- mp.write(center_text(fd2,19))
- mp.setCursorPos(1,7)
- mp.setTextColor(colors.black)
- mp.write(center_text(fd1,19))
- mp.setTextColor(colors.black)
- if submission then
- local sub_name = submission.name
- if contains(all_foods,sub_name) then
- if contains(made_foods,sub_name) then
- kill(i)
- else
- made_foods[#made_foods+1] = sub_name
- made_names[#made_names+1] = submission.displayName
- bp.pushItems(chestStorage, 1)
- s.primed = true
- fillBottom(mp,colors.green,i)
- end
- end
- end
- else
- setTime(mp,0,i)
- end
- end
- if roundTime+t1-t2 < 0 then
- t1 = os.epoch("utc")/1000
- for i,s in pairs(stations) do
- if s.alive and not s.primed then
- kill(i)
- else
- s.primed = false
- local mp = peripheral.wrap(s.monitor)
- fillBottom(mp,colors.white,i)
- end
- end
- end
- sleep(0)
- end
- print("EOF")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement