Commit 312b9db56e705df16efa6f205cec67c802103358
1 parent
9962b061
่ๅ
Showing
6 changed files
with
205 additions
and
9 deletions
Show diff stats
src/ProtocolCode.lua
@@ -21,6 +21,8 @@ actionCodes = { | @@ -21,6 +21,8 @@ actionCodes = { | ||
21 | Role_updateItems = 107, | 21 | Role_updateItems = 107, |
22 | Role_changeUpdate = 108, | 22 | Role_changeUpdate = 108, |
23 | Role_pipelining = 109, | 23 | Role_pipelining = 109, |
24 | + Role_saleItemRpc = 110, | ||
25 | + Role_openItemRpc = 111, | ||
24 | 26 | ||
25 | Adv_startAdvRpc = 151, | 27 | Adv_startAdvRpc = 151, |
26 | Adv_roleFormatRpc = 152, | 28 | Adv_roleFormatRpc = 152, |
@@ -43,6 +45,7 @@ actionCodes = { | @@ -43,6 +45,7 @@ actionCodes = { | ||
43 | Hero_loveItemRpc = 212, | 45 | Hero_loveItemRpc = 212, |
44 | Hero_loveTaskRpc = 213, | 46 | Hero_loveTaskRpc = 213, |
45 | Hero_changeSkinRpc = 214, | 47 | Hero_changeSkinRpc = 214, |
48 | + Hero_createHeroRpc = 215, | ||
46 | 49 | ||
47 | Hang_startRpc = 251, | 50 | Hang_startRpc = 251, |
48 | Hang_checkRpc = 252, | 51 | Hang_checkRpc = 252, |
src/actions/HeroAction.lua
@@ -404,4 +404,25 @@ function _M.changeSkinRpc(agent, data) | @@ -404,4 +404,25 @@ function _M.changeSkinRpc(agent, data) | ||
404 | return true | 404 | return true |
405 | end | 405 | end |
406 | 406 | ||
407 | +function _M.createHeroRpc(agent, data) | ||
408 | + local role = agent.role | ||
409 | + local msg = MsgPack.unpack(data) | ||
410 | + local heroType = msg.heroType | ||
411 | + local unitData = csvdb["unitCsv"][heroType] | ||
412 | + if not unitData then return end | ||
413 | + local cost = globalCsv.unit_fragment_cost[unitData["rare"]] | ||
414 | + if not cost then return end | ||
415 | + if role:getItemCount(heroType) < cost then return end | ||
416 | + | ||
417 | + for _, hero in pairs(role.heros) do | ||
418 | + if hero:getProperty("type") == heroType then return end | ||
419 | + end | ||
420 | + | ||
421 | + role:costItems({[heroType] = cost}, {}) | ||
422 | + role:award({[heroType + ItemStartId.Hero] = 1}, {}) | ||
423 | + | ||
424 | + SendPacket(actionCodes.Hero_createHeroRpc, "") | ||
425 | + return true | ||
426 | +end | ||
427 | + | ||
407 | return _M | 428 | return _M |
408 | \ No newline at end of file | 429 | \ No newline at end of file |
src/actions/RoleAction.lua
@@ -246,4 +246,58 @@ function _M.syncTimeRpc(agent, data) | @@ -246,4 +246,58 @@ function _M.syncTimeRpc(agent, data) | ||
246 | return true | 246 | return true |
247 | end | 247 | end |
248 | 248 | ||
249 | +function _M.saleItemRpc(agent, data) | ||
250 | + local role = agent.role | ||
251 | + local msg = MsgPack.unpack(data) | ||
252 | + local itemId = msg.itemId | ||
253 | + local count = msg.count | ||
254 | + if math.illegalNum(count, 1, role:getItemCount(itemId)) then return end | ||
255 | + local itemData = csvdb["itemCsv"][itemId] | ||
256 | + if itemData.sell_effect == "" then return end | ||
257 | + local sellEffect = itemData.sell_effect:toArray(true, "=") | ||
258 | + | ||
259 | + role:costItems({[itemId] = count}, {}) | ||
260 | + local reward = role:award({[sellEffect[1]] = sellEffect[2] * count}, {}) | ||
261 | + | ||
262 | + SendPacket(actionCodes.Role_saleItemRpc, MsgPack.pack({reward = reward})) | ||
263 | + return true | ||
264 | +end | ||
265 | + | ||
266 | +function _M.openItemRpc(agent, data) | ||
267 | + local role = agent.role | ||
268 | + local msg = MsgPack.unpack(data) | ||
269 | + local itemId = msg.itemId | ||
270 | + local count = msg.count | ||
271 | + if math.illegalNum(count, 1, role:getItemCount(itemId)) then return end | ||
272 | + local itemData = csvdb["itemCsv"][itemId] | ||
273 | + if itemData.use_type ~= 2 then return end | ||
274 | + local randomData = csvdb["item_randomCsv"][tonumber(itemData.use_effect)] | ||
275 | + if not randomData then return end | ||
276 | + | ||
277 | + local reward = randomData.gift:toNumMap() | ||
278 | + for _id, _count in pairs(reward) do | ||
279 | + reward[_id] = _count * count | ||
280 | + end | ||
281 | + if randomData.random_num > 0 and randomData.random_gift ~= "" then | ||
282 | + for i = 1, count do | ||
283 | + local pool = {} | ||
284 | + for _, temp in ipairs(randomData.random_gift:toArray()) do | ||
285 | + table.insert(pool, temp:toArray(true, "=")) | ||
286 | + end | ||
287 | + local needCount = math.min(#pool, randomData.random_num) | ||
288 | + for j = 1, needCount do | ||
289 | + local idx = math.randWeight(pool, 3) | ||
290 | + reward[pool[idx][1]] = (reward[pool[idx][1]] or 0) + pool[idx][2] | ||
291 | + table.remove(pool, idx) | ||
292 | + end | ||
293 | + end | ||
294 | + end | ||
295 | + role:costItems({[itemId] = count}, {}) | ||
296 | + reward = role:award(reward, {}) | ||
297 | + | ||
298 | + SendPacket(actionCodes.Role_openItemRpc, MsgPack.pack({reward = reward})) | ||
299 | + return true | ||
300 | +end | ||
301 | + | ||
302 | + | ||
249 | return _M | 303 | return _M |
250 | \ No newline at end of file | 304 | \ No newline at end of file |
src/models/Role.lua
@@ -28,12 +28,15 @@ Role.schema = { | @@ -28,12 +28,15 @@ Role.schema = { | ||
28 | ctime = {"number", skynet.timex()}, -- ๅๅปบๆถ้ด | 28 | ctime = {"number", skynet.timex()}, -- ๅๅปบๆถ้ด |
29 | ignoreMt = {"number", 0}, -- ๅฟฝ็ฅ็ปดๆคๆฆๆช | 29 | ignoreMt = {"number", 0}, -- ๅฟฝ็ฅ็ปดๆคๆฆๆช |
30 | sversion = {"number", globalCsv.StructVersion or 0}, -- ้ๆดๆฐๆฎ็ๆฌ | 30 | sversion = {"number", globalCsv.StructVersion or 0}, -- ้ๆดๆฐๆฎ็ๆฌ |
31 | - | 31 | + diamond = {"number", 0}, |
32 | + reDiamond = {"number", 0}, | ||
32 | -- roleInfo | 33 | -- roleInfo |
33 | level = {"number", 0}, | 34 | level = {"number", 0}, |
34 | items = {"string", ""}, | 35 | items = {"string", ""}, |
35 | loveStatus = {"string", ""}, --็ป่ฎก่ง่ฒ็ๆ้ซ ๅฅฝๆๅบฆ็ญ็บง ็ฑปๅ็ธๅ ณ -- type=loveL type=loveL | 36 | loveStatus = {"string", ""}, --็ป่ฎก่ง่ฒ็ๆ้ซ ๅฅฝๆๅบฆ็ญ็บง ็ฑปๅ็ธๅ ณ -- type=loveL type=loveL |
36 | 37 | ||
38 | + bagLimit = {"table", globalCsv.store_limit_max}, | ||
39 | + | ||
37 | --ๅ้ฉ็ธๅ ณ | 40 | --ๅ้ฉ็ธๅ ณ |
38 | advPass = {"string", ""}, -- ้ๅ ณ่ฎฐๅฝ | 41 | advPass = {"string", ""}, -- ้ๅ ณ่ฎฐๅฝ |
39 | advItems = {"string", ""}, -- ๅ้ฉไธดๆถ่ๅ | 42 | advItems = {"string", ""}, -- ๅ้ฉไธดๆถ่ๅ |
@@ -147,6 +150,8 @@ function Role:data() | @@ -147,6 +150,8 @@ function Role:data() | ||
147 | level = self:getProperty("level"), | 150 | level = self:getProperty("level"), |
148 | items = self:getProperty("items"):toNumMap(), | 151 | items = self:getProperty("items"):toNumMap(), |
149 | loveStatus = self:getProperty("loveStatus"):toNumMap(), | 152 | loveStatus = self:getProperty("loveStatus"):toNumMap(), |
153 | + diamond = self:getAllDiamond(), | ||
154 | + bagLimit = self:getProperty("bagLimit"), | ||
150 | 155 | ||
151 | advPass = self:getProperty("advPass"), | 156 | advPass = self:getProperty("advPass"), |
152 | advInfo = self:getProperty("advInfo"), | 157 | advInfo = self:getProperty("advInfo"), |
src/models/RolePlugin.lua
@@ -35,6 +35,29 @@ function RolePlugin.bind(Role) | @@ -35,6 +35,29 @@ function RolePlugin.bind(Role) | ||
35 | 35 | ||
36 | end | 36 | end |
37 | 37 | ||
38 | + local function checkItemCount(self, itemId, count) | ||
39 | + local itemData = csvdb["itemCsv"][itemId] | ||
40 | + -- ็ง็ฑป ็ฑปๅๆฐ้้ๅถ | ||
41 | + local page = globalCsv.store_type[itemData.type] | ||
42 | + local limit = self:getProperty("bagLimit")[page] | ||
43 | + if limit and self:getItemCount(itemId) == 0 then | ||
44 | + local curCount = 0 | ||
45 | + local items = self:getProperty("items"):toNumMap() | ||
46 | + for _itemId, _count in pairs(items) do | ||
47 | + local _itemData = csvdb["itemCsv"][itemId] | ||
48 | + if globalCsv.store_type[_itemData.type] == page then | ||
49 | + curCount = curCount + 1 | ||
50 | + if curCount >= limit then | ||
51 | + count = 0 | ||
52 | + break | ||
53 | + end | ||
54 | + end | ||
55 | + end | ||
56 | + end | ||
57 | + -- ๅ ถไป | ||
58 | + | ||
59 | + return count | ||
60 | + end | ||
38 | 61 | ||
39 | local function _award(self, itemId, count, params) | 62 | local function _award(self, itemId, count, params) |
40 | local itemData = csvdb["itemCsv"][itemId] | 63 | local itemData = csvdb["itemCsv"][itemId] |
@@ -49,13 +72,16 @@ function RolePlugin.bind(Role) | @@ -49,13 +72,16 @@ function RolePlugin.bind(Role) | ||
49 | end | 72 | end |
50 | end, | 73 | end, |
51 | } | 74 | } |
52 | - | ||
53 | - if itemTypeAward[curType] then | ||
54 | - itemTypeAward[curType]() | ||
55 | - else | ||
56 | - params.itemId = itemId | ||
57 | - params.count = count | ||
58 | - self:addItem(params) | 75 | + -- ๅฏนๆฐ้็ญๆฅ |
76 | + local count = checkItemCount(self, itemId, count) | ||
77 | + if count ~= 0 then | ||
78 | + if itemTypeAward[curType] then | ||
79 | + itemTypeAward[curType]() | ||
80 | + else | ||
81 | + params.itemId = itemId | ||
82 | + params.count = count | ||
83 | + self:addItem(params) | ||
84 | + end | ||
59 | end | 85 | end |
60 | 86 | ||
61 | return count, change -- count ๅทๆฐๅฎ้ ๅๆพ็ๅฅๅฑไธชๆฐ change ็ฉๅๅฎ้ ๅฅๅฑไธๅฝๅid ไธ็ฌฆ ๅฐฑๅ็่ฝฌๆข ่ไธๅฎ้ ๅๅฅ | 87 | return count, change -- count ๅทๆฐๅฎ้ ๅๆพ็ๅฅๅฑไธชๆฐ change ็ฉๅๅฎ้ ๅฅๅฑไธๅฝๅid ไธ็ฌฆ ๅฐฑๅ็่ฝฌๆข ่ไธๅฎ้ ๅๅฅ |
@@ -83,7 +109,9 @@ function RolePlugin.bind(Role) | @@ -83,7 +109,9 @@ function RolePlugin.bind(Role) | ||
83 | end | 109 | end |
84 | table.insert(allChange, {form = {[itemId] = count}, to = cr}) | 110 | table.insert(allChange, {form = {[itemId] = count}, to = cr}) |
85 | else | 111 | else |
86 | - reward[itemId] = (reward[itemId] or 0) + count | 112 | + if count > 0 then |
113 | + reward[itemId] = (reward[itemId] or 0) + count | ||
114 | + end | ||
87 | end | 115 | end |
88 | end | 116 | end |
89 | 117 | ||
@@ -92,6 +120,10 @@ function RolePlugin.bind(Role) | @@ -92,6 +120,10 @@ function RolePlugin.bind(Role) | ||
92 | 120 | ||
93 | function Role:addItem(params) | 121 | function Role:addItem(params) |
94 | params = params or {} | 122 | params = params or {} |
123 | + if params.itemId == ItemId.Diamond then | ||
124 | + self:gainDiamond(params) | ||
125 | + return | ||
126 | + end | ||
95 | local items = self:getProperty("items") | 127 | local items = self:getProperty("items") |
96 | local origin = items:getv(params.itemId, 0) | 128 | local origin = items:getv(params.itemId, 0) |
97 | local nums = origin+params.count | 129 | local nums = origin+params.count |
@@ -119,18 +151,88 @@ function RolePlugin.bind(Role) | @@ -119,18 +151,88 @@ function RolePlugin.bind(Role) | ||
119 | end | 151 | end |
120 | 152 | ||
121 | function Role:costItems(itemCountT, params) | 153 | function Role:costItems(itemCountT, params) |
154 | + if itemCountT[ItemId.Diamond] then --ไผๅ ๆฃ้ค้ป็ณ | ||
155 | + local pms = clone(params or {}) | ||
156 | + pms.count = itemCountT[ItemId.Diamond] | ||
157 | + if not self:costDiamond(pms) then | ||
158 | + return | ||
159 | + end | ||
160 | + itemCountT[ItemId.Diamond] = nil | ||
161 | + end | ||
122 | for itemId, count in pairs(itemCountT) do | 162 | for itemId, count in pairs(itemCountT) do |
123 | local pms = clone(params or {}) | 163 | local pms = clone(params or {}) |
124 | pms.itemId = itemId | 164 | pms.itemId = itemId |
125 | pms.count = - count | 165 | pms.count = - count |
126 | self:addItem(pms) | 166 | self:addItem(pms) |
127 | end | 167 | end |
168 | + return true | ||
128 | end | 169 | end |
129 | 170 | ||
130 | function Role:getItemCount(itemId) | 171 | function Role:getItemCount(itemId) |
172 | + if itemId == ItemId.Diamond then | ||
173 | + return self:getAllDiamond() | ||
174 | + end | ||
131 | return self:getProperty("items"):getv(itemId, 0) | 175 | return self:getProperty("items"):getv(itemId, 0) |
132 | end | 176 | end |
133 | 177 | ||
178 | + function Role:getAllDiamond() | ||
179 | + return self:getProperty("diamond") + self:getProperty("reDiamond") | ||
180 | + end | ||
181 | + | ||
182 | + function Role:gainDiamond(params) | ||
183 | + if not params or type(params) ~= "table" then return false end | ||
184 | + local count = tonum(params.count) | ||
185 | + if isnan(count) then | ||
186 | + return false | ||
187 | + end | ||
188 | + local origind = self:getProperty("diamond") | ||
189 | + local originr = self:getProperty("reDiamond") | ||
190 | + local origin = origind + originr | ||
191 | + if params.isRecharge then | ||
192 | + self:incrProperty("reDiamond", count) | ||
193 | + else | ||
194 | + self:incrProperty("diamond", count) | ||
195 | + end | ||
196 | + self:notifyUpdateProperty("diamond", self:getAllDiamond()) | ||
197 | + return true | ||
198 | + end | ||
199 | + | ||
200 | + function Role:costDiamond(params) | ||
201 | + if not params or type(params) ~= "table" then return false end | ||
202 | + local count = tonum(params.count) | ||
203 | + if isnan(count) then | ||
204 | + return false | ||
205 | + end | ||
206 | + if count <= 0 then | ||
207 | + return false | ||
208 | + end | ||
209 | + local origind = self:getProperty("diamond") | ||
210 | + local originr = self:getProperty("reDiamond") | ||
211 | + local origin = origind + originr | ||
212 | + | ||
213 | + if origin < 0 then | ||
214 | + return false | ||
215 | + end | ||
216 | + if origin < count then | ||
217 | + return false | ||
218 | + end | ||
219 | + local last = count | ||
220 | + local costFirst = {"diamond", "reDiamond"} | ||
221 | + if params.isRecharge then | ||
222 | + costFirst = {"reDiamond", "diamond"} | ||
223 | + end | ||
224 | + last = math.max(last - self:getProperty(costFirst[1]), 0) | ||
225 | + if last < count then | ||
226 | + self:incrProperty(costFirst[1], last - count) | ||
227 | + end | ||
228 | + if last > 0 then | ||
229 | + self:incrProperty(costFirst[2], -last) | ||
230 | + end | ||
231 | + | ||
232 | + self:notifyUpdateProperty("diamond", self:getAllDiamond()) | ||
233 | + return true | ||
234 | + end | ||
235 | + | ||
134 | function Role:addHero(params) | 236 | function Role:addHero(params) |
135 | local roleId = self:getProperty("id") | 237 | local roleId = self:getProperty("id") |
136 | local heroId = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "hero", 1)) | 238 | local heroId = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "hero", 1)) |
src/utils/MathUtil.lua
@@ -39,4 +39,15 @@ function math.randWeight(dataset, field) | @@ -39,4 +39,15 @@ function math.randWeight(dataset, field) | ||
39 | end | 39 | end |
40 | 40 | ||
41 | return nil | 41 | return nil |
42 | +end | ||
43 | + | ||
44 | +function math.illegalNum(num, min, max) | ||
45 | + local illegal = true | ||
46 | + for i = min, max do | ||
47 | + if num == i then | ||
48 | + illegal = false | ||
49 | + break | ||
50 | + end | ||
51 | + end | ||
52 | + return illegal | ||
42 | end | 53 | end |
43 | \ No newline at end of file | 54 | \ No newline at end of file |