Commit 36204e3cf3a6005f1d45c66caf74292ce325888a
1 parent
21419c7b
贩卖逻辑
Showing
6 changed files
with
100 additions
and
20 deletions
Show diff stats
src/actions/DinerAction.lua
@@ -14,19 +14,62 @@ function _M.addSellRpc( agent, data ) | @@ -14,19 +14,62 @@ function _M.addSellRpc( agent, data ) | ||
14 | if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then | 14 | if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then |
15 | return | 15 | return |
16 | end | 16 | end |
17 | - if slot > role.dinerData:getMaxSlots() then | ||
18 | - return | ||
19 | - end | 17 | + slot = tostring(slot) |
18 | + | ||
20 | local dish = msg.dish | 19 | local dish = msg.dish |
21 | local dishSet = csvdb["diner_dishCsv"][dish] | 20 | local dishSet = csvdb["diner_dishCsv"][dish] |
22 | if not dishSet then | 21 | if not dishSet then |
23 | return | 22 | return |
24 | end | 23 | end |
24 | + local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0) | ||
25 | + if dishLevel == 0 then | ||
26 | + return | ||
27 | + end | ||
28 | + local dishData = dishSet[dishLevel] | ||
29 | + if not dishData then | ||
30 | + return | ||
31 | + end | ||
32 | + | ||
33 | + local calSell = role.dinerData:updateSell(slot, true) or { | ||
34 | + deltaCount = 0, | ||
35 | + deltaTime = 0, | ||
36 | + lastCount = 0, | ||
37 | + } | ||
25 | local count = msg.count | 38 | local count = msg.count |
26 | - if math.illegalNum(count, 1, role.dinerData:getMaxDishs()) then | 39 | + local maxDishCount = role.dinerData:getMaxDishs() |
40 | + if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then | ||
27 | return | 41 | return |
28 | end | 42 | end |
29 | 43 | ||
44 | + local cost = dishData.material:toNumMap() | ||
45 | + for _, n in pairs(cost) do | ||
46 | + n = n * count | ||
47 | + end | ||
48 | + if not role:checkItemEnough(cost) then | ||
49 | + return | ||
50 | + end | ||
51 | + | ||
52 | + role:costItems(cost) | ||
53 | + role.dinerData:updateSell(slot) | ||
54 | + | ||
55 | + local sells = json.decode(role.dinerData:getProperty("sells")) | ||
56 | + if not sells[slot] then | ||
57 | + sells[slot] = { | ||
58 | + dish = dish, | ||
59 | + level = dishLevel, | ||
60 | + reward = "", | ||
61 | + count = 0, | ||
62 | + } | ||
63 | + end | ||
64 | + local sell = sells[slot] | ||
65 | + sell.count = sell.count + count | ||
66 | + sell.time = skynet.timex() - calSell.deltaTime | ||
67 | + sell.hot = role.dinerData:getProperty("hot"):getv(sell.dish, 0) | ||
68 | + | ||
69 | + role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) | ||
70 | + SendPacket(actionCodes.Diner_addSellRpc, "") | ||
71 | + | ||
72 | + return true | ||
30 | end | 73 | end |
31 | 74 | ||
32 | function _M.getSellRewardRpc( agent, data ) | 75 | function _M.getSellRewardRpc( agent, data ) |
@@ -54,7 +97,7 @@ function _M.levelUpRpc( agent, data ) | @@ -54,7 +97,7 @@ function _M.levelUpRpc( agent, data ) | ||
54 | return | 97 | return |
55 | end | 98 | end |
56 | 99 | ||
57 | - role:costItems(cost, {}) | 100 | + role:costItems(cost) |
58 | role.dinerData:updateProperty({field = "level", value = buildL:setv(index, curLevel + 1)}) | 101 | role.dinerData:updateProperty({field = "level", value = buildL:setv(index, curLevel + 1)}) |
59 | 102 | ||
60 | SendPacket(actionCodes.Diner_levelUpRpc, '') | 103 | SendPacket(actionCodes.Diner_levelUpRpc, '') |
src/actions/HangAction.lua
@@ -289,7 +289,7 @@ function _M.quickRpc(agent , data) | @@ -289,7 +289,7 @@ function _M.quickRpc(agent , data) | ||
289 | if not costs[curCount] then return end | 289 | if not costs[curCount] then return end |
290 | if costs[curCount] > 0 then | 290 | if costs[curCount] > 0 then |
291 | if not role:checkItemEnough({[ItemId.Diamond] = costs[curCount]}) then return end | 291 | if not role:checkItemEnough({[ItemId.Diamond] = costs[curCount]}) then return end |
292 | - role:costItems({[ItemId.Diamond] = costs[curCount]}, {}) | 292 | + role:costItems({[ItemId.Diamond] = costs[curCount]}) |
293 | end | 293 | end |
294 | 294 | ||
295 | role.dailyData:updateProperty({field = "hangQC", value = curCount}) | 295 | role.dailyData:updateProperty({field = "hangQC", value = curCount}) |
src/actions/HeroAction.lua
@@ -25,7 +25,7 @@ function _M.levelUpRpc( agent, data ) | @@ -25,7 +25,7 @@ function _M.levelUpRpc( agent, data ) | ||
25 | local curData = csvdb["unit_expCsv"][hero:getProperty("level")] | 25 | local curData = csvdb["unit_expCsv"][hero:getProperty("level")] |
26 | local cost = {[ItemId.Exp] = curData.exp, [ItemId.Gold] = curData.gold} | 26 | local cost = {[ItemId.Exp] = curData.exp, [ItemId.Gold] = curData.gold} |
27 | if not role:checkItemEnough(cost) then return end | 27 | if not role:checkItemEnough(cost) then return end |
28 | - role:costItems(cost, {}) | 28 | + role:costItems(cost) |
29 | hero:updateProperty({field = "level", delta = 1}) | 29 | hero:updateProperty({field = "level", delta = 1}) |
30 | 30 | ||
31 | SendPacket(actionCodes.Hero_levelUpRpc, '') | 31 | SendPacket(actionCodes.Hero_levelUpRpc, '') |
@@ -43,7 +43,7 @@ function _M.breakRpc( agent, data ) | @@ -43,7 +43,7 @@ function _M.breakRpc( agent, data ) | ||
43 | local curData = csvdb["unit_breakCsv"][hero:getProperty("breakL")] | 43 | local curData = csvdb["unit_breakCsv"][hero:getProperty("breakL")] |
44 | local cost = {[ItemId.BreakCost] = curData.cost, [ItemId.Gold] = curData.gold} | 44 | local cost = {[ItemId.BreakCost] = curData.cost, [ItemId.Gold] = curData.gold} |
45 | if not role:checkItemEnough(cost) then return end | 45 | if not role:checkItemEnough(cost) then return end |
46 | - role:costItems(cost, {}) | 46 | + role:costItems(cost) |
47 | hero:updateProperty({field = "breakL", delta = 1}) | 47 | hero:updateProperty({field = "breakL", delta = 1}) |
48 | 48 | ||
49 | SendPacket(actionCodes.Hero_breakRpc, '') | 49 | SendPacket(actionCodes.Hero_breakRpc, '') |
@@ -62,7 +62,7 @@ function _M.wakeRpc(agent, data) | @@ -62,7 +62,7 @@ function _M.wakeRpc(agent, data) | ||
62 | cost[ItemId.HeroFC[csvdb["unitCsv"][hero:getProperty("type")].rare]] = less[hero:getProperty("type")] | 62 | cost[ItemId.HeroFC[csvdb["unitCsv"][hero:getProperty("type")].rare]] = less[hero:getProperty("type")] |
63 | if not role:checkItemEnough(cost) then return end | 63 | if not role:checkItemEnough(cost) then return end |
64 | end | 64 | end |
65 | - role:costItems(cost, {}) | 65 | + role:costItems(cost) |
66 | hero:updateProperty({field = "wakeL", delta = 1}) | 66 | hero:updateProperty({field = "wakeL", delta = 1}) |
67 | 67 | ||
68 | SendPacket(actionCodes.Hero_wakeRpc, '') | 68 | SendPacket(actionCodes.Hero_wakeRpc, '') |
@@ -113,7 +113,7 @@ function _M.talentRpc(agent, data) | @@ -113,7 +113,7 @@ function _M.talentRpc(agent, data) | ||
113 | end | 113 | end |
114 | 114 | ||
115 | if not role:checkItemEnough(cost) then return end | 115 | if not role:checkItemEnough(cost) then return end |
116 | - role:costItems(cost, {}) | 116 | + role:costItems(cost) |
117 | talent = talent:incrv(index, 1) | 117 | talent = talent:incrv(index, 1) |
118 | 118 | ||
119 | --是否进阶 | 119 | --是否进阶 |
@@ -424,7 +424,7 @@ function _M.createHeroRpc(agent, data) | @@ -424,7 +424,7 @@ function _M.createHeroRpc(agent, data) | ||
424 | if hero:getProperty("type") == heroType then return end | 424 | if hero:getProperty("type") == heroType then return end |
425 | end | 425 | end |
426 | 426 | ||
427 | - role:costItems({[heroType] = cost}, {}) | 427 | + role:costItems({[heroType] = cost}) |
428 | role:award({[heroType + ItemStartId.Hero] = 1}, {}) | 428 | role:award({[heroType + ItemStartId.Hero] = 1}, {}) |
429 | 429 | ||
430 | SendPacket(actionCodes.Hero_createHeroRpc, "") | 430 | SendPacket(actionCodes.Hero_createHeroRpc, "") |
src/actions/RoleAction.lua
@@ -256,7 +256,7 @@ function _M.saleItemRpc(agent, data) | @@ -256,7 +256,7 @@ function _M.saleItemRpc(agent, data) | ||
256 | if itemData.sell_effect == "" then return end | 256 | if itemData.sell_effect == "" then return end |
257 | local sellEffect = itemData.sell_effect:toArray(true, "=") | 257 | local sellEffect = itemData.sell_effect:toArray(true, "=") |
258 | 258 | ||
259 | - role:costItems({[itemId] = count}, {}) | 259 | + role:costItems({[itemId] = count}) |
260 | local reward = role:award({[sellEffect[1]] = sellEffect[2] * count}, {}) | 260 | local reward = role:award({[sellEffect[1]] = sellEffect[2] * count}, {}) |
261 | 261 | ||
262 | SendPacket(actionCodes.Role_saleItemRpc, MsgPack.pack({reward = reward})) | 262 | SendPacket(actionCodes.Role_saleItemRpc, MsgPack.pack({reward = reward})) |
@@ -292,7 +292,7 @@ function _M.openItemRpc(agent, data) | @@ -292,7 +292,7 @@ function _M.openItemRpc(agent, data) | ||
292 | end | 292 | end |
293 | end | 293 | end |
294 | end | 294 | end |
295 | - role:costItems({[itemId] = count}, {}) | 295 | + role:costItems({[itemId] = count}) |
296 | reward = role:award(reward, {}) | 296 | reward = role:award(reward, {}) |
297 | 297 | ||
298 | SendPacket(actionCodes.Role_openItemRpc, MsgPack.pack({reward = reward})) | 298 | SendPacket(actionCodes.Role_openItemRpc, MsgPack.pack({reward = reward})) |
src/models/Diner.lua
@@ -6,10 +6,10 @@ end | @@ -6,10 +6,10 @@ end | ||
6 | 6 | ||
7 | Diner.schema = { | 7 | Diner.schema = { |
8 | buildL = {"string", ""}, -- 家具等级 1=1 2=1 3=1 | 8 | buildL = {"string", ""}, -- 家具等级 1=1 2=1 3=1 |
9 | - order = {"string", ""}, -- 特殊订单 | ||
10 | - slots = {"string", ""}, -- 贩卖位置 | 9 | + order = {"string", "[]"}, -- 特殊订单 |
10 | + sells = {"string", "[]"}, -- 贩卖位置 | ||
11 | hot = {"string", ""}, -- 今日热门 | 11 | hot = {"string", ""}, -- 今日热门 |
12 | - dishTree = {"string", ""}, -- 料理天赋 | 12 | + dishTree = {"string", "1=1 2=1 3=1"}, -- 料理天赋 |
13 | skillTree = {"string", ""}, -- 支援天赋 | 13 | skillTree = {"string", ""}, -- 支援天赋 |
14 | } | 14 | } |
15 | 15 | ||
@@ -76,13 +76,51 @@ function Diner:notifyUpdateProperty(field, newValue, oldValue) | @@ -76,13 +76,51 @@ function Diner:notifyUpdateProperty(field, newValue, oldValue) | ||
76 | SendPacket(actionCodes.Diner_updateProperty, MsgPack.pack(datas)) | 76 | SendPacket(actionCodes.Diner_updateProperty, MsgPack.pack(datas)) |
77 | end | 77 | end |
78 | 78 | ||
79 | -function Diner:doSell(notify) | ||
80 | - | 79 | +function Diner:updateSell(slot, calOnly) |
80 | + local sells = json.decode(self:getProperty("sells")) | ||
81 | + local sell = sells[slot] | ||
82 | + if not sell or sell.count <= 0 then | ||
83 | + return | ||
84 | + end | ||
85 | + local dishData = csvdb["diner_dishCsv"][sell.dish][sell.level] | ||
86 | + | ||
87 | + local deltaTime = 0 | ||
88 | + local deltaCount = 0 | ||
89 | + local timePass = skynet.timex() - sell.time | ||
90 | + local sellTime = dishData.sell_time | ||
91 | + if self:getProperty("hot"):getv(sell.dish, 0) > 0 then | ||
92 | + sellTime = sellTime * 1.5 | ||
93 | + end | ||
94 | + deltaCount = math.floor(timePass / sellTime) | ||
95 | + if deltaCount < sell.count then | ||
96 | + deltaTime = math.floor(timePass - sellTime * deltaCount) | ||
97 | + end | ||
98 | + deltaCount = math.min(deltaCount, sell.count) | ||
99 | + local lastCount = sell.count - deltaCount | ||
100 | + | ||
101 | + if not calOnly then | ||
102 | + sell.time = skynet.timex() - deltaTime | ||
103 | + sell.count = lastCount | ||
104 | + sell.level = self:getProperty("dishTree"):getv(sell.dish, 1) | ||
105 | + | ||
106 | + self:setProperty("sells", json.encode(sells)) | ||
107 | + end | ||
108 | + return { | ||
109 | + deltaCount = deltaCount, | ||
110 | + deltaTime = deltaTime, | ||
111 | + lastCount = lastCount, | ||
112 | + } | ||
81 | end | 113 | end |
82 | 114 | ||
83 | function Diner:getMaxSlots() | 115 | function Diner:getMaxSlots() |
84 | local slotCount = globalCsv.diner_sell_slots_init | 116 | local slotCount = globalCsv.diner_sell_slots_init |
85 | 117 | ||
118 | + local hangPass = self.owner:getProperty("hangPass") | ||
119 | + for _, carbonId in ipairs(globalCsv.diner_sell_slots_unlock) do | ||
120 | + if hangPass[carbonId] then | ||
121 | + slotCount = slotCount + 1 | ||
122 | + end | ||
123 | + end | ||
86 | 124 | ||
87 | return slotCount | 125 | return slotCount |
88 | end | 126 | end |
src/models/RolePlugin.lua
@@ -191,8 +191,8 @@ function RolePlugin.bind(Role) | @@ -191,8 +191,8 @@ function RolePlugin.bind(Role) | ||
191 | end | 191 | end |
192 | 192 | ||
193 | function Role:costItems(itemCountT, params) | 193 | function Role:costItems(itemCountT, params) |
194 | + local pms = clone(params or {}) | ||
194 | if itemCountT[ItemId.Diamond] then --优先扣除钻石 | 195 | if itemCountT[ItemId.Diamond] then --优先扣除钻石 |
195 | - local pms = clone(params or {}) | ||
196 | pms.count = itemCountT[ItemId.Diamond] | 196 | pms.count = itemCountT[ItemId.Diamond] |
197 | if not self:costDiamond(pms) then | 197 | if not self:costDiamond(pms) then |
198 | return | 198 | return |
@@ -200,7 +200,6 @@ function RolePlugin.bind(Role) | @@ -200,7 +200,6 @@ function RolePlugin.bind(Role) | ||
200 | itemCountT[ItemId.Diamond] = nil | 200 | itemCountT[ItemId.Diamond] = nil |
201 | end | 201 | end |
202 | for itemId, count in pairs(itemCountT) do | 202 | for itemId, count in pairs(itemCountT) do |
203 | - local pms = clone(params or {}) | ||
204 | pms.itemId = itemId | 203 | pms.itemId = itemId |
205 | pms.count = - count | 204 | pms.count = - count |
206 | self:addItem(pms) | 205 | self:addItem(pms) |