Commit cccc9c705a0ca03fd7ee6186dddaec8a992ce58c
1 parent
f317b790
商城
Showing
5 changed files
with
148 additions
and
2 deletions
Show diff stats
src/ProtocolCode.lua
... | ... | @@ -0,0 +1,107 @@ |
1 | +local _M = {} | |
2 | + | |
3 | +function _M.rechargeRpc(agent , data) | |
4 | + local role = agent.role | |
5 | + local msg = MsgPack.unpack(data) | |
6 | + local id = msg.id | |
7 | + local dataSet = csvdb["shop_rechargeCsv"][id] | |
8 | + if not dataSet then return end | |
9 | + local diamondCount | |
10 | + if dataSet.type == 0 then -- 钻石 | |
11 | + local rechargeF = role:getProperty("rechargeF") | |
12 | + diamondCount = dataSet.diamond + dataSet.diamondExtra | |
13 | + if not rechargeF[id] then | |
14 | + diamondCount = diamondCount + dataSet.diamondFirst | |
15 | + rechargeF[id] = 1 | |
16 | + role:updateProperty({field = "rechargeF", value = rechargeF}) | |
17 | + end | |
18 | + role:gainDiamond({count = diamondCount, isRecharge = true}) | |
19 | + elseif dataSet.type == 1 then --月卡 | |
20 | + return | |
21 | + elseif dataSet.type == 2 then -- 赛季通行证 | |
22 | + return | |
23 | + else | |
24 | + return | |
25 | + end | |
26 | + | |
27 | + -- 累充 | |
28 | + local rmb = dataSet.rmb | |
29 | + role:updateProperty({field = "rmbC", delta = rmb}) | |
30 | + | |
31 | + SendPacket(actionCodes.Store_rechargeRpc, MsgPack.pack({diamond = diamondCount})) | |
32 | + return true | |
33 | +end | |
34 | + | |
35 | + | |
36 | +function _M.dailyBuyRpc(agent , data) | |
37 | + local role = agent.role | |
38 | + local msg = MsgPack.unpack(data) | |
39 | + local id = msg.id | |
40 | + local count = msg.count or 1 | |
41 | + | |
42 | + local dataSet = csvdb["shop_diamondCsv"][id] | |
43 | + if not dataSet then return 1 end | |
44 | + | |
45 | + local dailySDC = role.dailyData:getProperty("dailySDC") | |
46 | + | |
47 | + if math.illegalNum(count, 1, (dataSet.limit == 0 and math.huge or dataSet.limit - (dailySDC[id] or 0))) then return 1 end | |
48 | + | |
49 | + local cost = dataSet.cost | |
50 | + if dataSet.type == 0 then | |
51 | + local dailySDD = role.dailyData:getProperty("dailySDD") | |
52 | + if dailySDD[id] then -- 折扣 | |
53 | + cost = math.ceil(cost * (1 - dataSet.disount / 100)) | |
54 | + end | |
55 | + elseif dataSet.type == 1 then | |
56 | + else | |
57 | + return 3 | |
58 | + end | |
59 | + | |
60 | + if not role:costDiamond({count = cost * count}) then | |
61 | + return 4 | |
62 | + end | |
63 | + | |
64 | + if dataSet.limit ~= 0 then | |
65 | + dailySDC[id] = (dailySDC[id] or 0) + count | |
66 | + role.dailyData:updateProperty({field = "dailySDC", value = dailySDC}) | |
67 | + end | |
68 | + local reward = role:award(dataSet.gift) | |
69 | + | |
70 | + SendPacket(actionCodes.Store_dailyBuyRpc, MsgPack.pack({reward = reward})) | |
71 | + return true | |
72 | +end | |
73 | + | |
74 | + | |
75 | +function _M.dinerBuyRpc(agent , data) | |
76 | + local role = agent.role | |
77 | + local msg = MsgPack.unpack(data) | |
78 | + local id = msg.id | |
79 | + local count = msg.count or 1 | |
80 | + | |
81 | + local dataSet = csvdb["shop_dinerCsv"][id] | |
82 | + if not dataSet then return end | |
83 | + | |
84 | + local dinerS = role:getProperty("dinerS") | |
85 | + if math.illegalNum(count, 1, (dataSet.limit == 0 and math.huge or dataSet.limit - (dinerS[id] or 0))) then return 1 end | |
86 | + | |
87 | + local cost = {[ItemId.DinerCoin] = dataSet.cost} | |
88 | + if not role:checkItemEnough(cost) then return end | |
89 | + | |
90 | + if dataSet.limit ~= 0 then | |
91 | + dinerS[id] = (dinerS[id] or 0) + count | |
92 | + role:updateProperty({field = "dinerS", value = dinerS}) | |
93 | + end | |
94 | + | |
95 | + role:costItems(cost) | |
96 | + | |
97 | + local gift = {} | |
98 | + for _id, _count in pairs(dataSet.gift:toNumMap()) do | |
99 | + gift[_id] = _count * count | |
100 | + end | |
101 | + local reward = role:award(gift) | |
102 | + | |
103 | + SendPacket(actionCodes.Store_dinerBuyRpc, MsgPack.pack({reward = reward})) | |
104 | + return true | |
105 | +end | |
106 | + | |
107 | +return _M | |
0 | 108 | \ No newline at end of file | ... | ... |
src/models/Daily.lua
... | ... | @@ -19,6 +19,9 @@ Daily.schema = { |
19 | 19 | giveFP = {"table", {}}, -- 给谁送过心心 |
20 | 20 | getFP = {"table", {}}, -- 领过谁的心心 |
21 | 21 | pvpFree = {"number", 0}, -- pvp使用免费次数 |
22 | + | |
23 | + dailySDC = {"table", {}}, -- daily shop diamond count {[id] = count} -- 每日商城购买次数统计 | |
24 | + dailySDD = {"table", {}}, -- daily shop diamond disount {[id] = 1} -- 每日商城折扣统计 | |
22 | 25 | } |
23 | 26 | |
24 | 27 | function Daily:updateProperty(params) |
... | ... | @@ -43,12 +46,28 @@ end |
43 | 46 | |
44 | 47 | function Daily:refreshDailyData(notify) |
45 | 48 | redisproxy:del(FRIEND_POINT:format(self.owner:getProperty("id"))) |
49 | + local dataMap = {} | |
46 | 50 | for field, schema in pairs(self.schema) do |
47 | 51 | if field ~= "key" then |
48 | 52 | local typ, def = table.unpack(schema) |
49 | - self:setProperty(field, def) | |
53 | + dataMap[field] = def | |
54 | + end | |
55 | + end | |
56 | + -- 每日折扣搞一下 | |
57 | + local dailySDD = {} | |
58 | + local sddPool = {} | |
59 | + for id, data in pairs(csvdb["shop_diamondCsv"]) do | |
60 | + if data.type == 0 and data.disount ~= 0 then | |
61 | + table.insert(sddPool, id) | |
50 | 62 | end |
51 | 63 | end |
64 | + for i = 1, math.min(#sddPool, globalCsv.shop_diamond_disount_count) do | |
65 | + local idx = math.randomInt(1, #sddPool) | |
66 | + dailySDD[sddPool[idx]] = 1 | |
67 | + table.remove(sddPool, idx) | |
68 | + end | |
69 | + dataMap["dailySDD"] = dailySDD | |
70 | + self:setProperties(dataMap) | |
52 | 71 | if notify then |
53 | 72 | self.owner:notifyUpdateProperties(self:data()) |
54 | 73 | end |
... | ... | @@ -67,6 +86,8 @@ function Daily:data() |
67 | 86 | giveFP = self:getProperty("giveFP"), |
68 | 87 | getFP = self:getProperty("getFP"), |
69 | 88 | pvpFree = self:getProperty("pvpFree"), |
89 | + dailySDC = self:getProperty("dailySDC"), | |
90 | + dailySDD = self:getProperty("dailySDD"), | |
70 | 91 | } |
71 | 92 | end |
72 | 93 | ... | ... |
src/models/Role.lua
... | ... | @@ -106,6 +106,11 @@ Role.schema = { |
106 | 106 | |
107 | 107 | achiveT = {"table", {}}, -- 成就计数统计 achivement_type {id = status} |
108 | 108 | achiveV = {"table", {}}, -- 成就领奖统计 achivement {id = status} |
109 | + | |
110 | + rechargeF = {"table", {}}, -- 是否首次充值某一项 -- —{[id] = 1} -- 不存在就是没有充值过 | |
111 | + dinerS = {"table", {}}, -- 美食币商城 购买记录 {[id] = count} | |
112 | + | |
113 | + rmbC = {"number", 0}, -- 人民币重置额 | |
109 | 114 | } |
110 | 115 | |
111 | 116 | |
... | ... | @@ -250,6 +255,11 @@ function Role:data() |
250 | 255 | wTask = self:getProperty("wTask"), |
251 | 256 | achiveT = self:getProperty("achiveT"), |
252 | 257 | achiveV = self:getProperty("achiveV"), |
258 | + | |
259 | + rechargeF = self:getProperty("rechargeF"), | |
260 | + dinerS = self:getProperty("dinerS"), | |
261 | + | |
262 | + rmbC = self:getProperty("rmbC"), | |
253 | 263 | } |
254 | 264 | end |
255 | 265 | ... | ... |
src/models/RolePlugin.lua
... | ... | @@ -36,8 +36,12 @@ function RolePlugin.bind(Role) |
36 | 36 | |
37 | 37 | |
38 | 38 | if isCrossWeek(ltime, now) then |
39 | - self:setProperty("wTask", {}) | |
39 | + self:setProperties({ | |
40 | + wTask = {}, | |
41 | + dinerS = {}, | |
42 | + }) | |
40 | 43 | response.wTask = {} |
44 | + response.dinerS = {} | |
41 | 45 | end |
42 | 46 | |
43 | 47 | if notify then | ... | ... |