Commit ea40710fd057ce3ba3958f41a54b745552d95996
1 parent
823ab846
活动
Showing
8 changed files
with
187 additions
and
24 deletions
Show diff stats
src/GlobalVar.lua
src/ProtocolCode.lua
src/actions/ActivityAction.lua
... | ... | @@ -125,14 +125,41 @@ function _M.signRpc(agent, data) |
125 | 125 | end |
126 | 126 | signs[curDay] = yearMonth |
127 | 127 | |
128 | - local raward = role:award(monthData[curDay].item, {log = {desc = "sign", int1 = yearMonth, int2 = curDay}}) | |
128 | + local reward = role:award(monthData[curDay].item, {log = {desc = "sign", int1 = yearMonth, int2 = curDay}}) | |
129 | 129 | role:changeUpdates({{type = "sign", field = curDay, value = yearMonth}}) |
130 | 130 | |
131 | - SendPacket(actionCodes.Activity_signRpc, MsgPack.pack(raward)) | |
131 | + SendPacket(actionCodes.Activity_signRpc, MsgPack.pack(reward)) | |
132 | 132 | return true |
133 | 133 | end |
134 | 134 | |
135 | 135 | |
136 | +function _M.actSignRpc(agent, data) | |
137 | + local role = agent.role | |
138 | + if not role.activity:isOpen("Sign") then return end | |
139 | + | |
140 | + local curData = role.activity:getActData("Sign") | |
141 | + local reward = {} | |
142 | + for day, csvData in ipairs(csvdb["new_signlnCsv"]) do | |
143 | + if day <= (curData[0] or 0) then | |
144 | + if not curData[day] then | |
145 | + curData[day] = -1 | |
146 | + -- 奖励 | |
147 | + for itemId, count in pairs(csvData.reward:toNumMap()) do | |
148 | + reward[itemId] = (reward[itemId] or 0) + count | |
149 | + end | |
150 | + end | |
151 | + else | |
152 | + break | |
153 | + end | |
154 | + end | |
155 | + if next(reward) then | |
156 | + self.activity:updateActData("Sign", curData) | |
157 | + reward = role:award(reward, {log = "actSign"}) | |
158 | + end | |
159 | + SendPacket(actionCodes.Activity_actSignRpc, MsgPack.pack(reward)) | |
160 | + return true | |
161 | +end | |
162 | + | |
136 | 163 | |
137 | 164 | |
138 | 165 | return _M |
139 | 166 | \ No newline at end of file | ... | ... |
src/actions/RoleAction.lua
... | ... | @@ -121,10 +121,14 @@ function _M.loginRpc( agent, data ) |
121 | 121 | role:advEndlessSeasonCheck(true) -- 冒险赛季更新检查 |
122 | 122 | |
123 | 123 | -- 跨天登陆事件 |
124 | - role:updateTimeReset(now) | |
124 | + local resetMode = role:updateTimeReset(now) | |
125 | + if not resetMode["CrossDay"] then -- 没有跨天 | |
126 | + self.activity:checkActivityStatus(now, false, false) | |
127 | + end | |
128 | + | |
125 | 129 | redisproxy:zadd(FRIEND_RECOMMEND, now, roleId) |
126 | 130 | |
127 | - for _, name in ipairs({"dailyData", "dinerData"}) do | |
131 | + for _, name in ipairs({"dailyData", "dinerData", "activity"}) do | |
128 | 132 | response[name] = role[name]:data() |
129 | 133 | end |
130 | 134 | ... | ... |
src/adv/Adv.lua
... | ... | @@ -776,8 +776,10 @@ function Adv:over(success, rewardRatio, overType) |
776 | 776 | end |
777 | 777 | reward = self.owner:award(reward, {log = {desc = "advOver", int1 = self.chapterId}}) |
778 | 778 | |
779 | + local backAdvCount | |
779 | 780 | if not self:isEndless() then |
780 | - self.owner:changeAdvCount(self.level - chapterData.limitlevel) | |
781 | + backAdvCount = chapterData.limitlevel - self.level | |
782 | + self.owner:changeAdvCount(-backAdvCount) | |
781 | 783 | end |
782 | 784 | |
783 | 785 | if success then |
... | ... | @@ -819,6 +821,16 @@ function Adv:over(success, rewardRatio, overType) |
819 | 821 | advAFWear = {}, |
820 | 822 | }) |
821 | 823 | self:backEnd(success, score, scoreInfo, reward, overType, scoreReward, chapterId) |
824 | + self:pushBackEvent(AdvBackEventType.End, { | |
825 | + success = success, | |
826 | + score = score, | |
827 | + scoreInfo = scoreInfo, | |
828 | + reward = reward, | |
829 | + type = overType, | |
830 | + scoreAward = scoreAward, | |
831 | + chapterId = chapterId, | |
832 | + backAdvCount = backAdvCount, | |
833 | + }) | |
822 | 834 | end |
823 | 835 | |
824 | 836 | function Adv:exit() |
... | ... | @@ -1925,9 +1937,6 @@ function Adv:backNext() |
1925 | 1937 | self:pushBackEvent(AdvBackEventType.Next, {}) |
1926 | 1938 | end |
1927 | 1939 | |
1928 | -function Adv:backEnd(success, score, scoreInfo, reward, overType, scoreAward, chapterId) | |
1929 | - self:pushBackEvent(AdvBackEventType.End, {success = success, score = score, scoreInfo = scoreInfo, reward = reward, type = overType, scoreAward = scoreAward, chapterId = chapterId}) | |
1930 | -end | |
1931 | 1940 | |
1932 | 1941 | function Adv:backBlockChange(roomId, blockId, itemChangeType) |
1933 | 1942 | self:pushBackEvent(AdvBackEventType.BlockChange, {roomId = roomId, blockId = blockId, itemChangeType = itemChangeType}) | ... | ... |
src/models/Activity.lua
... | ... | @@ -2,7 +2,7 @@ local Activity = class("Activity", require("shared.ModelBase")) |
2 | 2 | |
3 | 3 | |
4 | 4 | Activity.ActivityType = { |
5 | - DoubleDrop = 1, -- 双倍掉落 | |
5 | + Sign = 1, -- 签到 | |
6 | 6 | } |
7 | 7 | |
8 | 8 | |
... | ... | @@ -10,7 +10,7 @@ local function checkActivityType(activityType) |
10 | 10 | if type(activityType) == "string" then |
11 | 11 | activityType = Activity.ActivityType[activityType] |
12 | 12 | end |
13 | - return activityType | |
13 | + return activityType or 0 | |
14 | 14 | end |
15 | 15 | |
16 | 16 | |
... | ... | @@ -22,13 +22,13 @@ end |
22 | 22 | |
23 | 23 | |
24 | 24 | Activity.schema = { |
25 | - ctime = {"table", {}}, -- 最近检查某项活动的开始时间 {id = time} | |
26 | - _1 = {"table", {}}, | |
25 | + ctime = {"table", {}}, -- 最近检查某项活动的开始时间 {id = time} | |
26 | + act1 = {"table", {}}, -- {0 = day, 1= -1, 2 = -1} == 签到活动 | |
27 | 27 | } |
28 | 28 | |
29 | 29 | function Activity:data() |
30 | 30 | return { |
31 | - _1 = self:getProperty("_1"), | |
31 | + act1 = self:getProperty("act1"), | |
32 | 32 | } |
33 | 33 | end |
34 | 34 | |
... | ... | @@ -54,26 +54,141 @@ function Activity:updateProperty(params) |
54 | 54 | end |
55 | 55 | |
56 | 56 | |
57 | +function Activity:isOpenRaw(activityType, now) | |
58 | + activityType = checkActivityType(activityType) | |
59 | + local actData = csvdb["activity_ctrlCsv"][activityType] | |
60 | + if not actData then return end | |
61 | + | |
62 | + if actData.time == "" then -- 关闭 | |
63 | + return false | |
64 | + end | |
65 | + | |
66 | + local st = 0 | |
67 | + local et = 0 | |
68 | + local now = skynet.timex() | |
69 | + | |
70 | + if actData.ttype == 0 then -- 时间开放 | |
71 | + local openTimes = actData.time:toArray(false, "=") | |
72 | + if openTimes[1] ~= "0" then | |
73 | + st = toUnixtime(openTimes[1]..string_format("%02x", RESET_TIME)) | |
74 | + end | |
75 | + if openTimes[2] ~= "0" then | |
76 | + et = toUnixtime(openTimes[2]..string_format("%02x", RESET_TIME)) | |
77 | + end | |
78 | + elseif actData.ttype == 1 then -- 周期开放 | |
79 | + local openTimes = actData.time:toArray(true, "=") | |
80 | + local resetTime = toUnixtime(tostring(openTimes[1]) .. string_format("%02x", RESET_TIME)) | |
81 | + local r = math.floor((now - resetTime) / (openTimes[3] * 86400)) | |
82 | + st = resetTime + r * (openTimes[3] * 86400) | |
83 | + et = st + openTimes[2] * 86400 | |
84 | + else | |
85 | + return | |
86 | + end | |
87 | + | |
88 | + if now >= st and (et == 0 or now < et) then | |
89 | + return true, st | |
90 | + end | |
91 | + return false | |
92 | +end | |
93 | + | |
94 | +-- 缓存开放 | |
57 | 95 | function Activity:isOpen(activityType) |
58 | 96 | activityType = checkActivityType(activityType) |
97 | + return self._isOpen[activityType] | |
98 | +end | |
99 | + | |
100 | +function Activity:getActData(actType) | |
101 | + actType = checkActivityType(actType) | |
102 | + return self:getProperty("act" .. actType) | |
103 | +end | |
59 | 104 | |
105 | +function Activity:updateActData(actType, data, notNotify) | |
106 | + actType = checkActivityType(actType) | |
107 | + self:updateProperty({field = "act" .. actType, value = data, notNotify = notNotify}) | |
60 | 108 | end |
61 | 109 | |
110 | + | |
62 | 111 | -- 跨天刷新 --登录刷新 |
63 | -function Activity:checkActivityStatus(ltime, now, notify) | |
64 | - | |
112 | +function Activity:checkActivityStatus(now, isCrossDay, notify) | |
113 | + self._isOpen = {} | |
114 | + local ctime = self:getProperty("ctime") | |
115 | + local change = false | |
116 | + for actType, actData in paris(csvdb["activity_ctrlCsv"]) do | |
117 | + local isOpen, startTime = self:isOpenRaw(actType, now) | |
118 | + self._isOpen[actType] = isOpen | |
119 | + | |
120 | + if isOpen then | |
121 | + if ctime[actType] and ctime[actType] == startTime then -- 还是之前的状态 开放中 | |
122 | + else -- 重置 | |
123 | + ctime[actType] = startTime | |
124 | + self:closeActivity(actType, notify, true) | |
125 | + self:initActivity(actType, isCrossDay, notify) | |
126 | + change = true | |
127 | + end | |
128 | + else | |
129 | + if ctime[actType] then | |
130 | + self:closeActivity(actType, notify) | |
131 | + ctime[actType] = nil | |
132 | + change = true | |
133 | + end | |
134 | + end | |
135 | + end | |
136 | + if change then | |
137 | + self:setProperty("ctime", ctime) | |
138 | + end | |
65 | 139 | end |
66 | 140 | |
67 | -local checkActivityFunc = {} | |
141 | +local activityFunc = {} | |
68 | 142 | |
69 | -checkActivityFunc[Activity.ActivityType.DoubleDrop] = function(self, notNotify, activityType, ...) | |
143 | +activityFunc[Activity.ActivityType.Sign] = { | |
144 | + -- ["check"] = function(self, actType, notify) -- 检查 | |
145 | + -- end, | |
146 | + ["init"] = function(self, actType, isCrossDay, notify) | |
147 | + if not isCrossDay then | |
148 | + activityFunc[Activity.ActivityType.Sign]["crossDay"](self, actType, notify) | |
149 | + end | |
150 | + end, | |
151 | + -- ["close"] = function(self, actType, notify) | |
152 | + -- end, | |
153 | + ["crossDay"] = function(self, actType, notify) | |
154 | + local curData = self:getActData(actType) | |
155 | + curData[0] = (curData[0] or 0) + 1 | |
156 | + local actData = csvdb["new_signlnCsv"] | |
157 | + if curData[0] > #actData then return end -- 满了就忽略了 | |
158 | + | |
159 | + -- 没满更新一下 | |
160 | + self:updateActData(actType, curData, not notify) | |
161 | + end, | |
162 | +} | |
70 | 163 | |
164 | +function Activity:initActivity(actType, isCrossDay, notify) | |
165 | + if activityFunc[actType] and activityFunc[actType]['close'] then | |
166 | + activityFunc[actType]["init"](self, actType, isCrossDay, notify) | |
167 | + end | |
168 | +end | |
169 | + | |
170 | +function Activity:closeActivity(actType, notify, notUpdateAct) | |
171 | + if activityFunc[actType] and activityFunc[actType]['close'] then | |
172 | + activityFunc[actType]["close"](self, actType, notify) | |
173 | + end | |
174 | + self:updateActData(actType, Activity.schema["act" .. actType][2], not notify or notUpdateAct) | |
175 | +end | |
176 | + | |
177 | +function Activity:refreshDailyData(notify) | |
178 | + for actType, status in pairs(self._isOpen) do | |
179 | + if status then | |
180 | + if activityFunc[actType] and activityFunc[actType]['crossDay'] then | |
181 | + activityFunc[actType]["crossDay"](self, actType, notify) | |
182 | + end | |
183 | + end | |
184 | + end | |
71 | 185 | end |
72 | 186 | |
73 | -function Activity:checkActivityEnter(notNotify, activityType, ...) | |
187 | +function Activity:checkActivity(notNotify, activityType, ...) | |
74 | 188 | if not activityType then return end |
75 | - if checkActivityFunc[activityType] then | |
76 | - checkActivityFunc[activityType](self, notNotify, activityType, ...) | |
189 | + if not self:isOpen(activityType) then return end | |
190 | + if activityFunc[activityType] and activityFunc[activityType]['check'] then | |
191 | + activityFunc[activityType]["check"](self, activityType, not notNotify, ...) | |
77 | 192 | end |
78 | 193 | end |
79 | 194 | ... | ... |
src/models/RoleTask.lua
... | ... | @@ -526,7 +526,7 @@ function RoleTask.bind(Role) |
526 | 526 | end |
527 | 527 | |
528 | 528 | function Role:checkActivityTask(notNotify, activityType, ...) |
529 | - self.activity:checkActivityEnter(notNotify, activityType, ...) | |
529 | + self.activity:checkActivity(notNotify, activityType, ...) | |
530 | 530 | end |
531 | 531 | |
532 | 532 | end | ... | ... |
src/models/RoleTimeReset.lua
... | ... | @@ -4,9 +4,12 @@ RoleTimeReset.bind = function (Role) |
4 | 4 | |
5 | 5 | -- 重置内容 对应 GlobalVar TimeReset |
6 | 6 | local ResetFunc = {} |
7 | -ResetFunc["CrossDay"] = function(self, notify, response) | |
7 | +ResetFunc["CrossDay"] = function(self, notify, response, now) | |
8 | + self.activity:checkActivityStatus(now, true, notify) | |
9 | + | |
8 | 10 | self.dailyData:refreshDailyData(notify) |
9 | 11 | self.dinerData:refreshDailyData(notify) |
12 | + self.activity:refreshDailyData(notify) | |
10 | 13 | |
11 | 14 | self:setProperty("dTask", {}) |
12 | 15 | self:advRandomSupportEffect(not notify) |
... | ... | @@ -55,10 +58,13 @@ function Role:updateTimeReset(now, notify) |
55 | 58 | end |
56 | 59 | if not next(needResetId) then return end |
57 | 60 | |
61 | + local resetMode = {} | |
62 | + | |
58 | 63 | local response = {} |
59 | 64 | for funcName, resetId in pairs(TimeReset) do |
60 | 65 | if needResetId[resetId] and ResetFunc[funcName] then |
61 | - ResetFunc[funcName](self, notify, response) | |
66 | + ResetFunc[funcName](self, notify, response, now) | |
67 | + resetMode[funcName] = true | |
62 | 68 | end |
63 | 69 | end |
64 | 70 | |
... | ... | @@ -71,6 +77,7 @@ function Role:updateTimeReset(now, notify) |
71 | 77 | if notify then |
72 | 78 | self:notifyUpdateProperties(response) |
73 | 79 | end |
80 | + return resetMode | |
74 | 81 | end |
75 | 82 | |
76 | 83 | -- 持续时间取 min(interval, duration) duration 填 0 默认使用 interval 作为持续时间 | ... | ... |