Commit 03a6166a38cb1b3d7b358f613258e96890832f82

Authored by zhouhaihai
1 parent 8019d0bb

餐厅优化

src/ProtocolCode.lua
... ... @@ -88,6 +88,8 @@ actionCodes = {
88 88 Diner_expediteSellRpc = 310,
89 89 Diner_getGreenhouseRpc = 311,
90 90 Diner_addWantFoodRpc = 312,
  91 + Diner_initTaskRpc = 313,
  92 + Diner_handleTaskRpc = 314,
91 93  
92 94 Tower_roleFormatRpc = 350,
93 95 Tower_startBattleRpc = 351,
... ...
src/actions/CarAction.lua
... ... @@ -135,7 +135,9 @@ function _M.saleEquipRpc(agent, data )
135 135 if math.illegalNum(count, 1, own) then return end
136 136 end
137 137 local reward = {}
  138 + local allCount = 0
138 139 for id, count in pairs(backs) do
  140 + allCount = allCount + count
139 141 local itemData = csvdb["itemCsv"][id]
140 142 local typ = math.floor((id-7000)/100)
141 143 local lv = (id-7000)%100
... ... @@ -146,6 +148,7 @@ function _M.saleEquipRpc(agent, data )
146 148 reward[k] = (reward[k] or 0) + v * count
147 149 end
148 150 end
  151 + role:checkTaskEnter("SaleEquip", {count = allCount})
149 152 reward = role:award(reward)
150 153 SendPacket(actionCodes.Car_saleEquipRpc, MsgPack.pack({reward = reward}))
151 154 return true
... ... @@ -158,7 +161,9 @@ function _M.saleRuneRpc(agent, data )
158 161 if not backs then return end
159 162  
160 163 local reward = {}
  164 + local count = 0
161 165 for _, uid in pairs(backs) do
  166 + count = count + 1
162 167 local rune = role.runeBag[uid]
163 168 if not rune then return end
164 169 if rune:getProperty("refer") ~= 0 then return end
... ... @@ -171,7 +176,7 @@ function _M.saleRuneRpc(agent, data )
171 176 end
172 177  
173 178 role:delRunes(backs)
174   -
  179 + role:checkTaskEnter("DecoRune", {count = count})
175 180 reward = role:award(reward)
176 181  
177 182 SendPacket(actionCodes.Car_saleRuneRpc, MsgPack.pack({reward = reward}))
... ...
src/actions/DinerAction.lua
... ... @@ -9,70 +9,71 @@ local _M = {}
9 9 function _M.addSellRpc( agent, data )
10 10 local role = agent.role
11 11 local msg = MsgPack.unpack(data)
12   - for _,sellData in pairs(msg) do
13   - local slot = sellData.slot
14   - local sells = json.decode(role.dinerData:getProperty("sells"))
15   - if sells[slot] and sells[slot].count and sells[slot].count ~= 0 then
16   - return 0
17   - end
18   - if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then
19   - return 1
20   - end
21   - slot = tostring(slot)
  12 + local sellData = msg
22 13  
23   - local dish = sellData.dish
24   - local dishSet = csvdb["diner_dishCsv"][dish]
25   - if not dishSet then
26   - return 2
27   - end
28   - local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0)
29   - if dishLevel == 0 then
30   - return 3
31   - end
32   - local dishData = dishSet[dishLevel]
33   - if not dishData then
34   - return 4
35   - end
  14 + local slot = sellData.slot
  15 + local sells = json.decode(role.dinerData:getProperty("sells"))
  16 + if sells[slot] and sells[slot].count and sells[slot].count ~= 0 then
  17 + return 0
  18 + end
  19 + if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then
  20 + return 1
  21 + end
  22 + slot = tostring(slot)
36 23  
37   - local calSell = role.dinerData:updateSell(slot, true) or {
38   - deltaCount = 0,
39   - deltaTime = 0,
40   - lastCount = 0,
41   - }
42   - local count = sellData.count
43   - local maxDishCount = role.dinerData:getMaxDishs()
44   - if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then
45   - return 5
46   - end
  24 + local dish = sellData.dish
  25 + local dishSet = csvdb["diner_dishCsv"][dish]
  26 + if not dishSet then
  27 + return 2
  28 + end
  29 + local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0)
  30 + if dishLevel == 0 then
  31 + return 3
  32 + end
  33 + local dishData = dishSet[dishLevel]
  34 + if not dishData then
  35 + return 4
  36 + end
