SHOW:
|
|
- or go back to the newest paste.
| 1 | - | local monitor = peripheral.wrap("top")
|
| 1 | + | local monitor = peripheral.wrap("left")
|
| 2 | - | local wired = peripheral.wrap("back")
|
| 2 | + | local wired = peripheral.wrap("bottom")
|
| 3 | local stand | |
| 4 | local pim | |
| 5 | for k,v in pairs(wired.getNamesRemote()) do | |
| 6 | local type = wired.getTypeRemote(v) | |
| 7 | - | if type == "me_fuzzy_storage_bus" then |
| 7 | + | |
| 8 | if type == "appeng_me_tilestoragebus" then | |
| 9 | stand = peripheral.wrap(v) | |
| 10 | elseif type == "pim" then | |
| 11 | pim = peripheral.wrap(v) | |
| 12 | end | |
| 13 | end | |
| 14 | ||
| 15 | ||
| 16 | if pim == nil then error("No PIM") end
| |
| 17 | if stand == nil then error("No storage bus") end
| |
| 18 | print(stand.listMethodsData()) | |
| 19 | ||
| 20 | local standdir = "north" | |
| 21 | local rsside = "bottom" | |
| 22 | local high = 10 | |
| 23 | local low = 0 | |
| 24 | local wait = 3 | |
| 25 | ||
| 26 | local w,h = monitor.getSize() | |
| 27 | ||
| 28 | local armorMenu, menu | |
| 29 | ||
| 30 | local armor = {}
| |
| 31 | armor[1] = colors.orange | |
| 32 | armor[2] = colors.magenta | |
| 33 | armor[3] = colors.lightBlue | |
| 34 | armor[4] = colors.yellow | |
| 35 | ||
| 36 | local lights = {}
| |
| 37 | lights[1] = colors.lime | |
| 38 | lights[2] = colors.pink | |
| 39 | lights[3] = colors.gray | |
| 40 | lights[4] = colors.lightGray | |
| 41 | ||
| 42 | local inUse = {}
| |
| 43 | inUse[1] = false | |
| 44 | inUse[2] = false | |
| 45 | inUse[3] = false | |
| 46 | inUse[4] = false | |
| 47 | ||
| 48 | --[[ | |
| 49 | local lightSum = function() | |
| 50 | local sum = 0 | |
| 51 | for i = 1,4 do | |
| 52 | if not inUse[i] then sum = sum + lights[i] end | |
| 53 | end | |
| 54 | return sum | |
| 55 | end | |
| 56 | ]]-- | |
| 57 | ||
| 58 | local cutNetwork = function(n) | |
| 59 | local current = rs.getBundledOutput(rsside) | |
| 60 | rs.setBundledOutput(rsside,current-armor[n]) | |
| 61 | end | |
| 62 | ||
| 63 | local powerNetwork = function(n) | |
| 64 | local current = rs.getBundledOutput(rsside) | |
| 65 | rs.setBundledOutput(rsside,current+armor[n]) | |
| 66 | end | |
| 67 | ||
| 68 | local cutLights = function(n) | |
| 69 | local current = rs.getBundledOutput(rsside) | |
| 70 | rs.setBundledOutput(rsside,current-lights[n]) | |
| 71 | end | |
| 72 | ||
| 73 | local powerLights = function(n) | |
| 74 | local current = rs.getBundledOutput(rsside) | |
| 75 | rs.setBundledOutput(rsside,current+lights[n]) | |
| 76 | end | |
| 77 | ||
| 78 | local armorToStand = function(n) | |
| 79 | if stand.getPriority() == high then | |
| 80 | error("Stand not empty.")
| |
| 81 | return | |
| 82 | end | |
| 83 | stand.setPriority(high) | |
| 84 | powerNetwork(n) | |
| 85 | sleep(wait) | |
| 86 | cutNetwork(n) | |
| 87 | cutLights(n) | |
| 88 | end | |
| 89 | ||
| 90 | local clearStand = function() | |
| 91 | stand.setPriority(low) | |
| 92 | for i=1,4 do powerNetwork(i) end | |
| 93 | sleep(wait) | |
| 94 | for i=1,4 do cutNetwork(i) end | |
| 95 | end | |
| 96 | ||
| 97 | local equipArmor = function() | |
| 98 | local inv = pim.getInvName() | |
| 99 | if inv == "EmptyInventory" then return end | |
| 100 | for i=39,36,-1 do | |
| 101 | local data = pim.getStackInSlot(i) | |
| 102 | if data ~= nil then | |
| 103 | term.clear() | |
| 104 | term.setTextColor(colors.red) | |
| 105 | term.setCursorPos(math.floor((w-41)/2),math.floor(h/2)) | |
| 106 | term.write("Already wearing armor. Touch to continue.")
| |
| 107 | os.pullEvent("monitor_touch")
| |
| 108 | clearStand() | |
| 109 | return false | |
| 110 | end | |
| 111 | end | |
| 112 | pim.pullIntoSlot(standdir,0,1,39) | |
| 113 | sleep(0.33) | |
| 114 | pim.pullIntoSlot(standdir,1,1,38) | |
| 115 | sleep(0.33) | |
| 116 | pim.pullIntoSlot(standdir,2,1,37) | |
| 117 | sleep(0.33) | |
| 118 | pim.pullIntoSlot(standdir,3,1,36) | |
| 119 | stand.setPriority(low) | |
| 120 | return true | |
| 121 | end | |
| 122 | ||
| 123 | local unequipArmor = function() | |
| 124 | local inv = pim.getInvName() | |
| 125 | if inv == "EmptyInventory" then return end | |
| 126 | pim.pushIntoSlot(standdir,39,1,0) | |
| 127 | sleep(0.33) | |
| 128 | pim.pushIntoSlot(standdir,38,1,1) | |
| 129 | sleep(0.33) | |
| 130 | pim.pushIntoSlot(standdir,37,1,2) | |
| 131 | sleep(0.33) | |
| 132 | pim.pushIntoSlot(standdir,36,1,3) | |
| 133 | stand.setPriority(high) | |
| 134 | end | |
| 135 | ||
| 136 | local activateSuit = function(suit,n) | |
| 137 | if inUse[n] then | |
| 138 | term.setBackgroundColor(colors.black) | |
| 139 | term.clear() | |
| 140 | term.setCursorPos(math.floor((w-44)/2),math.floor(h/2)) | |
| 141 | term.write("Please stand on the suit pad to remove suit.")
| |
| 142 | while pim.getInvName() == "EmptyInventory" do | |
| 143 | sleep(1) | |
| 144 | end | |
| 145 | unequipArmor() | |
| 146 | sleep(1) | |
| 147 | clearStand() | |
| 148 | powerLights(n) | |
| 149 | armorMenu[suit].color = colors.lime | |
| 150 | inUse[n] = false | |
| 151 | else | |
| 152 | term.setBackgroundColor(colors.black) | |
| 153 | term.clear() | |
| 154 | term.setCursorPos(math.floor((w-43)/2),math.floor(h/2)) | |
| 155 | term.write("Please stand on the suit pad to equip suit.")
| |
| 156 | armorToStand(n) | |
| 157 | while pim.getInvName() == "EmptyInventory" do | |
| 158 | sleep(1) | |
| 159 | end | |
| 160 | if equipArmor() then | |
| 161 | armorMenu[suit].color = colors.red | |
| 162 | inUse[n] = true | |
| 163 | else | |
| 164 | powerLights(n) | |
| 165 | end | |
| 166 | end | |
| 167 | end | |
| 168 | ||
| 169 | local printButton = function(button,color) | |
| 170 | term.setBackgroundColor(color) | |
| 171 | for j = 1,button.sizeY do | |
| 172 | term.setCursorPos(button.X,button.Y+j-1) | |
| 173 | term.write(string.rep(" ",button.sizeX))
| |
| 174 | end | |
| 175 | if type(button.text) == "table" then | |
| 176 | local n = #button.text | |
| 177 | for i = 1,n do | |
| 178 | term.setCursorPos(button.X+math.floor((button.sizeX-button.text[i]:len())/2),button.Y+math.floor((button.sizeY-n)/2)+i-1) | |
| 179 | term.write(button.text[i]) | |
| 180 | end | |
| 181 | else | |
| 182 | term.setCursorPos(button.X+math.floor((button.sizeX-button.text:len())/2),button.Y+math.floor(button.sizeY/2)) | |
| 183 | term.write(button.text) | |
| 184 | end | |
| 185 | end | |
| 186 | ||
| 187 | local printButtons = function(buttons) | |
| 188 | for k,v in pairs(buttons) do | |
| 189 | printButton(v,v.color) | |
| 190 | end | |
| 191 | end | |
| 192 | ||
| 193 | local flashButton = function(button) | |
| 194 | printButton(button, button.colorFlash) | |
| 195 | sleep(0.2) | |
| 196 | printButton(button, button.color) | |
| 197 | sleep(0.1) | |
| 198 | end | |
| 199 | ||
| 200 | local waitForButton = function(buttons) | |
| 201 | local button | |
| 202 | while button == nil do | |
| 203 | local e, side, X, Y = os.pullEvent("monitor_touch")
| |
| 204 | for k,v in pairs(buttons) do | |
| 205 | if X >= v.X and X <= v.X+v.sizeX and Y >= v.Y and Y <= v.Y+v.sizeY then | |
| 206 | button = k | |
| 207 | break | |
| 208 | end | |
| 209 | end | |
| 210 | end | |
| 211 | return button | |
| 212 | end | |
| 213 | ||
| 214 | armorMenu = | |
| 215 | {
| |
| 216 | ["powersuit"] = {},
| |
| 217 | ["thaumium"] = {},
| |
| 218 | ["quantum"] = {},
| |
| 219 | ["nano"] = {},
| |
| 220 | } | |
| 221 | ||
| 222 | armorMenu["powersuit"].text = {"Power","Suit"}
| |
| 223 | armorMenu["powersuit"].X = 2 | |
| 224 | armorMenu["powersuit"].Y = math.floor((h-6)/2) | |
| 225 | armorMenu["powersuit"].sizeX = 11 | |
| 226 | armorMenu["powersuit"].sizeY = 6 | |
| 227 | armorMenu["powersuit"].color = colors.lime | |
| 228 | armorMenu["powersuit"].colorFlash= colors.red | |
| 229 | armorMenu["powersuit"].func = function () activateSuit("powersuit",1) end
| |
| 230 | ||
| 231 | armorMenu["thaumium"].text = {"Thaumium", "Armor"}
| |
| 232 | armorMenu["thaumium"].X = 14 | |
| 233 | armorMenu["thaumium"].Y = math.floor((h-6)/2) | |
| 234 | armorMenu["thaumium"].sizeX = 11 | |
| 235 | armorMenu["thaumium"].sizeY = 6 | |
| 236 | armorMenu["thaumium"].color = colors.lime | |
| 237 | armorMenu["thaumium"].colorFlash= colors.red | |
| 238 | armorMenu["thaumium"].func = function () activateSuit("thaumium",2) end
| |
| 239 | ||
| 240 | armorMenu["quantum"].text = {"Quantum", "Armor"}
| |
| 241 | armorMenu["quantum"].X = 26 | |
| 242 | armorMenu["quantum"].Y = math.floor((h-6)/2) | |
| 243 | armorMenu["quantum"].sizeX = 11 | |
| 244 | armorMenu["quantum"].sizeY = 6 | |
| 245 | armorMenu["quantum"].color = colors.lime | |
| 246 | armorMenu["quantum"].colorFlash= colors.red | |
| 247 | armorMenu["quantum"].func = function () activateSuit("quantum",3) end
| |
| 248 | ||
| 249 | armorMenu["nano"].text = {"Nano", "Armor"}
| |
| 250 | armorMenu["nano"].X = 38 | |
| 251 | armorMenu["nano"].Y = math.floor((h-6)/2) | |
| 252 | armorMenu["nano"].sizeX = 11 | |
| 253 | armorMenu["nano"].sizeY = 6 | |
| 254 | armorMenu["nano"].color = colors.lime | |
| 255 | armorMenu["nano"].colorFlash= colors.red | |
| 256 | armorMenu["nano"].func = function () activateSuit("nano",4) end
| |
| 257 | ||
| 258 | ||
| 259 | term.redirect(monitor) | |
| 260 | term.setBackgroundColor(colors.black) | |
| 261 | term.clear() | |
| 262 | term.setTextColor(colors.red) | |
| 263 | term.setCursorPos(math.floor((w-15)/2),math.floor(h/2)) | |
| 264 | term.write("Touch to start.")
| |
| 265 | os.pullEvent("monitor_touch")
| |
| 266 | term.clear() | |
| 267 | sleep(0.3) | |
| 268 | ||
| 269 | term.setCursorPos(math.floor((w-15)/2),math.floor(h/2)) | |
| 270 | textutils.slowWrite("Initializing...",15)
| |
| 271 | for i=1,4 do powerLights(i) sleep(0.3) end | |
| 272 | clearStand() | |
| 273 | ||
| 274 | ||
| 275 | term.setBackgroundColor(colors.black) | |
| 276 | term.clear() | |
| 277 | ||
| 278 | term.setTextColor(colors.yellow) | |
| 279 | ||
| 280 | term.setCursorPos(math.floor((w-27)/2),3) | |
| 281 | term.write("Armor Selection System v1.0")
| |
| 282 | ||
| 283 | term.setTextColor(colors.white) | |
| 284 | ||
| 285 | menu = armorMenu | |
| 286 | ||
| 287 | while true do | |
| 288 | term.setBackgroundColor(colors.black) | |
| 289 | term.clear() | |
| 290 | term.setTextColor(colors.yellow) | |
| 291 | term.setCursorPos(math.floor((w-27)/2),3) | |
| 292 | term.write("Armor Selection System v1.0")
| |
| 293 | term.setTextColor(colors.white) | |
| 294 | printButtons(menu) | |
| 295 | local b = waitForButton(armorMenu) | |
| 296 | menu[b].func() | |
| 297 | end |