Commit ecf875630fc00c38d800c7a8d2e5f3e6dbb77ac3
1 parent
2c04a149
feat: 挂机图鉴的扩展功能——额外宝藏奖励
Showing
7 changed files
with
515 additions
and
305 deletions
Show diff stats
src/ProtocolCode.lua
... | ... | @@ -67,6 +67,8 @@ actionCodes = { |
67 | 67 | Role_itemConvertDevilTicketRpc = 148, -- 兑换魔鬼训练营门票 |
68 | 68 | Role_unRegisterRpc = 149, --注销账号 |
69 | 69 | Role_searchAllRoleRpc = 150, --查询所有服的角色信息 |
70 | + Role_takeTreasureRpc = 151, --抓取额外宝藏 | |
71 | + Role_treasureMapRpc = 152, --兑换宝藏图 | |
70 | 72 | |
71 | 73 | Adv_startAdvRpc = 151, |
72 | 74 | Adv_startHangRpc = 152, | ... | ... |
src/actions/GmAction.lua
... | ... | @@ -1008,7 +1008,7 @@ function _M.treasure(role, pms) |
1008 | 1008 | dump(treasureList) |
1009 | 1009 | return "宝藏图鉴" |
1010 | 1010 | elseif pm1 == "FLUSH" then |
1011 | - local treasureList= role.dailyData:getTreasrueList(role) | |
1011 | + local treasureList= role.dailyData:getTreasureList(role) | |
1012 | 1012 | dump(treasureList) |
1013 | 1013 | return "宝藏图鉴" |
1014 | 1014 | elseif pm1 == "CHECK" then |
... | ... | @@ -1171,5 +1171,40 @@ function _M.draw_code(role, pms) |
1171 | 1171 | return ret |
1172 | 1172 | end |
1173 | 1173 | |
1174 | +table.insert(helpDes, {"抓取额外宝藏", "treasure_extra"}) | |
1175 | +function _M.treasure_extra(role, pms) | |
1176 | + local extraCount = role.dailyData:getProperty("treasureExtraCount") --每日发现额外宝藏使用次数(累计),隔天清零 | |
1177 | + local mapCount = role.dailyData:getProperty("treasureMapCount") | |
1178 | + local baseExtra = role.dailyData:getProperty("treasureBaseExtra") | |
1179 | + | |
1180 | + if extraCount >= globalCsv.idle_treasure_extra_limie then return 1 end | |
1181 | + if mapCount <= 0 then return 2 end | |
1182 | + | |
1183 | + baseExtra = baseExtra + globalCsv.idle_treasure_base_extra | |
1184 | + | |
1185 | + local tmpTreasure, treasureListExtra = role.dailyData:getTreasureExtra(baseExtra) | |
1186 | + | |
1187 | + dump(tmpTreasure) | |
1188 | + dump(treasureListExtra) | |
1189 | + if not tmpTreasure then return 3 end | |
1190 | + | |
1191 | + role.dailyData:updateProperty({field = "treasureExtraCount", delta = 1}) | |
1192 | + role.dailyData:updateProperty({field = "treasureBaseExtra", value = mapCount - 1}) | |
1193 | + role.dailyData:updateProperty({field = "treasureBaseExtra", value = baseExtra}) | |
1194 | + | |
1195 | + return "成功" | |
1196 | +end | |
1197 | + | |
1198 | +table.insert(helpDes, {"兑换宝藏图", "treasure_map"}) | |
1199 | +function _M.treasure_map(role, pms) | |
1200 | + local count = tonumber(pms.pm1 or 1) | |
1201 | + local cost ={[ItemId.Jade] = globalCsv.idle_treasure_buy * count} | |
1202 | + if not role:checkItemEnough(cost) then return -1 end | |
1203 | + if not role:costItems(cost, {log = {desc = "treasureMap", int1 = count}}) then return -2 end | |
1204 | + role.dailyData:updateProperty({field = "treasureMapCount", delta = 1*count}) | |
1205 | + | |
1206 | + local treasureMapCount = role.dailyData:getProperty("treasureMapCount") | |
1207 | + return treasureMapCount | |
1208 | +end | |
1174 | 1209 | |
1175 | 1210 | return _M |
1176 | 1211 | \ No newline at end of file | ... | ... |
src/actions/HangAction.lua
... | ... | @@ -125,10 +125,18 @@ local function checkReward(role, isTreasure, carbonId) |
125 | 125 | randomItem() |
126 | 126 | end |
127 | 127 | |
128 | - --挂机得到的宝藏加入到挂机奖励 | |
129 | - if isTreasure or false == true then | |
130 | - local treasureList= role.dailyData:checkTreasureList(carbonId or hangInfo.carbonId) or {} | |
131 | - for _, val in pairs(treasureList) do | |
128 | + --挂机得到的宝藏加入到挂机奖励 + 额外宝藏奖励 | |
129 | + if isTreasure then | |
130 | + local treasureList= role.dailyData:checkTreasureList(carbonId or hangInfo.carbonId) | |
131 | + for _, val in pairs(treasureList or {}) do | |
132 | + local award = val.award:toNumMap() | |
133 | + for k,v in pairs(award) do | |
134 | + items[k] = (items[k] or 0) + v | |
135 | + end | |
136 | + end | |
137 | + | |
138 | + treasureList = role.dailyData:checkTreasureListExtra(carbonId or hangInfo.carbonId) | |
139 | + for _, val in pairs(treasureList or {}) do | |
132 | 140 | local award = val.award:toNumMap() |
133 | 141 | for k,v in pairs(award) do |
134 | 142 | items[k] = (items[k] or 0) + v |
... | ... | @@ -339,7 +347,7 @@ function _M.endBattleRpc(agent, data) |
339 | 347 | |
340 | 348 | --刷新宝藏图鉴 |
341 | 349 | if isWin and globalCsv.idle_treasure_point and globalCsv.idle_treasure_point == carbonId then |
342 | - role.dailyData:getTreasrueList() | |
350 | + role.dailyData:getTreasureList() | |
343 | 351 | end |
344 | 352 | |
345 | 353 | role:updateProperty({field = "hangInfo", value = hangInfo}) |
... | ... | @@ -513,8 +521,17 @@ function _M.quickRpc(agent , data) |
513 | 521 | end |
514 | 522 | |
515 | 523 | --宝藏加速 |
516 | - local treasureList = role.dailyData:quickTreasureList(hangInfo.carbonId, time) or {} | |
517 | - for id, val in pairs(treasureList) do | |
524 | + local treasureList = role.dailyData:quickTreasureList(hangInfo.carbonId, time) | |
525 | + for _, val in pairs(treasureList or {}) do | |
526 | + local award = val.award:toNumMap() | |
527 | + for k,v in pairs(award) do | |
528 | + reward[k] = (reward[k] or 0) + v | |
529 | + end | |
530 | + end | |
531 | + | |
532 | + --额外宝藏加速 | |
533 | + treasureList = role.dailyData:quickTreasureListExtra(hangInfo.carbonId, time) | |
534 | + for _, val in pairs(treasureList or {}) do | |
518 | 535 | local award = val.award:toNumMap() |
519 | 536 | for k,v in pairs(award) do |
520 | 537 | reward[k] = (reward[k] or 0) + v | ... | ... |
src/actions/RoleAction.lua
... | ... | @@ -1900,4 +1900,40 @@ function _M.itemConvertDevilTicketRpc(agent, data) |
1900 | 1900 | return true |
1901 | 1901 | end |
1902 | 1902 | |
1903 | +function _M.takeTreasureRpc(agent, data) | |
1904 | + local role = agent.role | |
1905 | + local extraCount = role.dailyData:getProperty("treasureExtraCount") --每日发现额外宝藏使用次数(累计),隔天清零 | |
1906 | + local mapCount = role.dailyData:getProperty("treasureMapCount") | |
1907 | + local baseExtra = role.dailyData:getProperty("treasureBaseExtra") | |
1908 | + | |
1909 | + if extraCount >= globalCsv.idle_treasure_extra_limie then return 1 end | |
1910 | + if mapCount <= 0 then return 2 end | |
1911 | + | |
1912 | + baseExtra = baseExtra + globalCsv.idle_treasure_base_extra | |
1913 | + | |
1914 | + local tmpTreasure, treasureListExtra = role.dailyData:getTreasureExtra(baseExtra) | |
1915 | + if not tmpTreasure then return 3 end | |
1916 | + | |
1917 | + role.dailyData:updateProperty({field = "treasureExtraCount", delta = 1}) | |
1918 | + role.dailyData:updateProperty({field = "treasureBaseExtra", value = mapCount - 1}) | |
1919 | + role.dailyData:updateProperty({field = "treasureBaseExtra", value = baseExtra}) | |
1920 | + | |
1921 | + SendPacket(actionCodes.Role_takeTreasureRpc, MsgPack.pack({treasureListExtra = treasureListExtra, treasure = tmpTreasure})) | |
1922 | + return true | |
1923 | +end | |
1924 | + | |
1925 | +function _M.treasureMapRpc(agent,data) | |
1926 | + local role = agent.role | |
1927 | + local msg = MsgPack.unpack(data) | |
1928 | + local count = msg.count or 1 | |
1929 | + local cost ={[ItemId.Jade] = globalCsv.idle_treasure_buy * count} | |
1930 | + if not role:checkItemEnough(cost) then return 1 end | |
1931 | + if not role:costItems(cost, {log = {desc = "treasureMap", int1 = count}}) then return 2 end | |
1932 | + role.dailyData:updateProperty({field = "treasureMapCount", delta = 1*count}) | |
1933 | + | |
1934 | + local treasureMapCount = role.dailyData:getProperty("treasureMapCount") | |
1935 | + SendPacket(actionCodes.Role_treasureMapRpc, MsgPack.pack({mapCount = treasureMapCount})) | |
1936 | + return true | |
1937 | +end | |
1938 | + | |
1903 | 1939 | return _M |
1904 | 1940 | \ No newline at end of file | ... | ... |
src/models/Daily.lua
1 | 1 | -- 日常数据 |
2 | 2 | |
3 | 3 | local Daily = class("Daily", require("shared.ModelBaseMysql")) |
4 | - | |
5 | -oneDay = 60*60*24 | |
4 | +local DailyPlugin = import(".DailyPlugin") --宝藏相关 | |
5 | +DailyPlugin.bind(Daily) | |
6 | 6 | |
7 | 7 | function Daily:ctor(properties) |
8 | 8 | Daily.super.ctor(self, properties) |
... | ... | @@ -37,6 +37,11 @@ Daily.schema = { |
37 | 37 | treasureBase = {"number", 0}, -- 资源值 |
38 | 38 | treasureList = {"table", {}}, --挂机图鉴 |
39 | 39 | |
40 | + treasureListExtra = {"table", {}}, --额外宝藏,挂机图鉴扩展功能 | |
41 | + treasureMapCount = {"number", 0}, --宝藏图,消耗一张宝藏图可以发现一次额外宝藏 | |
42 | + treasureExtraCount = {"number", 0}, --每日发现额外宝藏使用次数(累计),隔天清零 | |
43 | + treasureBaseExtra = {"number", 0}, --额外宝藏资源值 | |
44 | + | |
40 | 45 | chatTimes = {"number", 0}, --每日发言次数 |
41 | 46 | } |
42 | 47 | |
... | ... | @@ -73,7 +78,9 @@ function Daily:refreshDailyData(notify) |
73 | 78 | elseif field == "treasureBase" then |
74 | 79 | dataMap[field] = globalCsv.idle_treasure_base + self.owner:getBnousTreasureBaseMaximum() |
75 | 80 | elseif field == "treasureList" then |
76 | - dataMap[field] = self:getTreasrueList() | |
81 | + dataMap[field] = self:getTreasureList() | |
82 | + elseif field == "treasureExtraCount" then | |
83 | + dataMap[field] = 0 | |
77 | 84 | elseif field == "pvpBought" then |
78 | 85 | dataMap[field] = 0 |
79 | 86 | elseif field ~= "key" then |
... | ... | @@ -101,300 +108,6 @@ function Daily:refreshDailyData(notify) |
101 | 108 | end |
102 | 109 | end |
103 | 110 | |
104 | ---解锁 | |
105 | -function Daily:checkUnlock(treaval) | |
106 | - local role = self.owner | |
107 | - local treasureC = treaval.unlock:toArray(true, "=") | |
108 | - local show = false | |
109 | - if treasureC[1] == 1 then --通关关卡 | |
110 | - show = self.owner:checkHangPass(treasureC[2]) | |
111 | - elseif treasureC[1] == 2 then --通关拾荒章节=x层 | |
112 | - show = role:checkAdvChapterPass(treasureC[2]) | |
113 | - elseif treasureC[1] == 3 then --拥有指定id的角色时 | |
114 | - local hero = role:getHeroByID(treasureC[2]) | |
115 | - if hero then show = true end | |
116 | - else | |
117 | - show = true | |
118 | - end | |
119 | - return show | |
120 | -end | |
121 | - | |
122 | ---CD | |
123 | -function Daily:checkTreasureExpired(treasureAttr, treasureList) | |
124 | - local curInfo = treasureList[treasureAttr.id] | |
125 | - if curInfo then | |
126 | - -- check finish | |
127 | - if curInfo["expire_time"] then | |
128 | - if curInfo.cool_time > 1 then | |
129 | - if skynet.timex() >= curInfo["expire_time"] then | |
130 | - treasureList[treasureAttr.id] = nil | |
131 | - curInfo = clone(treasureAttr) | |
132 | - elseif skynet.timex() >= curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却 | |
133 | - curInfo = nil | |
134 | - else | |
135 | - curInfo = clone(treasureAttr) | |
136 | - end | |
137 | - else | |
138 | - if skynet.timex() >= curInfo["expire_time"] then | |
139 | - treasureList[treasureAttr.id] = nil | |
140 | - end | |
141 | - curInfo = clone(treasureAttr) | |
142 | - end | |
143 | - end | |
144 | - else | |
145 | - curInfo = clone(treasureAttr) | |
146 | - end | |
147 | - | |
148 | - return curInfo | |
149 | -end | |
150 | - | |
151 | ---资源 | |
152 | -function Daily:checkTreasureBase(treasureList, treasureBase, removeId) | |
153 | - local tmptreasure = {} | |
154 | - local num = 0 | |
155 | - for k, val in pairs(treasureList) do | |
156 | - if removeId and val.id == removeId then | |
157 | - treasureList[k] = nil | |
158 | - else | |
159 | - if treasureBase >= val.treasure_value then | |
160 | - treasureBase = treasureBase - val.treasure_value | |
161 | - tmptreasure[val.id] = val | |
162 | - num = num + 1 | |
163 | - end | |
164 | - end | |
165 | - | |
166 | - end | |
167 | - return tmptreasure, num | |
168 | -end | |
169 | - | |
170 | ---绑定通关关卡 | |
171 | -function Daily:checkChapters() | |
172 | - local chapters = {} | |
173 | - local tmp_chapters = {} | |
174 | - local treasureList = self:getProperty("treasureList") | |
175 | - if next(treasureList) then | |
176 | - for _, curInfo in pairs(treasureList) do | |
177 | - if curInfo["expire_time"] or not curInfo["end_time"] then | |
178 | - tmp_chapters[curInfo.chapter_id] = curInfo | |
179 | - end | |
180 | - end | |
181 | - end | |
182 | - local hangInfo = self.owner:getProperty("hangInfo") or {} | |
183 | - for chapter_id, val in pairs(csvdb["idle_battleCsv"]) do | |
184 | - if chapter_id ~= hangInfo.carbonId then | |
185 | - if self.owner:checkHangPass(chapter_id) then | |
186 | - if next(tmp_chapters) and not tmp_chapters[chapter_id] then | |
187 | - chapters[chapter_id] = val | |
188 | - else | |
189 | - chapters[chapter_id] = val | |
190 | - end | |
191 | - end | |
192 | - end | |
193 | - | |
194 | - end | |
195 | - return chapters | |
196 | -end | |
197 | - | |
198 | ---权重 | |
199 | -function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase) | |
200 | - local removeId | |
201 | - local chapters = self:checkChapters() | |
202 | - local treasure | |
203 | - if next(chapters) == nil then return end | |
204 | - | |
205 | - --扣除在挖宝列表里未过期宝藏的资源值 | |
206 | - for _, val in pairs(treasureList) do | |
207 | - if not val["expire_time"] then | |
208 | - treasureBase = treasureBase - val["treasure_value"] | |
209 | - end | |
210 | - end | |
211 | - | |
212 | - while next(tmptreasure) do | |
213 | - local tmp, num = self:checkTreasureBase(tmptreasure, treasureBase, removeId) | |
214 | - | |
215 | - if num == 0 then | |
216 | - break | |
217 | - elseif num == 1 then | |
218 | - for _, val in pairs(tmp) do | |
219 | - treasure = val | |
220 | - end | |
221 | - else | |
222 | - local id = math.randWeight(tmp, "weight") --宝藏id | |
223 | - if not id then | |
224 | - break | |
225 | - end | |
226 | - treasure = tmp[id] | |
227 | - end | |
228 | - | |
229 | - if treasureBase >= treasure.treasure_value then | |
230 | - --扣除资源值 | |
231 | - treasureBase = treasureBase - treasure.treasure_value | |
232 | - else | |
233 | - break | |
234 | - end | |
235 | - local chapterId = math.randWeight(chapters, "treasure_weight") --关卡id | |
236 | - if not chapterId then | |
237 | - break | |
238 | - end | |
239 | - | |
240 | - treasure.chapter_id = chapterId | |
241 | - treasureList[treasure.id] = treasure | |
242 | - removeId = treasure.id | |
243 | - end | |
244 | -end | |
245 | - | |
246 | ---chapterId | |
247 | -function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId) | |
248 | - local treasure = nil | |
249 | - | |
250 | - if not curInfo then | |
251 | - return treasure | |
252 | - end | |
253 | - local treasureBase = self:getProperty("treasureBase") | |
254 | - | |
255 | - --开始挖宝关卡ID=挂机关卡ID | |
256 | - if chapterId == curInfo.chapter_id then | |
257 | - --开始挖宝 | |
258 | - if not curInfo["end_time"] then | |
259 | - curInfo["end_time"] = skynet.timex() + curInfo.working_time | |
260 | - else | |
261 | - if skynet.timex() >= curInfo["end_time"] then | |
262 | - if curInfo.cool_time > 1 then | |
263 | - --宝藏冷却时间 | |
264 | - if not curInfo["expire_time"] then | |
265 | - if treasureBase >= curInfo["treasure_value"] then | |
266 | - treasureBase = treasureBase - curInfo["treasure_value"] | |
267 | - | |
268 | - treasure = treasureList[curInfo.id] | |
269 | - curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay | |
270 | - end | |
271 | - else | |
272 | - --已经领取宝藏 检索宝藏冷却时间 | |
273 | - if skynet.timex() >= curInfo["expire_time"] then | |
274 | - treasureList[curInfo.id] = nil | |
275 | - end | |
276 | - end | |
277 | - else | |
278 | - if treasureBase >= curInfo["treasure_value"] then | |
279 | - treasureBase = treasureBase - curInfo["treasure_value"] | |
280 | - | |
281 | - treasure = treasureList[curInfo.id] | |
282 | - treasureList[curInfo.id] = nil | |
283 | - end | |
284 | - end | |
285 | - end | |
286 | - end | |
287 | - else | |
288 | - --已经开始挖宝 | |
289 | - if curInfo["end_time"] then | |
290 | - if skynet.timex() >= curInfo["end_time"] then | |
291 | - if curInfo.cool_time > 1 then | |
292 | - --宝藏冷却时间 | |
293 | - if not curInfo["expire_time"] then | |
294 | - if treasureBase >= curInfo["treasure_value"] then | |
295 | - treasureBase = treasureBase - curInfo["treasure_value"] | |
296 | - | |
297 | - treasure = treasureList[curInfo.id] | |
298 | - curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay | |
299 | - end | |
300 | - | |
301 | - else | |
302 | - --已经领取宝藏 检索宝藏冷却时间 | |
303 | - if skynet.timex() >= curInfo["expire_time"] then | |
304 | - treasureList[curInfo.id] = nil | |
305 | - end | |
306 | - end | |
307 | - else | |
308 | - if treasureBase >= curInfo["treasure_value"] then | |
309 | - treasureBase = treasureBase - curInfo["treasure_value"] | |
310 | - | |
311 | - treasure = treasureList[curInfo.id] | |
312 | - treasureList[curInfo.id] = nil | |
313 | - end | |
314 | - end | |
315 | - else | |
316 | - curInfo["end_time"] = nil | |
317 | - end | |
318 | - end | |
319 | - end | |
320 | - return treasure | |
321 | -end | |
322 | - | |
323 | -function Daily:buyTreasure(treasureList) | |
324 | - local boughtTreasurer = {} | |
325 | - local treasureBase = self:getProperty("treasureBase") | |
326 | - for id, val in pairs(treasureList) do | |
327 | - if treasureBase >= val.treasure_value then | |
328 | - boughtTreasurer[id] = val | |
329 | - treasureBase = treasureBase - val.treasure_value | |
330 | - end | |
331 | - end | |
332 | - self:updateProperty({field = "treasureBase", value = treasureBase}) | |
333 | - return boughtTreasurer | |
334 | -end | |
335 | - | |
336 | ---重置宝藏图鉴 | |
337 | -function Daily:resetTreasureList() | |
338 | - self:updateProperty({field = "treasureList", value = {}}) | |
339 | -end | |
340 | - | |
341 | ---宝藏图鉴 | |
342 | -function Daily:getTreasrueList() | |
343 | - local tmpcsv = csvdb["idle_treasureCsv"] | |
344 | - local treasureList = self:getProperty("treasureList") or {} --挖宝列表 过期删除 领取奖励删除 跨天更新 | |
345 | - local tmptreasure = {} | |
346 | - local treasureBase = globalCsv.idle_treasure_base + self.owner:getBnousTreasureBaseMaximum() | |
347 | - for id, val in pairs(tmpcsv) do | |
348 | - if self:checkUnlock(val) == true then | |
349 | - local treasure = self:checkTreasureExpired(val, treasureList) | |
350 | - if treasure then | |
351 | - table.insert(tmptreasure, treasure) | |
352 | - end | |
353 | - end | |
354 | - end | |
355 | - table.sort(tmptreasure, function (a,b) return a.treasure_value > b.treasure_value end) | |
356 | - | |
357 | - self:checkTreasureWeight(treasureList, tmptreasure, treasureBase) | |
358 | - self:updateProperty({field = "treasureList", value = treasureList}) | |
359 | - self:updateProperty({field = "treasureBase", value = treasureBase}) | |
360 | - return treasureList | |
361 | -end | |
362 | - | |
363 | - | |
364 | ---检索挖宝列表 | |
365 | -function Daily:checkTreasureList(chapterId) | |
366 | - local treasureList = self:getProperty("treasureList") or {} | |
367 | - local tmptreasure = {} | |
368 | - for id, val in pairs(treasureList) do | |
369 | - local treasure = self:checkTreasureChapterId(val, treasureList, chapterId) | |
370 | - if treasure ~= nil then | |
371 | - tmptreasure[id] = treasure | |
372 | - end | |
373 | - end | |
374 | - | |
375 | - if next(tmptreasure) == nil then | |
376 | - self:updateProperty({field = "treasureList", value = treasureList}) | |
377 | - return nil | |
378 | - end | |
379 | - local boughtTreasurer = self:buyTreasure(tmptreasure) | |
380 | - self:updateProperty({field = "treasureList", value = treasureList}) | |
381 | - return boughtTreasurer | |
382 | -end | |
383 | - | |
384 | ---宝藏加速 | |
385 | -function Daily:quickTreasureList(chapterId, time) | |
386 | - local treasureList = self:getProperty("treasureList") or {} | |
387 | - if next(treasureList) then | |
388 | - for id, val in pairs(treasureList) do | |
389 | - if val["end_time"] and val["chapter_id"] and chapterId == val["chapter_id"] then | |
390 | - val["end_time"] = val["end_time"] - time | |
391 | - end | |
392 | - end | |
393 | - end | |
394 | - self:updateProperty({field = "treasureList", value = treasureList}) | |
395 | - return self:checkTreasureList(chapterId) | |
396 | -end | |
397 | - | |
398 | 111 | function Daily:data() |
399 | 112 | return { |
400 | 113 | hangQC = self:getProperty("hangQC"), |
... | ... | @@ -417,6 +130,10 @@ function Daily:data() |
417 | 130 | curPool = self:getProperty("curPool"), |
418 | 131 | treasureBase = self:getProperty("treasureBase"), |
419 | 132 | treasureList = self:getProperty("treasureList"), |
133 | + treasureListExtra = self:getProperty("treasureListExtra"), | |
134 | + treasureMapCount = self:getProperty("treasureMapCount"), | |
135 | + treasureExtraCount = self:getProperty("treasureExtraCount"), | |
136 | + treasureBaseExtra = self:getProperty("treasureBaseExtra"), | |
420 | 137 | chatTimes = self:getProperty("chatTimes"), |
421 | 138 | } |
422 | 139 | end | ... | ... |
... | ... | @@ -0,0 +1,402 @@ |
1 | + | |
2 | +local DailyPlugin = {} | |
3 | +oneDay = 60*60*24 | |
4 | +function DailyPlugin.bind(Daily) | |
5 | + --解锁 | |
6 | + function Daily:checkUnlock(treaval) | |
7 | + local role = self.owner | |
8 | + local treasureC = treaval.unlock:toArray(true, "=") | |
9 | + if treasureC[1] == 1 then --通关关卡 | |
10 | + return self.owner:checkHangPass(treasureC[2]) | |
11 | + elseif treasureC[1] == 2 then --通关拾荒章节=x层 | |
12 | + return role:checkAdvChapterPass(treasureC[2]) | |
13 | + elseif treasureC[1] == 3 then --拥有指定id的角色时 | |
14 | + local hero = role:getHeroByID(treasureC[2]) | |
15 | + if hero then return true end | |
16 | + else | |
17 | + return true | |
18 | + end | |
19 | + return false | |
20 | + end | |
21 | + | |
22 | + --CD | |
23 | + function Daily:checkTreasureExpired(treasureAttr, treasureList) | |
24 | + local curInfo = treasureList[treasureAttr.id] | |
25 | + if curInfo then | |
26 | + -- check finish | |
27 | + if curInfo["expire_time"] then | |
28 | + if curInfo.cool_time > 1 then | |
29 | + if skynet.timex() >= curInfo["expire_time"] then | |
30 | + treasureList[treasureAttr.id] = nil | |
31 | + curInfo = clone(treasureAttr) | |
32 | + elseif skynet.timex() >= curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却 | |
33 | + curInfo = nil | |
34 | + else | |
35 | + curInfo = clone(treasureAttr) | |
36 | + end | |
37 | + else | |
38 | + if skynet.timex() >= curInfo["expire_time"] then | |
39 | + treasureList[treasureAttr.id] = nil | |
40 | + end | |
41 | + curInfo = clone(treasureAttr) | |
42 | + end | |
43 | + end | |
44 | + else | |
45 | + curInfo = clone(treasureAttr) | |
46 | + end | |
47 | + | |
48 | + return curInfo | |
49 | + end | |
50 | + | |
51 | + --绑定通关关卡 | |
52 | + function Daily:checkChapters(treasureList, treasureListOther) | |
53 | + local chapters = {} | |
54 | + local tmp_chapters = {} | |
55 | + | |
56 | + for _, curInfo in pairs(treasureList or {}) do | |
57 | + if curInfo["expire_time"] or not curInfo["end_time"] then | |
58 | + tmp_chapters[curInfo.chapter_id] = curInfo | |
59 | + end | |
60 | + end | |
61 | + | |
62 | + for _, curInfo in pairs(treasureListOther or {}) do | |
63 | + if curInfo["expire_time"] or not curInfo["end_time"] then | |
64 | + tmp_chapters[curInfo.chapter_id] = curInfo | |
65 | + end | |
66 | + end | |
67 | + | |
68 | + local hangInfo = self.owner:getProperty("hangInfo") or {} | |
69 | + for chapter_id, val in pairs(csvdb["idle_battleCsv"]) do | |
70 | + if chapter_id ~= hangInfo.carbonId then | |
71 | + if self.owner:checkHangPass(chapter_id) then | |
72 | + if next(tmp_chapters) and not tmp_chapters[chapter_id] then | |
73 | + chapters[chapter_id] = val | |
74 | + else | |
75 | + chapters[chapter_id] = val | |
76 | + end | |
77 | + end | |
78 | + end | |
79 | + | |
80 | + end | |
81 | + return chapters | |
82 | + end | |
83 | + | |
84 | + --权重 | |
85 | + function Daily:checkTreasureWeight(treasureList, tmpTreasure, treasureBase, treasureListOther) | |
86 | + local chapters = self:checkChapters(treasureList, treasureListOther) | |
87 | + if not chapters or not next(chapters) then return end | |
88 | + | |
89 | + --扣除在挖宝列表里未过期宝藏的资源值 | |
90 | + for _, val in pairs(treasureList) do | |
91 | + if not val["expire_time"] then | |
92 | + treasureBase = treasureBase - val["treasure_value"] | |
93 | + end | |
94 | + end | |
95 | + | |
96 | + if tmpTreasure and next(tmpTreasure) then | |
97 | + table.sort(tmpTreasure, function (a, b) return a.treasure_value > b.treasure_value end) | |
98 | + end | |
99 | + | |
100 | + local treasure | |
101 | + while next(tmpTreasure or {}) do | |
102 | + local tmp = {} | |
103 | + local tmpBase = treasureBase | |
104 | + for _, val in pairs(tmpTreasure) do | |
105 | + if tmpBase >= val.treasure_value then | |
106 | + tmpBase = tmpBase - val.treasure_value | |
107 | + tmp[val.id] = val | |
108 | + end | |
109 | + end | |
110 | + if not next(tmp) then break end | |
111 | + | |
112 | + local id = math.randWeight(tmp, "weight") --宝藏id | |
113 | + if not id then break end | |
114 | + | |
115 | + treasure = tmp[id] | |
116 | + if treasureBase < treasure.treasure_value then break end | |
117 | + --扣除资源值 | |
118 | + treasureBase = treasureBase - treasure.treasure_value | |
119 | + | |
120 | + local chapterId = math.randWeight(chapters, "treasure_weight") --关卡id | |
121 | + if not chapterId then break end | |
122 | + | |
123 | + treasure.chapter_id = chapterId | |
124 | + treasureList[treasure.id] = treasure | |
125 | + | |
126 | + tmpTreasure[treasure.id] = nil | |
127 | + chapters[chapterId] = nil | |
128 | + end | |
129 | + end | |
130 | + | |
131 | + --只抓一个 额外宝藏 | |
132 | + function Daily:getOneTreasureExtra(treasureList, tmpTreasure, treasureBase, treasureListOther) | |
133 | + local chapters = self:checkChapters(treasureList, treasureListOther) | |
134 | + if not chapters or not next(chapters) then return end | |
135 | + | |
136 | + --扣除在挖宝列表里未过期宝藏的资源值 | |
137 | + for _, val in pairs(treasureList) do | |
138 | + if not val["expire_time"] then | |
139 | + treasureBase = treasureBase - val["treasure_value"] | |
140 | + end | |
141 | + end | |
142 | + | |
143 | + if tmpTreasure and next(tmpTreasure) then | |
144 | + table.sort(tmpTreasure, function (a, b) return a.treasure_value > b.treasure_value end) | |
145 | + end | |
146 | + | |
147 | + local treasure | |
148 | + local tmp = {} | |
149 | + local tmpBase = treasureBase | |
150 | + for _, val in pairs(tmpTreasure) do | |
151 | + if tmpBase >= val.treasure_value then | |
152 | + tmpBase = tmpBase - val.treasure_value | |
153 | + tmp[val.id] = val | |
154 | + end | |
155 | + end | |
156 | + if not next(tmp) then return end | |
157 | + | |
158 | + local id = math.randWeight(tmp, "weight") --宝藏id | |
159 | + if not id then return end | |
160 | + | |
161 | + treasure = tmp[id] | |
162 | + if treasureBase < treasure.treasure_value then return end | |
163 | + --扣除资源值 | |
164 | + treasureBase = treasureBase - treasure.treasure_value | |
165 | + | |
166 | + local chapterId = math.randWeight(chapters, "treasure_weight") --关卡id | |
167 | + if not chapterId then return end | |
168 | + | |
169 | + | |
170 | + treasure.chapter_id = chapterId | |
171 | + treasureList[treasure.id] = treasure | |
172 | + | |
173 | + return treasure | |
174 | + end | |
175 | + | |
176 | + --chapterId | |
177 | + function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId, treasureBase) | |
178 | + if not curInfo then return nil end | |
179 | + | |
180 | + local treasure = nil | |
181 | + --开始挖宝关卡ID=挂机关卡ID | |
182 | + if chapterId == curInfo.chapter_id then | |
183 | + --开始挖宝 | |
184 | + if not curInfo["end_time"] then | |
185 | + curInfo["end_time"] = skynet.timex() + curInfo.working_time | |
186 | + else | |
187 | + if skynet.timex() >= curInfo["end_time"] then | |
188 | + if curInfo.cool_time > 1 then | |
189 | + --宝藏冷却时间 | |
190 | + if not curInfo["expire_time"] then | |
191 | + if treasureBase >= curInfo["treasure_value"] then | |
192 | + treasureBase = treasureBase - curInfo["treasure_value"] | |
193 | + | |
194 | + treasure = treasureList[curInfo.id] | |
195 | + curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay | |
196 | + end | |
197 | + else | |
198 | + --已经领取宝藏 检索宝藏冷却时间 | |
199 | + if skynet.timex() >= curInfo["expire_time"] then | |
200 | + treasureList[curInfo.id] = nil | |
201 | + end | |
202 | + end | |
203 | + else | |
204 | + if treasureBase >= curInfo["treasure_value"] then | |
205 | + treasureBase = treasureBase - curInfo["treasure_value"] | |
206 | + | |
207 | + treasure = treasureList[curInfo.id] | |
208 | + treasureList[curInfo.id] = nil | |
209 | + end | |
210 | + end | |
211 | + end | |
212 | + end | |
213 | + else | |
214 | + --已经开始挖宝 | |
215 | + if curInfo["end_time"] then | |
216 | + if skynet.timex() >= curInfo["end_time"] then | |
217 | + if curInfo.cool_time > 1 then | |
218 | + --宝藏冷却时间 | |
219 | + if not curInfo["expire_time"] then | |
220 | + if treasureBase >= curInfo["treasure_value"] then | |
221 | + treasureBase = treasureBase - curInfo["treasure_value"] | |
222 | + | |
223 | + treasure = treasureList[curInfo.id] | |
224 | + curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay | |
225 | + end | |
226 | + | |
227 | + else | |
228 | + --已经领取宝藏 检索宝藏冷却时间 | |
229 | + if skynet.timex() >= curInfo["expire_time"] then | |
230 | + treasureList[curInfo.id] = nil | |
231 | + end | |
232 | + end | |
233 | + else | |
234 | + if treasureBase >= curInfo["treasure_value"] then | |
235 | + treasureBase = treasureBase - curInfo["treasure_value"] | |
236 | + | |
237 | + treasure = treasureList[curInfo.id] | |
238 | + treasureList[curInfo.id] = nil | |
239 | + end | |
240 | + end | |
241 | + else | |
242 | + curInfo["end_time"] = nil | |
243 | + end | |
244 | + end | |
245 | + end | |
246 | + return treasure | |
247 | + end | |
248 | + | |
249 | + function Daily:buyTreasure(treasureList) | |
250 | + local boughtTreasure = {} | |
251 | + local treasureBase = self:getProperty("treasureBase") | |
252 | + for id, val in pairs(treasureList) do | |
253 | + if treasureBase >= val.treasure_value then | |
254 | + boughtTreasure[id] = val | |
255 | + treasureBase = treasureBase - val.treasure_value | |
256 | + end | |
257 | + end | |
258 | + self:updateProperty({field = "treasureBase", value = treasureBase}) | |
259 | + return boughtTreasure | |
260 | + end | |
261 | + | |
262 | + --重置宝藏图鉴 | |
263 | + function Daily:resetTreasureList() | |
264 | + self:updateProperty({field = "treasureList", value = {}}) | |
265 | + self:updateProperty({field = "treasureListExtra", value = {}}) | |
266 | + end | |
267 | + | |
268 | + --宝藏图鉴 | |
269 | + function Daily:getTreasureList() | |
270 | + local tmpcsv = csvdb["idle_treasureCsv"] | |
271 | + local treasureList = self:getProperty("treasureList") or {} --挖宝列表 过期删除 领取奖励删除 跨天更新 | |
272 | + local treasureListExtra = self:getProperty("treasureListExtra") or {} --额外宝藏列表 过期删除 领取奖励删除 跨天更新 | |
273 | + local tmpTreasure = {} | |
274 | + local treasureBase = globalCsv.idle_treasure_base + self.owner:getBnousTreasureBaseMaximum() | |
275 | + for _, val in pairs(tmpcsv) do | |
276 | + if self:checkUnlock(val) == true then | |
277 | + local treasure = self:checkTreasureExpired(val, treasureList) | |
278 | + if treasure then | |
279 | + table.insert(tmpTreasure, treasure) | |
280 | + end | |
281 | + end | |
282 | + end | |
283 | + | |
284 | + if not next(tmpTreasure) then return treasureList end | |
285 | + | |
286 | + self:checkTreasureWeight(treasureList, tmpTreasure, treasureBase, treasureListExtra) | |
287 | + self:updateProperty({field = "treasureList", value = treasureList}) | |
288 | + self:updateProperty({field = "treasureBase", value = treasureBase}) | |
289 | + return treasureList | |
290 | + end | |
291 | + | |
292 | + | |
293 | + --检索挖宝列表 获得宝藏 | |
294 | + function Daily:checkTreasureList(chapterId) | |
295 | + local treasureList = self:getProperty("treasureList") or {} | |
296 | + local treasureBase = self:getProperty("treasureBase") or {} | |
297 | + local tmpTreasure = {} | |
298 | + for id, val in pairs(treasureList) do | |
299 | + local treasure = self:checkTreasureChapterId(val, treasureList, chapterId, treasureBase) | |
300 | + if treasure then | |
301 | + tmpTreasure[id] = treasure | |
302 | + end | |
303 | + end | |
304 | + | |
305 | + if not next(tmpTreasure) then | |
306 | + self:updateProperty({field = "treasureList", value = treasureList}) | |
307 | + return nil | |
308 | + end | |
309 | + local boughtTreasure = self:buyTreasure(tmpTreasure) | |
310 | + self:updateProperty({field = "treasureList", value = treasureList}) | |
311 | + return boughtTreasure | |
312 | + end | |
313 | + | |
314 | + --宝藏加速 | |
315 | + function Daily:quickTreasureList(chapterId, time) | |
316 | + local treasureList = self:getProperty("treasureList") or {} | |
317 | + if next(treasureList) then | |
318 | + for _, val in pairs(treasureList) do | |
319 | + if val["end_time"] and val["chapter_id"] and chapterId == val["chapter_id"] then | |
320 | + val["end_time"] = val["end_time"] - time | |
321 | + end | |
322 | + end | |
323 | + end | |
324 | + self:updateProperty({field = "treasureList", value = treasureList}) | |
325 | + return self:checkTreasureList(chapterId) | |
326 | + end | |
327 | + | |
328 | + --宝藏功能优化——增加"发现宝藏"功能 | |
329 | + function Daily:buyTreasureExtra(treasureList) | |
330 | + local boughtTreasure = {} | |
331 | + local treasureBase = self:getProperty("treasureExtraBase") | |
332 | + for id, val in pairs(treasureList) do | |
333 | + if treasureBase >= val.treasure_value then | |
334 | + boughtTreasure[id] = val | |
335 | + treasureBase = treasureBase - val.treasure_value | |
336 | + end | |
337 | + end | |
338 | + self:updateProperty({field = "treasureExtraBase", value = treasureBase}) | |
339 | + return boughtTreasure | |
340 | + end | |
341 | + | |
342 | + function Daily:getTreasureExtra(tmpBaseExtra) | |
343 | + local tmpcsv = csvdb["idle_treasureCsv"] | |
344 | + local treasureList = self:getProperty("treasureList") or {} --挖宝列表 过期删除 领取奖励删除 跨天更新 | |
345 | + local treasureListExtra = self:getProperty("treasureListExtra") or {} --额外宝藏 过期删除 领取奖励删除 跨天更新 | |
346 | + | |
347 | + local tmpTreasure = {} | |
348 | + for _, val in pairs(tmpcsv) do | |
349 | + if self:checkUnlock(val) then | |
350 | + local treasure = self:checkTreasureExpired(val, treasureListExtra) | |
351 | + if treasure then | |
352 | + table.insert(tmpTreasure, treasure) | |
353 | + end | |
354 | + end | |
355 | + end | |
356 | + if not next(tmpTreasure) then return nil, treasureListExtra end | |
357 | + | |
358 | + local tmp = self:getOneTreasureExtra(treasureListExtra, tmpTreasure, tmpBaseExtra, treasureList) | |
359 | + self:updateProperty({field = "treasureListExtra", value = treasureListExtra}) | |
360 | + return tmp, treasureListExtra | |
361 | + end | |
362 | + | |
363 | + --检索宝藏列表 获得额外宝藏 | |
364 | + function Daily:checkTreasureListExtra(chapterId) | |
365 | + local treasureListExtra = self:getProperty("treasureListExtra") or {} | |
366 | + local treasureBaseExtra = self:getProperty("treasureBaseExtra") or {} | |
367 | + local tmpTreasure = {} | |
368 | + for id, val in pairs(treasureListExtra) do | |
369 | + local treasure = self:checkTreasureChapterId(val, treasureListExtra, chapterId, treasureBaseExtra) | |
370 | + if treasure then | |
371 | + tmpTreasure[id] = treasure | |
372 | + end | |
373 | + end | |
374 | + | |
375 | + if next(tmpTreasure) then | |
376 | + self:updateProperty({field = "treasureListExtra", value = treasureListExtra}) | |
377 | + return nil | |
378 | + end | |
379 | + | |
380 | + local boughtTreasure = self:buyTreasureExtra(tmpTreasure) | |
381 | + self:updateProperty({field = "treasureListExtra", value = treasureListExtra}) | |
382 | + return boughtTreasure | |
383 | + end | |
384 | + | |
385 | + --额外宝藏加速 | |
386 | + function Daily:quickTreasureListExtra(chapterId, time) | |
387 | + local treasureListExtra = self:getProperty("treasureListExtra") or {} | |
388 | + if next(treasureListExtra) then | |
389 | + for _, val in pairs(treasureListExtra) do | |
390 | + if val["end_time"] and val["chapter_id"] and chapterId == val["chapter_id"] then | |
391 | + val["end_time"] = val["end_time"] - time | |
392 | + end | |
393 | + end | |
394 | + end | |
395 | + | |
396 | + self:updateProperty({field = "treasureListExtra", value = treasureListExtra}) | |
397 | + return self:checkTreasureListExtra(chapterId) | |
398 | + end | |
399 | +end | |
400 | + | |
401 | + | |
402 | +return DailyPlugin | |
0 | 403 | \ No newline at end of file | ... | ... |
src/models/RoleLog.lua