|
@@ -3,8 +3,10 @@ local code = require "code"
|
3
|
3
|
local util_user = require("utils.util_user")
|
4
|
4
|
local lib_game_mysql = require("lib_game_mysql")
|
5
|
5
|
local util_order = require("utils.util_order")
|
|
6
|
+local gameConst = require("const.gameConst")
|
6
|
7
|
|
7
|
8
|
local shopAdapt = require("adapt.shopAdapt")
|
|
9
|
+local resAdapt = require("adapt.resAdapt")
|
8
|
10
|
|
9
|
11
|
local dataBag = require("data.bag")
|
10
|
12
|
|
|
@@ -171,4 +173,28 @@ function root:shop_get_order(role, msg)
|
171
|
173
|
return code.OK, ret
|
172
|
174
|
end
|
173
|
175
|
|
|
176
|
+-- 购买道具
|
|
177
|
+function root:shop_buy_item(role, msg)
|
|
178
|
+ local uid = role.uid
|
|
179
|
+ local id = msg.id
|
|
180
|
+ local count = msg.count
|
|
181
|
+ local conf = resAdapt:get_item_conf(id)
|
|
182
|
+ if conf == nil or conf.price == nil then
|
|
183
|
+ return code.PARAMTER_ERROR
|
|
184
|
+ end
|
|
185
|
+ -- 道具消耗
|
|
186
|
+ local costItems = {{id = gameConst.ITEM_ID.GOLD, count = conf.price * count}}
|
|
187
|
+ local ok = dataBag:is_enough(uid, costItems)
|
|
188
|
+ if not ok then
|
|
189
|
+ return code.RES.NOT_ENOUGH
|
|
190
|
+ end
|
|
191
|
+ local keyEvent = "shop-item-" .. tostring(id)
|
|
192
|
+ dataBag:consume_items(uid, costItems, keyEvent)
|
|
193
|
+ -- 发放物品
|
|
194
|
+ local items = {{id = id, count = count}}
|
|
195
|
+ dataBag:add_items(uid, items, keyEvent)
|
|
196
|
+
|
|
197
|
+ return code.OK, {items = items}
|
|
198
|
+end
|
|
199
|
+
|
174
|
200
|
return root
|