47 37  
48   - local cost = dishData.material:toNumMap()
49   - for k, n in pairs(cost) do
50   - cost[k] = n * count
51   - end
52   - if not role:checkItemEnough(cost) then
53   - return 6
54   - end
  38 + local calSell = role.dinerData:updateSell(slot, true) or {
  39 + deltaCount = 0,
  40 + deltaTime = 0,
  41 + lastCount = 0,
  42 + }
  43 + local count = sellData.count
  44 + local maxDishCount = role.dinerData:getMaxDishs()
  45 + if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then
  46 + return 5
  47 + end
55 48  
56   - role:costItems(cost)
57   - role.dinerData:updateSell(slot)
  49 + local cost = dishData.material:toNumMap()
  50 + for k, n in pairs(cost) do
  51 + cost[k] = n * count
  52 + end
  53 + if not role:checkItemEnough(cost) then
  54 + return 6
  55 + end
58 56  
59   - -- local dirty = false
60   - -- if dirty then
61   - -- role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order"))
62   - -- end
  57 + role:costItems(cost)
  58 + role.dinerData:updateSell(slot)
63 59  
64   - sells = json.decode(role.dinerData:getProperty("sells"))
65   - if not sells[slot] then
66   - sells[slot] = {
67   - reward = "",
68   - }
69   - end
70   - sells[slot].dish = dish
71   - sells[slot].level = dishLevel
72   - sells[slot].count = count
73   - sells[slot].time = skynet.timex() - calSell.deltaTime
74   - role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
  60 + role:checkTaskEnter("MakeFood", {id = dish, count = count})
  61 + -- local dirty = false
  62 + -- if dirty then
  63 + -- role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order"))
  64 + -- end
  65 +
  66 + sells = json.decode(role.dinerData:getProperty("sells"))
  67 + if not sells[slot] then
  68 + sells[slot] = {
  69 + reward = "",
  70 + }
75 71 end
  72 + sells[slot].dish = dish
  73 + sells[slot].level = dishLevel
  74 + sells[slot].count = count
  75 + sells[slot].time = skynet.timex() - calSell.deltaTime
  76 + role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
