Commit f4c65591354382ead8213749c1896f334e7e59a5
1 parent
8da953a7
抽奖
Showing
4 changed files
with
42 additions
and
0 deletions
Show diff stats
src/GlobalVar.lua
src/ProtocolCode.lua
src/actions/AdvAction.lua
| ... | ... | @@ -362,5 +362,40 @@ function _M.workshopRpc(agent, data) |
| 362 | 362 | return true |
| 363 | 363 | end |
| 364 | 364 | |
| 365 | +function _M.wheelSurfRpc(agent, data) | |
| 366 | + local role = agent.role | |
| 367 | + local msg = MsgPack.unpack(data) | |
| 368 | + if not role:isFuncOpen(FuncOpenType.AdvWheelSurf) then return end | |
| 369 | + if not role._advWheelSurfCount then return end | |
| 370 | + | |
| 371 | + local drawData = csvdb["adv_wheelsurfCsv"][role:getFuncLv(FuncOpenType.AdvWheelSurf)] | |
| 372 | + if not drawData then return end | |
| 373 | + | |
| 374 | + local costs = drawData.cost:toArray(true, "=") | |
| 375 | + local maxt = math.max(#costs, drawData.time) | |
| 376 | + | |
| 377 | + if role._advWheelSurfCount >= maxt then | |
| 378 | + role._advWheelSurfCount = nil | |
| 379 | + return | |
| 380 | + end | |
| 381 | + | |
| 382 | + local cost = costs[role._advWheelSurfCount + 1] | |
| 383 | + if cost > 0 then | |
| 384 | + if not role:checkItemEnough({[ItemId.Diamond] = cost}) then return end | |
| 385 | + role:costItems({[ItemId.Diamond] = cost}) | |
| 386 | + end | |
| 387 | + | |
| 388 | + role._advWheelSurfCount = role._advWheelSurfCount + 1 | |
| 389 | + if role._advWheelSurfCount >= maxt then | |
| 390 | + role._advWheelSurfCount = nil | |
| 391 | + end | |
| 392 | + | |
| 393 | + local gift = drawData.pool:randWeight(true) | |
| 394 | + | |
| 395 | + local reward = role:award({[gift[1]] = gift[2]}) | |
| 396 | + SendPacket(actionCodes.Adv_wheelSurfRpc, MsgPack.pack({reward = reward})) | |
| 397 | + return true | |
| 398 | +end | |
| 399 | + | |
| 365 | 400 | |
| 366 | 401 | return _M |
| 367 | 402 | \ No newline at end of file | ... | ... |
src/adv/Adv.lua
| ... | ... | @@ -49,6 +49,8 @@ function Adv:initByChapter(chapterId, level, isToNext, notNotify) |
| 49 | 49 | self.lastEnemyId = 1 |
| 50 | 50 | self.mapStack = {1} -- 最后一个为当前的地图 |
| 51 | 51 | |
| 52 | + self.owner._advWheelSurfCount = nil -- 抽奖进行次数 | |
| 53 | + | |
| 52 | 54 | -- 随机出地图 |
| 53 | 55 | local mapId = self:randomMapId(chapterId, level) |
| 54 | 56 | self.maps = {} |
| ... | ... | @@ -157,6 +159,9 @@ function Adv:over(success) |
| 157 | 159 | if success then |
| 158 | 160 | reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap()) |
| 159 | 161 | self.owner:checkTaskEnter(self.owner.TaskType.AdvPass, {id = self.chapterId}) |
| 162 | + if self.owner:isFuncOpen(FuncOpenType.AdvWheelSurf) then | |
| 163 | + self.owner._advWheelSurfCount = 0 -- 抽奖进行次数 | |
| 164 | + end | |
| 160 | 165 | end |
| 161 | 166 | self:clear() |
| 162 | 167 | ... | ... |