Commit 87cc3a35ee96d7a3b5301fbbd91376612fda8a80
1 parent
a6c04593
餐厅建筑升级逻辑
Showing
8 changed files
with
225 additions
and
32 deletions
Show diff stats
src/ProtocolCode.lua
@@ -57,6 +57,11 @@ actionCodes = { | @@ -57,6 +57,11 @@ actionCodes = { | ||
57 | Hang_getRewardItemRpc = 258, | 57 | Hang_getRewardItemRpc = 258, |
58 | Hang_getRewardCoinRpc = 259, | 58 | Hang_getRewardCoinRpc = 259, |
59 | 59 | ||
60 | + Diner_updateProperty = 300, | ||
61 | + Diner_addSellRpc = 301, | ||
62 | + Diner_getSellRewardRpc = 302, | ||
63 | + Diner_levelUpRpc = 303, | ||
64 | + Diner_talentUpRpc = 304, | ||
60 | } | 65 | } |
61 | 66 | ||
62 | rpcResponseBegin = 10000 | 67 | rpcResponseBegin = 10000 |
src/RedisKeys.lua
1 | - | ||
2 | - | ||
3 | -R_INCR = "role:%d:autoincr" | 1 | +-- role |
2 | +R_INCR = "role:%d:autoincr" | ||
4 | R_HEROS = "role:%d:heroIds" | 3 | R_HEROS = "role:%d:heroIds" |
5 | -R_HERO = "hero:%d:%d" | 4 | +R_HERO = "hero:%d:%d" |
6 | R_DAILY = "role:%d:daily" | 5 | R_DAILY = "role:%d:daily" |
6 | +R_DINER = "role:%d:diner" -- 餐厅 | ||
7 | 7 | ||
8 | -- -- role | 8 | -- -- role |
9 | -- R_FARM_KEY = "role:%d:farm" | 9 | -- R_FARM_KEY = "role:%d:farm" |
@@ -0,0 +1,64 @@ | @@ -0,0 +1,64 @@ | ||
1 | +local ipairs = ipairs | ||
2 | +local table = table | ||
3 | +local math = math | ||
4 | +local redisproxy = redisproxy | ||
5 | +local MsgPack = MsgPack | ||
6 | + | ||
7 | +local _M = {} | ||
8 | + | ||
9 | +function _M.addSellRpc( agent, data ) | ||
10 | + local role = agent.role | ||
11 | + local msg = MsgPack.unpack(data) | ||
12 | + | ||
13 | + local slot = msg.slot | ||
14 | + if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then | ||
15 | + return | ||
16 | + end | ||
17 | + if slot > role.dinerData:getMaxSlots() then | ||
18 | + return | ||
19 | + end | ||
20 | + local dish = msg.dish | ||
21 | + local dishSet = csvdb["diner_dishCsv"][dish] | ||
22 | + if not dishSet then | ||
23 | + return | ||
24 | + end | ||
25 | + local count = msg.count | ||
26 | + if math.illegalNum(count, 1, role.dinerData:getMaxDishs()) then | ||
27 | + return | ||
28 | + end | ||
29 | + | ||
30 | +end | ||
31 | + | ||
32 | +function _M.getSellRewardRpc( agent, data ) | ||
33 | + | ||
34 | +end | ||
35 | + | ||
36 | +function _M.levelUpRpc( agent, data ) | ||
37 | + local role = agent.role | ||
38 | + local msg = MsgPack.unpack(data) | ||
39 | + | ||
40 | + local index = msg.index | ||
41 | + local buildingData = csvdb["diner_buildingCsv"][index] | ||
42 | + if not buildingData then | ||
43 | + return | ||
44 | + end | ||
45 | + | ||
46 | + local buildL = role.dinerData:getProperty("buildL") | ||
47 | + local curLevel = buildL:getv(index, 1) | ||
48 | + if curLevel >= #buildingData then | ||
49 | + return | ||
50 | + end | ||
51 | + | ||
52 | + local cost = buildingData[curLevel].starCost:toNumMap() | ||
53 | + if not role:checkItemEnough(cost) then | ||
54 | + return | ||
55 | + end | ||
56 | + | ||
57 | + role:costItems(cost, {}) | ||
58 | + role.dinerData:updateProperty({field = "level", value = buildL:setv(index, curLevel + 1)}) | ||
59 | + | ||
60 | + SendPacket(actionCodes.Diner_levelUpRpc, '') | ||
61 | + return true | ||
62 | +end | ||
63 | + | ||
64 | +return _M | ||
0 | \ No newline at end of file | 65 | \ No newline at end of file |
src/actions/RoleAction.lua
@@ -123,7 +123,7 @@ function _M.loginRpc( agent, data ) | @@ -123,7 +123,7 @@ function _M.loginRpc( agent, data ) | ||
123 | role:setProperty("ltime", now) | 123 | role:setProperty("ltime", now) |
124 | 124 | ||
125 | 125 | ||
126 | - for _, name in ipairs({"dailyData"}) do | 126 | + for _, name in ipairs({"dailyData", "dinerData"}) do |
127 | response[name] = role[name]:data() | 127 | response[name] = role[name]:data() |
128 | end | 128 | end |
129 | 129 |
src/models/Daily.lua
@@ -7,8 +7,9 @@ function Daily:ctor(properties) | @@ -7,8 +7,9 @@ function Daily:ctor(properties) | ||
7 | end | 7 | end |
8 | 8 | ||
9 | Daily.schema = { | 9 | Daily.schema = { |
10 | - commentHero = {"string", ""}, --单日评论食灵记录 type=1 | ||
11 | - hangQC ={"number", 0}, -- 挂机快速次数 | 10 | + commentHero = {"string", ""}, -- 单日评论食灵记录 type=1 |
11 | + hangQC = {"number", 0}, -- 挂机快速次数 | ||
12 | + dinerQC = {"number", 0}, -- 贩卖加速次数 | ||
12 | } | 13 | } |
13 | 14 | ||
14 | function Daily:updateProperty(params) | 15 | function Daily:updateProperty(params) |
@@ -41,8 +42,8 @@ end | @@ -41,8 +42,8 @@ end | ||
41 | 42 | ||
42 | function Daily:data() | 43 | function Daily:data() |
43 | return { | 44 | return { |
44 | - -- dailyTaskStatus = self:getProperty("dailyTaskStatus"), | ||
45 | hangQC = self:getProperty("hangQC"), | 45 | hangQC = self:getProperty("hangQC"), |
46 | + dinerQC = self:getProperty("dinerQC"), | ||
46 | } | 47 | } |
47 | end | 48 | end |
48 | 49 |
@@ -0,0 +1,108 @@ | @@ -0,0 +1,108 @@ | ||
1 | +local Diner = class("Diner", require("shared.ModelBase")) | ||
2 | + | ||
3 | +function Diner:ctor(properties) | ||
4 | + Diner.super.ctor(self, properties) | ||
5 | +end | ||
6 | + | ||
7 | +Diner.schema = { | ||
8 | + buildL = {"string", ""}, -- 家具等级 1=1 2=1 3=1 | ||
9 | + order = {"string", ""}, -- 特殊订单 | ||
10 | + slots = {"string", ""}, -- 贩卖位置 | ||
11 | + hot = {"string", ""}, -- 今日热门 | ||
12 | + dishTree = {"string", ""}, -- 料理天赋 | ||
13 | + skillTree = {"string", ""}, -- 支援天赋 | ||
14 | +} | ||
15 | + | ||
16 | +function Diner:refreshDailyData(notify) | ||
17 | + -- 热门料理 | ||
18 | + local hotPool = {} | ||
19 | + local dishTree = self:getProperty("dishTree"):toNumMap() | ||
20 | + local hangPass = self.owner:getProperty("hangPass") | ||
21 | + | ||
22 | + for index, dishData in ipairs(csvdb["diner_dishCsv"]) do | ||
23 | + local check = true | ||
24 | + local dish = dishData[1] | ||
25 | + if dish.unlock_tree > 0 and not dishTree[dish.unlock_tree] then | ||
26 | + check = false | ||
27 | + end | ||
28 | + if dish.unlock_carbon > 0 and not hangPass[dish.unlock_carbon] then | ||
29 | + check = false | ||
30 | + end | ||
31 | + if check then | ||
32 | + table.insert(hotPool, index) | ||
33 | + end | ||
34 | + end | ||
35 | + if #hotPool >= 2 then | ||
36 | + local hot = "" | ||
37 | + for n = 1, 2 do | ||
38 | + local index = math.random(1, #hotPool) | ||
39 | + hot = hot:setv(hotPool[index], 1) | ||
40 | + table.remove(hotPool, index) | ||
41 | + end | ||
42 | + self:updateProperty({field = "hot", value = hot, notNotify = not notify}) | ||
43 | + self:setProperty("hot", hot) | ||
44 | + end | ||
45 | + | ||
46 | + -- 特殊订单 | ||
47 | + local order = {} | ||
48 | + | ||
49 | +end | ||
50 | + | ||
51 | +function Diner:updateProperty(params) | ||
52 | + params = params or {} | ||
53 | + if not self.schema[params.field] then | ||
54 | + return | ||
55 | + end | ||
56 | + local oldValue = self:getProperty(params.field) | ||
57 | + if params.value then | ||
58 | + self:setProperty(params.field, params.value) | ||
59 | + elseif params.delta then | ||
60 | + self:incrProperty(params.field, params.delta) | ||
61 | + else | ||
62 | + return | ||
63 | + end | ||
64 | + local newValue = self:getProperty(params.field) | ||
65 | + if not params.notNotify then | ||
66 | + self:notifyUpdateProperty(params.field, newValue, oldValue) | ||
67 | + end | ||
68 | +end | ||
69 | + | ||
70 | +function Diner:notifyUpdateProperty(field, newValue, oldValue) | ||
71 | + local datas = { | ||
72 | + key = field, | ||
73 | + newValue = newValue, | ||
74 | + oldValue = oldValue, | ||
75 | + } | ||
76 | + SendPacket(actionCodes.Diner_updateProperty, MsgPack.pack(datas)) | ||
77 | +end | ||
78 | + | ||
79 | +function Diner:doSell(notify) | ||
80 | + | ||
81 | +end | ||
82 | + | ||
83 | +function Diner:getMaxSlots() | ||
84 | + local slotCount = globalCsv.diner_sell_slots_init | ||
85 | + | ||
86 | + | ||
87 | + return slotCount | ||
88 | +end | ||
89 | + | ||
90 | +function Diner:getMaxDishs() | ||
91 | + local dishCount = globalCsv.diner_sell_dish_init | ||
92 | + | ||
93 | + local buildingCsv = csvdb["diner_buildingCsv"] | ||
94 | + for id, level in pairs(self:getProperty("buildL"):toNumMap()) do | ||
95 | + if buildingCsv[id][level].storage > 0 then | ||
96 | + dishCount = dishCount + buildingCsv[id][level].storage | ||
97 | + end | ||
98 | + end | ||
99 | + return dishCount | ||
100 | +end | ||
101 | + | ||
102 | +function Diner:data() | ||
103 | + local properties = {"buildL", "order", "hot", "dishTree", "skillTree"} | ||
104 | + local data = self:getProperties(properties) | ||
105 | + return data | ||
106 | +end | ||
107 | + | ||
108 | +return Diner | ||
0 | \ No newline at end of file | 109 | \ No newline at end of file |
src/models/Hero.lua
@@ -6,15 +6,15 @@ HeroPlugin.bind(Hero) | @@ -6,15 +6,15 @@ HeroPlugin.bind(Hero) | ||
6 | Hero.schema = { | 6 | Hero.schema = { |
7 | id = {"number"}, | 7 | id = {"number"}, |
8 | type = {"number", 0}, | 8 | type = {"number", 0}, |
9 | - level = {"number", 1}, -- 等级 | ||
10 | - breakL = {"number", 0}, -- 突破等级 | ||
11 | - wakeL = {"number", 0}, -- 觉醒等级 | ||
12 | - skillL = {"string", ""}, -- 技能等级 1=1 2=1 3=1 | ||
13 | - talent = {"string", ""}, -- 0=阶段 1=1 2=1 3=1 4=1 四个天赋当前阶段的等级 阶段默认为1 等级默认为0 | ||
14 | - battleV = {"number", 0}, -- 保存战斗力 | ||
15 | - loveExp = {"number", 0}, --好感度经验 | ||
16 | - loveL = {"number", 0}, --好感度等级 | ||
17 | - skin = {"number", 0}, --皮肤 0 、 1、 2、 3 | 9 | + level = {"number", 1}, -- 等级 |
10 | + breakL = {"number", 0}, -- 突破等级 | ||
11 | + wakeL = {"number", 0}, -- 觉醒等级 | ||
12 | + skillL = {"string", ""}, -- 技能等级 1=1 2=1 3=1 | ||
13 | + talent = {"string", ""}, -- 0=阶段 1=1 2=1 3=1 4=1 四个天赋当前阶段的等级 阶段默认为1 等级默认为0 | ||
14 | + battleV = {"number", 0}, -- 保存战斗力 | ||
15 | + loveExp = {"number", 0}, --好感度经验 | ||
16 | + loveL = {"number", 0}, --好感度等级 | ||
17 | + skin = {"number", 0}, --皮肤 0 、 1、 2、 3 | ||
18 | } | 18 | } |
19 | 19 | ||
20 | function Hero:ctor( properties ) | 20 | function Hero:ctor( properties ) |
@@ -22,18 +22,12 @@ function Hero:ctor( properties ) | @@ -22,18 +22,12 @@ function Hero:ctor( properties ) | ||
22 | end | 22 | end |
23 | 23 | ||
24 | function Hero:notifyUpdateProperty(field, newValue, oldValue) | 24 | function Hero:notifyUpdateProperty(field, newValue, oldValue) |
25 | - local updateData = { | ||
26 | - id = self:getProperty("id"), | ||
27 | - datas = { | ||
28 | - { | ||
29 | - key = field, | ||
30 | - newValue = newValue, | ||
31 | - oldValue = oldValue or "", | ||
32 | - }, | ||
33 | - } | 25 | + local datas = { |
26 | + key = field, | ||
27 | + newValue = newValue, | ||
28 | + oldValue = oldValue, | ||
34 | } | 29 | } |
35 | - | ||
36 | - SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) | 30 | + self:notifyUpdateProperties(datas) |
37 | end | 31 | end |
38 | 32 | ||
39 | function Hero:notifyUpdateProperties(params) | 33 | function Hero:notifyUpdateProperties(params) |
@@ -41,7 +35,6 @@ function Hero:notifyUpdateProperties(params) | @@ -41,7 +35,6 @@ function Hero:notifyUpdateProperties(params) | ||
41 | id = self:getProperty("id"), | 35 | id = self:getProperty("id"), |
42 | datas = params | 36 | datas = params |
43 | } | 37 | } |
44 | - | ||
45 | SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) | 38 | SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) |
46 | end | 39 | end |
47 | 40 |
src/models/RolePlugin.lua
@@ -11,6 +11,7 @@ function RolePlugin.bind(Role) | @@ -11,6 +11,7 @@ function RolePlugin.bind(Role) | ||
11 | function Role:loadAll() | 11 | function Role:loadAll() |
12 | self:loadDaily() | 12 | self:loadDaily() |
13 | self:loadHeros() | 13 | self:loadHeros() |
14 | + self:loadDiner() | ||
14 | end | 15 | end |
15 | 16 | ||
16 | function Role:reloadWhenLogin() | 17 | function Role:reloadWhenLogin() |
@@ -24,6 +25,7 @@ function RolePlugin.bind(Role) | @@ -24,6 +25,7 @@ function RolePlugin.bind(Role) | ||
24 | local response = {} | 25 | local response = {} |
25 | 26 | ||
26 | self.dailyData:refreshDailyData(notify) | 27 | self.dailyData:refreshDailyData(notify) |
28 | + self.dinerData:refreshDailyData(notify) | ||
27 | 29 | ||
28 | if notify then | 30 | if notify then |
29 | self:notifyUpdateProperties(response) | 31 | self:notifyUpdateProperties(response) |
@@ -171,10 +173,18 @@ function RolePlugin.bind(Role) | @@ -171,10 +173,18 @@ function RolePlugin.bind(Role) | ||
171 | 173 | ||
172 | function Role:checkItemEnough(itemCountT) | 174 | function Role:checkItemEnough(itemCountT) |
173 | local less = {} | 175 | local less = {} |
176 | + if not next(itemCountT) then | ||
177 | + return false, less | ||
178 | + end | ||
174 | for itemId, count in pairs(itemCountT) do | 179 | for itemId, count in pairs(itemCountT) do |
175 | - local last = self:getItemCount(itemId) - count | ||
176 | - if last < 0 then | ||
177 | - less[itemId] = -last | 180 | + if count <= 0 then |
181 | + -- 判断物品数量值不应该小于等于0 | ||
182 | + less[itemId] = 0 | ||
183 | + else | ||
184 | + local last = self:getItemCount(itemId) - count | ||
185 | + if last < 0 then | ||
186 | + less[itemId] = -last | ||
187 | + end | ||
178 | end | 188 | end |
179 | end | 189 | end |
180 | return (not next(less)), less -- 是否足够,,缺什么缺多少 | 190 | return (not next(less)), less -- 是否足够,,缺什么缺多少 |
@@ -334,6 +344,18 @@ function RolePlugin.bind(Role) | @@ -334,6 +344,18 @@ function RolePlugin.bind(Role) | ||
334 | end | 344 | end |
335 | end | 345 | end |
336 | 346 | ||
347 | + function Role:loadDiner() | ||
348 | + local roleId = self:getProperty("id") | ||
349 | + local dataKey = string.format(R_DINER, roleId) | ||
350 | + self.dinerData = require("models.Diner").new({key = dataKey}) | ||
351 | + self.dinerData.owner = self | ||
352 | + if not redisproxy:exists(dataKey) then | ||
353 | + self.dinerData:create() | ||
354 | + else | ||
355 | + self.dinerData:load() | ||
356 | + end | ||
357 | + end | ||
358 | + | ||
337 | function Role:getAdvData() | 359 | function Role:getAdvData() |
338 | if not self.advData then | 360 | if not self.advData then |
339 | self.advData = require("adv.Adv").new(self) | 361 | self.advData = require("adv.Adv").new(self) |