QQ群

DP新手福利+签到+消耗材料抽奖

[复制链接]
查看43 | 回复0 | 2026-2-2 21:11:36 | 显示全部楼层 |阅读模式
自改版签到
链接: https://pan.baidu.com/s/1iVA_iDIUi4oZOsqXglcfFA?pwd=4x72 提取码: 4x72 复制这段内容后打开百度网盘手机App,操作更方便哦
  1. local lastSignInTime = {}  
  2. local lastSignInTime = {}  

  3. -- 新手福利道具配置:{物品ID, 数量, 物品名称}
  4. local newbieItems = {
  5.     {8289, 20, "幸运礼盒"}
  6. }  -- 新手福利道具列表

  7. -- 签到道具配置:{物品ID, 数量, 物品名称}
  8. local signItems = {
  9.     {8289, 2, "幸运礼盒"},  -- 幸运礼盒*2
  10.     {8289, 1, "幸运礼盒"},  -- 幸运礼盒*1
  11.     {992, 1, "幸运盲盒"},   -- 幸运盲盒*1
  12.     {3340, 5, "金币"},      -- 金币*5
  13.     {3340, 10, "金币"},     -- 金币*10
  14.     {20203008, 20, "精炼的时空石"},  -- 精炼的时空石*20
  15.     {20203008, 40, "精炼的时空石"},  -- 精炼的时空石*40
  16.     {3326, 100, "强烈的气息"},      -- 强烈的气息*100
  17.     {3326, 300, "强烈的气息"},      -- 强烈的气息*300
  18.     {20203015, 15, "光之根源"},     -- 光之根源*15
  19.     {20203016, 15, "暗之根源"},     -- 暗之根源*15
  20.     {20203014, 5, "魔岩石"},        -- 魔岩石*5
  21.     {2020011114, 2, "+14 装备增幅券"},  -- +14 装备增幅券*2
  22.     {20203032, 30, "数据芯片"},     -- 数据芯片*30
  23.     {3341, 30, "魔刹石"},           -- 魔刹石*30
  24.     {2021012006, 5, "反物质粒子"},  -- 反物质粒子*5
  25.     {2021012004, 5, "永恒的黑瞳石"}, -- 永恒的黑瞳石*5
  26.     {20203009, 15, "浓缩的魔能石"}, -- 浓缩的魔能石*15
  27.     {20203009, 30, "浓缩的魔能石"}, -- 浓缩的魔能石*30
  28.     {20203011, 20, "魔能石"},       -- 魔能石*20
  29.     {20203011, 40, "魔能石"},       -- 魔能石*40
  30.     {100220519, 1, "超大陆 - 罗迪尼亚的熔岩腰带"},
  31.     {100070551, 1, "超大陆 - 瓦巴拉的大地上衣"},
  32.     {100120544, 1, "超大陆 - 盘古大陆的地震护腿"},
  33.     {100270515, 1, "超大陆 - 凯诺兰的地壳战靴"},
  34.     {100170519, 1, "超大陆 - 潘诺西亚的火山肩甲"},
  35.     {100200554, 1, "死亡的进行曲腰带"},
  36.     {100050698, 1, "妄想的偏执狂上衣"},
  37.     {100100610, 1, "执着的自恋狂护腿"},
  38.     {100250573, 1, "人格的伪装者战靴"},
  39.     {100150579, 1, "崩坏的二次元护肩"},
  40.     {100230480, 1, "刺杀者德叉伽的龙王腰带"},
  41.     {100080526, 1, "逆鳞摩那斯的龙王上衣"},
  42.     {100130512, 1, "搅拌乳海的婆苏吉的蛇神护腿"},
  43.     {100280475, 1, "青莲优钵罗的龙神战靴"},
  44.     {100180480, 1, "海龙王娑伽罗的战神肩甲"},
  45.     {100210550, 1, "维波的凝滞腰带"},
  46.     {100060599, 1, "虚无之空间胸甲"},
  47.     {100110585, 1, "斯狄尔的超合金腿甲"},
  48.     {100260566, 1, "布兰兹的业火长靴"},
  49.     {100160526, 1, "欧格罗斯的生命肩甲"},
  50.     {100240341, 1, "嫉妒之舌腰带"},
  51.     {100090368, 1, "傲慢之眼上衣"},
  52.     {100140363, 1, "暴食之口护腿"},
  53.     {100290354, 1, "怠惰之足战靴"},
  54.     {100190334, 1, "贪婪之手肩甲"},
  55.     {9121137, 1, "王座本源"},
  56.     {9121116, 1, "王冠非冠"},
  57.     {100312425, 1, "启明星的指引"},
  58.     {100300733, 1, "氤氲之息"},
  59.     {100322294, 1, "清泉流响"},
  60.     {100344511, 1, "波利斯的黄金杯"},
  61.     {100352822, 1, "罗塞塔石碑"}
  62. }  -- 签到道具配置

  63. local on_input = function(fnext, _user, input)
  64.     local user = game.fac.user(_user)
  65.     logger.info("INPUT|%d|%s|%s", user:GetAccId(), user:GetCharacName(), input)
  66.     local currentTime = os.time()  -- 获取当前时间戳
  67.     local accId = user:GetAccId()
  68.     local characNo = user:GetCharacNo()
  69.     local characName = user:GetCharacName()

  70.     -- 每日签到逻辑
  71.     if input == "//签到" then
  72.         -- 处理签到日期(早上6点为分界)
  73.         local current_date
  74.         if tonumber(os.date("%H", currentTime)) < 6 then
  75.             local yesterday = currentTime - (24 * 60 * 60)
  76.             current_date = os.date("%Y-%m-%d", yesterday)
  77.         else
  78.             current_date = os.date("%Y-%m-%d")
  79.         end
  80.         local log_file_path = string.format("/var/log/game_sign_in_%s.log", current_date)
  81.         
  82.         -- 检查是否已签到
  83.         local hasSigned = false
  84.         local logFile = io.open(log_file_path, "r")
  85.         if logFile then
  86.             for line in logFile:lines() do
  87.                 if string.match(line, tostring(accId)) then
  88.                     hasSigned = true
  89.                     break
  90.                 end
  91.             end
  92.             logFile:close()
  93.         end
  94.         
  95.         if hasSigned then
  96.             -- 计算下次签到时间(次日6点)
  97.             local lastMidnight = os.time({
  98.                 year = os.date("*t", currentTime).year,
  99.                 month = os.date("*t", currentTime).month,
  100.                 day = os.date("*t", currentTime).day,
  101.                 hour = 0, min = 0, sec = 0
  102.             })
  103.             local nextSixAM = lastMidnight + 24 * 3600 + 6 * 3600  -- 次日6点
  104.             local cooldown = nextSixAM - currentTime
  105.             
  106.             -- 调整凌晨6点前的显示时间
  107.             if tonumber(os.date("%H", currentTime)) < 6 then
  108.                 cooldown = cooldown - (24 * 3600)
  109.             end
  110.             
  111.             -- 格式化剩余时间
  112.             local hours = math.floor(cooldown / 3600)
  113.             local minutes = math.floor((cooldown % 3600) / 60)
  114.             local seconds = cooldown % 60
  115.             
  116.             user:SendNotiPacketMessage("------------------------------------------", 1)
  117.             user:SendNotiPacketMessage("您今天已经签到完毕,请勿重复签到!", 3)
  118.             user:SendNotiPacketMessage(string.format("距离下次签到剩余时间:%d小时%d分钟%d秒", hours, minutes, seconds), 2)
  119.             user:SendNotiPacketMessage("------------------------------------------", 1)
  120.             return 0
  121.         end
  122.         
  123.         -- 随机选择三个签到道具(允许重复)
  124.         local selectedItems = {}
  125.         local itemsCount = #signItems
  126.         
  127.         for i = 1, 3 do
  128.             local randomIndex = math.random(1, itemsCount)
  129.             table.insert(selectedItems, signItems[randomIndex])
  130.         end
  131.         
  132.         -- 发送签到奖励
  133.         user:SendNotiPacketMessage("------------------------------------------", 1)
  134.         user:SendNotiPacketMessage("签到成功!获得以下奖励:", 2)
  135.         
  136.         local logItems = {}
  137.         for i, item in ipairs(selectedItems) do
  138.             local itemId = item[1]
  139.             local itemCount = item[2]
  140.             local itemName = item[3]
  141.             
  142.             -- 发送邮件
  143.             dpx.mail.item(characNo, 3, "每日签到奖励", "感谢您的每日签到,这是您的奖励", tostring(itemId), tostring(itemCount))
  144.             
  145.             -- 发送获得物品通知
  146.             user:SendNotiPacketMessage(string.format("%d. %s*%d", i, itemName, itemCount), 2)
  147.             
  148.             -- 记录物品信息用于日志
  149.             table.insert(logItems, string.format("%s(%d)*%d", itemName, itemId, itemCount))
  150.         end
  151.         
  152.         user:SendNotiPacketMessage("奖励已发送至邮件,请注意查收", 2)
  153.         user:SendNotiPacketMessage("------------------------------------------", 1)
  154.         
  155.         -- 记录签到时间和日志
  156.         lastSignInTime[characNo] = currentTime
  157.         local logFile = io.open(log_file_path, "a")
  158.         if logFile then
  159.             local logMsg = string.format("%s | %d | %s | 签到成功,获得物品:%s\n",
  160.                 os.date("%Y-%m-%d %H:%M:%S"), accId, characName, table.concat(logItems, ","))
  161.             logFile:write(logMsg)
  162.             logFile:close()
  163.         end
  164.         
  165.         return 0
  166.     end

  167.     -- 新手福利领取逻辑
  168.     if input == "//领新手福利" then
  169.         local newbieLogPath = "/var/log/game_newbie_reward.log"
  170.         local hasReceived = false
  171.         
  172.         -- 检查是否已领取新手福利
  173.         local newbieFile = io.open(newbieLogPath, "r")
  174.         if newbieFile then
  175.             for line in newbieFile:lines() do
  176.                 if string.match(line, tostring(accId)) then
  177.                     hasReceived = true
  178.                     break
  179.                 end
  180.             end
  181.             newbieFile:close()
  182.         end
  183.         
  184.         if hasReceived then
  185.             user:SendNotiPacketMessage("------------------------------------------", 1)
  186.             user:SendNotiPacketMessage("您已领取过新手福利,每个账号仅能领取一次", 3)
  187.             user:SendNotiPacketMessage("------------------------------------------", 1)
  188.             return 0
  189.         end
  190.         
  191.         -- 发送新手福利
  192.         for _, item in ipairs(newbieItems) do
  193.             local itemId = item[1]
  194.             local itemCount = item[2]
  195.             local itemName = item[3]
  196.             dpx.mail.item(characNo, 3, "新手福利", "欢迎加入游戏,这是您的新手福利", tostring(itemId), tostring(itemCount))
  197.             user:SendNotiPacketMessage(string.format("获得 %s*%d", itemName, itemCount), 2)
  198.         end
  199.         
  200.         -- 记录领取日志
  201.         local logFile = io.open(newbieLogPath, "a")
  202.         if logFile then
  203.             local logMsg = string.format("%s | %d | %s | 新手福利领取成功\n", os.date("%Y-%m-%d %H:%M:%S"), accId, characName)
  204.             logFile:write(logMsg)
  205.             logFile:close()
  206.         end
  207.         
  208.         user:SendNotiPacketMessage("------------------------------------------", 1)
  209.         user:SendNotiPacketMessage("新手福利已全部发送,请注意重选一下角色查收邮件", 2)
  210.         user:SendNotiPacketMessage("------------------------------------------", 1)
  211.         return 0
  212.     end

  213.     -- 消耗道具抽奖系统 - 放在普通抽奖后面
  214.     if input == "//抽奖" then
  215.         local lotteryLogPath = "/var/log/game_coin_lottery_records.log"
  216.         local accId = user:GetAccId()
  217.         local characNo = user:GetCharacNo()
  218.         local characName = user:GetCharacName()
  219.         
  220.         -- 消耗道具配置
  221.         local consumeItemId = 8059 -- 黑钻硬币(材料)
  222.         local consumeItemName = "黑钻硬币"
  223.         
  224.         -- 读取消耗抽奖记录文件,获取当前抽奖次数
  225.         local lotteryCount = 0
  226.         local countFile = io.open(lotteryLogPath .. ".count", "r")
  227.         if countFile then
  228.             for line in countFile:lines() do
  229.                 local accIdInFile, count = string.match(line, "(%d+)|(%d+)")
  230.                 if accIdInFile and tonumber(accIdInFile) == accId then
  231.                     lotteryCount = tonumber(count)
  232.                     break
  233.                 end
  234.             end
  235.             countFile:close()
  236.         end
  237.         
  238.         -- 修正消耗数量计算(翻倍:1, 2, 4, 8, 16...)
  239.         -- 第一次:lotteryCount=0 -> 2^0=1
  240.         -- 第二次:lotteryCount=1 -> 2^1=2
  241.         -- 第三次:lotteryCount=2 -> 2^2=4
  242.         local consumeCount = 2^lotteryCount
  243.         
  244.         -- 检查玩家是否有足够的黑钻硬币
  245.         local totalCoins = 0
  246.         for i = 0, 400 do
  247.             local itemInfo = dpx.item.info(user.cptr, game.ItemSpace.INVENTORY, i)
  248.             if itemInfo and itemInfo.id == consumeItemId then
  249.                 totalCoins = totalCoins + itemInfo.count
  250.             end
  251.         end
  252.         
  253.         if totalCoins < consumeCount then
  254.             user:SendNotiPacketMessage("------------------------------------------", 1)
  255.             user:SendNotiPacketMessage("❌ 抽奖失败!", 3)
  256.             user:SendNotiPacketMessage(string.format("需要消耗:%s×%d", consumeItemName, consumeCount), 3)
  257.             user:SendNotiPacketMessage(string.format("您的黑钻硬币不足(拥有:%d,需要:%d)", totalCoins, consumeCount), 3)
  258.             user:SendNotiPacketMessage("------------------------------------------", 1)
  259.             return 0
  260.         end
  261.         
  262.         -- 奖池配置
  263.         local lotteryItems = {
  264.             {44261, 1, "紫黑晶体项链", 1},  -- 添加概率值
  265.             {44259, 1, "红黄晶体项链", 1},
  266.             {3242, 1, "矛盾的结晶体", 19},
  267.             {3038, 1, "黑色大晶体", 19},
  268.             {3041, 1, "蓝色大晶体", 10},
  269.             {3042, 1, "无色大晶体", 10},
  270.             {3165, 1, "五彩晶体", 10},
  271.             {3263, 1, "金色大晶体", 10},
  272.             {3040, 1, "红色大晶体", 10},
  273.             {3039, 1, "白色大晶体", 10}
  274.         }
  275.         
  276.         -- 检查消耗抽奖记录文件
  277.         local hasDrawnItems = {}
  278.         local lotteryFile = io.open(lotteryLogPath, "r")
  279.         if lotteryFile then
  280.             for line in lotteryFile:lines() do
  281.                 local parts = {}
  282.                 for part in string.gmatch(line, "[^|]+") do
  283.                     table.insert(parts, part)
  284.                 end
  285.                 if #parts >= 4 then
  286.                     local accIdInFile = tonumber(parts[2])
  287.                     local itemId = tonumber(parts[4])
  288.                     if accIdInFile and accIdInFile == accId then
  289.                         hasDrawnItems[itemId] = true
  290.                     end
  291.                 end
  292.             end
  293.             lotteryFile:close()
  294.         end
  295.         
  296.         -- 检查奖池是否已清空
  297.         local availableCount = 0
  298.         for _, item in ipairs(lotteryItems) do
  299.             local itemId = item[1]
  300.             if not hasDrawnItems[itemId] then
  301.                 availableCount = availableCount + 1
  302.             end
  303.         end
  304.         
  305.         if availableCount == 0 then
  306.             user:SendNotiPacketMessage("------------------------------------------", 1)
  307.             user:SendNotiPacketMessage("🎊 消耗抽奖奖池已清空!所有道具都已抽取完毕。", 3)
  308.             user:SendNotiPacketMessage("------------------------------------------", 1)
  309.             return 0
  310.         end
  311.         
  312.         -- 构建可用奖池
  313.         local availableItems = {}
  314.         for _, item in ipairs(lotteryItems) do
  315.             local itemId = item[1]
  316.             if not hasDrawnItems[itemId] then
  317.                 table.insert(availableItems, item)
  318.             end
  319.         end
  320.         
  321.         -- 随机抽取一个道具
  322.         math.randomseed(tostring(os.time()):reverse():sub(1, 7))
  323.         local randomIndex = math.random(1, #availableItems)
  324.         local selectedItem = availableItems[randomIndex]
  325.         local itemId = selectedItem[1]
  326.         local itemCount = selectedItem[2]
  327.         local itemName = selectedItem[3]
  328.         
  329.         -- 扣除消耗的道具
  330.         local remainingToDelete = consumeCount
  331.         for i = 0, 400 do
  332.             if remainingToDelete <= 0 then
  333.                 break
  334.             end
  335.             
  336.             local itemInfo = dpx.item.info(user.cptr, game.ItemSpace.INVENTORY, i)
  337.             if itemInfo and itemInfo.id == consumeItemId then
  338.                 local deleteCount = math.min(remainingToDelete, itemInfo.count)
  339.                 dpx.item.delete(user.cptr, game.ItemSpace.INVENTORY, i, deleteCount)
  340.                 remainingToDelete = remainingToDelete - deleteCount
  341.                
  342.                 -- 记录删除日志
  343.                 logger.info(string.format("消耗抽奖扣除道具:格子%d, 扣除%d个,剩余需要扣除%d个", i, deleteCount, remainingToDelete))
  344.             end
  345.         end
  346.         
  347.         -- 发送背包更新
  348.         user:SendItemSpace(game.ItemSpace.INVENTORY)
  349.         
  350.         -- 记录抽奖结果
  351.         local logFile = io.open(lotteryLogPath, "a")
  352.         if logFile then
  353.             local logMsg = string.format("%s|%d|%s|%d|%s|消耗:%d|抽奖次数:%d\n",
  354.                 os.date("%Y-%m-%d %H:%M:%S"), accId, characName, itemId, itemName, consumeCount, lotteryCount+1)
  355.             logFile:write(logMsg)
  356.             logFile:close()
  357.         end
  358.         
  359.         -- 更新抽奖次数记录
  360.         local countLogFile = io.open(lotteryLogPath .. ".count", "w")
  361.         if countLogFile then
  362.             countLogFile:write(string.format("%d|%d\n", accId, lotteryCount + 1))
  363.             countLogFile:close()
  364.         end
  365.         
  366.         -- 发送奖励到邮件
  367.         dpx.mail.item(characNo, 3, "消耗抽奖奖励", "恭喜您在消耗抽奖中获得以下道具!", tostring(itemId), tostring(itemCount))
  368.         
  369.         -- 计算剩余道具数量
  370.         local remainingCount = availableCount - 1
  371.         
  372.         -- 发送抽奖结果消息
  373.         user:SendNotiPacketMessage("------------------------------------------", 1)
  374.         user:SendNotiPacketMessage("🎉 消耗抽奖成功!", 2)
  375.         user:SendNotiPacketMessage(string.format("消耗:%s×%d", consumeItemName, consumeCount), 2)
  376.         user:SendNotiPacketMessage(string.format("获得:%s", itemName), 2)
  377.         user:SendNotiPacketMessage(string.format("剩余可抽取道具:%d/%d", remainingCount, #lotteryItems), 2)
  378.         user:SendNotiPacketMessage(string.format("当前抽奖次数:%d", lotteryCount + 1), 2)
  379.         user:SendNotiPacketMessage("奖励已发送至邮件,请注意查收", 2)
  380.         user:SendNotiPacketMessage("------------------------------------------", 1)
  381.         
  382.         return 0
  383.     end

  384.     -- 查看消耗抽奖状态
  385.     if input == "//查看奖池" then
  386.         local lotteryLogPath = "/var/log/game_coin_lottery_records.log"
  387.         local accId = user:GetAccId()
  388.         local characName = user:GetCharacName()
  389.         
  390.         -- 读取消耗抽奖次数
  391.         local lotteryCount = 0
  392.         local countFile = io.open(lotteryLogPath .. ".count", "r")
  393.         if countFile then
  394.             for line in countFile:lines() do
  395.                 local accIdInFile, count = string.match(line, "(%d+)|(%d+)")
  396.                 if accIdInFile and tonumber(accIdInFile) == accId then
  397.                     lotteryCount = tonumber(count)
  398.                     break
  399.                 end
  400.             end
  401.             countFile:close()
  402.         end
  403.         
  404.         -- 计算下次需要消耗的道具数量
  405.         local nextConsumeCount = 1
  406.         if lotteryCount > 0 then
  407.             nextConsumeCount = 2^lotteryCount
  408.         end
  409.         
  410.         -- 奖池配置
  411.         local lotteryItems = {
  412.             {44261, 1, "紫黑晶体项链"},
  413.             {44259, 1, "红黄晶体项链"},
  414.             {3242, 1, "矛盾的结晶体"},
  415.             {3038, 1, "黑色大晶体"},
  416.             {3041, 1, "蓝色大晶体"},
  417.             {3042, 1, "无色大晶体"},
  418.             {3165, 1, "五彩晶体"},
  419.             {3263, 1, "金色大晶体"},
  420.             {3040, 1, "红色大晶体"},
  421.             {3039, 1, "白色大晶体"}
  422.         }
  423.         
  424.         -- 检查消耗抽奖记录文件
  425.         local hasDrawnItems = {}
  426.         local lotteryFile = io.open(lotteryLogPath, "r")
  427.         if lotteryFile then
  428.             for line in lotteryFile:lines() do
  429.                 local parts = {}
  430.                 for part in string.gmatch(line, "[^|]+") do
  431.                     table.insert(parts, part)
  432.                 end
  433.                 if #parts >= 4 then
  434.                     local accIdInFile = tonumber(parts[2])
  435.                     local itemId = tonumber(parts[4])
  436.                     if accIdInFile and accIdInFile == accId then
  437.                         hasDrawnItems[itemId] = true
  438.                     end
  439.                 end
  440.             end
  441.             lotteryFile:close()
  442.         end
  443.         
  444.         -- 构建已抽取和未抽取的道具列表
  445.         local remainingItems = {}
  446.         local drawnItems = {}
  447.         
  448.         for _, item in ipairs(lotteryItems) do
  449.             local itemId = item[1]
  450.             local itemName = item[3]
  451.             if hasDrawnItems[itemId] then
  452.                 table.insert(drawnItems, itemName)
  453.             else
  454.                 table.insert(remainingItems, itemName)
  455.             end
  456.         end
  457.         
  458.         user:SendNotiPacketMessage("------------------------------------------", 1)
  459.         user:SendNotiPacketMessage("🎯 消耗抽奖状态", 2)
  460.         user:SendNotiPacketMessage(string.format("账号:%s", characName), 2)
  461.         user:SendNotiPacketMessage(string.format("已抽奖次数:%d", lotteryCount), 2)
  462.         user:SendNotiPacketMessage(string.format("下次抽奖消耗:黑钻硬币×%d", nextConsumeCount), 2)
  463.         user:SendNotiPacketMessage(string.format("总道具数:%d | 已抽取:%d | 剩余:%d",
  464.             #lotteryItems, #drawnItems, #remainingItems), 2)
  465.         
  466.         if #drawnItems > 0 then
  467.             user:SendNotiPacketMessage("已抽取道具:", 2)
  468.             for i, itemName in ipairs(drawnItems) do
  469.                 user:SendNotiPacketMessage(string.format("%d. %s", i, itemName), 2)
  470.             end
  471.         end
  472.         
  473.         if #remainingItems > 0 then
  474.             user:SendNotiPacketMessage("剩余道具:", 2)
  475.             for i, itemName in ipairs(remainingItems) do
  476.                 user:SendNotiPacketMessage(string.format("%d. %s", i, itemName), 2)
  477.             end
  478.         else
  479.             user:SendNotiPacketMessage("🎊 所有道具都已抽取完毕!", 2)
  480.         end
  481.         
  482.         user:SendNotiPacketMessage("------------------------------------------", 1)
  483.         return 0
  484.     end

  485.     return fnext()
  486. end</b></font></b></font>
复制代码

具消耗抽奖是一次次翻倍的  第一次1个  第二次2个  第三次4个以此类推  可以模仿某些插件    也可以平替土罐  自己改消耗的道具代码  一次性开十个  可调概率  卖消耗材料代码就行了


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则