Commit ed322ed236b8d4e4a901889198835e653a8ce539
1 parent
3847ba2d
餐厅 顾客 系统
Showing
3 changed files
with
220 additions
and
15 deletions
Show diff stats
src/ProtocolCode.lua
@@ -115,6 +115,8 @@ actionCodes = { | @@ -115,6 +115,8 @@ actionCodes = { | ||
115 | Diner_initTaskRpc = 313, | 115 | Diner_initTaskRpc = 313, |
116 | Diner_handleTaskRpc = 314, | 116 | Diner_handleTaskRpc = 314, |
117 | Diner_rankRpc = 315, | 117 | Diner_rankRpc = 315, |
118 | + Diner_entrustRpc = 316, | ||
119 | + Diner_collectRpc = 317, | ||
118 | 120 | ||
119 | Tower_roleFormatRpc = 350, | 121 | Tower_roleFormatRpc = 350, |
120 | Tower_startBattleRpc = 351, | 122 | Tower_startBattleRpc = 351, |
src/actions/DinerAction.lua
@@ -74,6 +74,37 @@ function _M.addSellRpc( agent, data ) | @@ -74,6 +74,37 @@ function _M.addSellRpc( agent, data ) | ||
74 | sells[slot].level = dishLevel | 74 | sells[slot].level = dishLevel |
75 | sells[slot].count = count | 75 | sells[slot].count = count |
76 | sells[slot].time = skynet.timex() - calSell.deltaTime | 76 | sells[slot].time = skynet.timex() - calSell.deltaTime |
77 | + | ||
78 | + -- 检查解锁的顾客 | ||
79 | + local had = {} | ||
80 | + for _, sell in pairs(sells) do | ||
81 | + if sell.dish then | ||
82 | + had[sell.dish] = sell.level | ||
83 | + end | ||
84 | + end | ||
85 | + | ||
86 | + local customer = self.dinerData:getProperty("customer") | ||
87 | + local change = false | ||
88 | + for cId, cData in pairs(csvdb["diner_customerCsv"]) do | ||
89 | + if not customer[cId] then | ||
90 | + local unlock = true | ||
91 | + for needId, lv in pairs(cData.unlock:toNumMap()) do | ||
92 | + if not had[needId] or had[needId] < lv then | ||
93 | + unlock = false | ||
94 | + break | ||
95 | + end | ||
96 | + end | ||
97 | + if unlock then | ||
98 | + change = true | ||
99 | + customer[cId] = 0 | ||
100 | + end | ||
101 | + end | ||
102 | + end | ||
103 | + | ||
104 | + if change then | ||
105 | + role.dinerData:updateProperty({field = "customer", value = customer}) | ||
106 | + end | ||
107 | + | ||
77 | role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) | 108 | role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) |
78 | SendPacket(actionCodes.Diner_addSellRpc, "") | 109 | SendPacket(actionCodes.Diner_addSellRpc, "") |
79 | return true | 110 | return true |
@@ -713,5 +744,94 @@ function _M.rankRpc(agent , data) | @@ -713,5 +744,94 @@ function _M.rankRpc(agent , data) | ||
713 | return true | 744 | return true |
714 | end | 745 | end |
715 | 746 | ||
747 | +function _M.entrustRpc(agent , data) | ||
748 | + local role = agent.role | ||
749 | + local msg = MsgPack.unpack(data) | ||
750 | + | ||
751 | + local ctype = msg.ctype | ||
752 | + | ||
753 | + local entrust = role.dinerData:getProperty("entrust") | ||
754 | + if not entrust[1] then return end | ||
755 | + | ||
756 | + local reward | ||
757 | + if ctype == 1 then -- 完成 | ||
758 | + local curData = csvdb["diner_missionCsv"][entrust[1]] | ||
759 | + if not curData then return end | ||
760 | + | ||
761 | + if curData.type == 1 then | ||
762 | + local cost = curData.condition:toNumMap() | ||
763 | + if not role:checkItemEnough(cost) then return end | ||
764 | + role:costItems(cost) | ||
765 | + elseif curData.type == 2 then | ||
766 | + -- todo 数据校验 | ||
767 | + else | ||
768 | + return | ||
769 | + end | ||
770 | + | ||
771 | + reward = role:award(curData.reward) | ||
772 | + elseif ctype == 2 then -- 放弃 | ||
773 | + table.remove(entrust, 1) | ||
774 | + else | ||
775 | + return | ||
776 | + end | ||
777 | + role.dinerData:updateProperty({field = "entrust", value = entrust}) | ||
778 | + | ||
779 | + SendPacket(actionCodes.Diner_entrustRpc, MsgPack.pack({reward = reward})) | ||
780 | + return true | ||
781 | +end | ||
782 | + | ||
783 | +function _M.collectRpc(agent , data) | ||
784 | + local role = agent.role | ||
785 | + local msg = MsgPack.unpack(data) | ||
786 | + | ||
787 | + local id = msg.id | ||
788 | + if not id or not csvdb["diner_customerCsv"][id] then return end | ||
789 | + local customer = role.dinerData:getProperty("customer") | ||
790 | + if customer[id] ~= 0 then | ||
791 | + return | ||
792 | + end | ||
793 | + | ||
794 | + -- 完成前更新一波 后面 加成可能不一样 | ||
795 | + local sells = json.decode(role.dinerData:getProperty("sells")) | ||
796 | + for slot, _ in pairs(sells) do | ||
797 | + role.dinerData:updateSell(slot) | ||
798 | + end | ||
799 | + | ||
800 | + customer[id] = 1 | ||
801 | + role.dinerData:updateProperty({field = "customer", value = customer}) -- 解锁了 | ||
802 | + | ||
803 | + SendPacket(actionCodes.Diner_collectRpc, '') | ||
804 | + return true | ||
805 | +end | ||
806 | + | ||
807 | +function _M.comboRewardRpc(agent , data) | ||
808 | + local role = agent.role | ||
809 | + local msg = MsgPack.unpack(data) | ||
810 | + | ||
811 | + local id = msg.id | ||
812 | + | ||
813 | + local comboData = csvdb["diner_customer_comboCsv"][id] | ||
814 | + if not id or not comboData then return end | ||
815 | + local comboStatus = role.dinerData:getProperty("comboStatus") | ||
816 | + if comboStatus[id] == -1 then return end | ||
817 | + | ||
818 | + local customer = role.dinerData:getProperty("customer") | ||
819 | + | ||
820 | + for _, nId in ipairs(comboData.customer:toArray(true, "=")) do | ||
821 | + if customer[nId] ~= 1 then | ||
822 | + return | ||
823 | + end | ||
824 | + end | ||
825 | + | ||
826 | + comboStatus[id] = 1 | ||
827 | + role:award(comboData.reward) | ||
828 | + | ||
829 | + role.dinerData:updateProperty({field = "comboStatus", value = comboStatus}) -- 解锁了 | ||
830 | + | ||
831 | + SendPacket(actionCodes.Diner_comboRewardRpc, '') | ||
832 | + return true | ||
833 | +end | ||
834 | + | ||
835 | + | ||
716 | 836 | ||
717 | return _M | 837 | return _M |
718 | \ No newline at end of file | 838 | \ No newline at end of file |
src/models/Diner.lua
@@ -14,6 +14,10 @@ Diner.schema = { | @@ -14,6 +14,10 @@ Diner.schema = { | ||
14 | expedite = {"number",1}, --每日加速次数 | 14 | expedite = {"number",1}, --每日加速次数 |
15 | gfood = {"table", {}}, -- 愿望食材 {{id = 123, st = 1232144},} | 15 | gfood = {"table", {}}, -- 愿望食材 {{id = 123, st = 1232144},} |
16 | task = {"table", {}}, -- 任务刷新 {et = 消失时间 id = 任务id, refuse = 0} | 16 | task = {"table", {}}, -- 任务刷新 {et = 消失时间 id = 任务id, refuse = 0} |
17 | + entrustB = {"table", {}}, -- 委托完成过的记录 {id = 1} | ||
18 | + entrust = {"table", {}}, -- 委托 {id, id, id} | ||
19 | + customer = {"table", {}}, -- 解锁的顾客 {id = 1} -- 1 (已解锁) 0(达成条件 可解锁 服务器用) | ||
20 | + comboStatus = {"table", {}}, -- 组合领取奖励状态 {id = -1} --有表示已经领取奖励 | ||
17 | } | 21 | } |
18 | 22 | ||
19 | function Diner:rankResetData(notify) | 23 | function Diner:rankResetData(notify) |
@@ -21,9 +25,55 @@ function Diner:rankResetData(notify) | @@ -21,9 +25,55 @@ function Diner:rankResetData(notify) | ||
21 | end | 25 | end |
22 | 26 | ||
23 | function Diner:refreshDailyData(notify) | 27 | function Diner:refreshDailyData(notify) |
28 | + | ||
29 | + -- 委托 | ||
30 | + local entrust = self:getProperty("entrust") | ||
31 | + local hangPass = self.owner:getProperty("hangPass") | ||
32 | + local entrustB = self:getProperty("entrustB") | ||
33 | + local had = {} | ||
34 | + local pool = {} | ||
35 | + local change = false | ||
36 | + for i = 1, 3 do | ||
37 | + if not entrust[i] then | ||
38 | + if not next(pool) then | ||
39 | + for id, data in pairs(csvdb["diner_missionCsv"]) do | ||
40 | + local show = true | ||
41 | + if data.show ~= "" then | ||
42 | + -- 不填=默认刷出,1=达成前置任务,2=通关关卡 | ||
43 | + local showC = data.show:toArray(true, "=") | ||
44 | + if showC[1] == 1 then | ||
45 | + if not hangPass[showC[2]] then | ||
46 | + show = false | ||
47 | + end | ||
48 | + elseif showC[1] == 2 then | ||
49 | + if not entrustB[showC[2]] then | ||
50 | + show = false | ||
51 | + end | ||
52 | + end | ||
53 | + end | ||
54 | + if show then | ||
55 | + table.insert(pool, id) | ||
56 | + end | ||
57 | + end | ||
58 | + end | ||
59 | + | ||
60 | + if #pool > 0 then | ||
61 | + local idx = math.randomInt(1, #pool) | ||
62 | + entrust[i] = pool[idx] | ||
63 | + change = true | ||
64 | + table.remove(pool, idx) | ||
65 | + end | ||
66 | + if not next(pool) then | ||
67 | + break | ||
68 | + end | ||
69 | + else | ||
70 | + had[entrust[i]] = 1 | ||
71 | + end | ||
72 | + end | ||
73 | + self:updateProperty({field = "entrust", value = entrust, notNotify = not notify}) | ||
74 | + | ||
24 | -- 每日加速次数 | 75 | -- 每日加速次数 |
25 | self:updateProperty({field = "expedite", value = 1, notNotify = not notify}) | 76 | self:updateProperty({field = "expedite", value = 1, notNotify = not notify}) |
26 | - self:setProperty("expedite", 1) | ||
27 | -- 特殊订单 | 77 | -- 特殊订单 |
28 | local orders = json.decode(self:getProperty("order")) | 78 | local orders = json.decode(self:getProperty("order")) |
29 | local hadTask = {} | 79 | local hadTask = {} |
@@ -118,32 +168,52 @@ function Diner:calSellReward(sell, delta, dishData) | @@ -118,32 +168,52 @@ function Diner:calSellReward(sell, delta, dishData) | ||
118 | if delta <= 0 then | 168 | if delta <= 0 then |
119 | return reward, popular | 169 | return reward, popular |
120 | end | 170 | end |
171 | + local addReward = {} | ||
121 | for key, value in pairs(dishData.item_normal:toNumMap()) do | 172 | for key, value in pairs(dishData.item_normal:toNumMap()) do |
122 | - reward = reward:incrv(key, value * delta) | 173 | + addReward[key] = (addReward[key] or 0) + value * delta |
123 | end | 174 | end |
124 | - popular = popular + dishData.famous_normal * delta | ||
125 | 175 | ||
176 | + popular = dishData.famous_normal * delta | ||
177 | + | ||
178 | + local upValue = {} | ||
179 | + -- 建筑加成 | ||
126 | for buildType = 1, 6 do | 180 | for buildType = 1, 6 do |
127 | local level = self:getProperty("buildL"):getv(buildType, 1) | 181 | local level = self:getProperty("buildL"):getv(buildType, 1) |
128 | local buildData = csvdb["diner_buildingCsv"][buildType][level] | 182 | local buildData = csvdb["diner_buildingCsv"][buildType][level] |
129 | if buildData.gold_up > 0 then | 183 | if buildData.gold_up > 0 then |
130 | - local value = reward:getv(ItemId.Gold, 0) | ||
131 | - value = math.floor(value * (100 + buildData.gold_up) / 100) | ||
132 | - if value > 0 then | ||
133 | - reward = reward:setv(ItemId.Gold, value) | ||
134 | - end | 184 | + upValue[ItemId.Gold] = (upValue[ItemId.Gold] or 0) + buildData.gold_up |
135 | end | 185 | end |
136 | if buildData.item_up > 0 then | 186 | if buildData.item_up > 0 then |
137 | - local value = reward:getv(ItemId.DinerCoin, 0) | ||
138 | - value = math.floor(value * (100 + buildData.item_up) / 100) | ||
139 | - if value > 0 then | ||
140 | - reward = reward:setv(ItemId.DinerCoin, value) | ||
141 | - end | 187 | + upValue[ItemId.DinerCoin] = (upValue[ItemId.DinerCoin] or 0) + buildData.gold_up |
142 | end | 188 | end |
143 | if buildData and buildData.famous_up > 0 then | 189 | if buildData and buildData.famous_up > 0 then |
144 | - popular = math.floor(popular * (100 + buildData.famous_up) / 100) | 190 | + upValue[-1] = (upValue[-1] or 0) + buildData.famous_up |
191 | + end | ||
192 | + end | ||
193 | + | ||
194 | + -- 收集加成 | ||
195 | + local collectCount = 0 | ||
196 | + for _id , status in pairs(self:getProperty("customer")) do | ||
197 | + if status == 1 then | ||
198 | + collectCount = collectCount + 1 | ||
145 | end | 199 | end |
146 | end | 200 | end |
201 | + local collectAdd = 0 | ||
202 | + for _, collectData in ipairs(csvdb["diner_customer_collectCsv"]) do | ||
203 | + if collectData.num <= collectCount then | ||
204 | + collectAdd = collectData.bonus | ||
205 | + else | ||
206 | + break | ||
207 | + end | ||
208 | + end | ||
209 | + upValue[-1] = (upValue[-1] or 0) + collectAdd | ||
210 | + | ||
211 | + for id, count in pairs(addReward) do | ||
212 | + addReward[id] = math.floor(count * (1 + (upValue[id] or 0) / 100)) | ||
213 | + reward = reward:incrv(id, addReward[id]) | ||
214 | + end | ||
215 | + popular = math.floor(popular * (1 + (upValue[-1] or 0) / 100)) | ||
216 | + | ||
147 | return reward, popular | 217 | return reward, popular |
148 | end | 218 | end |
149 | 219 | ||
@@ -293,7 +363,20 @@ function Diner:getPopularRank() | @@ -293,7 +363,20 @@ function Diner:getPopularRank() | ||
293 | end | 363 | end |
294 | 364 | ||
295 | function Diner:data() | 365 | function Diner:data() |
296 | - local properties = {"buildL", "order", "sells", "dishTree", "skillTree","popular","expedite","gfood", "task"} | 366 | + local properties = { |
367 | + "buildL", | ||
368 | + "order", | ||
369 | + "sells", | ||
370 | + "dishTree", | ||
371 | + "skillTree", | ||
372 | + "popular", | ||
373 | + "expedite", | ||
374 | + "gfood", | ||
375 | + "task", | ||
376 | + "entrust", | ||
377 | + "customer", | ||
378 | + "comboStatus", | ||
379 | + } | ||
297 | local data = self:getProperties(properties) | 380 | local data = self:getProperties(properties) |
298 | return data | 381 | return data |
299 | end | 382 | end |