diff --git a/src/models/Role.lua b/src/models/Role.lua index 12de7c7..f7f6640 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -1,15 +1,17 @@ local Role = class("Role", require("shared.ModelBase")) -local RoleLog = import(".RoleLog") -local RolePlugin = import(".RolePlugin") -local RoleTask = import(".RoleTask") -local RoleActivity = import(".RoleActivity") -local RoleChangeStruct = import(".RoleChangeStruct") -local RolePvp = import(".RolePvp") -local RoleCross = import(".RoleCross") +local RoleLog = import(".RoleLog") --日志相关 +local RolePlugin = import(".RolePlugin") --基础功能 +local RoleTimeReset = import(".RoleTimeReset") --时间重置相关 +local RoleTask = import(".RoleTask") --角色任务 +local RoleActivity = import(".RoleActivity") --活动相关 +local RoleChangeStruct = import(".RoleChangeStruct") --角色数据额结构更改 +local RolePvp = import(".RolePvp") -- pvp +local RoleCross = import(".RoleCross") -- 跨服务请求相关 RoleLog.bind(Role) RolePlugin.bind(Role) +RoleTimeReset.bind(Role) RoleTask.bind(Role) RoleActivity.bind(Role) RoleChangeStruct.bind(Role) @@ -42,6 +44,7 @@ Role.schema = { ctime = {"number", skynet.timex()}, -- 创建时间 ignoreMt = {"number", 0}, -- 忽略维护拦截 sversion = {"number", globalCsv.StructVersion or 0}, -- 重整数据版本 + timeReset = {"table", {}}, --重置轮回记录 diamond = {"number", 0}, reDiamond = {"number", 0}, setting = {"table", {}}, --设置 @@ -107,6 +110,9 @@ Role.schema = { pvpTBH = {"table", {}}, -- pvp 他人可用的战斗信息 pvpTBVH = {"table", {}}, -- pvp 他人可用的战斗力 pvpMH = {"table", {}}, -- pvp 匹配的对手 高级 {{t = 1, id = roleId}, {t = 2, id = id}, {t = 2, id = id}} -- t 1 玩家 2 机器人 + pvpHGift = {"table", {}}, -- pvp 高级段位每小时奖励缓存 + pvpHGTime = {"number", 0}, -- pvp 高级段位上次奖励刷新时间 + pvpShop = {"table", {}}, -- pvp 商店{id = count} 对应商店id 购买次数 potionBag = {"table", {}}, -- 营养剂背包 @@ -247,6 +253,7 @@ function Role:data() funcOpen = self:getProperty("funcOpen"), funcLv = self:getProperty("funcLv"), -- loveStatus = self:getProperty("loveStatus"):toNumMap(), + timeReset = self:getProperty("timeReset"), diamond = self:getAllDiamond(), bagLimit = self:getProperty("bagLimit"), silent = self:getProperty("silent"), @@ -284,6 +291,9 @@ function Role:data() pvpTC = self:getProperty("pvpTC"), pvpTH = self:getProperty("pvpTH"), + pvpHGift = self:getProperty("pvpHGift"), + pvpHGTime = self:getProperty("pvpHGTime"), + pvpShop = self:getProperty("pvpShop"), potionBag = self:getProperty("potionBag"), storyB = self:getProperty("storyB"), diff --git a/src/models/RoleCross.lua b/src/models/RoleCross.lua index c1c2fe4..64509cc 100644 --- a/src/models/RoleCross.lua +++ b/src/models/RoleCross.lua @@ -55,6 +55,18 @@ RoleCross.bind = function (Role) return info end + -- 高级pvp 排行榜 + function Role:pvpHRankInfo() + local info = { + name = self:getProperty("name"), + level = self:getProperty("level"), + headId = self:getProperty("headId"), + ltime = self:getProperty("ltime"), + battleV = self:getProperty("pvpTBVH"), + } + return info + end + function Role:accountInit(initData) -- 道具 local reward = {} @@ -295,6 +307,19 @@ function CMD.pvpHInfo(roleId) } end +-- 高级pvp 排行榜 +function CMD:pvpHRankInfo() + local info = CMD.getProperties(roleId, {"name", "level", "headId", "pvpTBVH", "ltime"}) + local info = { + name = info.name, + level = info.level, + headId = info.headId, + ltime = info.ltime, + battleV = info.pvpTBVH, + } + return info +end + RoleCross.handle = function(cmd, roleId, ...) SRole = SRole or require("models.Role") if CMD[cmd] then diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index a0888db..4d7750c 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -19,64 +19,6 @@ function RolePlugin.bind(Role) SendPacket(...) end - function Role:onCrossDay(now, notify) - local ltime = self:getProperty("ltime") - - if isCrossDay(ltime, now) then - local response = {} - - self.dailyData:refreshDailyData(notify) - self.dinerData:refreshDailyData(notify) - self:setProperty("dTask", {}) - self:advRandomSupportEffect() - response.dTask = {} - response.advSup = self:getProperty("advSup") - - - if isCrossWeek(ltime, now) then - self:setProperties({ - wTask = {}, - dinerS = {}, - }) - response.wTask = {} - response.dinerS = {} - end - - if notify then - self:notifyUpdateProperties(response) - end - - if RESET_TIME == RESET_RANK_TIME then - self:onResetRank_raw(ltime, now, notify) - end - self:setProperty("ltime", now) - - return true - end - end - - function Role:onResetRank(now, notify) - local ltime = self:getProperty("ltime") - if isCrossDay(ltime, now, RESET_RANK_TIME) then - local response = self:onResetRank_raw(ltime, now, notify) - - if notify and next(response) then - self:notifyUpdateProperties(response) - end - - self:setProperty("ltime", now) - return true - end - end - - function Role:onResetRank_raw(ltime, now, notify) - local response = {} - - self.dinerData:rankResetData(notify) - - return response - end - function Role:onOfflineEvent() -- 设置最新的登录时间 self:setProperty("ltime", skynet.timex()) @@ -884,8 +826,9 @@ function RolePlugin.bind(Role) self:updateProperty({field = "advSup", value = advSup, notNotify = notNotify}) end - local StdDinerRankTime = toUnixtime("20190101"..string.format("%02x", RESET_RANK_TIME)) --跨天时间 + function Role:getCurDinerRankKey() + local StdDinerRankTime = toUnixtime("20190101"..string.format("%02x", math.floor(self:getTimeResetDataStart(TimeReset.DinerRank) / 3600))) --跨天时间 local now = skynet.timex() local idx = 1 if math.floor((now - StdDinerRankTime) / 86400) % 2 == 1 then @@ -1121,6 +1064,7 @@ function RolePlugin.bind(Role) -- update function Role:onRecoverTimer(now) + self:updateTimeReset(now, true) self:checkNewEvent(now) end diff --git a/src/models/RoleTimeReset.lua b/src/models/RoleTimeReset.lua new file mode 100644 index 0000000..05925f2 --- /dev/null +++ b/src/models/RoleTimeReset.lua @@ -0,0 +1,124 @@ +local RoleTimeReset = {} + +RoleTimeReset.bind = function (Role) + +-- 重置内容 对应 GlobalVar TimeReset +local ResetFunc = {} +ResetFunc["CrossDay"] = function(self, notify, response) + self.dailyData:refreshDailyData(notify) + self.dinerData:refreshDailyData(notify) + + self:setProperty("dTask", {}) + self:advRandomSupportEffect() + + response.dTask = {} + response.advSup = self:getProperty("advSup") +end + +ResetFunc["CrossWeek"] = function(self, notify, response) + self:setProperties({ + wTask = {}, + dinerS = {}, + }) + response.wTask = {} + response.dinerS = {} +end + + +ResetFunc["DinerRank"] = function(self, notify, response) + self.dinerData:rankResetData(notify) +end + +ResetFunc["PvpShop"] = function(self, notify, response) + self:setProperty("pvpShop", {}) + response.pvpShop = {} +end + + +function Role:updateTimeReset(now, notify) + local timeReset = self:getProperty("timeReset") + + local passTime = now - START_RESET_TIME + + local needResetId = {} + for resetId, resetData in pairs(csvdb["time_resetCsv"]) do + local curRound = math.floor((passTime - resetData.start) / resetData.interval) + if not timeReset[resetId] or curRound ~= timeReset[resetId] then + needResetId[resetId] = curRound + end + end + if not next(needResetId) then return end + + local response = {} + for funcName, resetId in pairs(TimeReset) do + if needResetId[resetId] and ResetFunc[funcName] then + ResetFunc[funcName](self, notify, response) + end + end + + for resetId, round in pairs(needResetId) do + timeReset[resetId] = round + end + self:setProperty("timeReset", timeReset) + response.timeReset = timeReset + + if notify then + self:notifyUpdateProperties(response) + end +end + +-- 持续时间取 min(interval, duration) duration 填 0 默认使用 interval 作为持续时间 +local function getTimeResetDuration(rtype) + local resetData = csvdb["time_resetCsv"][rtype] + if not resetData then return 0 end + return resetData.duration == 0 and resetData.interval or math.min(resetData.interval, resetData.duration) +end + +--检查功能是否是在开放期 +function Role:isTimeResetOpen(rtype) + local resetData = csvdb["time_resetCsv"][rtype] + if not resetData or getTimeResetDuration(rtype) >= resetData.interval then + return true + end + + return self:getTimeResetEndTime(rtype) > skynet.timex() +end + +-- 当前轮次 开始时间 +function Role:getTimeResetStartTime(rtype) + local timeReset = self:getProperty("timeReset") + if not timeReset[rtype] then return 0 end + local resetData = csvdb["time_resetCsv"][rtype] + if not resetData then return 0 end + return START_RESET_TIME + timeReset[rtype] * resetData.interval + resetData.start +end + +-- 当前轮次 结束时间 +function Role:getTimeResetEndTime(rtype) + return self:getTimeResetStartTime(rtype) + getTimeResetDuration(rtype) +end + +function Role:getTimeResetRound(rtype) + local timeReset = self:getProperty("timeReset") + return timeReset[rtype] or 0 +end + +function Role:getTimeResetDataStart(rtype) + local resetData = csvdb["time_resetCsv"][rtype] + if not resetData then return 0 end + return resetData.start +end + + + + + + + +end + + + + + +return RoleTimeReset \ No newline at end of file diff --git a/src/services/agent_util.lua b/src/services/agent_util.lua index 622651b..933dd8a 100644 --- a/src/services/agent_util.lua +++ b/src/services/agent_util.lua @@ -39,43 +39,6 @@ local function check_heart_beat(agent, now) end end -local PointDataMark = {} -local resetTimeStr = string.format("%02d00", RESET_TIME) -local resetRankTimeStr = string.format("%02d00", RESET_RANK_TIME) - -local function check_daily_reset(agent, now) - local date = os.date("*t", now) - local timeStr = string.format("%02d%02d", date.hour, date.min) - local dataStr = date.year .. string.format("%02d", date.month) .. string.format("%02d", date.day) - - local function timeEffect(checkTimeStr) - if timeStr ~= checkTimeStr then - return false - end - if PointDataMark[dataStr] and PointDataMark[dataStr][checkTimeStr] then - return false - end - PointDataMark[dataStr] = PointDataMark[dataStr] or {} - PointDataMark[dataStr][checkTimeStr] = true - return true - end - - if timeEffect(resetTimeStr) then - -- 刷新每日数据 - local role = agent.role - if role then - role:onCrossDay(now, true) - end - end - if resetTimeStr ~= resetRankTimeStr and timeEffect(resetRankTimeStr) then - -- 刷新排行榜需要重置的数据 - local role = agent.role - if role then - role:onResetRank(now, true) - end - end -end - function _M:update(agent) local now = skynet.timex() local role = agent.role @@ -83,7 +46,6 @@ function _M:update(agent) pcall(check_heart_beat, agent, now) nextCheckTime = now + HEART_TIMER_INTERVAL end - pcall(check_daily_reset, agent, now) pcall(role.onRecoverTimer, role, now) end -- libgit2 0.21.2