Commit a85b344f64c759f22a46d12b5bb082e5396930ac
1 parent
899d9b8a
feat: 挂机图鉴
新增组件信息如下: 1. daily中新增字段treasureList 2. 增加宝藏图鉴接口 3. 增加挖宝接口 4. 增加通过英雄id获取英雄信息的函数
Showing
4 changed files
with
252 additions
and
0 deletions
Show diff stats
src/actions/GmAction.lua
@@ -984,5 +984,27 @@ function _M.drawHero(role, t, act) | @@ -984,5 +984,27 @@ function _M.drawHero(role, t, act) | ||
984 | return result | 984 | return result |
985 | end | 985 | end |
986 | 986 | ||
987 | +table.insert(helpDes, {"宝藏图鉴", "treasure", "list"} ) | ||
988 | +function _M.treasure(role, pms) | ||
989 | + local pm1 = pms.pm1 | ||
990 | + if pm1 == "LIST" then | ||
991 | + local treasureList= role.dailyData:getTreasrueList(role) | ||
992 | + for id, val in pairs(treasureList) do | ||
993 | + print(string.format("%s:%d:%d:%d:%d", val.name, val.weight, val.treasure_value, val.expire_time or 0, val.cool_time or 0)) | ||
994 | + end | ||
995 | + return "宝藏图鉴" | ||
996 | + elseif pm1 == "CHECK" then | ||
997 | + local treasureList = role.dailyData:checkTreasureList(role) | ||
998 | + for id, val in pairs(treasureList) do | ||
999 | + print(string.format("%s:%d:%d:%d:%d", val.name, val.weight, val.treasure_value, val.expire_time or 0, val.cool_time or 0)) | ||
1000 | + end | ||
1001 | + return "挖宝成功" | ||
1002 | + elseif pm1 == "RESET" then | ||
1003 | + role.dailyData:resetTreasureList() | ||
1004 | + return "重置宝藏图鉴" | ||
1005 | + else | ||
1006 | + return "暂无指令: ".. pm1 | ||
1007 | + end | ||
1008 | +end | ||
987 | 1009 | ||
988 | return _M | 1010 | return _M |
989 | \ No newline at end of file | 1011 | \ No newline at end of file |
src/actions/HangAction.lua
@@ -114,6 +114,15 @@ local function checkReward(role) | @@ -114,6 +114,15 @@ local function checkReward(role) | ||
114 | randomItem() | 114 | randomItem() |
115 | end | 115 | end |
116 | 116 | ||
117 | + --挂机得到的宝藏加入到挂机奖励 | ||
118 | + local treasureList= role.dailyData:checkTreasureList(hangInfo.carbonId) | ||
119 | + for id, val in pairs(treasureList) do | ||
120 | + local award = val.award:toNumMap() | ||
121 | + for k,v in pairs(award) do | ||
122 | + items[k] = (award[k] or 0) + v | ||
123 | + end | ||
124 | + end | ||
125 | + | ||
117 | if coinCount > 0 or itemCount > 0 then | 126 | if coinCount > 0 or itemCount > 0 then |
118 | return true | 127 | return true |
119 | end | 128 | end |
src/models/Daily.lua
@@ -2,6 +2,8 @@ | @@ -2,6 +2,8 @@ | ||
2 | 2 | ||
3 | local Daily = class("Daily", require("shared.ModelBaseMysql")) | 3 | local Daily = class("Daily", require("shared.ModelBaseMysql")) |
4 | 4 | ||
5 | +oneDay = 60*60*24 | ||
6 | + | ||
5 | function Daily:ctor(properties) | 7 | function Daily:ctor(properties) |
6 | Daily.super.ctor(self, properties) | 8 | Daily.super.ctor(self, properties) |
7 | end | 9 | end |
@@ -30,6 +32,8 @@ Daily.schema = { | @@ -30,6 +32,8 @@ Daily.schema = { | ||
30 | unlockPool = {"table", {}}, -- 解锁的属性卡池 | 32 | unlockPool = {"table", {}}, -- 解锁的属性卡池 |
31 | curPool = {"number", 0}, -- 属性卡池当前索引 | 33 | curPool = {"number", 0}, -- 属性卡池当前索引 |
32 | drawHeroCnt = {"number", 0}, -- 每日抽卡次数 | 34 | drawHeroCnt = {"number", 0}, -- 每日抽卡次数 |
35 | + | ||
36 | + treasureList = {"table", {}}, --挂机图鉴 | ||
33 | } | 37 | } |
34 | 38 | ||
35 | function Daily:updateProperty(params) | 39 | function Daily:updateProperty(params) |
@@ -60,6 +64,8 @@ function Daily:refreshDailyData(notify) | @@ -60,6 +64,8 @@ function Daily:refreshDailyData(notify) | ||
60 | if self:getProperty(field) > 0 then | 64 | if self:getProperty(field) > 0 then |
61 | dataMap[field] = 0 | 65 | dataMap[field] = 0 |
62 | end | 66 | end |
67 | + elseif field == "treasureList" then | ||
68 | + dataMap[field] = self:getTreasrueList() | ||
63 | elseif field ~= "key" then | 69 | elseif field ~= "key" then |
64 | local typ, def = table.unpack(schema) | 70 | local typ, def = table.unpack(schema) |
65 | dataMap[field] = def | 71 | dataMap[field] = def |
@@ -85,6 +91,211 @@ function Daily:refreshDailyData(notify) | @@ -85,6 +91,211 @@ function Daily:refreshDailyData(notify) | ||
85 | end | 91 | end |
86 | end | 92 | end |
87 | 93 | ||
94 | +--解锁 | ||
95 | +function Daily:checkUnlock(treaval) | ||
96 | + local role = self.owner | ||
97 | + local treasureC = treaval.unlock:toArray(true, "=") | ||
98 | + local show = false | ||
99 | + if treasureC[1] == 1 then --通关关卡 | ||
100 | + if not self.owner:checkHangPass(treasureC[2]) then show = true end | ||
101 | + elseif treasureC[1] == 2 then --通关拾荒章节=x层 | ||
102 | + local chapterId = treasureC[2] | ||
103 | + local layer = 1 | ||
104 | + local advCsv = csvdb["adv_chapterCsv"][chapterId] | ||
105 | + if not advCsv then return false end --不存在的章节 | ||
106 | + if math.floor(chapterId / 100) ~= 2 then | ||
107 | + layer = math.min(layer, advCsv.limitlevel) | ||
108 | + end | ||
109 | + local advPass = role:getProperty("advPass") | ||
110 | + if (advPass[chapterId] or 0) < layer then | ||
111 | + show = false | ||
112 | + else | ||
113 | + show = true | ||
114 | + end | ||
115 | + elseif treasureC[1] == 3 then --拥有指定id的角色时 | ||
116 | + local hero = role:getHeroByID(treasureC[2]) | ||
117 | + if hero then show = true end | ||
118 | + else | ||
119 | + show = true | ||
120 | + end | ||
121 | + return show | ||
122 | +end | ||
123 | + | ||
124 | +--CD | ||
125 | +function Daily:checkTreasureExpired(treasureAttr, treasureList) | ||
126 | + local curInfo = treasureList[treasureAttr.id] | ||
127 | + if curInfo then | ||
128 | + -- check finish | ||
129 | + if curInfo["expire_time"] then | ||
130 | + if curInfo.cool_time > 1 then | ||
131 | + if skynet.timex() > curInfo["expire_time"] then --已过期 | ||
132 | + treasureList[treasureAttr.id] = nil | ||
133 | + elseif skynet.timex() > curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却 | ||
134 | + curInfo = nil | ||
135 | + end | ||
136 | + else | ||
137 | + if skynet.timex() > curInfo["expire_time"] then | ||
138 | + treasureList[treasureAttr.id] = nil | ||
139 | + end | ||
140 | + end | ||
141 | + end | ||
142 | + else | ||
143 | + curInfo = clone(treasureAttr) | ||
144 | + end | ||
145 | + | ||
146 | + return curInfo | ||
147 | +end | ||
148 | + | ||
149 | +--资源 | ||
150 | +function Daily:checkTreasureBase(treasureList, treasureBase, removeId) | ||
151 | + local tmptreasure = {} | ||
152 | + for k, val in pairs(treasureList) do | ||
153 | + if removeId and val.id == removeId then | ||
154 | + table.remove(treasureList, k) | ||
155 | + else | ||
156 | + if treasureBase >= val.treasure_value then | ||
157 | + treasureBase = treasureBase - val.treasure_value | ||
158 | + tmptreasure[val.id] = val | ||
159 | + end | ||
160 | + end | ||
161 | + | ||
162 | + end | ||
163 | + return tmptreasure | ||
164 | +end | ||
165 | + | ||
166 | +--权重 | ||
167 | +function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase) | ||
168 | + local removeId | ||
169 | + while next(tmptreasure) do | ||
170 | + local tmp = self:checkTreasureBase(tmptreasure, treasureBase, removeId) | ||
171 | + print(treasureBase) | ||
172 | + local id = math.randWeight(tmp, "weight") --宝藏id | ||
173 | + if not id then | ||
174 | + break | ||
175 | + end | ||
176 | + | ||
177 | + local treasure = tmp[id] | ||
178 | + if treasureBase >= treasure.treasure_value then | ||
179 | + --扣除资源值 | ||
180 | + treasureBase = treasureBase - treasure.treasure_value | ||
181 | + else | ||
182 | + break | ||
183 | + end | ||
184 | + | ||
185 | + local chapterId = math.randWeight(csvdb["idle_battleCsv"], "treasure_weight") --关卡id | ||
186 | + if not chapterId then | ||
187 | + break | ||
188 | + end | ||
189 | + | ||
190 | + treasure.chapter_id = chapterId | ||
191 | + treasureList[id] = treasure | ||
192 | + removeId = id | ||
193 | + end | ||
194 | +end | ||
195 | + | ||
196 | +--chapterId | ||
197 | +function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId) | ||
198 | + local treasure = nil | ||
199 | + | ||
200 | + if not curInfo then | ||
201 | + print("curInfo is nil") | ||
202 | + return treasure | ||
203 | + end | ||
204 | + | ||
205 | + if chapterId == curInfo.chapter_id then --开始挖宝关卡ID=挂机关卡ID | ||
206 | + if not curInfo["expire_time"] then | ||
207 | + if curInfo.cool_time > 1 then | ||
208 | + curInfo["expire_time"] = skynet.timex() + curInfo.working_time + curInfo.cool_time * oneDay | ||
209 | + else | ||
210 | + curInfo["expire_time"] = skynet.timex() + curInfo.working_time | ||
211 | + end | ||
212 | + else | ||
213 | + if skynet.timex() > curInfo["expire_time"] then --已过期 | ||
214 | + treasure = table.remove(treasureList, curInfo.id) | ||
215 | + elseif skynet.timex() > curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却 | ||
216 | + treasure = curInfo | ||
217 | + end | ||
218 | + end | ||
219 | + else | ||
220 | + if curInfo["expire_time"] then | ||
221 | + if skynet.timex() > curInfo["expire_time"] then --已过期 | ||
222 | + treasure = table.remove(treasureList, curInfo.id) | ||
223 | + elseif skynet.timex() > curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却 | ||
224 | + treasure = curInfo | ||
225 | + else | ||
226 | + curInfo["expire_time"] = nil | ||
227 | + end | ||
228 | + end | ||
229 | + end | ||
230 | + return treasure | ||
231 | +end | ||
232 | + | ||
233 | +function Daily:buyTreasure(treasureList) | ||
234 | + local boughtTreasurer = {} | ||
235 | + local treasureBase = globalCsv.idle_treasure_base | ||
236 | + for id, val in pairs(treasureList) do | ||
237 | + treasureBase = treasureBase - val.treasure_value | ||
238 | + if treasureBase < 0 then | ||
239 | + treasureBase = treasureBase + val.treasure_value | ||
240 | + print("资源余额不足") | ||
241 | + return | ||
242 | + else | ||
243 | + boughtTreasurer[id] = val | ||
244 | + end | ||
245 | + end | ||
246 | + self:updateProperty({field = "treasureBase", value = treasureBase}) | ||
247 | + return boughtTreasurer | ||
248 | +end | ||
249 | + | ||
250 | +--重置宝藏图鉴 | ||
251 | +function Daily:resetTreasureList() | ||
252 | + self:updateProperty({field = "treasureList", value = {}}) | ||
253 | +end | ||
254 | + | ||
255 | +--宝藏图鉴 | ||
256 | +function Daily:getTreasrueList() | ||
257 | + print("宝藏图鉴...") | ||
258 | + local tmpcsv = csvdb["idle_treasureCsv"] | ||
259 | + local treasureList = self:getProperty("treasureList") --挖宝列表 过期删除 领取奖励删除 跨天更新 | ||
260 | + local tmptreasure = {} | ||
261 | + local treasureBase = globalCsv.idle_treasure_base | ||
262 | + for id, val in pairs(tmpcsv) do | ||
263 | + if self:checkUnlock(val) == true then | ||
264 | + local treasure = self:checkTreasureExpired(val, treasureList) | ||
265 | + if treasure then | ||
266 | + table.insert(tmptreasure, treasure) | ||
267 | + end | ||
268 | + end | ||
269 | + end | ||
270 | + table.sort(tmptreasure, function (a,b) return a.treasure_value > b.treasure_value end) | ||
271 | + | ||
272 | + self:checkTreasureWeight(treasureList, tmptreasure, treasureBase) | ||
273 | + self:updateProperty({field = "treasureList", value = treasureList}) | ||
274 | + return treasureList | ||
275 | +end | ||
276 | + | ||
277 | + | ||
278 | +--检索挖宝列表 | ||
279 | +function Daily:checkTreasureList(chapterId) | ||
280 | + print("检索挖宝列表") | ||
281 | + local treasureList = self:getProperty("treasureList") | ||
282 | + local tmptreasure = {} | ||
283 | + for id, val in pairs(treasureList) do | ||
284 | + local treasure = self:checkTreasureChapterId(val, treasureList, chapterId) | ||
285 | + if treasure ~= nil then | ||
286 | + tmptreasure[id] = treasure | ||
287 | + end | ||
288 | + end | ||
289 | + | ||
290 | + if next(tmptreasure) == nil then | ||
291 | + print("宝藏列表为空") | ||
292 | + return nil | ||
293 | + end | ||
294 | + local boughtTreasurer = self:buyTreasure(tmptreasure) | ||
295 | + self:updateProperty({field = "treasureList", value = treasureList}) | ||
296 | + return boughtTreasurer | ||
297 | +end | ||
298 | + | ||
88 | function Daily:data() | 299 | function Daily:data() |
89 | return { | 300 | return { |
90 | hangQC = self:getProperty("hangQC"), | 301 | hangQC = self:getProperty("hangQC"), |
@@ -104,6 +315,7 @@ function Daily:data() | @@ -104,6 +315,7 @@ function Daily:data() | ||
104 | goldBuyT = self:getProperty("goldBuyT"), | 315 | goldBuyT = self:getProperty("goldBuyT"), |
105 | unlockPool = self:getProperty("unlockPool"), | 316 | unlockPool = self:getProperty("unlockPool"), |
106 | curPool = self:getProperty("curPool"), | 317 | curPool = self:getProperty("curPool"), |
318 | + treasureList = self:getProperty("treasureList"), | ||
107 | } | 319 | } |
108 | end | 320 | end |
109 | 321 |
src/models/RolePlugin.lua
@@ -636,6 +636,15 @@ function RolePlugin.bind(Role) | @@ -636,6 +636,15 @@ function RolePlugin.bind(Role) | ||
636 | return count | 636 | return count |
637 | end | 637 | end |
638 | 638 | ||
639 | + function Role:getHeroByID(heroId) | ||
640 | + for id, hero in pairs(self.heros) do | ||
641 | + if id == heroId then | ||
642 | + return hero | ||
643 | + end | ||
644 | + end | ||
645 | + return nil | ||
646 | + end | ||
647 | + | ||
639 | 648 | ||
640 | function Role:loadHeros() | 649 | function Role:loadHeros() |
641 | local roleId = self:getProperty("id") | 650 | local roleId = self:getProperty("id") |