From 4864d579d05defc7e204e01be240adf00f0803b3 Mon Sep 17 00:00:00 2001 From: zhengshouren <448949750@qq.com> Date: Fri, 24 May 2019 17:38:18 +0800 Subject: [PATCH] 领取任务,锁定任务,获得特殊任务 --- src/GlobalVar.lua | 4 ++-- src/ProtocolCode.lua | 3 +++ src/actions/DinerAction.lua | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/models/Diner.lua | 10 +++++----- 4 files changed, 113 insertions(+), 7 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index f3659d2..7007aa6 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -42,7 +42,7 @@ ItemType = { Cuisine = 11, -- 料理(用于增加好感度、贩卖获得金币) LunchBox = 12, -- 便当盒(料理合成,冒险系统消耗道具) TimeBox = 13, -- 时间箱(开启需要时间,随机产出道具) - AdvItem = 14 -- 冒险道具 + AdvItem = 14, -- 冒险道具 } -- 物品起始id @@ -60,8 +60,8 @@ ItemId = { EquipUp = 11, -- 装备升级材料 DinerCoin = 12, --后勤物资 LoveUp = 14, --好感度提升道具 + DinerSpTask = 20, -- 餐厅任务采购券 LoveBreak = 21, --好感度突破道具 - BoxKey = 20, -- 开箱钥匙 PvpKey = 22, -- 开箱钥匙 LunchFragment = 23, HeroFC = {700, 701, 702, 703}, -- 通用角色碎片 diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index e44bd88..8baeca4 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -64,6 +64,9 @@ actionCodes = { Diner_talentUpRpc = 304, Diner_skillUpRpc = 305, Diner_removeSellRpc = 306, + Diner_lockTaskRpc = 307, + Diner_finishTaskRpc = 308, + Diner_getSpecialTaskRpc = 309, } rpcResponseBegin = 10000 diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index 22efc26..01a73cc 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -282,4 +282,107 @@ function _M.skillUpRpc( agent, data ) return true end +function _M.lockTaskRpc( agent, data ) + local role = agent.role + local msg = MsgPack.unpack(data) + local index = msg.index + + if math.illegalNum(index, 1, 7) then + return 1 + end + local orders = json.decode(role.dinerData:getProperty("order")) + local order = orders[index] + if not order then + return 2 + end + if order.lock ~= 0 then + return 3 + end + + order.lock = 1 + role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) + SendPacket(actionCodes.Diner_lockTaskRpc, '') + return true +end + +function _M.finishTaskRpc( agent, data ) + local role = agent.role + local msg = MsgPack.unpack(data) + local index = msg.index + + if math.illegalNum(index, 1, 7) then + return 1 + end + local orders = json.decode(role.dinerData:getProperty("order")) + local order = orders[index] + if not order then + return 2 + end + if order.lock == 2 then + return 3 + end + local taskSet = csvdb["diner_questCsv"][order.lv] + if not taskSet then + return 4 + end + local taskData = taskSet[order.id] + if not taskData then + return 5 + end + if order.n <= taskData.value then + return 6 + end + + order.lock = 2 + role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) + for type, count in pairs(taskData.reward:toNumMap()) do + role:addItem({itemId = type, count = count}) + end + + SendPacket(actionCodes.Diner_finishTaskRpc, '') + return true +end + +function _M.getSpecialTaskRpc( agent, data ) + local role = agent.role + local msg = MsgPack.unpack(data) + + local cost = {[DinerSpTask] = 1} + if not role:checkItemEnough(cost) then + return 1 + end + + local orders = json.decode(role.dinerData:getProperty("order")) + if #orders > 6 then + return 2 + end + + local taskLevel = role.dinerData:getProperty("buildL"):getv(5, 1) + local taskData = csvdb["diner_questCsv"][taskLevel] + if not taskData then + return 3 + end + local taskPool = {} + for _, data in pairs(taskData) do + if data.rarity >= 3 then + table.inser(taskPool, data) + end + end + if #taskPool == 0 then + return 4 + end + + role:costItems(cost) + + local index = math.randWeight(taskPool, "chance") + local data = taskPool[index] + + table.insert(orders, {lv = taskLevel, id = data.id, n = 0, lock = 0}) + role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) + + SendPacket(actionCodes.Diner_getSpecialTaskRpc, '') + return true +end + + return _M \ No newline at end of file diff --git a/src/models/Diner.lua b/src/models/Diner.lua index 5b7eb5b..e8643dc 100644 --- a/src/models/Diner.lua +++ b/src/models/Diner.lua @@ -94,11 +94,11 @@ end function Diner:checkDinerTask(type, count, param1, param2, notNotify) local orders = json.decode(self:getProperty("order")) local dirty = false - for _, task in ipairs(orders) do - local taskSet = csvdb["diner_questCsv"][task.lv] - if taskSet and taskSet[task.id] then - local data = taskSet[task.id] - if data.type == type and data.condition1 == param1 and task.lock > 0 then + for _, order in ipairs(orders) do + local taskSet = csvdb["diner_questCsv"][order.lv] + if taskSet and taskSet[order.id] then + local data = taskSet[order.id] + if data.type == type and data.condition1 == param1 and order.lock > 0 then data.n = data.n + count dirty = true end -- libgit2 0.21.2