|
|
@@ -1,6 +1,10 @@
|
|
|
local Lang = require("common.Lang")
|
|
|
local Msg = require("core.Msg")
|
|
|
local ObjHuman = require("core.ObjHuman")
|
|
|
+local InnerMsg = require("core.InnerMsg")
|
|
|
+local Config = require("Config")
|
|
|
+local MiddleManager = require("middle.MiddleManager")
|
|
|
+local CommonDB = require("common.CommonDB")
|
|
|
local ZhuanpanExcel = require("excel.zhuanpan")
|
|
|
local ItemDefine = require("bag.ItemDefine")
|
|
|
local BagLogic = require("bag.BagLogic")
|
|
|
@@ -1764,6 +1768,31 @@ local function getWeekProgress(field)
|
|
|
return weekTotal
|
|
|
end
|
|
|
|
|
|
+-- 检查账号下是否有任何角色已领取指定游戏圈任务(账号级别判断)
|
|
|
+local function checkAccountYouxiTaskClaimed(account, taskId)
|
|
|
+ if not account then return false end
|
|
|
+ local config = YOUXI_TASK_CONFIG[taskId]
|
|
|
+ if not config then return false end
|
|
|
+ LuaMongo.find(DB.db_char, {account = account}, {zhuanpan = 1})
|
|
|
+ while true do
|
|
|
+ local data = {}
|
|
|
+ if not LuaMongo.next(data) then break end
|
|
|
+ local yt = data.zhuanpan and data.zhuanpan.youxiTask
|
|
|
+ if yt then
|
|
|
+ if config.taskType == "once" then
|
|
|
+ if yt.joinGetTime then return true end
|
|
|
+ elseif config.taskType == "daily" then
|
|
|
+ local field = (taskId == 2) and yt.dailyLike or yt.dailyComment
|
|
|
+ if field and field.getTime and Util.isSameDay(field.getTime) then return true end
|
|
|
+ elseif config.taskType == "weekly" then
|
|
|
+ local field = (taskId == 4) and yt.dailyLike or yt.dailyComment
|
|
|
+ if field and field.weekGetTime and isCurrentWeek(field.weekGetTime) then return true end
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+ return false
|
|
|
+end
|
|
|
+
|
|
|
-- 游戏圈任务查询(前端上传 SDK 数据,后端存储并计算进度)
|
|
|
function youxiTaskQuery(human, msg)
|
|
|
local msgRet = Msg.gc.GC_ZHUANPAN_YOUXI_TASK_QUERY
|
|
|
@@ -1802,7 +1831,8 @@ function youxiTaskQuery(human, msg)
|
|
|
|
|
|
if config.taskType == "once" then
|
|
|
taskData.progress = yt.joined and 1 or 0
|
|
|
- if yt.joinGetTime then
|
|
|
+ local claimed = yt.joinGetTime or checkAccountYouxiTaskClaimed(human.db.account, taskId)
|
|
|
+ if claimed then
|
|
|
taskData.status = 2
|
|
|
elseif yt.joined then
|
|
|
taskData.status = 1
|
|
|
@@ -1815,7 +1845,8 @@ function youxiTaskQuery(human, msg)
|
|
|
local dayCount = (field and field.dayTime and Util.isSameDay(field.dayTime)) and (field.count or 0) or 0
|
|
|
taskData.progress = math.min(dayCount, config.target)
|
|
|
local getTime = field and field.getTime
|
|
|
- if getTime and Util.isSameDay(getTime) then
|
|
|
+ local claimed = (getTime and Util.isSameDay(getTime)) or checkAccountYouxiTaskClaimed(human.db.account, taskId)
|
|
|
+ if claimed then
|
|
|
taskData.status = 2
|
|
|
elseif dayCount >= config.target then
|
|
|
taskData.status = 1
|
|
|
@@ -1828,7 +1859,8 @@ function youxiTaskQuery(human, msg)
|
|
|
local weekCount = getWeekProgress(field)
|
|
|
taskData.progress = math.min(weekCount, config.target)
|
|
|
local weekGetTime = field and field.weekGetTime
|
|
|
- if weekGetTime and isCurrentWeek(weekGetTime) then
|
|
|
+ local claimed = (weekGetTime and isCurrentWeek(weekGetTime)) or checkAccountYouxiTaskClaimed(human.db.account, taskId)
|
|
|
+ if claimed then
|
|
|
taskData.status = 2
|
|
|
elseif weekCount >= config.target then
|
|
|
taskData.status = 1
|
|
|
@@ -1864,9 +1896,12 @@ function youxiTaskGetReward(human, taskId)
|
|
|
local yt = human.db.zhuanpan.youxiTask
|
|
|
local now = os.time()
|
|
|
|
|
|
- -- 校验条件 & 重复领取
|
|
|
+ -- 校验条件 & 重复领取(账号级别判断,同账号多角色共享)
|
|
|
+ -- 先查当前角色内存,没有再查 DB 其他角色(与美团订阅奖励模式一致)
|
|
|
+ local account = human.db.account
|
|
|
if config.taskType == "once" then
|
|
|
- if yt.joinGetTime then
|
|
|
+ local claimed = yt.joinGetTime or checkAccountYouxiTaskClaimed(account, taskId)
|
|
|
+ if claimed then
|
|
|
return Broadcast.sendErr(human, "已领取过")
|
|
|
end
|
|
|
if not yt.joined then
|
|
|
@@ -1875,7 +1910,9 @@ function youxiTaskGetReward(human, taskId)
|
|
|
|
|
|
elseif config.taskType == "daily" then
|
|
|
local field = (taskId == 2) and yt.dailyLike or yt.dailyComment
|
|
|
- if field and field.getTime and Util.isSameDay(field.getTime) then
|
|
|
+ local getTime = field and field.getTime
|
|
|
+ local claimed = (getTime and Util.isSameDay(getTime)) or checkAccountYouxiTaskClaimed(account, taskId)
|
|
|
+ if claimed then
|
|
|
return Broadcast.sendErr(human, "今日已领取")
|
|
|
end
|
|
|
local dayCount = (field and field.dayTime and Util.isSameDay(field.dayTime)) and (field.count or 0) or 0
|
|
|
@@ -1885,7 +1922,9 @@ function youxiTaskGetReward(human, taskId)
|
|
|
|
|
|
elseif config.taskType == "weekly" then
|
|
|
local field = (taskId == 4) and yt.dailyLike or yt.dailyComment
|
|
|
- if field and field.weekGetTime and isCurrentWeek(field.weekGetTime) then
|
|
|
+ local weekGetTime = field and field.weekGetTime
|
|
|
+ local claimed = (weekGetTime and isCurrentWeek(weekGetTime)) or checkAccountYouxiTaskClaimed(account, taskId)
|
|
|
+ if claimed then
|
|
|
return Broadcast.sendErr(human, "本周已领取")
|
|
|
end
|
|
|
if getWeekProgress(field) < config.target then
|
|
|
@@ -1923,6 +1962,189 @@ function youxiTaskGetReward(human, taskId)
|
|
|
youxiTaskQuery(human, nil)
|
|
|
end
|
|
|
|
|
|
+-----------------------添加桌面(本地存储,账号级,同游戏圈写法)-----------------------
|
|
|
+
|
|
|
+-- 检查账号下所有角色是否已添加过桌面(查本服MongoDB)
|
|
|
+local function checkAccountDesktopAdded(account, channelId, platform)
|
|
|
+ if not account then return false end
|
|
|
+ local key = tostring(channelId) .. "_" .. tostring(platform)
|
|
|
+ LuaMongo.find(DB.db_char, {account = account}, {zhuanpan = 1})
|
|
|
+ while true do
|
|
|
+ local data = {}
|
|
|
+ if not LuaMongo.next(data) then break end
|
|
|
+ local da = data.zhuanpan and data.zhuanpan.desktopAdded
|
|
|
+ if da and da[key] then return true end
|
|
|
+ end
|
|
|
+ return false
|
|
|
+end
|
|
|
+
|
|
|
+-- 上报添加桌面
|
|
|
+function dyDesktopSetLocal(human, channelId, platform)
|
|
|
+ if not channelId or not platform or platform == "" then
|
|
|
+ return Broadcast.sendErr(human, "参数缺失")
|
|
|
+ end
|
|
|
+
|
|
|
+ human.db.zhuanpan = human.db.zhuanpan or {}
|
|
|
+ human.db.zhuanpan.desktopAdded = human.db.zhuanpan.desktopAdded or {}
|
|
|
+ local key = tostring(channelId) .. "_" .. tostring(platform)
|
|
|
+ human.db.zhuanpan.desktopAdded[key] = true
|
|
|
+
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[dyDesktopSetLocal] 添加桌面 account=" .. tostring(human.db.account)
|
|
|
+ .. " channelId=" .. tostring(channelId) .. " platform=" .. tostring(platform))
|
|
|
+
|
|
|
+ local ok, err = pcall(function()
|
|
|
+ dyDesktopQueryLocal(human, channelId, platform)
|
|
|
+ end)
|
|
|
+ if not ok then
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[dyDesktopSetLocal] 错误: 下发查询失败: " .. tostring(err))
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+-- 查询桌面添加状态
|
|
|
+function dyDesktopQueryLocal(human, channelId, platform)
|
|
|
+ if not channelId or not platform or platform == "" then
|
|
|
+ return Broadcast.sendErr(human, "参数缺失")
|
|
|
+ end
|
|
|
+
|
|
|
+ local msgRet = Msg.gc.GC_ZHUANPAN_DY_DESKTOP_QUERY
|
|
|
+ if not msgRet then return end
|
|
|
+
|
|
|
+ human.db.zhuanpan = human.db.zhuanpan or {}
|
|
|
+ human.db.zhuanpan.desktopAdded = human.db.zhuanpan.desktopAdded or {}
|
|
|
+ local key = tostring(channelId) .. "_" .. tostring(platform)
|
|
|
+
|
|
|
+ local added = human.db.zhuanpan.desktopAdded[key]
|
|
|
+ if not added then
|
|
|
+ added = checkAccountDesktopAdded(human.db.account, channelId, platform)
|
|
|
+ end
|
|
|
+
|
|
|
+ msgRet.channelId = channelId
|
|
|
+ msgRet.platform = platform
|
|
|
+ msgRet.isDesktopAdded = added and 1 or 0
|
|
|
+
|
|
|
+ Log.write(Log.LOGID_DEBUG, "[dyDesktopQueryLocal] account=" .. tostring(human.db.account)
|
|
|
+ .. " channelId=" .. tostring(channelId) .. " platform=" .. tostring(platform)
|
|
|
+ .. " isDesktopAdded=" .. tostring(msgRet.isDesktopAdded))
|
|
|
+
|
|
|
+ if human.fd then
|
|
|
+ Msg.send(msgRet, human.fd)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+-----------------------添加桌面(跨服中心服存储,账号级多区服共享)-----------------------
|
|
|
+--
|
|
|
+---- 从 newUniqueTag 解析出 serverId 和 account(格式: "channelID|serverTag|account")
|
|
|
+--local function parseUniqueTag(newUniqueTag)
|
|
|
+-- local parts = {}
|
|
|
+-- for part in string.gmatch(newUniqueTag, "([^|]+)") do
|
|
|
+-- table.insert(parts, part)
|
|
|
+-- end
|
|
|
+-- return tonumber(parts[2]), parts[3] -- serverId, account
|
|
|
+--end
|
|
|
+--
|
|
|
+---- 普通服:上报添加桌面 → 发消息给中心服写入
|
|
|
+--function dyDesktopSet(human, channelId, platform)
|
|
|
+-- if not channelId or not platform or platform == "" then
|
|
|
+-- return Broadcast.sendErr(human, "参数缺失")
|
|
|
+-- end
|
|
|
+--
|
|
|
+-- local newUniqueTag = human.db.newUniqueTag or human.newUniqueTag
|
|
|
+-- if not newUniqueTag then
|
|
|
+-- return Broadcast.sendErr(human, "账号标识缺失")
|
|
|
+-- end
|
|
|
+-- local serverId, account = parseUniqueTag(newUniqueTag)
|
|
|
+--
|
|
|
+-- local tMsg = InnerMsg.lw.LW_DESKTOP_SET
|
|
|
+-- tMsg.nSrcServerID = Config.SVR_INDEX
|
|
|
+-- tMsg.channelId = channelId
|
|
|
+-- tMsg.serverId = serverId or 0
|
|
|
+-- tMsg.account = account or ""
|
|
|
+-- tMsg.platform = platform
|
|
|
+-- InnerMsg.sendMsg(0, tMsg)
|
|
|
+--
|
|
|
+-- Log.write(Log.LOGID_DEBUG, "[dyDesktopSet] 发送中心服 channelId=" .. tostring(channelId)
|
|
|
+-- .. " serverId=" .. tostring(serverId) .. " account=" .. tostring(account) .. " platform=" .. tostring(platform))
|
|
|
+--end
|
|
|
+--
|
|
|
+---- 普通服:查询桌面添加状态 → 发消息给中心服查询
|
|
|
+--function dyDesktopQuery(human, channelId, platform)
|
|
|
+-- if not channelId or not platform or platform == "" then
|
|
|
+-- return Broadcast.sendErr(human, "参数缺失")
|
|
|
+-- end
|
|
|
+--
|
|
|
+-- local newUniqueTag = human.db.newUniqueTag or human.newUniqueTag
|
|
|
+-- if not newUniqueTag then
|
|
|
+-- return Broadcast.sendErr(human, "账号标识缺失")
|
|
|
+-- end
|
|
|
+-- local serverId, account = parseUniqueTag(newUniqueTag)
|
|
|
+--
|
|
|
+-- local tMsg = InnerMsg.lw.LW_DESKTOP_QUERY
|
|
|
+-- tMsg.nSrcServerID = Config.SVR_INDEX
|
|
|
+-- tMsg.channelId = channelId
|
|
|
+-- tMsg.serverId = serverId or 0
|
|
|
+-- tMsg.account = account or ""
|
|
|
+-- tMsg.platform = platform
|
|
|
+-- InnerMsg.sendMsg(0, tMsg)
|
|
|
+--
|
|
|
+-- Log.write(Log.LOGID_DEBUG, "[dyDesktopQuery] 发送中心服 channelId=" .. tostring(channelId)
|
|
|
+-- .. " serverId=" .. tostring(serverId) .. " account=" .. tostring(account) .. " platform=" .. tostring(platform))
|
|
|
+--end
|
|
|
+--
|
|
|
+---- 普通服:收到中心服查询回包,找到玩家下发 GC 协议
|
|
|
+--function NS_DesktopQueryResult(msg)
|
|
|
+-- -- 用三个字段重新拼出 newUniqueTag 来查找在线玩家
|
|
|
+-- local newUniqueTag = tostring(msg.channelId) .. "|" .. tostring(msg.serverId) .. "|" .. tostring(msg.account)
|
|
|
+-- local human = ObjHuman.onlineNewUniqueTag[newUniqueTag]
|
|
|
+-- if not human or not human.fd then
|
|
|
+-- Log.write(Log.LOGID_DEBUG, "[NS_DesktopQueryResult] 玩家不在线 newUniqueTag=" .. newUniqueTag)
|
|
|
+-- return
|
|
|
+-- end
|
|
|
+--
|
|
|
+-- local msgRet = Msg.gc.GC_ZHUANPAN_DY_DESKTOP_QUERY
|
|
|
+-- if not msgRet then return end
|
|
|
+--
|
|
|
+-- msgRet.channelId = msg.channelId
|
|
|
+-- msgRet.platform = msg.platform
|
|
|
+-- msgRet.isDesktopAdded = msg.isDesktopAdded
|
|
|
+--
|
|
|
+-- Msg.send(msgRet, human.fd)
|
|
|
+--end
|
|
|
+--
|
|
|
+---- 中心服:收到普通服上报,写入 MongoDB 后回包最新状态
|
|
|
+--function CS_DesktopSet(msg)
|
|
|
+-- CommonDB.SetDesktopData(msg.channelId, msg.serverId, msg.account, msg.platform)
|
|
|
+--
|
|
|
+-- Log.write(Log.LOGID_DEBUG, "[CS_DesktopSet] 写入完成 channelId=" .. tostring(msg.channelId)
|
|
|
+-- .. " serverId=" .. tostring(msg.serverId) .. " account=" .. tostring(msg.account) .. " platform=" .. tostring(msg.platform))
|
|
|
+--
|
|
|
+-- local tMsg = InnerMsg.wl.WL_DESKTOP_QUERY
|
|
|
+-- tMsg.channelId = msg.channelId
|
|
|
+-- tMsg.serverId = msg.serverId
|
|
|
+-- tMsg.account = msg.account
|
|
|
+-- tMsg.platform = msg.platform
|
|
|
+-- tMsg.isDesktopAdded = 1
|
|
|
+--
|
|
|
+-- local fd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
|
|
|
+-- InnerMsg.sendMsg(fd, tMsg)
|
|
|
+--end
|
|
|
+--
|
|
|
+---- 中心服:收到普通服查询请求,读 MongoDB 后回包
|
|
|
+--function CS_DesktopQuery(msg)
|
|
|
+-- local added = CommonDB.IsDesktopAdded(msg.channelId, msg.serverId, msg.account, msg.platform)
|
|
|
+--
|
|
|
+-- local tMsg = InnerMsg.wl.WL_DESKTOP_QUERY
|
|
|
+-- tMsg.channelId = msg.channelId
|
|
|
+-- tMsg.serverId = msg.serverId
|
|
|
+-- tMsg.account = msg.account
|
|
|
+-- tMsg.platform = msg.platform
|
|
|
+-- tMsg.isDesktopAdded = added and 1 or 0
|
|
|
+--
|
|
|
+-- local fd = MiddleManager.getFDBySvrIndex(msg.nSrcServerID)
|
|
|
+-- InnerMsg.sendMsg(fd, tMsg)
|
|
|
+--end
|
|
|
+
|
|
|
+
|
|
|
-- SDK 回调奖励发放(内部调用,与任务奖励独立)
|
|
|
-- items: {{itemId, count}, ...}
|
|
|
function youxiSdkReward(human, items)
|