DP新手福利+签到+消耗材料抽奖
自改版签到链接: https://pan.baidu.com/s/1iVA_iDIUi4oZOsqXglcfFA?pwd=4x72 提取码: 4x72 复制这段内容后打开百度网盘手机App,操作更方便哦local lastSignInTime = {}local lastSignInTime = {}
-- 新手福利道具配置:{物品ID, 数量, 物品名称}
local newbieItems = {
{8289, 20, "幸运礼盒"}
}-- 新手福利道具列表
-- 签到道具配置:{物品ID, 数量, 物品名称}
local signItems = {
{8289, 2, "幸运礼盒"},-- 幸运礼盒*2
{8289, 1, "幸运礼盒"},-- 幸运礼盒*1
{992, 1, "幸运盲盒"}, -- 幸运盲盒*1
{3340, 5, "金币"}, -- 金币*5
{3340, 10, "金币"}, -- 金币*10
{20203008, 20, "精炼的时空石"},-- 精炼的时空石*20
{20203008, 40, "精炼的时空石"},-- 精炼的时空石*40
{3326, 100, "强烈的气息"}, -- 强烈的气息*100
{3326, 300, "强烈的气息"}, -- 强烈的气息*300
{20203015, 15, "光之根源"}, -- 光之根源*15
{20203016, 15, "暗之根源"}, -- 暗之根源*15
{20203014, 5, "魔岩石"}, -- 魔岩石*5
{2020011114, 2, "+14 装备增幅券"},-- +14 装备增幅券*2
{20203032, 30, "数据芯片"}, -- 数据芯片*30
{3341, 30, "魔刹石"}, -- 魔刹石*30
{2021012006, 5, "反物质粒子"},-- 反物质粒子*5
{2021012004, 5, "永恒的黑瞳石"}, -- 永恒的黑瞳石*5
{20203009, 15, "浓缩的魔能石"}, -- 浓缩的魔能石*15
{20203009, 30, "浓缩的魔能石"}, -- 浓缩的魔能石*30
{20203011, 20, "魔能石"}, -- 魔能石*20
{20203011, 40, "魔能石"}, -- 魔能石*40
{100220519, 1, "超大陆 - 罗迪尼亚的熔岩腰带"},
{100070551, 1, "超大陆 - 瓦巴拉的大地上衣"},
{100120544, 1, "超大陆 - 盘古大陆的地震护腿"},
{100270515, 1, "超大陆 - 凯诺兰的地壳战靴"},
{100170519, 1, "超大陆 - 潘诺西亚的火山肩甲"},
{100200554, 1, "死亡的进行曲腰带"},
{100050698, 1, "妄想的偏执狂上衣"},
{100100610, 1, "执着的自恋狂护腿"},
{100250573, 1, "人格的伪装者战靴"},
{100150579, 1, "崩坏的二次元护肩"},
{100230480, 1, "刺杀者德叉伽的龙王腰带"},
{100080526, 1, "逆鳞摩那斯的龙王上衣"},
{100130512, 1, "搅拌乳海的婆苏吉的蛇神护腿"},
{100280475, 1, "青莲优钵罗的龙神战靴"},
{100180480, 1, "海龙王娑伽罗的战神肩甲"},
{100210550, 1, "维波的凝滞腰带"},
{100060599, 1, "虚无之空间胸甲"},
{100110585, 1, "斯狄尔的超合金腿甲"},
{100260566, 1, "布兰兹的业火长靴"},
{100160526, 1, "欧格罗斯的生命肩甲"},
{100240341, 1, "嫉妒之舌腰带"},
{100090368, 1, "傲慢之眼上衣"},
{100140363, 1, "暴食之口护腿"},
{100290354, 1, "怠惰之足战靴"},
{100190334, 1, "贪婪之手肩甲"},
{9121137, 1, "王座本源"},
{9121116, 1, "王冠非冠"},
{100312425, 1, "启明星的指引"},
{100300733, 1, "氤氲之息"},
{100322294, 1, "清泉流响"},
{100344511, 1, "波利斯的黄金杯"},
{100352822, 1, "罗塞塔石碑"}
}-- 签到道具配置
local on_input = function(fnext, _user, input)
local user = game.fac.user(_user)
logger.info("INPUT|%d|%s|%s", user:GetAccId(), user:GetCharacName(), input)
local currentTime = os.time()-- 获取当前时间戳
local accId = user:GetAccId()
local characNo = user:GetCharacNo()
local characName = user:GetCharacName()
-- 每日签到逻辑
if input == "//签到" then
-- 处理签到日期(早上6点为分界)
local current_date
if tonumber(os.date("%H", currentTime)) < 6 then
local yesterday = currentTime - (24 * 60 * 60)
current_date = os.date("%Y-%m-%d", yesterday)
else
current_date = os.date("%Y-%m-%d")
end
local log_file_path = string.format("/var/log/game_sign_in_%s.log", current_date)
-- 检查是否已签到
local hasSigned = false
local logFile = io.open(log_file_path, "r")
if logFile then
for line in logFile:lines() do
if string.match(line, tostring(accId)) then
hasSigned = true
break
end
end
logFile:close()
end
if hasSigned then
-- 计算下次签到时间(次日6点)
local lastMidnight = os.time({
year = os.date("*t", currentTime).year,
month = os.date("*t", currentTime).month,
day = os.date("*t", currentTime).day,
hour = 0, min = 0, sec = 0
})
local nextSixAM = lastMidnight + 24 * 3600 + 6 * 3600-- 次日6点
local cooldown = nextSixAM - currentTime
-- 调整凌晨6点前的显示时间
if tonumber(os.date("%H", currentTime)) < 6 then
cooldown = cooldown - (24 * 3600)
end
-- 格式化剩余时间
local hours = math.floor(cooldown / 3600)
local minutes = math.floor((cooldown % 3600) / 60)
local seconds = cooldown % 60
user:SendNotiPacketMessage("------------------------------------------", 1)
user:SendNotiPacketMessage("您今天已经签到完毕,请勿重复签到!", 3)
user:SendNotiPacketMessage(string.format("距离下次签到剩余时间:%d小时%d分钟%d秒", hours, minutes, seconds), 2)
user:SendNotiPacketMessage("------------------------------------------", 1)
return 0
end
-- 随机选择三个签到道具(允许重复)
local selectedItems = {}
local itemsCount = #signItems
for i = 1, 3 do
local randomIndex = math.random(1, itemsCount)
table.insert(selectedItems, signItems)
end
-- 发送签到奖励
user:SendNotiPacketMessage("------------------------------------------", 1)
user:SendNotiPacketMessage("签到成功!获得以下奖励:", 2)
local logItems = {}
for i, item in ipairs(selectedItems) do
local itemId = item
local itemCount = item
local itemName = item
-- 发送邮件
dpx.mail.item(characNo, 3, "每日签到奖励", "感谢您的每日签到,这是您的奖励", tostring(itemId), tostring(itemCount))
-- 发送获得物品通知
user:SendNotiPacketMessage(string.format("%d. %s*%d", i, itemName, itemCount), 2)
-- 记录物品信息用于日志
table.insert(logItems, string.format("%s(%d)*%d", itemName, itemId, itemCount))
end
user:SendNotiPacketMessage("奖励已发送至邮件,请注意查收", 2)
user:SendNotiPacketMessage("------------------------------------------", 1)
-- 记录签到时间和日志
lastSignInTime = currentTime
local logFile = io.open(log_file_path, "a")
if logFile then
local logMsg = string.format("%s | %d | %s | 签到成功,获得物品:%s\n",
os.date("%Y-%m-%d %H:%M:%S"), accId, characName, table.concat(logItems, ","))
logFile:write(logMsg)
logFile:close()
end
return 0
end
-- 新手福利领取逻辑
if input == "//领新手福利" then
local newbieLogPath = "/var/log/game_newbie_reward.log"
local hasReceived = false
-- 检查是否已领取新手福利
local newbieFile = io.open(newbieLogPath, "r")
if newbieFile then
for line in newbieFile:lines() do
if string.match(line, tostring(accId)) then
hasReceived = true
break
end
end
newbieFile:close()
end
if hasReceived then
user:SendNotiPacketMessage("------------------------------------------", 1)
user:SendNotiPacketMessage("您已领取过新手福利,每个账号仅能领取一次", 3)
user:SendNotiPacketMessage("------------------------------------------", 1)
return 0
end
-- 发送新手福利
for _, item in ipairs(newbieItems) do
local itemId = item
local itemCount = item
local itemName = item
dpx.mail.item(characNo, 3, "新手福利", "欢迎加入游戏,这是您的新手福利", tostring(itemId), tostring(itemCount))
user:SendNotiPacketMessage(string.format("获得 %s*%d", itemName, itemCount), 2)
end
-- 记录领取日志
local logFile = io.open(newbieLogPath, "a")
if logFile then
local logMsg = string.format("%s | %d | %s | 新手福利领取成功\n", os.date("%Y-%m-%d %H:%M:%S"), accId, characName)
logFile:write(logMsg)
logFile:close()
end
user:SendNotiPacketMessage("------------------------------------------", 1)
user:SendNotiPacketMessage("新手福利已全部发送,请注意重选一下角色查收邮件", 2)
user:SendNotiPacketMessage("------------------------------------------", 1)
return 0
end
-- 消耗道具抽奖系统 - 放在普通抽奖后面
if input == "//抽奖" then
local lotteryLogPath = "/var/log/game_coin_lottery_records.log"
local accId = user:GetAccId()
local characNo = user:GetCharacNo()
local characName = user:GetCharacName()
-- 消耗道具配置
local consumeItemId = 8059 -- 黑钻硬币(材料)
local consumeItemName = "黑钻硬币"
-- 读取消耗抽奖记录文件,获取当前抽奖次数
local lotteryCount = 0
local countFile = io.open(lotteryLogPath .. ".count", "r")
if countFile then
for line in countFile:lines() do
local accIdInFile, count = string.match(line, "(%d+)|(%d+)")
if accIdInFile and tonumber(accIdInFile) == accId then
lotteryCount = tonumber(count)
break
end
end
countFile:close()
end
-- 修正消耗数量计算(翻倍:1, 2, 4, 8, 16...)
-- 第一次:lotteryCount=0 -> 2^0=1
-- 第二次:lotteryCount=1 -> 2^1=2
-- 第三次:lotteryCount=2 -> 2^2=4
local consumeCount = 2^lotteryCount
-- 检查玩家是否有足够的黑钻硬币
local totalCoins = 0
for i = 0, 400 do
local itemInfo = dpx.item.info(user.cptr, game.ItemSpace.INVENTORY, i)
if itemInfo and itemInfo.id == consumeItemId then
totalCoins = totalCoins + itemInfo.count
end
end
if totalCoins < consumeCount then
user:SendNotiPacketMessage("------------------------------------------", 1)
user:SendNotiPacketMessage("❌ 抽奖失败!", 3)
user:SendNotiPacketMessage(string.format("需要消耗:%s×%d", consumeItemName, consumeCount), 3)
user:SendNotiPacketMessage(string.format("您的黑钻硬币不足(拥有:%d,需要:%d)", totalCoins, consumeCount), 3)
user:SendNotiPacketMessage("------------------------------------------", 1)
return 0
end
-- 奖池配置
local lotteryItems = {
{44261, 1, "紫黑晶体项链", 1},-- 添加概率值
{44259, 1, "红黄晶体项链", 1},
{3242, 1, "矛盾的结晶体", 19},
{3038, 1, "黑色大晶体", 19},
{3041, 1, "蓝色大晶体", 10},
{3042, 1, "无色大晶体", 10},
{3165, 1, "五彩晶体", 10},
{3263, 1, "金色大晶体", 10},
{3040, 1, "红色大晶体", 10},
{3039, 1, "白色大晶体", 10}
}
-- 检查消耗抽奖记录文件
local hasDrawnItems = {}
local lotteryFile = io.open(lotteryLogPath, "r")
if lotteryFile then
for line in lotteryFile:lines() do
local parts = {}
for part in string.gmatch(line, "[^|]+") do
table.insert(parts, part)
end
if #parts >= 4 then
local accIdInFile = tonumber(parts)
local itemId = tonumber(parts)
if accIdInFile and accIdInFile == accId then
hasDrawnItems = true
end
end
end
lotteryFile:close()
end
-- 检查奖池是否已清空
local availableCount = 0
for _, item in ipairs(lotteryItems) do
local itemId = item
if not hasDrawnItems then
availableCount = availableCount + 1
end
end
if availableCount == 0 then
user:SendNotiPacketMessage("------------------------------------------", 1)
user:SendNotiPacketMessage("🎊 消耗抽奖奖池已清空!所有道具都已抽取完毕。", 3)
user:SendNotiPacketMessage("------------------------------------------", 1)
return 0
end
-- 构建可用奖池
local availableItems = {}
for _, item in ipairs(lotteryItems) do
local itemId = item
if not hasDrawnItems then
table.insert(availableItems, item)
end
end
-- 随机抽取一个道具
math.randomseed(tostring(os.time()):reverse():sub(1, 7))
local randomIndex = math.random(1, #availableItems)
local selectedItem = availableItems
local itemId = selectedItem
local itemCount = selectedItem
local itemName = selectedItem
-- 扣除消耗的道具
local remainingToDelete = consumeCount
for i = 0, 400 do
if remainingToDelete <= 0 then
break
end
local itemInfo = dpx.item.info(user.cptr, game.ItemSpace.INVENTORY, i)
if itemInfo and itemInfo.id == consumeItemId then
local deleteCount = math.min(remainingToDelete, itemInfo.count)
dpx.item.delete(user.cptr, game.ItemSpace.INVENTORY, i, deleteCount)
remainingToDelete = remainingToDelete - deleteCount
-- 记录删除日志
logger.info(string.format("消耗抽奖扣除道具:格子%d, 扣除%d个,剩余需要扣除%d个", i, deleteCount, remainingToDelete))
end
end
-- 发送背包更新
user:SendItemSpace(game.ItemSpace.INVENTORY)
-- 记录抽奖结果
local logFile = io.open(lotteryLogPath, "a")
if logFile then
local logMsg = string.format("%s|%d|%s|%d|%s|消耗:%d|抽奖次数:%d\n",
os.date("%Y-%m-%d %H:%M:%S"), accId, characName, itemId, itemName, consumeCount, lotteryCount+1)
logFile:write(logMsg)
logFile:close()
end
-- 更新抽奖次数记录
local countLogFile = io.open(lotteryLogPath .. ".count", "w")
if countLogFile then
countLogFile:write(string.format("%d|%d\n", accId, lotteryCount + 1))
countLogFile:close()
end
-- 发送奖励到邮件
dpx.mail.item(characNo, 3, "消耗抽奖奖励", "恭喜您在消耗抽奖中获得以下道具!", tostring(itemId), tostring(itemCount))
-- 计算剩余道具数量
local remainingCount = availableCount - 1
-- 发送抽奖结果消息
user:SendNotiPacketMessage("------------------------------------------", 1)
user:SendNotiPacketMessage("🎉 消耗抽奖成功!", 2)
user:SendNotiPacketMessage(string.format("消耗:%s×%d", consumeItemName, consumeCount), 2)
user:SendNotiPacketMessage(string.format("获得:%s", itemName), 2)
user:SendNotiPacketMessage(string.format("剩余可抽取道具:%d/%d", remainingCount, #lotteryItems), 2)
user:SendNotiPacketMessage(string.format("当前抽奖次数:%d", lotteryCount + 1), 2)
user:SendNotiPacketMessage("奖励已发送至邮件,请注意查收", 2)
user:SendNotiPacketMessage("------------------------------------------", 1)
return 0
end
-- 查看消耗抽奖状态
if input == "//查看奖池" then
local lotteryLogPath = "/var/log/game_coin_lottery_records.log"
local accId = user:GetAccId()
local characName = user:GetCharacName()
-- 读取消耗抽奖次数
local lotteryCount = 0
local countFile = io.open(lotteryLogPath .. ".count", "r")
if countFile then
for line in countFile:lines() do
local accIdInFile, count = string.match(line, "(%d+)|(%d+)")
if accIdInFile and tonumber(accIdInFile) == accId then
lotteryCount = tonumber(count)
break
end
end
countFile:close()
end
-- 计算下次需要消耗的道具数量
local nextConsumeCount = 1
if lotteryCount > 0 then
nextConsumeCount = 2^lotteryCount
end
-- 奖池配置
local lotteryItems = {
{44261, 1, "紫黑晶体项链"},
{44259, 1, "红黄晶体项链"},
{3242, 1, "矛盾的结晶体"},
{3038, 1, "黑色大晶体"},
{3041, 1, "蓝色大晶体"},
{3042, 1, "无色大晶体"},
{3165, 1, "五彩晶体"},
{3263, 1, "金色大晶体"},
{3040, 1, "红色大晶体"},
{3039, 1, "白色大晶体"}
}
-- 检查消耗抽奖记录文件
local hasDrawnItems = {}
local lotteryFile = io.open(lotteryLogPath, "r")
if lotteryFile then
for line in lotteryFile:lines() do
local parts = {}
for part in string.gmatch(line, "[^|]+") do
table.insert(parts, part)
end
if #parts >= 4 then
local accIdInFile = tonumber(parts)
local itemId = tonumber(parts)
if accIdInFile and accIdInFile == accId then
hasDrawnItems = true
end
end
end
lotteryFile:close()
end
-- 构建已抽取和未抽取的道具列表
local remainingItems = {}
local drawnItems = {}
for _, item in ipairs(lotteryItems) do
local itemId = item
local itemName = item
if hasDrawnItems then
table.insert(drawnItems, itemName)
else
table.insert(remainingItems, itemName)
end
end
user:SendNotiPacketMessage("------------------------------------------", 1)
user:SendNotiPacketMessage("🎯 消耗抽奖状态", 2)
user:SendNotiPacketMessage(string.format("账号:%s", characName), 2)
user:SendNotiPacketMessage(string.format("已抽奖次数:%d", lotteryCount), 2)
user:SendNotiPacketMessage(string.format("下次抽奖消耗:黑钻硬币×%d", nextConsumeCount), 2)
user:SendNotiPacketMessage(string.format("总道具数:%d | 已抽取:%d | 剩余:%d",
#lotteryItems, #drawnItems, #remainingItems), 2)
if #drawnItems > 0 then
user:SendNotiPacketMessage("已抽取道具:", 2)
for i, itemName in ipairs(drawnItems) do
user:SendNotiPacketMessage(string.format("%d. %s", i, itemName), 2)
end
end
if #remainingItems > 0 then
user:SendNotiPacketMessage("剩余道具:", 2)
for i, itemName in ipairs(remainingItems) do
user:SendNotiPacketMessage(string.format("%d. %s", i, itemName), 2)
end
else
user:SendNotiPacketMessage("🎊 所有道具都已抽取完毕!", 2)
end
user:SendNotiPacketMessage("------------------------------------------", 1)
return 0
end
return fnext()
end</b></font></b></font>
具消耗抽奖是一次次翻倍的第一次1个第二次2个第三次4个以此类推可以模仿某些插件 也可以平替土罐自己改消耗的道具代码一次性开十个可调概率卖消耗材料代码就行了
页:
[1]