From 03a6166a38cb1b3d7b358f613258e96890832f82 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Sun, 29 Sep 2019 17:59:11 +0800 Subject: [PATCH] 餐厅优化 --- src/ProtocolCode.lua | 2 ++ src/actions/CarAction.lua | 7 ++++++- src/actions/DinerAction.lua | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------- src/actions/GmAction.lua | 10 +++++----- src/actions/HangAction.lua | 3 ++- src/actions/HeroAction.lua | 6 +++--- src/adv/Adv.lua | 2 +- src/models/Diner.lua | 3 ++- src/models/Role.lua | 3 +++ src/models/RolePlugin.lua | 3 ++- src/models/RoleTask.lua | 27 +++++++++++++++++++-------- 11 files changed, 193 insertions(+), 78 deletions(-) diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 29e394d..ddb4c45 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -88,6 +88,8 @@ actionCodes = { Diner_expediteSellRpc = 310, Diner_getGreenhouseRpc = 311, Diner_addWantFoodRpc = 312, + Diner_initTaskRpc = 313, + Diner_handleTaskRpc = 314, Tower_roleFormatRpc = 350, Tower_startBattleRpc = 351, diff --git a/src/actions/CarAction.lua b/src/actions/CarAction.lua index 25d8c3d..4c365aa 100644 --- a/src/actions/CarAction.lua +++ b/src/actions/CarAction.lua @@ -135,7 +135,9 @@ function _M.saleEquipRpc(agent, data ) if math.illegalNum(count, 1, own) then return end end local reward = {} + local allCount = 0 for id, count in pairs(backs) do + allCount = allCount + count local itemData = csvdb["itemCsv"][id] local typ = math.floor((id-7000)/100) local lv = (id-7000)%100 @@ -146,6 +148,7 @@ function _M.saleEquipRpc(agent, data ) reward[k] = (reward[k] or 0) + v * count end end + role:checkTaskEnter("SaleEquip", {count = allCount}) reward = role:award(reward) SendPacket(actionCodes.Car_saleEquipRpc, MsgPack.pack({reward = reward})) return true @@ -158,7 +161,9 @@ function _M.saleRuneRpc(agent, data ) if not backs then return end local reward = {} + local count = 0 for _, uid in pairs(backs) do + count = count + 1 local rune = role.runeBag[uid] if not rune then return end if rune:getProperty("refer") ~= 0 then return end @@ -171,7 +176,7 @@ function _M.saleRuneRpc(agent, data ) end role:delRunes(backs) - + role:checkTaskEnter("DecoRune", {count = count}) reward = role:award(reward) SendPacket(actionCodes.Car_saleRuneRpc, MsgPack.pack({reward = reward})) diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index 50811a2..3030d12 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -9,70 +9,71 @@ local _M = {} function _M.addSellRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) - for _,sellData in pairs(msg) do - local slot = sellData.slot - local sells = json.decode(role.dinerData:getProperty("sells")) - if sells[slot] and sells[slot].count and sells[slot].count ~= 0 then - return 0 - end - if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then - return 1 - end - slot = tostring(slot) + local sellData = msg - local dish = sellData.dish - local dishSet = csvdb["diner_dishCsv"][dish] - if not dishSet then - return 2 - end - local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0) - if dishLevel == 0 then - return 3 - end - local dishData = dishSet[dishLevel] - if not dishData then - return 4 - end + local slot = sellData.slot + local sells = json.decode(role.dinerData:getProperty("sells")) + if sells[slot] and sells[slot].count and sells[slot].count ~= 0 then + return 0 + end + if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then + return 1 + end + slot = tostring(slot) - local calSell = role.dinerData:updateSell(slot, true) or { - deltaCount = 0, - deltaTime = 0, - lastCount = 0, - } - local count = sellData.count - local maxDishCount = role.dinerData:getMaxDishs() - if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then - return 5 - end + local dish = sellData.dish + local dishSet = csvdb["diner_dishCsv"][dish] + if not dishSet then + return 2 + end + local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0) + if dishLevel == 0 then + return 3 + end + local dishData = dishSet[dishLevel] + if not dishData then + return 4 + end - local cost = dishData.material:toNumMap() - for k, n in pairs(cost) do - cost[k] = n * count - end - if not role:checkItemEnough(cost) then - return 6 - end + local calSell = role.dinerData:updateSell(slot, true) or { + deltaCount = 0, + deltaTime = 0, + lastCount = 0, + } + local count = sellData.count + local maxDishCount = role.dinerData:getMaxDishs() + if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then + return 5 + end - role:costItems(cost) - role.dinerData:updateSell(slot) + local cost = dishData.material:toNumMap() + for k, n in pairs(cost) do + cost[k] = n * count + end + if not role:checkItemEnough(cost) then + return 6 + end - -- local dirty = false - -- if dirty then - -- role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) - -- end + role:costItems(cost) + role.dinerData:updateSell(slot) - sells = json.decode(role.dinerData:getProperty("sells")) - if not sells[slot] then - sells[slot] = { - reward = "", - } - end - sells[slot].dish = dish - sells[slot].level = dishLevel - sells[slot].count = count - sells[slot].time = skynet.timex() - calSell.deltaTime - role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) + role:checkTaskEnter("MakeFood", {id = dish, count = count}) + -- local dirty = false + -- if dirty then + -- role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) + -- end + + sells = json.decode(role.dinerData:getProperty("sells")) + if not sells[slot] then + sells[slot] = { + reward = "", + } end + sells[slot].dish = dish + sells[slot].level = dishLevel + sells[slot].count = count + sells[slot].time = skynet.timex() - calSell.deltaTime + role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) SendPacket(actionCodes.Diner_addSellRpc, "") return true end @@ -590,4 +591,94 @@ function _M.getGreenhouseRpc( agent, data ) return true end +local function refreshTaskRpc(role, task) + local hadType = {} + if task.id and csvdb["task_specialCsv"][task.id] then + hadType[csvdb["task_specialCsv"][task.id].type] = 1 + end + local spTask = role:getProperty("spTask") + local taskCount = 0 + for id ,_ in pairs(spTask) do + hadType[csvdb["task_specialCsv"][id].type] = 1 + taskCount = taskCount + 1 + end + local pool = {} + if taskCount < globalCsv.diner_get_task_count_max then + local curLevel = role:getProperty("level") + for id, data in pairs(csvdb["task_specialCsv"]) do + if not hadType[data.type] then + local level = data.level:toArray(true, "=") + if curLevel >= level[1] and curLevel <= level[2] then + table.insert(pool, id) + end + end + end + end + if not next(pool) then --每次进都看看有没有任务可以领 + task.id = nil + task.et = 0 + else + local id = pool[math.randomInt(1, #pool)] + task.id = id + task.et = skynet.timex() + globalCsv.diner_get_task_time_max + end + return task +end + +-- 进入餐厅界面调用 +function _M.initTaskRpc(agent, data) + local role = agent.role + + local task = role.dinerData:getProperty("task") + + local now = skynet.timex() + + if not task.et or task.et <= now then --刷新了 + task = refreshTaskRpc(role, task) + role.dinerData:updateProperty({field = "task", value = task}) + end + + SendPacket(actionCodes.Diner_initTaskRpc, '') + return true +end + +-- 对任务进行处理调用 +function _M.handleTaskRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local cmd = msg.cmd -- 1 领取任务 2 拒绝任务 + + local task = role.dinerData:getProperty("task") + local now = skynet.timex() + if cmd == 1 then + if not task.id then return end + if task.et > now then + --领取任务 + task.id = nil + task.et = now + globalCsv.diner_get_task_time_max + task.refuse = nil + else + return + end + elseif cmd == 2 then -- 拒绝任务(重新领取) + if not task.id then return end + if (task.refuse or 0) >= globalCsv.diner_get_task_refuse_max then + -- 等待时间 + task.refuse = nil + task.id = nil + task.et = now + globalCsv.diner_get_task_time_max + else + task.refuse = (task.refuse or 0) + 1 + --刷新任务 + task = refreshTaskRpc(role, task) + end + else + return + end + role.dinerData:updateProperty({field = "task", value = task}) + + SendPacket(actionCodes.Diner_handleTaskRpc, '') + return true +end + return _M \ No newline at end of file diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index 8aba657..fb886f6 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -51,14 +51,14 @@ function _M.fb(role, pms) -- 直接通关 local carbonData = csvdb["idle_battleCsv"][carbonId] for _, pre in ipairs(carbonData.prepose:toArray(true, "=")) do passCarbon[pre] = 1 - role:checkTaskEnter(role.TaskType.HangPass, {id = pre}) + role:checkTaskEnter("HangPass", {id = pre}) addPre(pre) end end passCarbon[carbonId] = 1 addPre(carbonId) role:updateProperty({field = "hangPass", value = passCarbon}) - role:checkTaskEnter(role.TaskType.HangPass, {id = carbonId}) + role:checkTaskEnter("HangPass", {id = carbonId}) return "成功" end @@ -71,14 +71,14 @@ function _M.fbc(role, pms) -- 直接通关 local carbonData = csvdb["idle_battleCsv"][carbonId] for _, pre in ipairs(carbonData.prepose:toArray(true, "=")) do passCarbon[pre] = 1 - role:checkTaskEnter(role.TaskType.HangPass, {id = pre}) + role:checkTaskEnter("HangPass", {id = pre}) addPre(pre) end end addPre(carbonId) role:updateProperty({field = "hangInfo", value = {}}) role:updateProperty({field = "hangPass", value = passCarbon}) - role:checkTaskEnter(role.TaskType.HangPass, {id = carbonId}) + role:checkTaskEnter("HangPass", {id = carbonId}) return "成功" end @@ -98,7 +98,7 @@ function _M.love(role, pms) if role:getProperty("loveStatus"):getv(heroType, 0) < level then role:changeUpdates({{type = "loveStatus", field = heroType, value = level}}) -- 总的 end - role:checkTaskEnter(role.TaskType.LoveBreak, {heroType = heroType, loveL = level}) + role:checkTaskEnter("LoveBreak", {heroType = heroType, loveL = level}) end end return "成功" diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index 600a059..16738ee 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -181,7 +181,7 @@ function _M.endBattleRpc(agent, data) end reward = role:award(reward) - role:checkTaskEnter(role.TaskType.HangPass, {id = carbonId}) + role:checkTaskEnter("HangPass", {id = carbonId}) end hangInfo.key = nil role:updateProperty({field = "hangInfo", value = hangInfo}) @@ -228,6 +228,7 @@ function _M.getRewardRpc(agent , data) hangInfo.itemTime = nowTime role:updateProperty({field = "hangBag", value = items}) role:updateProperty({field = "hangInfo", value = hangInfo}) + role:checkTaskEnter("HangGet") SendPacket(actionCodes.Hang_getRewardRpc, MsgPack.pack({ reward = reward diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index 35929bf..a556c79 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -87,7 +87,7 @@ function _M.wakeRpc(agent, data) end hero:updateProperty({field = "wakeL", delta = 1}) - role:checkTaskEnter(role.TaskType.Wake, {heroType = typ, wakeL = hero:getProperty("wakeL")}) + role:checkTaskEnter("Wake", {heroType = typ, wakeL = hero:getProperty("wakeL")}) SendPacket(actionCodes.Hero_wakeRpc, '') return true @@ -404,7 +404,7 @@ function _M.loveItemRpc(agent, data) role:changeUpdates({{type = "loveStatus", field = curType, value = newLevel}}) -- 总的 end - role:checkTaskEnter(role.TaskType.LoveBreak, {heroType = curType, loveL = newLevel}) + role:checkTaskEnter("LoveBreak", {heroType = curType, loveL = newLevel}) else local delta = globalCsv.unit_love_presentValue[msg.itemId] @@ -458,7 +458,7 @@ function _M.loveTaskRpc(agent, data) role:changeUpdates({{type = "loveStatus", field = curType, value = newLevel}}) -- 总的 end - role:checkTaskEnter(role.TaskType.LoveBreak, {heroType = curType, loveL = newLevel}) + role:checkTaskEnter("LoveBreak", {heroType = curType, loveL = newLevel}) SendPacket(actionCodes.Hero_loveTaskRpc, "") return true diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 57e9a9e..b210623 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -168,7 +168,7 @@ function Adv:over(success) local reward if success then reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap()) - self.owner:checkTaskEnter(self.owner.TaskType.AdvPass, {id = self.chapterId}) + self.owner:checkTaskEnter("AdvPass", {id = self.chapterId}) -- 冒险队等级升一下子 local advL = self.owner:getProperty("advL") diff --git a/src/models/Diner.lua b/src/models/Diner.lua index f148beb..5d475b3 100644 --- a/src/models/Diner.lua +++ b/src/models/Diner.lua @@ -13,6 +13,7 @@ Diner.schema = { popular = {"number",0}, -- 累计人气 expedite = {"number",1}, --每日加速次数 gfood = {"table", {}}, -- 愿望食材 {{id = 123, st = 1232144},} + task = {"table", {}}, -- 任务刷新 {et = 消失时间 id = 任务id, refuse = 0} } function Diner:refreshDailyData(notify) @@ -242,7 +243,7 @@ function Diner:getMaxDishs() end function Diner:data() - local properties = {"buildL", "order", "sells", "dishTree", "skillTree","popular","expedite","gfood"} + local properties = {"buildL", "order", "sells", "dishTree", "skillTree","popular","expedite","gfood", "task"} local data = self:getProperties(properties) return data end diff --git a/src/models/Role.lua b/src/models/Role.lua index 0ea8a69..0a09cb8 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -73,6 +73,8 @@ Role.schema = { towerInfo = {"table", {c = globalCsv.tower_count_limit, l = 1}}, -- 当天爬塔消耗的次数 -- {t = time, c = count, l = layer, k = battleKey} towerF = {"table", {}}, -- 爬塔阵容 + + spTask = {"table", {}} -- 特殊任务 -- {id = status} } @@ -208,6 +210,7 @@ function Role:data() boxL = self:getProperty("boxL"), towerInfo = self:getProperty("towerInfo"), towerF = self:getProperty("towerF"), + spTask = self:getProperty("spTask"), } end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 613c741..e9e8fe1 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -86,6 +86,7 @@ function RolePlugin.bind(Role) local typ = math.floor((itemId-7000)/100) local lv = (itemId-7000)%100 self:addEquip(typ, lv, count ,pms) + self:checkTaskEnter("AddEquip", {equipId = itemId}, pms.notNotify) end, [ItemType.Rune] = function() local typ = math.floor((itemId-2000)/100) @@ -312,7 +313,7 @@ function RolePlugin.bind(Role) newHero.owner = self newHero:saveBattleValue() self.heros[heroId] = newHero - self:checkTaskEnter(self.TaskType.AddHero, {heroType = heroType, wakeL = newHero:getProperty("wakeL")}, params.notNotify) + self:checkTaskEnter("AddHero", {heroType = heroType, wakeL = newHero:getProperty("wakeL")}, params.notNotify) if not params.notNotify then local heroResponse = {} table.insert(heroResponse, newHero:data()) diff --git a/src/models/RoleTask.lua b/src/models/RoleTask.lua index 68d6300..5ca7fd3 100644 --- a/src/models/RoleTask.lua +++ b/src/models/RoleTask.lua @@ -1,12 +1,21 @@ --- 增加 checkTaskEnter 内的参数 记得增增加注释 +-- 增加 checkTaskEnter 内的参数 记得增加注释 local TaskType = { - HangPass = 1, -- id - AdvPass = 2, -- id - LoveBreak = 3, -- heroType loveL - Wake = 4, -- heroType wakeL - AddHero = 5, -- heroType wakeL + HangPass = 1, -- 挂机通关 - id + AdvPass = 2, -- 冒险通过关 - id + LoveBreak = 3, -- 好感度进阶 - heroType loveL + Wake = 4, -- 觉醒 - heroType wakeL + AddHero = 5, -- 增加角色 - heroType wakeL + AddEquip = 6, -- 获得装备 - equipId + DecoRune = 7, -- 分解符文 - count + SaleEquip = 8, -- 出售装备 - count + MakeFood = 9, -- 制作料理 - id count + HangGet = 10, -- 挂机收货 + FoodMGet = 11, -- 食材获取 + + --todo + PvpWin = 100, -- pvp胜利 } local function v(value) @@ -36,10 +45,12 @@ local RoleTask = {} function RoleTask.bind(Role) - Role.TaskType = TaskType - -- 任务相关入口 function Role:checkTaskEnter(taskType, params, notNotify) + params = params or {} + if type(taskType) == "string" then + taskType = TaskType[taskType] + end for _, listener in ipairs(TaskListeners) do if listener and listener.listen and listener.listen[taskType] and listener["func"] then local pms = {} -- libgit2 0.21.2