123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- --[[
- Descripttion:开箱子
- version:
- Author: Neo,Huang
- Date: 2023-11-15 22:34:35
- LastEditors: Neo,Huang
- LastEditTime: 2023-11-15 22:42:18
- --]]
- local code = require("code")
- local util_box = require("utils.util_box")
- local gameConst = require("const.gameConst")
- local itemUtil = require("utils.itemUtil")
- local boxAdapt = require("adapt.boxAdapt")
- local bagData = require("data.bag")
- local root = {}
- ----------------------------------------
- -- 盲盒
- ----------------------------------------
- -- 模块信息
- function root:box_blind_get_info(role, msg)
- local id = msg.id
- local ret = {
- boxInfoList = util_box:pack_box_info_list(id)
- }
- return code.OK, ret
- end
- -- 开盲盒
- function root:box_blind_open(role, msg)
- local id = msg.id
- local count = msg.count or 1
- if is_empty(id) then
- return code.PARAMTER_ERROR
- end
- local uid = role.uid
- local conf = boxAdapt:blind_get_box_key_info(id)
- local items = nil
- for i = 1, count do
- -- 掉落物品
- local itemId, itemCount = util_box:get_box_drop_item_and_count(id)
- if not is_empty(itemId) and not is_empty(itemCount) then
- local ok, costItems = bagData:is_enough(uid, {{id = gameConst.ITEM_ID.DIAMOND, count = conf.price}})
- if not ok then
- break
- end
- -- 消耗
- local keyEvent = string.format("box-blind-%s", tostring(id))
- bagData:consume_items(uid, costItems, keyEvent)
- -- 获取物品
- local _items = {{id = itemId, count = itemCount}}
- bagData:add_items(uid, _items, keyEvent)
- items = itemUtil.items_merge(items, _items)
- end
- end
- if is_empty(items) then
- return code.BAG.ITEM_NOT_ENOUGH
- end
- local ret = {
- items = items,
- boxInfo = util_box:pack_box_info(id)
- }
- return code.OK, ret
- end
- ----------------------------------------
- -- 追梦
- ----------------------------------------
- -- 开奖
- function root:box_dream_open(role, msg)
- local itemId = msg.itemId
- local odds = msg.odds
- if is_empty(itemId) or is_empty(odds) or odds < 5 or odds > 85 then
- return code.PARAMTER_ERROR
- end
- local confItem = resAdapt:get_item_conf(itemId)
- if is_empty(confItem) then
- return code.BAG.ITEM_NOT_EXIST
- end
- local uid = role.uid
- -- 消耗
- local costItems = {
- {id = gameConst.ITEM_ID.DIAMOND, count = math.floor(confItem.price / confItem.priceConst * odds)}
- }
- local ok, _costItems = bagData:is_enough(uid, costItems)
- if not ok then
- return code.BAG.ITEM_NOT_ENOUGH
- end
- -- 消耗
- local keyEvent = string.format("box-dream-%s", tostring(itemId))
- bagData:consume_items(uid, _costItems, keyEvent)
- -- 随机道具
- local awardList = {
- {id = itemId, count = 1, weight = adds},
- {id = gameConst.ITEM_ID.N1, count = 1, weight = 100 - odds}
- }
- local index = random_list_by_weight(awardList)
- local dropItem = {id = awardList[index].id, count = awardList[index].count}
- bagData:add_items(uid, {dropItem}, keyEvent)
- -- 记录/统计
- local isWin = dropItem.id == itemId
- util_box:dream_add_record(uid, itemId, odds, dropItem, isWin)
- util_box:dream_add_odds_times(odds, isWin)
- return code.OK, {dropItem = dropItem}
- end
- -- 精彩瞬间
- function root:box_dream_brilliant(role, msg)
- local list = util_box:dream_get_brilliants()
- return code.OK, {list = list}
- end
- -- 掉落记录
- function root:box_dream_records(role, msg)
- local list = util_box:dream_get_records()
- return code.OK, {list = list}
- end
- -- 全局统计
- function root:box_dream_statement(role, msg)
- local oddsTimesList = util_box:dream_get_statement()
- return code.OK, {oddsTimesList = oddsTimesList}
- end
- return root
|