Stawlie0

Untitled

Oct 14th, 2023
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.48 KB | None | 0 0
  1.     require("package").loaded["doublebuffer"] = nil
  2.     require("package").loaded["control"] = nil
  3.     require("package").loaded["casino"] = nil
  4.     require("package").loaded["sgui"] = nil
  5.    
  6.     local controlLib = require("control")
  7.     local charSpace = ' '
  8.    
  9.     local component = require("component")
  10.     local computer = require("computer")
  11.     local event = require("event")
  12.     local unicode = require("unicode")
  13.     local thread = require("thread")
  14.    
  15.     local Casino = require("casino")
  16.     local gui = require("sgui")
  17.    
  18.     local gpu = component.gpu
  19.     local radar = component.radar
  20.     local chatbox = component.chat_box
  21.    
  22.     chatbox.setName("§6BAZAR CASINO§7§o")
  23.     chatbox.say("§aМодули успешно загружены")
  24.    
  25.     local width, height = gpu.getResolution()
  26.    
  27.     gpu.setResolution(112,50)
  28.    
  29.     local win = {}
  30.     --Резервируем места
  31.     local function reservWin()
  32.         local x = 10 -- начальная Координата x
  33.         local y = 6  -- начальная координата y
  34.         for i = 1, 63 do
  35.             local id = controlLib.createLabel{
  36.                 x = x;
  37.                 y = y;
  38.                 text = ""
  39.             }
  40.             table.insert(win, id)
  41.             x = x + 36
  42.             if x > 108 then
  43.                 x = 10
  44.                 y = y+2
  45.             end
  46.         end
  47.         local id = controlLib.createLabel{
  48.             x = 46;
  49.             y = y;
  50.             text = ""
  51.         }
  52.         table.insert(win, id)
  53.     end
  54.    
  55.     reservWin()
  56.    
  57.     local function ClearWin()
  58.         for i = 1, 64 do
  59.             controlLib.updateControl(win[i], {
  60.                 text = ""
  61.             })
  62.         end
  63.     end
  64.    
  65.     local function saveToFile(filename, data)
  66.         local file = io.open(filename, "w")
  67.         if file then
  68.             file:write(serialization.serialize(data))
  69.             file:close()
  70.         else
  71.             error("Не удалось открыть файл для записи!")
  72.         end
  73.     end
  74.    
  75.     local function loadFromFile(filename)
  76.         local file = io.open(filename, "r")
  77.         if file then
  78.             local data = file:read("*a")
  79.             file:close()
  80.             return serialization.unserialize(data)
  81.         else
  82.             error("Не удалось открыть файл для чтения!")
  83.         end
  84.     end
  85.    
  86.     local myCasino = Casino:new()
  87.  
  88.     myCasino:addItem("&9Панель 6-го уровня", "Ultimate Hybrid Solar Panel", 1, 0.01)
  89.     myCasino:addItem("&9Панель 7-го уровня", "Hybrid Solar Panel", 1, 0.01)
  90.    
  91.     myCasino:search_transposers()
  92.     --myCasino:get_list()
  93.    
  94.     controlLib.drawAll()
  95.     --myCasino:displayItems()
  96.    
  97.     local function mainCasino(money)
  98.         local rewardsList = {}
  99.         local itemCounts = {}
  100.         myCasino:sendMoney(money)
  101.         chatbox.say("§6Баланс пополнен на §a$" .. money)
  102.         for i = 1, 64 do
  103.             controlLib.updateControl(win[i], {
  104.                 text = string.rep(" ", 36),
  105.             })
  106.         end
  107.         controlLib.drawAll()
  108.    
  109.         for i = 1, money do
  110.             local reward = myCasino:weightedRoll()
  111.             local displayName = string.gsub(reward.name, "&", "§", 1)
  112.    
  113.             component.proxy(reward.address).transferItem(0, 1, reward.count, reward.slot, i)
  114.    
  115.             local secondChar = string.sub(reward.name, 2, 2)
  116.             local modifiedString = string.sub(reward.name, 3)
  117.    
  118.             if reward and reward.name and reward.count then
  119.                 -- Суммируем количество одинаковых предметов и сохраняем шанс
  120.                 if itemCounts[displayName] then
  121.                     itemCounts[displayName].count = itemCounts[displayName].count + reward.count
  122.                 else
  123.                     itemCounts[displayName] = {count = reward.count, chance = reward.chance}
  124.                 end
  125.             end
  126.             controlLib.updateControl(win[i], {
  127.                 text = modifiedString,
  128.                 foreColor = gui.colors[secondChar],
  129.             })
  130.             controlLib.drawAll()
  131.             os.sleep(0.5)
  132.         end
  133.    
  134.         -- Создаем список для отсортированных результатов
  135.         for name, data in pairs(itemCounts) do
  136.             table.insert(rewardsList, {name = name, count = data.count, chance = data.chance})
  137.         end
  138.    
  139.         table.sort(rewardsList, function(a, b) return a.chance < b.chance end)
  140.    
  141.         local results = {}
  142.         for _, item in ipairs(rewardsList) do
  143.             table.insert(results, item.name .. ": " .. item.count .. "x")
  144.         end
  145.         local resultString = "\n" .. table.concat(results, "\n")
  146.         chatbox.say(resultString)        
  147.     end
  148.    
  149.     local totalCash = 0
  150.    
  151.     local permissions = {}
  152.     permissions["Stawlie_"] = true
  153.     permissions["NikkyFreaky"] = true
  154.    
  155.     local function chatMessageHandler()
  156.         chatbox.say("Модуль чата запущен")
  157.         while true do
  158.             local _, address, nick, msg = event.pull(0.1, "chat_message")
  159.             local words = {}
  160.             local countWords = 0
  161.    
  162.             if msg then
  163.                 msg = string.lower(msg)
  164.                 for word in msg:gmatch("%S+") do
  165.                     table.insert(words, word)
  166.                     countWords = countWords + 1
  167.                 end
  168.                
  169.                 if msg == "@list" then
  170.                     myCasino:get_list()
  171.                 end
  172.                
  173.                 if permissions[nick] then
  174.                     if words[1] == "@try" then
  175.                         chatbox.say("§fПопыток: §a§l" .. totalCash)
  176.                     elseif words[1] == "@off" then
  177.                         chatbox.say("§e§lПерезагружаюсь")
  178.                         computer.shutdown(true)
  179.                     elseif words[1] == "@add" then
  180.                         if words[2] then
  181.                             chatbox.say("§с&lПополняю")
  182.                             mainCasino(tonumber(words[2]))
  183.                         end
  184.                     elseif words[1] == "@owner" then
  185.                         if words[2] then
  186.                             permissions[words[2]] = true
  187.                         end
  188.                     end
  189.                 end
  190.             end
  191.         end
  192.     end
  193.    
  194.     thread.create(chatMessageHandler)
  195.    
  196.     local colors = { {0xFF0000, 0x0000FF}, {0x0000FF, 0x00FF00}, {0x00FF00, 0xFF0000} }
  197.     local indexColorGradient = 1
  198.    
  199.     while true do
  200.         gui.drawMain("[Casino BAZAR]", 0.3, colors[indexColorGradient][1], colors[indexColorGradient][2])
  201.        
  202.         indexColorGradient = indexColorGradient % #colors + 1
  203.        
  204.         local money = myCasino:SearchMoney()
  205.    
  206.         if money then
  207.             --totalCash = 0
  208.             mainCasino(money)
  209.             totalCash = totalCash + money
  210.             --saveToFile("/try.data", totalCash)
  211.         end
  212.         computer.pullSignal(2)
  213.     end
  214.    
  215.     --Проблемы
  216.     --Если существует 2 одинаковых предмета, например камень с шансом 0.3 и камень с шансом 0.2, алгоритм записывает адрес только первого камня, который попадется в списке
Advertisement
Add Comment
Please, Sign In to add comment