Advertisement
Guest User

a

a guest
Sep 23rd, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.19 KB | None | 0 0
  1. --[[
  2.  INSTRUCTIONS
  3.  
  4.  1. Modifier les cotåA5A9s en fonction d'ou sont placåA5A9 les påA5A9riphåA5A9riques.
  5.  2. Modifier la liste des aspects dans 'essentias', aucun autre aspect ne sera affichåA5A9 si il n'est pas dans cette liste
  6.  3. Modifier le tableau 'quantity' qui permet d'initialiser les valeurs des jars
  7.  4. DåA5A9finir les niveaux d'alerte
  8.  5. DåA5A9finir les couleurs d'affichage (choix uniquement avec les 'colors.choix' de l'api Colors de Computer Craft)
  9.  
  10.  
  11. --]]
  12.  
  13. --[[
  14.    
  15.     Faire une initialisation pour våA5A9rifier que les niveaux soit bien dåA5A9finie et que tout soit possible
  16.  
  17. --]]
  18.  
  19. -- ## DåA5A9finition des variables
  20.  
  21. -- påA5A9riphåA5A9riques
  22. coffre_side = "diamond_0"
  23. me_side = "appeng_me_tileterminal_0"
  24. coffreSFM = "north"
  25. monitor_side = "top"
  26.  
  27. -- niveaux de couleurs d'essence
  28. maxValue = 256
  29. lowValue = maxValue * 25/100
  30. highValue = maxValue * 50/100
  31.  
  32. -- couleurs d'affichage pour le niveau d'essence
  33. lowColor = colors.red
  34. mediumColor = colors.orange
  35. highColor = colors.green
  36. NaColor = colors.gray
  37. basicColor = colors.white
  38. backgroundColor = colors.black
  39.  
  40. -- liste des essences
  41. essentias = {
  42.     "Aer",
  43.     "Alienis",
  44.     "Aqua",
  45.     "Arbor",
  46.     "Auram",
  47.     "Bestia",
  48.     "Cognitio",
  49.     "Corpus",
  50.     "Desidia",
  51.     "Exanimis",
  52.     "Fabrico",
  53.     "Fames",
  54.     "Gelum",
  55.     "Granum",
  56.     "Gula",
  57.     "Herba",
  58.     "Humanus",
  59.     "Ignis",
  60.     "Infernus",
  61.     "Instrumentum",
  62.     "Invidia",
  63.     "Ira",
  64.     "Iter",
  65.     "Limus",
  66.     "Lucrum",
  67.     "Lux",
  68.     "Luxuria",
  69.     "Machina",
  70.     "Messis",
  71.     "Metallum",
  72.     "Meto",
  73.     "Mortuus",
  74.     "Motus",
  75.     "Ordo",
  76.     "Pannus",
  77.     "Perditio",
  78.     "Perfodio",
  79.     "Permutatio",
  80.     "Potentia",
  81.     "Praecantatio",
  82.     "Sano",
  83.     "Saxum",
  84.     "Sensus",
  85.     "Spiritus",
  86.     "Superbia",
  87.     "Telum",
  88.     "Tempestas",
  89.     "Tempus",
  90.     "Tenebrae",
  91.     "Terra",
  92.     "Tutamen",
  93.     "Vacuos",
  94.     "Venenum",
  95.     "Victus",
  96.     "Vinculum",
  97.     "Vitium",
  98.     "Vitreus",
  99.     "Volatus"
  100. }
  101.  
  102. -- initialisation de l'affichage des essences
  103. quantity = {
  104.     ["Aer"] = "N/A",
  105.     ["Alienis"] = "N/A",
  106.     ["Aqua"] = "N/A",
  107.     ["Arbor"] = "N/A",
  108.     ["Auram"] = "N/A",
  109.     ["Bestia"] = "N/A",
  110.     ["Cognitio"] = "N/A",
  111.     ["Corpus"] = "N/A",
  112.     ["Desidia"] = "N/A",
  113.     ["Exanimis"] = "N/A",
  114.     ["Fabrico"] = "N/A",
  115.     ["Fames"] = "N/A",
  116.     ["Gelum"] = "N/A",
  117.     ["Granum"] = "N/A",
  118.     ["Gula"] = "N/A",
  119.     ["Herba"] = "N/A",
  120.     ["Humanus"] = "N/A",
  121.     ["Ignis"] = "N/A",
  122.     ["Infernus"] = "N/A",
  123.     ["Instrumentum"] = "N/A",
  124.     ["Invidia"] = "N/A",
  125.     ["Ira"] = "N/A",
  126.     ["Iter"] = "N/A",
  127.     ["Limus"] = "N/A",
  128.     ["Lucrum"] = "N/A",
  129.     ["Lux"] = "N/A",
  130.     ["Luxuria"] = "N/A",
  131.     ["Machina"] = "N/A",
  132.     ["Messis"] = "N/A",
  133.     ["Metallum"] = "N/A",
  134.     ["Meto"] = "N/A",
  135.     ["Mortuus"] = "N/A",
  136.     ["Motus"] = "N/A",
  137.     ["Ordo"] = "N/A",
  138.     ["Pannus"] = "N/A",
  139.     ["Perditio"] = "N/A",
  140.     ["Perfodio"] = "N/A",
  141.     ["Permutatio"] = "N/A",
  142.     ["Potentia"] = "N/A",
  143.     ["Praecantatio"] = "N/A",
  144.     ["Sano"] = "N/A",
  145.     ["Saxum"] = "N/A",
  146.     ["Sensus"] = "N/A",
  147.     ["Spiritus"] = "N/A",
  148.     ["Superbia"] = "N/A",
  149.     ["Telum"] = "N/A",
  150.     ["Tempus"] = "N/A",
  151.     ["Tempestas"] = "N/A",
  152.     ["Tenebrae"] = "N/A",
  153.     ["Terra"] = "N/A",
  154.     ["Tempus"] = "N/A",
  155.     ["Tutamen"] = "N/A",
  156.     ["Vacuos"] = "N/A",
  157.     ["Venenum"] = "N/A",
  158.     ["Victus"] = "N/A",
  159.     ["Vinculum"] = "N/A",
  160.     ["Vitium"] = "N/A",
  161.     ["Vitreus"] = "N/A",
  162.     ["Volatus"] = "N/A"
  163. }
  164.  
  165. -- liste des aspects et les id correspondant
  166. essentiaId = {
  167.     ["Alienis"] = 368,
  168. }
  169.  
  170. -- liste des id åA5A0 approvisionner
  171. ressource = {
  172.     [368] = {["Alienis"] = 4, ["Iter"] = 4, ["Praecantatio"]=2}
  173. }
  174.  
  175. -- ## End DåA5A9finition
  176.  
  177.  
  178.  
  179.  
  180.  
  181. -- ## VåA5A9rif des paramåA5A8tres
  182.     print("Check settings...")
  183.     local arret = {}
  184.     local side = {"top", "bottom", "right", "left", "back", "front"}
  185.     local colors = {colors.white, colors.orange, colors.magenta, colors.lightBlue, colors.yellow, colors.lime, colors.pink, colors.gray, colors.lightGray, colors.cyan, colors.purple, colors.blue, colors.brown, colors.green, colors.red, colors.black}
  186.    
  187.    
  188.     -- test des couleurs
  189.     local testLowColor = false
  190.     local testMediumColor = false
  191.     local testHighColor = false
  192.     local testNaColor = false
  193.     local testBasicColor = false
  194.     local testBackgroundColor = false
  195.    
  196.     for index, color in pairs(colors) do
  197.         if lowColor == color then
  198.             testLowColor = true
  199.         end
  200.         if mediumColor == color then
  201.             testMediumColor = true
  202.         end
  203.         if highColor == color then
  204.             testHighColor = true
  205.         end
  206.         if NaColor == color then
  207.             testNaColor = true
  208.         end
  209.         if basicColor == color then
  210.             testBasicColor = true
  211.         end
  212.         if backgroundColor == color then
  213.             testBackgroundColor = true
  214.         end
  215.     end
  216.  
  217.     if testLowColor == false then
  218.         table.insert(arret, "lowColor")
  219.     end
  220.     if testMediumColor == false then
  221.         table.insert(arret, "mediumColor")
  222.     end
  223.     if testHighColor == false then
  224.         table.insert(arret, "highColor")
  225.     end
  226.     if testNaColor == false then
  227.         table.insert(arret, "NaColor")
  228.     end
  229.     if testBasicColor == false then
  230.         table.insert(arret, "basicColor")
  231.     end
  232.     if testBackgroundColor == false then
  233.         table.insert(arret, "backgroundColor")
  234.     end
  235.    
  236.  
  237.     -- test des påA5A9riphåA5A9riques
  238.     local testcoffre_side = false
  239.     local testMonitor_side = false
  240.     for index, side in pairs(side) do
  241.         if coffre_side == side then
  242.             testcoffre_side = true
  243.         end
  244.         if monitor_side == side then
  245.             testMonitor_side = true
  246.         end
  247.     end
  248.    
  249.     if testcoffre_side == false then
  250.         table.insert(arret, "coffre_side")
  251.     end
  252.     if testMonitor_side == false then
  253.         table.insert(arret, "monitor_side")
  254.     end
  255.    
  256.    
  257.     -- test des niveaux d'alerte coloråA5A9s
  258.     local testLowValue = false
  259.     local testHighValue = false
  260.    
  261.     if lowValue < 0 then
  262.         table.insert(arret, "lowValue")
  263.     end
  264.     if highValue < 0 then
  265.         table.insert(arret, "highValue")
  266.     end
  267.    
  268.     if lowValue > highValue then
  269.         table.insert(arret, "lowValue & highValue")
  270.     end
  271.    
  272.    
  273.     -- affichage des erreurs
  274.     if table.maxn(arret) ~= 0 then
  275.         local erreurs = "failing setting on parameters:\n"
  276.         for index, param in pairs(arret) do
  277.             erreurs = erreurs.."- '"..param.."'\n"
  278.         end
  279. --      error(erreurs)-- arrête du programme åA5A0 cause d'une erreur
  280.     end
  281.     print("Settings OK!")
  282.  
  283.  
  284.  
  285.  
  286. -- ## End VåA5A9rif des paramåA5A8tres
  287.  
  288.  
  289. -- ## Init
  290.  
  291. chest = peripheral.wrap(coffre_side)
  292. me=peripheral.wrap(me_side)
  293. m = peripheral.wrap(monitor_side)
  294. m.setBackgroundColor(backgroundColor)
  295. m.setTextScale(1)
  296. m.clear()
  297.  
  298. local largeurMax
  299. local tmpLargeur
  300. local x
  301. local y
  302. local affichage
  303. local lMon
  304. local hMon
  305. local tmpQuantity
  306.  
  307. local largeurTotale
  308.  
  309. -- ## End Init
  310.  
  311.  
  312.  
  313. -- ## Function
  314. function refill(_name,_quantity)
  315.     if redstone==true then
  316.         if _quantity <= lowValue then
  317.             idItem = essentiaId[_name]
  318.             if idItem ~= nil then   --au cas ou l'id n'a pas åA5A9tåA5A9 notåA5A9 pour cet aspect
  319.                 facteur = ressource[idItem][_name]
  320.                 if facteur ~= nil then  --au cas ou la ressource n'as pas åA5A9tåA5A9 notåA5A9 dans le tableau
  321.                     wanted = (highValue - panier[_name]) / facteur
  322.                     for k,v in pairs(ressource[idItem ]) do --k = aspect et v = sa quantitåA5A9 dans l'item
  323.                         panier[k] = panier[k] + v * wanted  --on update le panier total
  324.                         if me.containsItemType(idItem ,0) then  --cas ou l'on n'a pas l'id dans le coffre
  325.                             if me.countOfItemType(idItem ,0) < wanted then -- si l'on a moins d'item dans la me que demandåA9
  326.                                 wanted = me.countOfItemType(idItem ,0)
  327. print(wanted)
  328.                             end
  329.                             me.extractItem({id=idItem , dmg=0, qty=wanted},"north")
  330.                         end
  331.                     end
  332.                 end
  333.             end
  334.         end
  335.     end
  336. end
  337.  
  338.  
  339. -- ## End Function
  340.  
  341.  
  342.  
  343. -- ## Main
  344. local lTerm, hTerm = term.getSize()
  345.  
  346. local mesTerm = "... in execution ..."
  347. term.setCursorPos(math.ceil((lTerm-string.len(mesTerm))/2), math.ceil(hTerm/2))
  348. term.clear()
  349. term.write(mesTerm)
  350.  
  351. panier={}
  352. for k,v in pairs(quantity) do
  353.   panier[k]=0
  354. end
  355.  
  356. while true do
  357.     lMon, hMon = m.getSize()
  358.     redstone=true
  359.    
  360.  
  361.  
  362.  
  363.     lstPeriph=peripheral.getNames()         --on recupere la liste des peripheral dans un tableau
  364.     for k,v in pairs(quantity) do           --on remet toutes les valeurs des essences a 0 sur le tableau
  365.         quantity[k]="N/A"
  366.     end
  367.  
  368.     for k,periph in pairs(lstPeriph) do
  369.         if periph == monitor_side then      --on ne cherche evidement pas de jar sur le monitor
  370.         elseif periph == "left" then
  371.   elseif periph == "back" then
  372.   elseif periph == coffre_side then --on ne cherche evidement pas de jar sur le coffre
  373. elseif periph == me_side then
  374.         else                                --tous les autres peripheriques doivent etre des jars
  375.             jar=peripheral.wrap(periph)
  376.             local essentia = jar.getAspects()
  377.             if (essentia[1] == nil or essentia[1] == '') then
  378.             else
  379.                 local name = essentia[1]["name"]
  380.                 local quantityjar = jar.getAspectCount(name)
  381.                 if name and quantityjar then
  382.                     if quantity[name] == "N/A" then --cas ou la quantitåA5A9 est vide
  383.         quantity[name] = quantityjar
  384.                     else
  385.                         quantity[name] = quantityjar + quantity[name]
  386.                     end
  387.  
  388. --                  print(name.." : "..quantityjar)
  389.                 end
  390.             end
  391.         end
  392.     end
  393.  
  394.     lstPeriph=nil   -- vidage de la table des peripheral en cas de changement des jars
  395.    
  396.     m.clear()
  397.     largeurMax = 0
  398.     tmpLargeur = 0
  399.     largeurTotale = 0
  400.     x = 1
  401.     y = 1
  402.    
  403.     if quantity ~= nil then -- cas tableau vide
  404.         for index, name in pairs(essentias) do
  405.             tmpQuantity = quantity[name]
  406.             if tmpQuantity ~= nil then -- cas essence non repertoriåA5A9
  407.                 m.setCursorPos(x,y)
  408.                 tmpLargeur = 0
  409.                 if x > 1 then
  410.                     m.setTextColor(basicColor)
  411.                     m.write("|")
  412.                     m.setCursorPos(x+1,y)
  413.                     tmpLargeur = 1
  414.                 end
  415.                
  416.                 if tmpQuantity == "N/A" then
  417.                     m.setTextColor(NaColor)
  418.                 elseif tmpQuantity < lowValue then
  419.                     m.setTextColor(lowColor)
  420.                 elseif tmpQuantity > highValue then
  421.                     m.setTextColor(highColor)
  422.                 else
  423.                     m.setTextColor(mediumColor)
  424.                 end
  425.                
  426.                 affichage = name.." "..tmpQuantity
  427.                 m.write(affichage)          --Affichage sur le moniteur
  428. if tmpQuantity ~= "N/A" then
  429.                 refill(name,tmpQuantity)            --fonction de la gestion du remplissage
  430. end
  431.                 tmpLargeur = tmpLargeur + string.len(affichage)
  432.                
  433.                 if tmpLargeur > largeurMax then
  434.                     largeurMax = tmpLargeur
  435.                 end
  436.                 if y < hMon then
  437.                     y = y + 1
  438.                 else
  439.                     y = 1
  440.                     x = x + largeurMax
  441.                     largeurTotale = largeurTotale + largeurMax
  442.                 end
  443.                
  444.                 if largeurTotale > (lMon + 10) then
  445.                     print("Plus de moniteur d'affichage requis")   
  446.                     break
  447.                 end
  448.             end
  449.         end
  450.     end
  451.     sleep(5)
  452. end
  453. -- ## End Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement