Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rm /lib/casino.lua
- edit /lib/casino.lua
- local Casino = {}
- local component = require("component")
- local chatbox = component.chat_box
- function Casino:new()
- local newObj = {
- items = {}, -- список предметов, их шансы и дополнительные свойства
- totalChance = 0, -- общий шанс (сумма всех шансов)
- addressMoneyChest = nil, -- Адрес сундука с деньгами
- goodWin = 20, -- Последний хороший выигрыш
- }
- self.__index = self
- return setmetatable(newObj, self)
- end
- function Casino:addItem(name, title, count, chance)
- table.insert(self.items, {
- name = name,
- title = title,
- count = count,
- chance = chance,
- address = nil,
- slot = nil,
- })
- self.totalChance = self.totalChance + chance
- end
- math.randomseed(os.time())
- function Casino:roll(chance)
- local randomValue = math.random() * self.totalChance
- local accumulatedChance = 0
- if self.goodWin <= 0 then
- self.goodWin = self.goodWin - 1
- self.totalChance = self.totalChance - chance
- end
- for _, item in ipairs(self.items) do
- accumulatedChance = accumulatedChance + item.chance
- if randomValue <= accumulatedChance then
- if item.chance == 0.001 then
- self.goodWin = 100
- end
- return item
- end
- end
- end
- function Casino:SearchMoney()
- if not self.addressMoneyChest then
- chatbox.say("Address is nil.")
- os.sleep(0.5)
- return nil
- end
- local trans = component.proxy(self.addressMoneyChest)
- if not trans or not trans.getStackInSlot then -- Проверка успешности получения прокси
- chatbox.say("Не удалось получить прокси компонента для адреса.: " .. tostring(address))
- os.sleep(0.5)
- return nil
- end
- local stack = trans.getStackInSlot(0, 1)
- if stack and stack.name == "contenttweaker:money" and stack.size then -- Проверка наличия стека денег и обновление общего баланса
- chatbox.say(tostring(stack.name) .. " " .. stack.size)
- --totalCash = (totalCash or 0) + stack.size
- --table.insert(logs, {money = stack.size, getClosestPlayer()})
- return stack.size
- end
- return nil
- end
- function Casino:search_transposers()
- -- Предварительное создание маппинга элементов для быстрого поиска
- local itemMap = {}
- for _, item in ipairs(self.items or {}) do
- itemMap[item.name] = item
- end
- for address in component.list("transposer") do
- local trans = component.proxy(address)
- if not trans then return end
- local invName = trans.getInventoryName(0)
- if invName == "appliedenergistics2:interface" then
- local size = trans.getInventorySize(0) or 0
- for i = 1, size do
- local stack = trans.getStackInSlot(0, i)
- if stack then
- local item = itemMap[stack.name] or itemMap[stack.label]
- if item then
- item.address = address
- item.slot = i
- end
- end
- end
- else
- self.addressMoneyChest = address
- if chatbox then chatbox.say("§fСохранил адрес сундука с деньгами: " .. address) end
- end
- end
- end
- function Casino:get_list()
- local result = {}
- table.insert(result, "\n")
- for _, item in ipairs(self.items or {}) do
- local displayName = string.gsub(item.name, "&", "§", 1)
- if item.count == 1 then
- table.insert(result, "§l" .. displayName .. " Шанс: " .. item.chance * 100 * 10 .. "%")
- else
- table.insert(result, "§l" .. displayName .. " x" .. item.count.. " Шанс: " .. item.chance * 100 * 10 .. "%")
- end
- end
- local resultString = table.concat(result, "\n")
- chatbox.say(resultString)
- chatbox.say("§f" ..tostring(self.totalChance * 100) .. "%")
- end
- function Casino:sendMoney(count)
- component.proxy(self.addressMoneyChest).transferItem(0, 1, count, 1, 1)
- end
- return Casino
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement