From 37037eebce759fd4a355508ad01a73716de6ee58 Mon Sep 17 00:00:00 2001 From: zhengshouren <448949750@qq.com> Date: Thu, 23 May 2019 21:10:55 +0800 Subject: [PATCH] 计算奖励 --- skynet | 2 +- src/GlobalVar.lua | 2 +- src/actions/DinerAction.lua | 2 ++ src/actions/HangAction.lua | 1 + src/csvdata | 2 +- src/main.lua | 4 ++-- src/models/Diner.lua | 71 +++++++++++++++++++++++++++++++++++++++++++++-------------------------- src/models/Role.lua | 1 + 8 files changed, 54 insertions(+), 31 deletions(-) diff --git a/skynet b/skynet index 99bfdd1..dce5314 160000 --- a/skynet +++ b/skynet @@ -1 +1 @@ -Subproject commit 99bfdd1307c6d1747124b4d614ca55d6830f34aa +Subproject commit dce531485f84bb7a555e9bb35b22c58fb469192c diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 0f02f59..0a1346e 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -58,7 +58,7 @@ ItemId = { PlayerExp = 4, -- 突破材料 BreakCost = 10, -- 突破材料 EquipUp = 11, -- 装备升级材料 - SupSkillUp = 12, --支援技升级材料 + DinerCoin = 12, --后勤物资 LoveUp = 14, --好感度提升道具 LoveBreak = 21, --好感度突破道具 BoxKey = 20, -- 开箱钥匙 diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index c4b528e..6fcd765 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -59,6 +59,8 @@ function _M.addSellRpc( agent, data ) level = dishLevel, reward = {}, count = 0, + reward = "", + famous = 0, } end local sell = sells[slot] diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index 1006e0a..07b5930 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -193,6 +193,7 @@ end function _M.roleFormatRpc(agent , data) local role = agent.role local msg = MsgPack.unpack(data) + dump(msg) local hangTeam = role:getProperty("hangTeam") for slot, heroId in pairs(msg.heros) do if not role.heros[heroId] then diff --git a/src/csvdata b/src/csvdata index d3aeaae..a877f94 160000 --- a/src/csvdata +++ b/src/csvdata @@ -1 +1 @@ -Subproject commit d3aeaaee05774f52eb0a42f851adf90978fed324 +Subproject commit a877f94b084a3571e2f3d57e4997fd00c0a51eaf diff --git a/src/main.lua b/src/main.lua index d72eed9..f8318ef 100644 --- a/src/main.lua +++ b/src/main.lua @@ -15,8 +15,8 @@ skynet.start(function() ngxd = ngxd, redishost = "127.0.0.1", - redisport = 6100, - redisdb = 1, + redisport = 6379, + redisdb = 10, auth = nil, mongohost = "127.0.0.1", diff --git a/src/models/Diner.lua b/src/models/Diner.lua index ac719ce..3407bfb 100644 --- a/src/models/Diner.lua +++ b/src/models/Diner.lua @@ -76,6 +76,47 @@ function Diner:notifyUpdateProperty(field, newValue, oldValue) SendPacket(actionCodes.Diner_updateProperty, MsgPack.pack(datas)) end +local function calSellReward(sell, delta, dishData) + local reward = sell.reward or "" + local famous = sell.famous or 0 + if delta <= 0 then + return reward, famous + end + for type, value in pairs(dishData.item_normal:toNumMap()) do + reward = reward:incrv(type, value * delta) + end + famous = famous + dishData.famous_normal * delta + if sell.hot > 0 then + for type, value in pairs(dishData.item_popular:toNumMap()) do + reward = reward:incrv(type, value * delta) + end + famous = famous + dishData.famous_popular * delta + end + + for buildType = 1, 6 do + local level = self:getProperty("buildL"):getv(buildType, 1) + local buildData = csvdb["diner_buildingCsv"][buildType][level] + if buildData.gold_up > 0 then + local value = reward:getv(ItemId.Gold, 0) + value = math.floor(value * (100 + buildData.gold_up) / 100) + if value > 0 then + reward = reward:setv(ItemId.Gold, value) + end + end + if buildData.item_up > 0 then + local value = reward:getv(ItemId.DinerCoin, 0) + value = math.floor(value * (100 + buildData.item_up) / 100) + if value > 0 then + reward = reward:setv(ItemId.DinerCoin, value) + end + end + if buildData and buildData.famous_up > 0 then + famous = math.floor(famous * (100 + buildData.famous_up) / 100) + end + end + return reward, famous +end + function Diner:updateSell(slot, calOnly) local sells = json.decode(self:getProperty("sells")) local sell = sells[slot] @@ -88,9 +129,7 @@ function Diner:updateSell(slot, calOnly) local deltaCount = 0 local timePass = skynet.timex() - sell.time local sellTime = dishData.sell_time - if self:getProperty("hot"):getv(sell.dish, 0) > 0 then - sellTime = sellTime * 1.5 - end + deltaCount = math.floor(timePass / sellTime) if deltaCount < sell.count then deltaTime = math.floor(timePass - sellTime * deltaCount) @@ -99,33 +138,13 @@ function Diner:updateSell(slot, calOnly) local lastCount = sell.count - deltaCount if not calOnly then - local reward = {} - if deltaCount > 0 then - local tmp = dishData.item_normal:toNumMap() - if sell.hot then - for k,v in pairs(dishData.item_popular:toNumMap()) do - if tmp[k] then - tmp[k] = tmp[k] + v - else - tmp[k] = v - end - end - end - - for k, n in pairs(tmp) do - local sum = n*deltaCount - if reward[tostring(k)] then - reward[tostring(k)] = reward[tostring(k)] + sum - else - reward[tostring(k)] = sum - end - end - end - + local reward, famous = self:calSellReward(sell, deltaCount, dishData) sell.time = skynet.timex() - deltaTime sell.count = lastCount sell.level = self:getProperty("dishTree"):getv(sell.dish, 1) + sell.hot = self:getProperty("hot"):getv(sell.dish, 0) sell.reward = reward + sell.famous = famous self:setProperty("sells", json.encode(sells)) end return { diff --git a/src/models/Role.lua b/src/models/Role.lua index 3586f77..9b514ec 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -35,6 +35,7 @@ Role.schema = { exp = {"number", 0}, items = {"string", ""}, loveStatus = {"string", ""}, --统计角色的最高 好感度等级 类型相关 -- type=loveL type=loveL + crown = {"number", 0}, -- 看伴娘 bagLimit = {"table", globalCsv.store_limit_max}, -- libgit2 0.21.2