local ipairs = ipairs local table = table local math = math local redisproxy = redisproxy local MsgPack = MsgPack local _M = {} function _M.addSellRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local sellData = msg 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 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 calSell = role.dinerData:updateSell(slot, true) or { deltaCount = 0, deltaTime = 0, lastCount = 0, } local count = sellData.count or 0 local maxDishCount = role.dinerData:getMaxDishs() if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then return 5 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 role:costItems(cost, {log = {desc = "addSell"}}) role.dinerData:updateSell(slot) 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 = "", popular = 0, } end sells[slot].dish = dish sells[slot].level = dishLevel sells[slot].count = count sells[slot].time = skynet.timex() - calSell.deltaTime local timeSub = role:getBnousDiner(3,dishData.sell_time) local needTime = sells[slot].count * (dishData.sell_time + timeSub) + sells[slot].time - skynet.timex() role:pushMsg({type = "food", slot = slot, time = needTime}) -- 检查解锁的顾客 local had = {} for _, sell in pairs(sells) do if sell.dish then had[sell.dish] = sell.level end end local customer = role.dinerData:getProperty("customer") local change = false for cId, cData in pairs(csvdb["diner_customerCsv"]) do if not customer[cId] then local unlock = true for needId, lv in pairs(cData.unlock:toNumMap()) do if not had[needId] or had[needId] < lv then unlock = false break end end if unlock then change = true customer[cId] = 0 end end end if change then role.dinerData:updateProperty({field = "customer", value = customer}) end role:finishGuide(28) role:mylog("diner_action", {desc = "addSell", int1 = dish, int2 = count}) role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) SendPacket(actionCodes.Diner_addSellRpc, "") return true end function _M.removeSellRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local slot = msg.slot if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then return 1 end slot = tostring(slot) local sells = json.decode(role.dinerData:getProperty("sells")) local sell = sells[slot] if not sell then return 2 end local dish = sell.dish local dishSet = csvdb["diner_dishCsv"][dish] if not dishSet then return 3 end local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0) if dishLevel == 0 then return 4 end local dishData = dishSet[dishLevel] if not dishData then return 5 end local temp = role.dinerData:updateSell(slot) or { deltaCount = 0, deltaTime = 0, lastCount = 0, } local reward, change = {} local cost = dishData.material:toNumMap() for k, n in pairs(cost) do local sum = n*sell.count reward[k] = sum end reward, change = role:award(reward, {log = {desc = "removeSell"}}) sells[slot].count = 0 role:pushCancel({type = "food", slot = slot}) role:log("restaurant_sale", { item_id = dish, -- 售卖物品ID restaurant_sale_seat = slot, -- 售卖物品所在位置 restaurant_sale_time = temp.deltaTime or 0, -- 售卖时长 restaurant_sale_type = 2, -- 售卖方式,正常售卖:0, 加速:1,移除售卖:2 restaurant_sale_coin = reward[ItemId.DinerCoin] or 0, -- 售卖获得美食币 restaurant_sale_gear = reward[ItemId.Gold] or 0, -- 售卖获得齿轮 }) role:mylog("diner_action", {desc = "removeSell", int1 = dish}) role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) SendPacket(actionCodes.Diner_removeSellRpc, MsgPack.pack({reward = reward, change = change})) return true end function _M.getSellRewardRpc( agent, data ) local role = agent.role local dirty = false local reward, popular = "", 0 local sells = json.decode(role.dinerData:getProperty("sells")) local deltaTimes = {} for slot, _ in pairs(sells) do local temp = role.dinerData:updateSell(slot) or { deltaCount = 0, deltaTime = 0, lastCount = 0, } deltaTimes[slot] = temp.deltaTime end sells = json.decode(role.dinerData:getProperty("sells")) for slot, sell in pairs(sells) do local rewards = sell.reward:toNumMap() for k,v in pairs(rewards) do reward = reward:incrv(k, v) end popular = popular + (sell.popular or 0) if rewards[ItemId.Gold] and rewards[ItemId.Gold] > 0 then if role.dinerData:checkDinerTask(DinerTask.DishWithGold, rewards[ItemId.Gold], sell.dish, nil, true) then dirty = true end if role.dinerData:checkDinerTask(DinerTask.DishWithGoldType, rewards[ItemId.Gold], math.ceil(sell.dish / 100), nil, true) then dirty = true end local dishData = csvdb["diner_dishCsv"][sell.dish][sell.level] if role.dinerData:checkDinerTask(DinerTask.DishWithGoldRare, rewards[ItemId.Gold], dishData.rarity, nil, true) then dirty = true end end sells[slot].reward = "" sells[slot].popular = 0 role:log("restaurant_sale", { item_id = sell.dish, -- 售卖物品ID restaurant_sale_seat = slot, -- 售卖物品所在位置 restaurant_sale_time = deltaTimes[slot] or 0, -- 售卖时长 restaurant_sale_type = 0, -- 售卖方式,正常售卖:0, 加速:1,移除售卖:2 restaurant_sale_coin = rewards[ItemId.DinerCoin] or 0, -- 售卖获得美食币 restaurant_sale_gear = rewards[ItemId.Gold] or 0, -- 售卖获得齿轮 }) end role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) local gift = reward:toNumMap() for k, v in pairs(gift) do if k == ItemId.Gold then role:checkTaskEnter("FoodSellGold", {count = v}) end end local reward, change = role:award(gift, {log = {desc = "dinerSell"}}) role.dinerData:popularAdd(popular) if dirty then role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) end role:mylog("diner_action", {desc = "sell"}) SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward, change = change})) return true end function _M.expediteSellRpc( agent, data ) local role = agent.role local count = role.dinerData:getProperty("expedite") local max = #globalCsv.diner_sell_quick_cost if count > max then return 1 end local diamond = globalCsv.diner_sell_quick_cost[count] if diamond > 0 then local cost = {[ItemId.Diamond] = diamond} if not role:checkItemEnough(cost) then return 2 end role:costItems(cost, {log = {desc = "dinerSellQ"}}) end local dirty = false local reward,popular = "", 0 local sells = json.decode(role.dinerData:getProperty("sells")) for slot, _ in pairs(sells) do role.dinerData:updateSell(slot) end sells = json.decode(role.dinerData:getProperty("sells")) for slot, sell in pairs(sells) do local result = role.dinerData:expediteSell(slot) if result then local rewards = result.reward:toNumMap() for k,v in pairs(result.reward:toNumMap()) do reward = reward:incrv(k,v) end popular = popular + result.popular if rewards[ItemId.Gold] and rewards[ItemId.Gold] > 0 then if role.dinerData:checkDinerTask(DinerTask.DishWithGold, rewards[ItemId.Gold], sell.dish, nil, true) then dirty = true end if role.dinerData:checkDinerTask(DinerTask.DishWithGoldType, rewards[ItemId.Gold], math.ceil(sell.dish / 100), nil, true) then dirty = true end local dishData = csvdb["diner_dishCsv"][sell.dish][sell.level] if role.dinerData:checkDinerTask(DinerTask.DishWithGoldRare, rewards[ItemId.Gold], dishData.rarity, nil, true) then dirty = true end end role:log("restaurant_sale", { item_id = sell.dish, -- 售卖物品ID restaurant_sale_seat = slot, -- 售卖物品所在位置 restaurant_sale_time = result.deltaTime or 0, -- 售卖时长 restaurant_sale_type = 1, -- 售卖方式,正常售卖:0, 加速:1,移除售卖:2 restaurant_sale_coin = rewards[ItemId.DinerCoin] or 0, -- 售卖获得美食币 restaurant_sale_gear = rewards[ItemId.Gold] or 0, -- 售卖获得齿轮 }) end end role.dinerData:notifyUpdateProperty("sells", role.dinerData:getProperty("sells")) role.dinerData:setProperty("expedite",count+1) role.dinerData:notifyUpdateProperty("expedite", count+1) local gift = reward:toNumMap() -- 特权卡获取加速获得额外道具 local coef = 1 --role.storeData:getProduceItemSpeedCoef() for k, v in pairs(gift) do if coef > 1 then v = math.floor(v * coef) gift[k] = v end if k == ItemId.Gold then role:checkTaskEnter("FoodSellGold", {count = v}) end end local change reward, change = role:award(gift, {log = {desc = "dinerSell"}}) role.dinerData:popularAdd(popular) if dirty then role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) end role:checkTaskEnter("FoodSellQuick") role:mylog("diner_action", {desc = "sellQ"}) SendPacket(actionCodes.Diner_expediteSellRpc, MsgPack.pack({reward = reward, change = change, popular = popular})) return true end function _M.levelUpRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local index = msg.index local buildingSet = csvdb["diner_buildingCsv"][index] if not buildingSet then return end local buildL = role.dinerData:getProperty("buildL") local curLevel = buildL:getv(index, 1) if curLevel >= #buildingSet then return end local buildingData = buildingSet[curLevel] if not buildingData then return end if buildingData.upLimit ~= "" then local id, level = buildingData.upLimit:match("(%d+)=(%d+)") if buildL:getv(tonumber(id), 1) < tonumber(level) then return end end local cost = buildingData.starCost:toNumMap() if not role:checkItemEnough(cost) then return end role:costItems(cost, {log = {desc = "dinerBuildUp", int1 = index}}) role.dinerData:updateProperty({field = "buildL", value = buildL:setv(index, curLevel + 1)}) role:checkTaskEnter("DinerLevelUp", {type = index, level = curLevel + 1}) role:log("restaurant_up", { restaurant_up_type = index - 1, --升级部件类型,店面:0, 接客:1, 满意度:2, 宣传:3, 广告:4, 周边:5 restaurant_up_gear = cost[ItemId.Gold] or 0, --消耗齿轮数量 restaurant_up_coin = cost[ItemId.DinerCoin] or 0, --花费美食币数量 restaurant_up_effectbef = curLevel, --升级前加成 restaurant_up_effect = curLevel + 1, --升级后加成 }) role:mylog("diner_action", {desc = "buildUp", int1 = index, int2 = curLevel + 1}) SendPacket(actionCodes.Diner_levelUpRpc, '') return true end function _M.talentUpRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local dish = msg.dish local dishTree = role.dinerData:getProperty("dishTree") local talentSet = csvdb["diner_talentCsv"][dish] if not talentSet then return 1 end local typ = math.floor(dish/100 + 1) local treeSet = csvdb["diner_treeCsv"][typ] if not treeSet then return 3 end local treeData = treeSet[dish] if not treeData then return 4 end -- 调理剂的默认等级是1级 local dishLevel = dishTree:getv(dish, treeData.rarity == 2 and 1 or 0) local talentData = talentSet[dishLevel] if not talentData then return 2 end if not talentSet[dishLevel+1] then return 21 end local limit = talentData.pointFront:toNumMap() for k,v in pairs(limit) do local lv = dishTree:getv(k, 0) if lv < v then return 5 end end if talentData.levelFront ~= "" then if not role:checkHangPass(tonumber(talentData.levelFront)) then return 9 end end local cost = talentData.cost:toNumMap() if not role:checkItemEnough(cost) then return 6 end -- 正在贩卖不能升级料理天赋 local sells = json.decode(role.dinerData:getProperty("sells")) for slot, _ in pairs(sells) do role.dinerData:updateSell(slot) end sells = json.decode(role.dinerData:getProperty("sells")) for _, sell in pairs(sells) do if sell.dish == msg.dish and sell.count > 0 then return 7 end end -- 正在冒险不能升级营养剂天赋 -- if talentData.effect:toArray(true,"=")[1] == 2 then -- if next(role:getProperty("advTeam")) then return 8 end -- end role:costItems(cost, {log = {desc = "talentUp", int1 = dish, int2 = dishLevel + 1}}) role.dinerData:updateProperty({field = "dishTree", value = dishTree:setv(dish, dishLevel + 1)}) -- local treePoint = talentData.tree_point:toNumMap() -- if next(treePoint) then -- role:award(treePoint) -- end role:checkTaskEnter("DinerTalentUp", {type = talentData.effect:toArray(true,"=")[1], level = dishLevel + 1}) role:finishGuide(27) role:log("carriage_logistics", { carriage_logistics_type = typ, -- 后勤室制作类型ID,变异:0,通常:1,魔法:2 carriage_logistics_itemid = dish, -- 后勤室升级物品或技能ID carriage_logistics_itemlv = dishLevel + 1, -- 升级后物品或技能等级 carriage_logistics_gear = cost[ItemId.Gold] or 0, -- 后勤室升级花费齿轮数量 carriage_logistics_coin = cost[ItemId.DinerCoin] or 0, -- 后勤室升级花费美食币数量 }) role:mylog("diner_action", {desc = "talentUp", int1 = dish, int2 = dishLevel + 1}) SendPacket(actionCodes.Diner_talentUpRpc, '') return true end function _M.skillUpRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local skill = msg.skill local skillSet = csvdb["diner_skillCsv"][skill] if not skillSet then return end local skillTree = role.dinerData:getProperty("skillTree") local skillLevel = skillTree:getv(skill, 1) local skillData = skillSet[skillLevel] if not skillData then return end if skillData.unlock ~= "" then local id, level = skillData.unlock:math("(%d+)=(%d+)") if skillTree:getv(tonumber(id), 1) < tonumber(level) then return end end local cost = skillData.cost:toNumMap() if not role:checkItemEnough(cost) then return end role:costItems(cost, {log = {desc = "dinerSkillUp", int1 = skill, int2 = skillLevel + 1}}) role.dinerData:updateProperty({field = "skillTree", value = skillTree:setv(skill, skillLevel + 1)}) role:mylog("diner_action", {desc = "skillUp", int1 = skill, int2 = skillLevel + 1}) SendPacket(actionCodes.Diner_skillUpRpc, '') return true end function _M.lockTaskRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local index = msg.index local orders = json.decode(role.dinerData:getProperty("order")) if math.illegalNum(index, 1, #orders) then return 1 end local order = orders[index] if not order then return 2 end if order.lock == 0 then order.lock = 1 else order.lock = 0 end role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) role:mylog("diner_action", {desc = "lockTask", int1 = order.id}) SendPacket(actionCodes.Diner_lockTaskRpc, MsgPack.pack({lock = order.lock})) return true end function _M.updateTaskRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local index = msg.index -- 0 接受任务,1 放弃已接受任务,2 完成已接受任务 local cmd = msg.cmd local orders = json.decode(role.dinerData:getProperty("order")) if math.illegalNum(index, 1, #orders) then return 1 end local order = orders[index] if not order then return 2 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 local reward, change if cmd == 0 then if order.status ~= 0 then return 30 end orders[index].status = 1 orders[index].lock = 1 role:checkTaskEnter("GetOderTask", {rarity = taskData.rarity}) role:mylog("diner_action", {desc = "getTask", int1 = order.id}) elseif cmd == 1 then if order.status ~= 1 then return 31 end orders[index].status = 0 orders[index].lock = 0 role:mylog("diner_action", {desc = "deleteTask", int1 = order.id}) elseif cmd == 2 then if order.status ~= 1 then return 32 end if order.n < taskData.value then return 6 end role:mylog("diner_action", {desc = "finishTask", int1 = order.id}) reward, change = role:award(taskData.reward, {log = {desc = "dinerFinishTask", int1 = order.id}}) table.remove(orders,index) role:checkTaskEnter("OverOderTask", {rarity = taskData.rarity}) else return 33 end role:log("restaurant_order", { restaurant_order_id = order.id, -- 订单任务ID restaurant_order_status = cmd, -- 订单任务状态,接受:0, 拒绝:1, 完成:2 restaurant_order_rwd = reward or {}, -- 订单完成奖励,json格式记录,{"itemid1":123,"itemid2":12,……….} restaurant_order_lv = taskData.rarity, -- 订单品质等级,普通:0, 稀有:1, 顶级:2, 豪华:3 restaurant_order_type = 1, -- 订单任务类型,0:特殊顾客,1:特别订单 }) role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) SendPacket(actionCodes.Diner_updateTaskRpc, MsgPack.pack({reward = reward, change = change})) return true end function _M.refreshTaskRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) --local cost = {[ItemId.Diamond] = 40} --if not role:checkItemEnough(cost) then -- return 1 --end local orders = json.decode(role.dinerData:getProperty("order")) local hadTask = {} local needCount = 0 for idx, temp in pairs(orders) do if temp.lock ~= 0 or temp.status ~= 0 then hadTask[temp.id] = 1 else needCount = needCount + 1 end end if needCount <= 0 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 pool = {} local dishTree = role.dinerData:getProperty("dishTree") for id, temp in pairs(taskData) do local unlock = true for _, front in ipairs(temp.front:toArray(true, "=")) do if dishTree:getv(front, 0) == 0 then unlock = false break end end if not hadTask[id] and unlock then table.insert(pool, temp) end end local needCount = math.min(#pool, needCount) -- 需要的任务个数 if needCount <= 0 then return end local cost = globalCsv.diner_task_refresh_cost:toNumMap() for itemId, count in pairs(cost) do cost[itemId] = count * needCount end if not role:checkItemEnough(cost) then return end role:costItems(cost, {log = {desc = "dinerReTask"}}) for idx, order in ipairs(orders) do if (order.lock == 0 and order.status == 0) then if needCount > 0 then local index = math.randWeight(pool, "chance") local data = pool[index] orders[idx] = {lv = taskLevel, id = data.id, n = 0, lock = 0, status = 0} needCount = needCount - 1 table.remove(pool, index) end end end role:finishGuide(41) role:mylog("diner_action", {desc = "reTask"}) role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) SendPacket(actionCodes.Diner_refreshTaskRpc, '') return true end function _M.addWantFoodRpc(agent , data) local role = agent.role local msg = MsgPack.unpack(data) local ids = msg.ids -- list local buildType = 6 local level = role.dinerData:getProperty("buildL"):getv(buildType, 1) local buildingData = csvdb["diner_buildingCsv"][buildType][level] if not buildingData then return 1 end if #ids > buildingData.business then return 2 end local had = {} for _, itemId in ipairs(ids) do if had[itemId] then return end had[itemId] = 1 local foodData = csvdb["diner_materialCsv"][itemId] if not foodData then return 3 end if foodData.unlock ~= 0 then if not role:checkHangPass(foodData.unlock) then return 4 end end end local gfood = {} for slot, itemId in ipairs(ids) do gfood[slot] = {id = itemId, st = skynet.timex()} end role:finishGuide(36) role:mylog("diner_action", {desc = "wantFood"}) role.dinerData:updateProperty({field = "gfood", value = gfood}) SendPacket(actionCodes.Diner_addWantFoodRpc, '') return true end function _M.getGreenhouseRpc( agent, data ) local role = agent.role -- local msg = MsgPack.unpack(data) local buildType = 6 local level = role.dinerData:getProperty("buildL"):getv(buildType, 1) local buildingData = csvdb["diner_buildingCsv"][buildType][level] if not buildingData then return 1 end local reward = {} local now = skynet.timex() local gfood = role.dinerData:getProperty("gfood") if not next(gfood) then return end local timeAdd = role:getBnousDiner(2,globalCsv.diner_get_food_time_max) for k , v in pairs(gfood) do local itemId = v.id local st = v.st local speed = globalCsv.diner_get_food_speed[csvdb["itemCsv"][itemId].quality] * buildingData.speed / 100 speed = speed + role:getBnousDiner(1,speed) local endTime = st + globalCsv.diner_get_food_time_max + timeAdd local endTime2 = math.min(now, endTime) reward[itemId] = math.floor((endTime2 - st) / speed) if endTime2 == endTime then gfood[k].st = now else gfood[k].st = st + speed * reward[itemId] end role:log("restaurant_material", { item_id = itemId, -- 获取物品ID restaurant_material_start = st, -- 申请获取时间 restaurant_material_time = endTime2 - st, -- 申请到领取耗时 restaurant_material_num = reward[itemId], -- 获取物品数量 }) end role.dinerData:updateProperty({field = "gfood", value = gfood}) local reward, change = role:award(reward, {log = {desc = "greenHourse", int1 = level}}) role:checkTaskEnter("FoodMGet") role:mylog("diner_action", {desc = "greenHourse"}) SendPacket(actionCodes.Diner_getGreenhouseRpc, MsgPack.pack({reward = reward, change = change})) 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 function _M.rankRpc(agent , data) local role = agent.role local rankInfo = role.dinerData:getPopularRank() SendPacket(actionCodes.Diner_rankRpc, MsgPack.pack(rankInfo)) return true end function _M.entrustRpc(agent , data) local role = agent.role local msg = MsgPack.unpack(data) local ctype = msg.ctype local entrust = role.dinerData:getProperty("entrust") local entrustId = entrust[1] if not entrustId then return end local reward, change if ctype == 1 then -- 完成 local curData = csvdb["diner_missionCsv"][entrustId] if not curData then return end if curData.type == 1 then local cost = curData.condition:toNumMap() if not role:checkItemEnough(cost) then return end role:costItems(cost, {log = {desc = "dinerEntrus", int1 = entrustId}}) elseif curData.type == 2 then -- todo 数据校验 else return end reward, change = role:award(curData.reward, {log = {desc = "dinerEntrus", int1 = entrustId}}) table.remove(entrust, 1) role:log("restaurant_order", { restaurant_order_id = entrustId, -- 订单任务ID restaurant_order_status = 2, -- 订单任务状态,接受:0, 拒绝:1, 完成:2 restaurant_order_rwd = reward or {}, -- 订单完成奖励,json格式记录,{"itemid1":123,"itemid2":12,……….} restaurant_order_lv = curData.type, -- 订单品质等级,普通:0, 稀有:1, 顶级:2, 豪华:3 restaurant_order_type = 0, -- 订单任务类型,0:特殊顾客,1:特别订单 }) elseif ctype == 2 then -- 放弃 table.remove(entrust, 1) else return end role.dinerData:updateProperty({field = "entrust", value = entrust}) role:finishGuide(26) role:mylog("diner_action", {desc = "entrus", short1 = ctype, int1 = entrustId}) role:checkTaskEnter("VillageApply", {}) SendPacket(actionCodes.Diner_entrustRpc, MsgPack.pack({reward = reward, change = change})) return true end function _M.collectRpc(agent , data) local role = agent.role local msg = MsgPack.unpack(data) local id = msg.id local customerData = csvdb["diner_customerCsv"][id] if not id or not customerData then return end local customer = role.dinerData:getProperty("customer") if customer[id] ~= 0 then return end -- 完成前更新一波 后面 加成可能不一样 local sells = json.decode(role.dinerData:getProperty("sells")) for slot, _ in pairs(sells) do role.dinerData:updateSell(slot) end local reward, change = role:award(customerData.reward, {log = {desc = "dinerCollect", int1 = id}}) customer[id] = 1 role.dinerData:updateProperty({field = "customer", value = customer}) -- 解锁了 local count = 0 for c_, v in pairs(customer) do count = count + 1 end role:log("restaurant_collect", { restaurant_collect_id = id, -- 图谱收集ID restaurant_collect_rwd = reward, -- 订单完成奖励,json格式记录,{"itemid1":123,"itemid2":12,……….} restaurant_collect_plan = count, -- 收集进度,即解锁顾客,数字表示 }) role:mylog("diner_action", {desc = "collect", int1 = id}) SendPacket(actionCodes.Diner_collectRpc, MsgPack.pack({reward = reward, change = change})) return true end function _M.comboRewardRpc(agent , data) local role = agent.role local msg = MsgPack.unpack(data) local id = msg.id local comboData = csvdb["diner_customer_comboCsv"][id] if not id or not comboData then return end local comboStatus = role.dinerData:getProperty("comboStatus") if comboStatus[id] == -1 then return end local customer = role.dinerData:getProperty("customer") for _, nId in ipairs(comboData.customer:toArray(true, "=")) do if customer[nId] ~= 1 then return end end comboStatus[id] = 1 local reward, change = role:award(comboData.reward, {log = {desc = "dinerCombo", int1 = id}}) role.dinerData:updateProperty({field = "comboStatus", value = comboStatus}) -- 解锁了 role:mylog("diner_action", {desc = "combo", int1 = id}) SendPacket(actionCodes.Diner_comboRewardRpc, MsgPack.pack({reward = reward, change = change})) return true end return _M