123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- local bagData = require("data.bag")
- local gameConst = require("const.gameConst")
- local root = class("bag", require("base.baseModule"))
- function root:ctor(uid)
- root.super.ctor(self, uid, "bag", "uid", true)
- self.uid = uid
- end
- function root:mysql_get_init_columns()
- return {
- uid = "int(11) unsigned NOT NULL",
- itemList = "JSON COMMENT '道具信息'",
- lastBid = "int(11) DEFAULT 0 COMMENT '最后使用的bid'",
- lastInitTime = "int(11) DEFAULT 0 COMMENT '最后初始化背包的时间戳'"
- }
- end
- ----------------------------------------
- -- 接口
- ----------------------------------------
- -- 请求获取背包信息
- function root:itf_get_info(role, msg)
- local items = self:redis_get_key_info("itemList")
- return code.OK, {items = items}
- end
- -- 分解
- function root:itf_exchange(role, msg)
- local items = msg.items
- if is_empty(items) then
- return code.PARAMTER_ERROR
- end
- local goldCount = 0
- for _, v in ipairs(items) do
- local price = resAdapt:get_item_price(v.id)
- if not is_empty(price) and not is_empty(v.count) then
- -- 可分解
- local costItems = {{id = v.id, count = v.count}}
- if bagData:is_enough(self.uid, costItems) then
- local addCount = price * v.count
- goldCount = goldCount + addCount
- bagData:consume_items(self.uid, costItems, "item-exchange")
- local eventId = string.format("item-exchange-%s", tostring(v.id))
- bagData:add_items(self.uid, {{id = gameConst.ITEM_ID.GOLD, count = addCount}}, eventId)
- end
- end
- end
- return code.OK, {goldCount = goldCount}
- end
- -- 提取
- function root:itf_draw(role, msg)
- return code.OK
- end
- return root
|