Commit cfd68b3aaba9633400e8fd6929f9dc9b77c42cb6
1 parent
875e5071
时间重置 新逻辑
Showing
5 changed files
with
169 additions
and
104 deletions
Show diff stats
src/models/Role.lua
1 | 1 | local Role = class("Role", require("shared.ModelBase")) |
2 | 2 | |
3 | -local RoleLog = import(".RoleLog") | |
4 | -local RolePlugin = import(".RolePlugin") | |
5 | -local RoleTask = import(".RoleTask") | |
6 | -local RoleActivity = import(".RoleActivity") | |
7 | -local RoleChangeStruct = import(".RoleChangeStruct") | |
8 | -local RolePvp = import(".RolePvp") | |
9 | -local RoleCross = import(".RoleCross") | |
3 | +local RoleLog = import(".RoleLog") --日志相关 | |
4 | +local RolePlugin = import(".RolePlugin") --基础功能 | |
5 | +local RoleTimeReset = import(".RoleTimeReset") --时间重置相关 | |
6 | +local RoleTask = import(".RoleTask") --角色任务 | |
7 | +local RoleActivity = import(".RoleActivity") --活动相关 | |
8 | +local RoleChangeStruct = import(".RoleChangeStruct") --角色数据额结构更改 | |
9 | +local RolePvp = import(".RolePvp") -- pvp | |
10 | +local RoleCross = import(".RoleCross") -- 跨服务请求相关 | |
10 | 11 | |
11 | 12 | RoleLog.bind(Role) |
12 | 13 | RolePlugin.bind(Role) |
14 | +RoleTimeReset.bind(Role) | |
13 | 15 | RoleTask.bind(Role) |
14 | 16 | RoleActivity.bind(Role) |
15 | 17 | RoleChangeStruct.bind(Role) |
... | ... | @@ -42,6 +44,7 @@ Role.schema = { |
42 | 44 | ctime = {"number", skynet.timex()}, -- 创建时间 |
43 | 45 | ignoreMt = {"number", 0}, -- 忽略维护拦截 |
44 | 46 | sversion = {"number", globalCsv.StructVersion or 0}, -- 重整数据版本 |
47 | + timeReset = {"table", {}}, --重置轮回记录 | |
45 | 48 | diamond = {"number", 0}, |
46 | 49 | reDiamond = {"number", 0}, |
47 | 50 | setting = {"table", {}}, --设置 |
... | ... | @@ -107,6 +110,9 @@ Role.schema = { |
107 | 110 | pvpTBH = {"table", {}}, -- pvp 他人可用的战斗信息 |
108 | 111 | pvpTBVH = {"table", {}}, -- pvp 他人可用的战斗力 |
109 | 112 | pvpMH = {"table", {}}, -- pvp 匹配的对手 高级 {{t = 1, id = roleId}, {t = 2, id = id}, {t = 2, id = id}} -- t 1 玩家 2 机器人 |
113 | + pvpHGift = {"table", {}}, -- pvp 高级段位每小时奖励缓存 | |
114 | + pvpHGTime = {"number", 0}, -- pvp 高级段位上次奖励刷新时间 | |
115 | + pvpShop = {"table", {}}, -- pvp 商店{id = count} 对应商店id 购买次数 | |
110 | 116 | |
111 | 117 | |
112 | 118 | potionBag = {"table", {}}, -- 营养剂背包 |
... | ... | @@ -247,6 +253,7 @@ function Role:data() |
247 | 253 | funcOpen = self:getProperty("funcOpen"), |
248 | 254 | funcLv = self:getProperty("funcLv"), |
249 | 255 | -- loveStatus = self:getProperty("loveStatus"):toNumMap(), |
256 | + timeReset = self:getProperty("timeReset"), | |
250 | 257 | diamond = self:getAllDiamond(), |
251 | 258 | bagLimit = self:getProperty("bagLimit"), |
252 | 259 | silent = self:getProperty("silent"), |
... | ... | @@ -284,6 +291,9 @@ function Role:data() |
284 | 291 | |
285 | 292 | pvpTC = self:getProperty("pvpTC"), |
286 | 293 | pvpTH = self:getProperty("pvpTH"), |
294 | + pvpHGift = self:getProperty("pvpHGift"), | |
295 | + pvpHGTime = self:getProperty("pvpHGTime"), | |
296 | + pvpShop = self:getProperty("pvpShop"), | |
287 | 297 | |
288 | 298 | potionBag = self:getProperty("potionBag"), |
289 | 299 | storyB = self:getProperty("storyB"), | ... | ... |
src/models/RoleCross.lua
... | ... | @@ -55,6 +55,18 @@ RoleCross.bind = function (Role) |
55 | 55 | return info |
56 | 56 | end |
57 | 57 | |
58 | + -- 高级pvp 排行榜 | |
59 | + function Role:pvpHRankInfo() | |
60 | + local info = { | |
61 | + name = self:getProperty("name"), | |
62 | + level = self:getProperty("level"), | |
63 | + headId = self:getProperty("headId"), | |
64 | + ltime = self:getProperty("ltime"), | |
65 | + battleV = self:getProperty("pvpTBVH"), | |
66 | + } | |
67 | + return info | |
68 | + end | |
69 | + | |
58 | 70 | function Role:accountInit(initData) |
59 | 71 | -- 道具 |
60 | 72 | local reward = {} |
... | ... | @@ -295,6 +307,19 @@ function CMD.pvpHInfo(roleId) |
295 | 307 | } |
296 | 308 | end |
297 | 309 | |
310 | +-- 高级pvp 排行榜 | |
311 | +function CMD:pvpHRankInfo() | |
312 | + local info = CMD.getProperties(roleId, {"name", "level", "headId", "pvpTBVH", "ltime"}) | |
313 | + local info = { | |
314 | + name = info.name, | |
315 | + level = info.level, | |
316 | + headId = info.headId, | |
317 | + ltime = info.ltime, | |
318 | + battleV = info.pvpTBVH, | |
319 | + } | |
320 | + return info | |
321 | +end | |
322 | + | |
298 | 323 | RoleCross.handle = function(cmd, roleId, ...) |
299 | 324 | SRole = SRole or require("models.Role") |
300 | 325 | if CMD[cmd] then | ... | ... |
src/models/RolePlugin.lua
... | ... | @@ -19,64 +19,6 @@ function RolePlugin.bind(Role) |
19 | 19 | SendPacket(...) |
20 | 20 | end |
21 | 21 | |
22 | - function Role:onCrossDay(now, notify) | |
23 | - local ltime = self:getProperty("ltime") | |
24 | - | |
25 | - if isCrossDay(ltime, now) then | |
26 | - local response = {} | |
27 | - | |
28 | - self.dailyData:refreshDailyData(notify) | |
29 | - self.dinerData:refreshDailyData(notify) | |
30 | - self:setProperty("dTask", {}) | |
31 | - self:advRandomSupportEffect() | |
32 | - response.dTask = {} | |
33 | - response.advSup = self:getProperty("advSup") | |
34 | - | |
35 | - | |
36 | - if isCrossWeek(ltime, now) then | |
37 | - self:setProperties({ | |
38 | - wTask = {}, | |
39 | - dinerS = {}, | |
40 | - }) | |
41 | - response.wTask = {} | |
42 | - response.dinerS = {} | |
43 | - end | |
44 | - | |
45 | - if notify then | |
46 | - self:notifyUpdateProperties(response) | |
47 | - end | |
48 | - | |
49 | - if RESET_TIME == RESET_RANK_TIME then | |
50 | - self:onResetRank_raw(ltime, now, notify) | |
51 | - end | |
52 | - self:setProperty("ltime", now) | |
53 | - | |
54 | - return true | |
55 | - end | |
56 | - end | |
57 | - | |
58 | - function Role:onResetRank(now, notify) | |
59 | - local ltime = self:getProperty("ltime") | |
60 | - if isCrossDay(ltime, now, RESET_RANK_TIME) then | |
61 | - local response = self:onResetRank_raw(ltime, now, notify) | |
62 | - | |
63 | - if notify and next(response) then | |
64 | - self:notifyUpdateProperties(response) | |
65 | - end | |
66 | - | |
67 | - self:setProperty("ltime", now) | |
68 | - return true | |
69 | - end | |
70 | - end | |
71 | - | |
72 | - function Role:onResetRank_raw(ltime, now, notify) | |
73 | - local response = {} | |
74 | - | |
75 | - self.dinerData:rankResetData(notify) | |
76 | - | |
77 | - return response | |
78 | - end | |
79 | - | |
80 | 22 | function Role:onOfflineEvent() |
81 | 23 | -- 设置最新的登录时间 |
82 | 24 | self:setProperty("ltime", skynet.timex()) |
... | ... | @@ -884,8 +826,9 @@ function RolePlugin.bind(Role) |
884 | 826 | self:updateProperty({field = "advSup", value = advSup, notNotify = notNotify}) |
885 | 827 | end |
886 | 828 | |
887 | - local StdDinerRankTime = toUnixtime("20190101"..string.format("%02x", RESET_RANK_TIME)) --跨天时间 | |
829 | + | |
888 | 830 | function Role:getCurDinerRankKey() |
831 | + local StdDinerRankTime = toUnixtime("20190101"..string.format("%02x", math.floor(self:getTimeResetDataStart(TimeReset.DinerRank) / 3600))) --跨天时间 | |
889 | 832 | local now = skynet.timex() |
890 | 833 | local idx = 1 |
891 | 834 | if math.floor((now - StdDinerRankTime) / 86400) % 2 == 1 then |
... | ... | @@ -1121,6 +1064,7 @@ function RolePlugin.bind(Role) |
1121 | 1064 | |
1122 | 1065 | -- update |
1123 | 1066 | function Role:onRecoverTimer(now) |
1067 | + self:updateTimeReset(now, true) | |
1124 | 1068 | self:checkNewEvent(now) |
1125 | 1069 | end |
1126 | 1070 | ... | ... |
... | ... | @@ -0,0 +1,124 @@ |
1 | +local RoleTimeReset = {} | |
2 | + | |
3 | +RoleTimeReset.bind = function (Role) | |
4 | + | |
5 | +-- 重置内容 对应 GlobalVar TimeReset | |
6 | +local ResetFunc = {} | |
7 | +ResetFunc["CrossDay"] = function(self, notify, response) | |
8 | + self.dailyData:refreshDailyData(notify) | |
9 | + self.dinerData:refreshDailyData(notify) | |
10 | + | |
11 | + self:setProperty("dTask", {}) | |
12 | + self:advRandomSupportEffect() | |
13 | + | |
14 | + response.dTask = {} | |
15 | + response.advSup = self:getProperty("advSup") | |
16 | +end | |
17 | + | |
18 | +ResetFunc["CrossWeek"] = function(self, notify, response) | |
19 | + self:setProperties({ | |
20 | + wTask = {}, | |
21 | + dinerS = {}, | |
22 | + }) | |
23 | + response.wTask = {} | |
24 | + response.dinerS = {} | |
25 | +end | |
26 | + | |
27 | + | |
28 | +ResetFunc["DinerRank"] = function(self, notify, response) | |
29 | + self.dinerData:rankResetData(notify) | |
30 | +end | |
31 | + | |
32 | +ResetFunc["PvpShop"] = function(self, notify, response) | |
33 | + self:setProperty("pvpShop", {}) | |
34 | + response.pvpShop = {} | |
35 | +end | |
36 | + | |
37 | + | |
38 | +function Role:updateTimeReset(now, notify) | |
39 | + local timeReset = self:getProperty("timeReset") | |
40 | + | |
41 | + local passTime = now - START_RESET_TIME | |
42 | + | |
43 | + local needResetId = {} | |
44 | + for resetId, resetData in pairs(csvdb["time_resetCsv"]) do | |
45 | + local curRound = math.floor((passTime - resetData.start) / resetData.interval) | |
46 | + if not timeReset[resetId] or curRound ~= timeReset[resetId] then | |
47 | + needResetId[resetId] = curRound | |
48 | + end | |
49 | + end | |
50 | + if not next(needResetId) then return end | |
51 | + | |
52 | + local response = {} | |
53 | + for funcName, resetId in pairs(TimeReset) do | |
54 | + if needResetId[resetId] and ResetFunc[funcName] then | |
55 | + ResetFunc[funcName](self, notify, response) | |
56 | + end | |
57 | + end | |
58 | + | |
59 | + for resetId, round in pairs(needResetId) do | |
60 | + timeReset[resetId] = round | |
61 | + end | |
62 | + self:setProperty("timeReset", timeReset) | |
63 | + response.timeReset = timeReset | |
64 | + | |
65 | + if notify then | |
66 | + self:notifyUpdateProperties(response) | |
67 | + end | |
68 | +end | |
69 | + | |
70 | +-- 持续时间取 min(interval, duration) duration 填 0 默认使用 interval 作为持续时间 | |
71 | +local function getTimeResetDuration(rtype) | |
72 | + local resetData = csvdb["time_resetCsv"][rtype] | |
73 | + if not resetData then return 0 end | |
74 | + return resetData.duration == 0 and resetData.interval or math.min(resetData.interval, resetData.duration) | |
75 | +end | |
76 | + | |
77 | +--检查功能是否是在开放期 | |
78 | +function Role:isTimeResetOpen(rtype) | |
79 | + local resetData = csvdb["time_resetCsv"][rtype] | |
80 | + if not resetData or getTimeResetDuration(rtype) >= resetData.interval then | |
81 | + return true | |
82 | + end | |
83 | + | |
84 | + return self:getTimeResetEndTime(rtype) > skynet.timex() | |
85 | +end | |
86 | + | |
87 | +-- 当前轮次 开始时间 | |
88 | +function Role:getTimeResetStartTime(rtype) | |
89 | + local timeReset = self:getProperty("timeReset") | |
90 | + if not timeReset[rtype] then return 0 end | |
91 | + local resetData = csvdb["time_resetCsv"][rtype] | |
92 | + if not resetData then return 0 end | |
93 | + return START_RESET_TIME + timeReset[rtype] * resetData.interval + resetData.start | |
94 | +end | |
95 | + | |
96 | +-- 当前轮次 结束时间 | |
97 | +function Role:getTimeResetEndTime(rtype) | |
98 | + return self:getTimeResetStartTime(rtype) + getTimeResetDuration(rtype) | |
99 | +end | |
100 | + | |
101 | +function Role:getTimeResetRound(rtype) | |
102 | + local timeReset = self:getProperty("timeReset") | |
103 | + return timeReset[rtype] or 0 | |
104 | +end | |
105 | + | |
106 | +function Role:getTimeResetDataStart(rtype) | |
107 | + local resetData = csvdb["time_resetCsv"][rtype] | |
108 | + if not resetData then return 0 end | |
109 | + return resetData.start | |
110 | +end | |
111 | + | |
112 | + | |
113 | + | |
114 | + | |
115 | + | |
116 | + | |
117 | + | |
118 | +end | |
119 | + | |
120 | + | |
121 | + | |
122 | + | |
123 | + | |
124 | +return RoleTimeReset | |
0 | 125 | \ No newline at end of file | ... | ... |
src/services/agent_util.lua
... | ... | @@ -39,43 +39,6 @@ local function check_heart_beat(agent, now) |
39 | 39 | end |
40 | 40 | end |
41 | 41 | |
42 | -local PointDataMark = {} | |
43 | -local resetTimeStr = string.format("%02d00", RESET_TIME) | |
44 | -local resetRankTimeStr = string.format("%02d00", RESET_RANK_TIME) | |
45 | - | |
46 | -local function check_daily_reset(agent, now) | |
47 | - local date = os.date("*t", now) | |
48 | - local timeStr = string.format("%02d%02d", date.hour, date.min) | |
49 | - local dataStr = date.year .. string.format("%02d", date.month) .. string.format("%02d", date.day) | |
50 | - | |
51 | - local function timeEffect(checkTimeStr) | |
52 | - if timeStr ~= checkTimeStr then | |
53 | - return false | |
54 | - end | |
55 | - if PointDataMark[dataStr] and PointDataMark[dataStr][checkTimeStr] then | |
56 | - return false | |
57 | - end | |
58 | - PointDataMark[dataStr] = PointDataMark[dataStr] or {} | |
59 | - PointDataMark[dataStr][checkTimeStr] = true | |
60 | - return true | |
61 | - end | |
62 | - | |
63 | - if timeEffect(resetTimeStr) then | |
64 | - -- 刷新每日数据 | |
65 | - local role = agent.role | |
66 | - if role then | |
67 | - role:onCrossDay(now, true) | |
68 | - end | |
69 | - end | |
70 | - if resetTimeStr ~= resetRankTimeStr and timeEffect(resetRankTimeStr) then | |
71 | - -- 刷新排行榜需要重置的数据 | |
72 | - local role = agent.role | |
73 | - if role then | |
74 | - role:onResetRank(now, true) | |
75 | - end | |
76 | - end | |
77 | -end | |
78 | - | |
79 | 42 | function _M:update(agent) |
80 | 43 | local now = skynet.timex() |
81 | 44 | local role = agent.role |
... | ... | @@ -83,7 +46,6 @@ function _M:update(agent) |
83 | 46 | pcall(check_heart_beat, agent, now) |
84 | 47 | nextCheckTime = now + HEART_TIMER_INTERVAL |
85 | 48 | end |
86 | - pcall(check_daily_reset, agent, now) | |
87 | 49 | pcall(role.onRecoverTimer, role, now) |
88 | 50 | end |
89 | 51 | ... | ... |