76 77 SendPacket(actionCodes.Diner_addSellRpc, "")
77 78 return true
78 79 end
... ... @@ -590,4 +591,94 @@ function _M.getGreenhouseRpc( agent, data )
590 591 return true
591 592 end
592 593  
  594 +local function refreshTaskRpc(role, task)
  595 + local hadType = {}
  596 + if task.id and csvdb["task_specialCsv"][task.id] then
  597 + hadType[csvdb["task_specialCsv"][task.id].type] = 1
  598 + end
  599 + local spTask = role:getProperty("spTask")
  600 + local taskCount = 0
  601 + for id ,_ in pairs(spTask) do
  602 + hadType[csvdb["task_specialCsv"][id].type] = 1
  603 + taskCount = taskCount + 1
  604 + end
  605 + local pool = {}
  606 + if taskCount < globalCsv.diner_get_task_count_max then
  607 + local curLevel = role:getProperty("level")
  608 + for id, data in pairs(csvdb["task_specialCsv"]) do
  609 + if not hadType[data.type] then
  610 + local level = data.level:toArray(true, "=")
  611 + if curLevel >= level[1] and curLevel <= level[2] then
  612 + table.insert(pool, id)
  613 + end
  614 + end
  615 + end
  616 + end
  617 + if not next(pool) then --每次进都看看有没有任务可以领
  618 + task.id = nil
  619 + task.et = 0
  620 + else
  621 + local id = pool[math.randomInt(1, #pool)]
  622 + task.id = id
  623 + task.et = skynet.timex() + globalCsv.diner_get_task_time_max
  624 + end
  625 + return task
  626 +end
  627 +
  628 +-- 进入餐厅界面调用
  629 +function _M.initTaskRpc(agent, data)
  630 + local role = agent.role
  631 +
  632 + local task = role.dinerData:getProperty("task")
  633 +
  634 + local now = skynet.timex()
  635 +
  636 + if not task.et or task.et <= now then --刷新了
  637 + task = refreshTaskRpc(role, task)
  638 + role.dinerData:updateProperty({field = "task", value = task})
  639 + end
  640 +
  641 + SendPacket(actionCodes.Diner_initTaskRpc, '')
  642 + return true
  643 +end
  644 +
  645 +-- 对任务进行处理调用
  646 +function _M.handleTaskRpc(agent, data)
  647 + local role = agent.role
  648 + local msg = MsgPack.unpack(data)
  649 + local cmd = msg.cmd -- 1 领取任务 2 拒绝任务
  650 +
  651 + local task = role.dinerData:getProperty("task")
  652 + local now = skynet.timex()
  653 + if cmd == 1 then
  654 + if not task.id then return end
  655 + if task.et > now then
  656 + --领取任务
  657 + task.id = nil
  658 + task.et = now + globalCsv.diner_get_task_time_max
  659 + task.refuse = nil
  660 + else
  661 + return
  662 + end
  663 + elseif cmd == 2 then -- 拒绝任务(重新领取)
  664 + if not task.id then return end
  665 + if (task.refuse or 0) >= globalCsv.diner_get_task_refuse_max then
  666 + -- 等待时间
  667 + task.refuse = nil
  668 + task.id = nil
  669 + task.et = now + globalCsv.diner_get_task_time_max
  670 + else
  671 + task.refuse = (task.refuse or 0) + 1
  672 + --刷新任务
  673 + task = refreshTaskRpc(role, task)
  674 + end
  675 + else
  676 + return
  677 + end
  678 + role.dinerData:updateProperty({field = "task", value = task})
  679 +
  680 + SendPacket(actionCodes.Diner_handleTaskRpc, '')
  681 + return true
  682 +end
  683 +
593 684 return _M
594 685 \ No newline at end of file
... ...
src/actions/GmAction.lua
... ... @@ -51,14 +51,14 @@ function _M.fb(role, pms) -- 直接通关
51 51 local carbonData = csvdb["idle_battleCsv"][carbonId]
52 52 for _, pre in ipairs(carbonData.prepose:toArray(true, "=")) do
53 53 passCarbon[pre] = 1
54   - role:checkTaskEnter(role.TaskType.HangPass, {id = pre})
  54 + role:checkTaskEnter("HangPass", {id = pre})
55 55 addPre(pre)
56 56 end
57 57 end
58 58 passCarbon[carbonId] = 1
59 59 addPre(carbonId)
60 60 role:updateProperty({field = "hangPass", value = passCarbon})
61   - role:checkTaskEnter(role.TaskType.HangPass, {id = carbonId})
  61 + role:checkTaskEnter("HangPass", {id = carbonId})
62 62 return "成功"
63 63 end
64 64  
... ... @@ -71,14 +71,14 @@ function _M.fbc(role, pms) -- 直接通关
71 71 local carbonData = csvdb["idle_battleCsv"][carbonId]
72 72 for _, pre in ipairs(carbonData.prepose:toArray(true, "=")) do
73 73 passCarbon[pre] = 1
74   - role:checkTaskEnter(role.TaskType.HangPass, {id = pre})
  74 + role:checkTaskEnter("HangPass", {id = pre})
75 75 addPre(pre)
76 76 end
77 77 end
78 78 addPre(carbonId)
79 79 role:updateProperty({field = "hangInfo", value = {}})
80 80 role:updateProperty({field = "hangPass", value = passCarbon})
81   - role:checkTaskEnter(role.TaskType.HangPass, {id = carbonId})
  81 + role:checkTaskEnter("HangPass", {id = carbonId})
82 82 return "成功"
83 83 end
84 84  
... ... @@ -98,7 +98,7 @@ function _M.love(role, pms)
98 98 if role:getProperty("loveStatus"):getv(heroType, 0) < level then
99 99 role:changeUpdates({{type = "loveStatus", field = heroType, value = level}}) -- 总的
100 100 end
101   - role:checkTaskEnter(role.TaskType.LoveBreak, {heroType = heroType, loveL = level})
  101 + role:checkTaskEnter("LoveBreak", {heroType = heroType, loveL = level})
102 102 end
103 103 end
104 104 return "成功"
... ...
src/actions/HangAction.lua
... ... @@ -181,7 +181,7 @@ function _M.endBattleRpc(agent, data)
181 181 end
182 182 reward = role:award(reward)
183 183  
184   - role:checkTaskEnter(role.TaskType.HangPass, {id = carbonId})
  184 + role:checkTaskEnter("HangPass", {id = carbonId})
185 185 end
186 186 hangInfo.key = nil
187 187 role:updateProperty({field = "hangInfo", value = hangInfo})
... ... @@ -228,6 +228,7 @@ function _M.getRewardRpc(agent , data)
228 228 hangInfo.itemTime = nowTime
229 229 role:updateProperty({field = "hangBag", value = items})
230 230 role:updateProperty({field = "hangInfo", value = hangInfo})
  231 + role:checkTaskEnter("HangGet")
231 232  
232 233 SendPacket(actionCodes.Hang_getRewardRpc, MsgPack.pack({
233 234 reward = reward
... ...
src/actions/HeroAction.lua
... ... @@ -87,7 +87,7 @@ function _M.wakeRpc(agent, data)
87 87 end
88 88 hero:updateProperty({field = "wakeL", delta = 1})
89 89  
90   - role:checkTaskEnter(role.TaskType.Wake, {heroType = typ, wakeL = hero:getProperty("wakeL")})
  90 + role:checkTaskEnter("Wake", {heroType = typ, wakeL = hero:getProperty("wakeL")})
91 91  
92 92 SendPacket(actionCodes.Hero_wakeRpc, '')
93 93 return true
... ... @@ -404,7 +404,7 @@ function _M.loveItemRpc(agent, data)
404 404 role:changeUpdates({{type = "loveStatus", field = curType, value = newLevel}}) -- 总的
405 405 end
406 406  
407   - role:checkTaskEnter(role.TaskType.LoveBreak, {heroType = curType, loveL = newLevel})
  407 + role:checkTaskEnter("LoveBreak", {heroType = curType, loveL = newLevel})
408 408  
409 409 else
410 410 local delta = globalCsv.unit_love_presentValue[msg.itemId]
... ... @@ -458,7 +458,7 @@ function _M.loveTaskRpc(agent, data)
458 458 role:changeUpdates({{type = "loveStatus", field = curType, value = newLevel}}) -- 总的
459 459 end
460 460  
461   - role:checkTaskEnter(role.TaskType.LoveBreak, {heroType = curType, loveL = newLevel})
  461 + role:checkTaskEnter("LoveBreak", {heroType = curType, loveL = newLevel})
462 462  
463 463 SendPacket(actionCodes.Hero_loveTaskRpc, "")
464 464 return true
... ...
src/adv/Adv.lua
... ... @@ -168,7 +168,7 @@ function Adv:over(success)
168 168 local reward
169 169 if success then
170 170 reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap())
171   - self.owner:checkTaskEnter(self.owner.TaskType.AdvPass, {id = self.chapterId})
  171 + self.owner:checkTaskEnter("AdvPass", {id = self.chapterId})
172 172  
173 173 -- 冒险队等级升一下子
174 174 local advL = self.owner:getProperty("advL")
... ...
src/models/Diner.lua
... ... @@ -13,6 +13,7 @@ Diner.schema = {
13 13 popular = {"number",0}, -- 累计人气
14 14 expedite = {"number",1}, --每日加速次数
15 15 gfood = {"table", {}}, -- 愿望食材 {{id = 123, st = 1232144},}
  16 + task = {"table", {}}, -- 任务刷新 {et = 消失时间 id = 任务id, refuse = 0}
16 17 }
17 18  
18 19 function Diner:refreshDailyData(notify)
... ... @@ -242,7 +243,7 @@ function Diner:getMaxDishs()
242 243 end
243 244  
244 245 function Diner:data()
245   - local properties = {"buildL", "order", "sells", "dishTree", "skillTree","popular","expedite","gfood"}
  246 + local properties = {"buildL", "order", "sells", "dishTree", "skillTree","popular","expedite","gfood", "task"}
246 247 local data = self:getProperties(properties)
247 248 return data
248 249 end
... ...
src/models/Role.lua
... ... @@ -73,6 +73,8 @@ Role.schema = {
73 73  
74 74 towerInfo = {"table", {c = globalCsv.tower_count_limit, l = 1}}, -- 当天爬塔消耗的次数 -- {t = time, c = count, l = layer, k = battleKey}
75 75 towerF = {"table", {}}, -- 爬塔阵容
  76 +
  77 + spTask = {"table", {}} -- 特殊任务 -- {id = status}
76 78 }
77 79  
78 80  
... ... @@ -208,6 +210,7 @@ function Role:data()
208 210 boxL = self:getProperty("boxL"),
209 211 towerInfo = self:getProperty("towerInfo"),
210 212 towerF = self:getProperty("towerF"),
  213 + spTask = self:getProperty("spTask"),
211 214  
212 215 }
213 216 end
... ...
src/models/RolePlugin.lua
... ... @@ -86,6 +86,7 @@ function RolePlugin.bind(Role)
86 86 local typ = math.floor((itemId-7000)/100)
87 87 local lv = (itemId-7000)%100
88 88 self:addEquip(typ, lv, count ,pms)
  89 + self:checkTaskEnter("AddEquip", {equipId = itemId}, pms.notNotify)
89 90 end,
90 91 [ItemType.Rune] = function()
91 92 local typ = math.floor((itemId-2000)/100)
... ... @@ -312,7 +313,7 @@ function RolePlugin.bind(Role)
312 313 newHero.owner = self
313 314 newHero:saveBattleValue()
314 315 self.heros[heroId] = newHero
315   - self:checkTaskEnter(self.TaskType.AddHero, {heroType = heroType, wakeL = newHero:getProperty("wakeL")}, params.notNotify)
  316 + self:checkTaskEnter("AddHero", {heroType = heroType, wakeL = newHero:getProperty("wakeL")}, params.notNotify)
316 317 if not params.notNotify then
317 318 local heroResponse = {}
318 319 table.insert(heroResponse, newHero:data())
... ...
src/models/RoleTask.lua
1 1  
2 2  
3   --- 增加 checkTaskEnter 内的参数 记得增加注释
  3 +-- 增加 checkTaskEnter 内的参数 记得增加注释
4 4 local TaskType = {
5   - HangPass = 1, -- id
6   - AdvPass = 2, -- id
7   - LoveBreak = 3, -- heroType loveL
8   - Wake = 4, -- heroType wakeL
9   - AddHero = 5, -- heroType wakeL
  5 + HangPass = 1, -- 挂机通关 - id
  6 + AdvPass = 2, -- 冒险通过关 - id
  7 + LoveBreak = 3, -- 好感度进阶 - heroType loveL
  8 + Wake = 4, -- 觉醒 - heroType wakeL
  9 + AddHero = 5, -- 增加角色 - heroType wakeL
  10 + AddEquip = 6, -- 获得装备 - equipId
  11 + DecoRune = 7, -- 分解符文 - count
  12 + SaleEquip = 8, -- 出售装备 - count
  13 + MakeFood = 9, -- 制作料理 - id count
  14 + HangGet = 10, -- 挂机收货
  15 + FoodMGet = 11, -- 食材获取
  16 +
  17 + --todo
  18 + PvpWin = 100, -- pvp胜利
10 19 }
11 20  
12 21 local function v(value)
... ... @@ -36,10 +45,12 @@ local RoleTask = {}
36 45  
37 46 function RoleTask.bind(Role)
38 47  
39   - Role.TaskType = TaskType
40   -
41 48 -- 任务相关入口
42 49 function Role:checkTaskEnter(taskType, params, notNotify)
  50 + params = params or {}
  51 + if type(taskType) == "string" then
  52 + taskType = TaskType[taskType]
  53 + end
43 54 for _, listener in ipairs(TaskListeners) do
44 55 if listener and listener.listen and listener.listen[taskType] and listener["func"] then
45 56 local pms = {}
... ...