-- ========================================
-- 配置表 - 签到奖励配置
-- ========================================
local SIGN_IN_CONFIG = {
-- NPC配置
npc_id = 1002, -- NPC配置ID
npc_name = "签到有礼", -- NPC显示名称
-- 奖励配置
rewards = {
{ type = "gamegold", value = 50, name = "元宝" }, -- 元宝奖励
{ type = "exp", value = 10000, name = "经验" }, -- 经验奖励
{ type = "gold", value = 10000, name = "绑定金币" }, -- 绑定金币奖励
{ type = "item", value = 1001, count = 1, name = "经验丹" },-- 经验丹物品
{ type = "item", value = 1002, count = 1, name = "材料礼盒" }-- 材料礼盒物品
},
-- 签到时间配置
reset_hour = 0, -- 每日重置时间(小时)
max_sign_days = 30, -- 最大连续签到天数
-- 连续签到额外奖励
consecutive_rewards = {
[7] = { gamegold = 100, item = { id = 1003, count = 1 } }, -- 7天额外奖励
[14] = { gamegold = 200, item = { id = 1004, count = 1 } }, -- 14天额外奖励
[30] = { gamegold = 500, item = { id = 1005, count = 1 } } -- 30天额外奖励
}
}
-- ========================================
-- 全局变量定义
-- ========================================
local NpcLib = NpcLib or {}
-- ========================================
-- 辅助函数 - 获取今日日期字符串
-- ========================================
local function GetTodayString()
local timestamp = os.time()
local date = os.date("*t", timestamp)
return string.format("%04d%02d%02d", date.year, date.month, date.day)
end
-- ========================================
-- 辅助函数 - 获取玩家最后签到日期
-- ========================================
local function GetLastSignDate(actor)
local last_date = getplayervalue(actor, 100) -- 使用玩家变量100存储签到日期
return last_date or ""
end
-- ========================================
-- 辅助函数 - 设置玩家最后签到日期
-- ========================================
local function SetLastSignDate(actor, date)
setplayervalue(actor, 100, date)
end
-- ========================================
-- 辅助函数 - 获取连续签到天数
-- ========================================
local function GetConsecutiveDays(actor)
local days = getplayervalue(actor, 101) -- 使用玩家变量101存储连续签到天数
return days or 0
end
-- ========================================
-- 辅助函数 - 设置连续签到天数
-- ========================================
local function SetConsecutiveDays(actor, days)
setplayervalue(actor, 101, days)
end
-- ========================================
-- 辅助函数 - 判断是否可以签到
-- ========================================
local function CanSignIn(actor)
local today = GetTodayString()
local last_date = GetLastSignDate(actor)
-- 如果今天已经签到过,返回false
if last_date == today then
return false, "今天已经签到过了"
end
return true, "可以签到"
end
-- ========================================
-- 辅助函数 - 计算连续签到天数
-- ========================================
local function CalculateConsecutiveDays(actor)
local today = GetTodayString()
local last_date = GetLastSignDate(actor)
local current_days = GetConsecutiveDays(actor)
if last_date == "" then
-- 第一次签到
return 1
end
-- 解析日期
local last_year = tonumber(last_date:sub(1, 4))
local last_month = tonumber(last_date:sub(5, 6))
local last_day = tonumber(last_date:sub(7, 8))
local today_year = tonumber(today:sub(1, 4))
local today_month = tonumber(today:sub(5, 6))
local today_day = tonumber(today:sub(7, 8))
-- 计算两个日期之间的天数差
local last_time = os.time({year=last_year, month=last_month, day=last_day})
local today_time = os.time({year=today_year, month=today_month, day=today_day})
local diff_days = (today_time - last_time) / (24 * 60 * 60)
if diff_days == 1 then
-- 连续签到
return current_days + 1
else
-- 断签,重新计算
return 1
end
end