| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804 |
- ------------------------------------------------------------
- -- 背包
- -- addItem 添加道具
- -- delItem 删除道具
- -- sendItemGetList 通用道具获得界面
- -- checkItemCnt 检查道具数量是否足够,否则提示
- -- getItemCnt 返回道具数量
- ------------------------------------------------------------
- local EquipExcel = require("excel.equip").equip
- local ItemExcel = require("excel.item").item
- local FuwenExcel = require("excel.fuwen").fuwen
- local ItemBuyExcel = require("excel.item").buy
- local ItemComonBuyExcel = require("excel.item").commonBuy
- local Log = require("common.Log")
- local LogDefine = require("common.LogDefine")
- local Lang = require("common.Lang")
- local Util = require("common.Util")
- local ObjHuman = require("core.ObjHuman")
- local Msg = require("core.Msg")
- local Broadcast = require("broadcast.Broadcast")
- local Grid = require("bag.Grid")
- local ItemLogic = require("bag.ItemLogic")
- local ItemDefine = require("bag.ItemDefine")
- local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
- local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
- local FuwenLogic = require("fuwen.FuwenLogic")
- local MiddleOption = require("middle.MiddleOption")
- local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
- local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
- local EquipLogic = require("equip.EquipLogic")
- -- local YunYingLogic = require("yunying.YunYingLogic")
- -- local PanelDefine = require("broadcast.PanelDefine")
- local HeroGrowUp = require("absAct.HeroGrowUp")
- local CommonDefine = require("common.CommonDefine")
- local CommonDB = require("common.CommonDB")
- local RoleStorageBox = require("roleSystem.RoleStorageBox")
- local TriggerDefine = require("trigger.TriggerDefine")
- local TriggerLogic = require("trigger.TriggerLogic")
- local ITEM_MOMENT_ADD_LIST = {}
- local jinbi_id=101
- local jinyan_id=111
- ADDITEM_TYPE_1 = 1 --顺序 不整合添加道具 非1 表示整合所有相同的道具数量
- ADDITEM_TYPE_2 = 2
- function updateMomentItem(type, itemID, itemCnt, quality)
- if type == ADDITEM_TYPE_1 then
- local len = #ITEM_MOMENT_ADD_LIST + 1
- ITEM_MOMENT_ADD_LIST[len] = {}
- ITEM_MOMENT_ADD_LIST[len][1] = itemID
- ITEM_MOMENT_ADD_LIST[len][2] = itemCnt
- ITEM_MOMENT_ADD_LIST[len][3] = quality
- else
- ITEM_MOMENT_ADD_LIST[itemID] = ITEM_MOMENT_ADD_LIST[itemID] or 0
- ITEM_MOMENT_ADD_LIST[itemID] = ITEM_MOMENT_ADD_LIST[itemID] + itemCnt
- end
- end
- -- 防止有报错 导致的 别的玩家 额外获得道具 在使用 通用的 添加之前 清除一次
- function cleanMomentItemList()
- Util.cleanTable(ITEM_MOMENT_ADD_LIST)
- end
- function addMomentItemList(human, logType, noSend)
- addItemList(human, ITEM_MOMENT_ADD_LIST, logType, noSend)
- cleanMomentItemList()
- end
- -- 通用道具添加 {[1] = {id, cnt}, [2] = {id,cnt}} or {[itemID] = itemCnt} 配表复杂 各自接口下自己for 添加
- function addItemList(human, list, logType, noSend)
- if not list or next(list) == nil then return end
- list = Util.copyTable(list)
- if list[1] and list[1][1] then
- local extraItemList = {}
- for _, item in ipairs(list) do
- addItem(human, item[1], item[2], logType, noSend, item[3])
- local extraItemInfo = RoleStorageBox.GetExtraItem(human, item[1], item[2], logType)
- if extraItemInfo then
- table.insert(extraItemList, extraItemInfo)
- end
- end
- -- 额外道具的处理
- for _, extraItem in ipairs(extraItemList) do
- table.insert(list, extraItem)
- addItem(human, extraItem[1], extraItem[2], logType, noSend, extraItem[3])
- end
- else
- local newList
- for itemID, itemCnt in pairs(list) do
- -- addItem(human, itemID, itemCnt, logType, noSend)
- local extraItemInfo = RoleStorageBox.GetExtraItem(human, itemID, itemCnt, logType)
- if extraItemInfo then
- itemCnt = itemCnt + extraItemInfo[2]
- newList = newList or {}
- newList[itemID] = {
- [2] = itemCnt, -- 兼容之前代码, 防止有ID为1的道具
- [4] = extraItemInfo[4]
- }
- end
- addItem(human, itemID, itemCnt, logType, noSend)
- end
- if newList then
- for itemId, itemInfo in pairs(newList) do
- list[itemId] = itemInfo
- end
- end
- end
- sendItemGetList(human, list, logType)
- end
- -- 增加装备,道具
- function addItem(human, id, cnt, logType, noSend, otherData)
- if cnt < 1 then return end
- local itemConfig = ItemDefine.getConfig(id)
- if not itemConfig then return end
- if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["item"] then
- assert()
- end
- cnt = calculateBonusItemCount(human,id,cnt,logType)
- MiddleOption.addItem(human, id, cnt, logType)
- if handlerSpObj(human, id, cnt, logType) then
- print("[addItem] 不进入背包物品直接返回 id, cnt = ", id, cnt)
- return
- end
- if handleFuwen(human, id, cnt, logType) then
- print("[addItem] 符文物品不进入背包物品直接返回 id, cnt = ", id, cnt)
- return
- end
- -- 装备走另外的逻辑
- if handleEquipAdd(human, id, cnt, logType, otherData) then
- print("[addItem] 装备物品其他方式处理 id, cnt = ", id, cnt)
- return
- end
- local oldCnt = human.db.bag[id] or 0
- local newCnt = math.min(oldCnt + cnt, ItemDefine.BAG_ITEM_MAX_CNT)
- human.db.bag[id] = newCnt
- if not noSend then
- sendChange(human, id, oldCnt < 1)
- end
- Log.write(Log.LOGID_OSS_ITEM, human.db._id, human.db.account, human.db.name, human.db.lv,
- LogDefine.DEFINE[logType] + LogDefine.TYPE["item"] , id, cnt, newCnt)
-
- -- 如果道具为公会贡献,记录到当日累计贡献中
- if id == ItemDefine.ITEM_UNION_COIN_ID then
- human.db.dailyBanggong = human.db.dailyBanggong or 0
- human.db.dailyBanggong = human.db.dailyBanggong + cnt
- human.db.totalBanggong = human.db.totalBanggong or 0
- human.db.totalBanggong = human.db.totalBanggong + cnt
- end
-
- -- 根据道具触发红点
- checkDotByID(human,id)
- return true
- end
- function checkDotByID(human,id)
- local itemConfig = ItemDefine.getConfig(id)
- local dotTb = itemConfig.dot
- local len = #dotTb
- for i = 1,len do
- RoleSystemLogic.onDot(human, dotTb[i])
- end
- end
- -- 根据id删除
- function delItem(human, id, cnt, logType, noSend, byId, byCnt)
- if cnt < 1 then return end
- local itemConfig = ItemExcel[id]
- if not itemConfig then return end
- if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["item"] then
- assert()
- end
- if id == ItemDefine.ITEM_JINBI_ID then
- return ObjHuman.updateJinbi(human, -cnt, logType, byId, byCnt)
- elseif id == ItemDefine.ITEM_ZUANSHI_ID then
- return ObjHuman.decZuanshi(human, -cnt, logType, byId, byCnt)
- elseif id == ItemDefine.ITEM_FRIEND_ID then
- return ObjHuman.updateFriendHeart(human, -cnt, logType)
- end
- local newCnt = (human.db.bag[id] or 0) - cnt
- if newCnt < 0 then assert(nil) end
- if newCnt < 1 then
- newCnt = nil
- end
- human.db.bag[id] = newCnt
-
- if not noSend then
- sendChange(human, id)
- end
- Log.write(Log.LOGID_OSS_ITEM, human.db._id, human.db.account, human.db.name, human.db.lv,
- LogDefine.DEFINE[logType] + LogDefine.TYPE["item"] , id, -cnt, newCnt or 0)
-
- if itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN or
- itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN_SKIN then
- RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_206)
- end
-
- if id == ItemDefine.ITEM_GREEN_EXP_ID then
- HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE18, cnt)
- TriggerLogic.PublishEvent(TriggerDefine.JINGYAN_DEL, human.db._id, cnt)
- end
- return true
- end
- -- 获得道具数量
- function getItemCnt(human, id, isUse)
- if id == ItemDefine.ITEM_JINBI_ID and not isUse then
- return human.db.jinbi or 0
- elseif id == ItemDefine.ITEM_ZUANSHI_ID and not isUse then
- return human.db.zuanshi or 0
- elseif id == ItemDefine.ITEM_FRIEND_ID and not isUse then
- return human.db.friendHeart or 0
- end
- return human.db.bag[id] or 0
- end
- -- 判断道具数量
- function checkItemCnt(human, id, cnt)
- if id == ItemDefine.ITEM_ZUANSHI_ID then
- return ObjHuman.checkRMB(human,cnt)
- end
- if getItemCnt(human, id) < cnt then
- local name = ItemDefine.getValue(id,"name")
- return Broadcast.sendErr(human,Util.format(Lang.COMMON_NO_ITEM, name))
- end
- return true
- end
- -- 特殊不进背包的道具
- function handlerSpObj(human, itemID, itemCnt, logType)
- local itemConfig = ItemExcel[itemID]
- if not itemConfig then return end
- if itemConfig.subType ~= ItemDefine.ITEM_SUBTYPE_SPOBJ then
- return
- end
- local cmdstr = itemConfig.cmd and itemConfig.cmd[1]
- if cmdstr and ItemLogic.cmd[cmdstr] then
- ItemLogic.onlyuse(human, itemID, itemCnt, logType, true)
-
- -- 根据道具触发红点
- checkDotByID(human,itemID)
- end
- if ItemDefine.checkIsWave(LogDefine.DEFINE[logType]) then
- sendRoll(human, itemID, itemCnt)
- end
- return true
- end
- -- 符文
- function handleFuwen(human, itemID, itemCnt, logType)
- if not FuwenExcel[itemID] then return end
-
- FuwenLogic.add(human, itemID, itemCnt, logType)
- if ItemDefine.checkIsWave(LogDefine.DEFINE[logType]) then
- sendRoll(human, itemID, itemCnt)
- end
- return true
- end
- -- 装备增加
- function handleEquipAdd(human, itemID, itemCnt, logType, otherData)
- if not EquipExcel[itemID] then return end
-
- EquipLogic.addEquip(human, itemID, itemCnt, logType, otherData)
-
- if EquipExcel[itemID].mainType == ItemDefine.MAINTYPE_EQUIP then
- if EquipExcel[itemID].level == 14 then
- ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_24,itemCnt)
- end
- end
- if ItemDefine.checkIsWave(LogDefine.DEFINE[logType]) then
- sendRoll(human, itemID, itemCnt)
- end
- return true
- end
- ---------------------------- msg --------------------------------
- -- 发送背包道具
- function sendBagList(human)
- local msgRet = Msg.gc.GC_BAG_LIST
- msgRet.list[0] = 0
- for itemID, itemCnt in pairs(human.db.bag) do
- msgRet.list[0] = msgRet.list[0] + 1
- local net = msgRet.list[msgRet.list[0]]
- Grid.makeItem(net, itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
- if msgRet.list[0] >= ItemDefine.PAGE_LIST_COUNT then
- Msg.send(msgRet, human.fd)
- msgRet.list[0] = 0
- end
- end
- if msgRet.list[0] > 0 then
- Msg.send(msgRet, human.fd)
- end
- end
- -- 改变
- function sendChange(human, itemID, isAdd)
- print("12131231进入下发逻辑")
- local msgRet = Msg.gc.GC_ITEM_BAG_CHANGE
- local itemCnt = human.db.bag[itemID] or 0
- msgRet.itemID = itemID
- msgRet.itemCnt = itemCnt
- msgRet.itemData[0] = 0
- if isAdd == true then
- print("下发为true")
- msgRet.itemData[0] = 1
- Grid.makeItem(msgRet.itemData[1], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
- end
- Msg.send(msgRet, human.fd)
- end
- -- 滚动
- function sendRoll(human, itemID, itemCnt)
-
- --[[local msgRet = Msg.gc.GC_ITEM_BAG_ROLL
- msgRet.itemData[0] = 1
- Grid.makeItem(msgRet.itemData[1], itemID, itemCnt)
- Msg.send(msgRet, human.fd)]]
- end
- -- 通用道具获得面板 list = {...}
- function sendItemGetList(human, list, logStr)
- if not list or not next(list) then return end
- if list[1] and list[1][1] then
- sendItemGetList1(human, list, logStr)
- else
- sendItemGetList2(human, list, logStr)
- end
- end
- -- 通用道具获得面板 list = {[1]={id,cnt},[2]={id2,cnt2}...}
- function sendItemGetList1(human, list, logStr)
- if not list or not next(list) then return end
- local msgRet = Msg.gc.GC_ITEM_GET_LIST
- msgRet.popupType = ItemDefine.checkIsWave(LogDefine.DEFINE[logStr]) and 1 or 0
- local len = math.min(#list, #msgRet.list)
- local cnt = 0
- cnt = EquipLogic.makeEquipItem(human, msgRet.list, cnt)
- local sourceId = 0
- for i=1,len do
- if cnt >= #msgRet.list then
- break
- end
- local itemID = list[i][1]
- local itemCnt = list[i][2]
- sourceId = list[i][4]
- itemCnt=calculateBonusItemCount(human,itemID,itemCnt,logStr)
- if not ItemDefine.isEquip(itemID) then
- cnt = cnt + 1
- --Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
- Grid.makeItem(msgRet.list[cnt], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID), nil, nil, sourceId)
- end
- end
- if cnt > 0 then
- msgRet.list[0] = cnt
- Msg.send(msgRet,human.fd)
- end
- end
- -- 通用道具获得面板2 list = {[id]=cnt,[id2]=cnt2}
- function sendItemGetList2(human, list, logStr)
- if not list or not next(list) then return end
- local msgRet = Msg.gc.GC_ITEM_GET_LIST
- msgRet.popupType = ItemDefine.checkIsWave(LogDefine.DEFINE[logStr]) and 1 or 0
- msgRet.list[0] = 0
- local cnt = 0
- cnt = EquipLogic.makeEquipItem(human, msgRet.list, cnt)
- local sourceId = 0
- for itemID, itemCnt in pairs(list) do
- if cnt >= #msgRet.list then
- break
- end
- -- itemCnt=calculateBonusItemCount(human,itemID,itemCnt,logStr)
- -- if not ItemDefine.isEquip(itemID) then
- -- cnt = cnt + 1
- -- --Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
- -- Grid.makeItem(msgRet.list[cnt], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
- -- end
- sourceId = 0
- local itemNum = 0
- if type(itemCnt) == "table" then
- itemNum = itemCnt[2]
- sourceId = itemCnt[4]
- else
- itemNum = itemCnt
- end
- itemNum=calculateBonusItemCount(human,itemID,itemNum,logStr)
- if not ItemDefine.isEquip(itemID) then
- cnt = cnt + 1
- --Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
- Grid.makeItem(msgRet.list[cnt], itemID, itemNum, nil,nil,nil, Grid.getOpflagAtBag(itemID), nil, nil, sourceId)
- end
- end
- --Msg.trace(msgRet)
- if cnt > 0 then
- msgRet.list[0] = cnt
- Msg.send(msgRet,human.fd)
- end
- end
- -- 通用道具获得面板2 list = {[id]=cnt,[id2]=cnt2}
- function sendItemGetList3(human, list, logStr)
- if not list or not next(list) then return end
- local msgRet = Msg.gc.GC_ITEM_GET_LIST
- msgRet.popupType = ItemDefine.checkIsWave(LogDefine.DEFINE[logStr]) and 1 or 0
- msgRet.list[0] = 0
- local cnt = 0
- cnt = EquipLogic.makeEquipItem(human, msgRet.list, cnt)
- for i = 1, #list do
- local items = list[i]
- for itemID, itemCnt in pairs(items) do
- if cnt >= #msgRet.list then
- break
- end
- if not ItemDefine.isEquip(itemID) then
- cnt = cnt + 1
- Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
- end
- end
- end
- if cnt > 0 then
- msgRet.list[0] = cnt
- Msg.send(msgRet,human.fd)
- end
- end
- -- 相同的道具自动叠加一起
- local SAME_ITEMS1 = {}
- local SAME_ITEMS2 = {}
- function sameItemTogether(list)
- if not list or not next(list) then return end
- for k in pairs(SAME_ITEMS1) do
- SAME_ITEMS1[k] = nil
- end
- for k in pairs(SAME_ITEMS2) do
- SAME_ITEMS2[k] = nil
- end
- for _, item in ipairs(list) do
- local itemID = item[1]
- local itemCnt = item[2]
- -- 装备符文不能叠加
- if not ItemDefine.isEquip(itemID) and not ItemDefine.isFuwen(itemID) then
- SAME_ITEMS1[itemID] = (SAME_ITEMS1[itemID] or 0) + itemCnt
- end
- end
- for itemID, itemCnt in pairs(SAME_ITEMS1) do
- SAME_ITEMS2[#SAME_ITEMS2 + 1] = {itemID, itemCnt}
- end
- return SAME_ITEMS2, SAME_ITEMS1
- end
- -- 背包道具出售
- function itemSell(human, itemID, itemCnt)
- if itemCnt < 1 then return end
- local itemConfig = ItemDefine.getConfig(itemID)
- if not itemConfig then return end
- if not itemConfig.price then return end
- local saleItemID = itemConfig.price[1]
- local saleItemCnt = itemConfig.price[2]
- if not saleItemCnt or saleItemCnt < 1 then return end -- 不能出售
- local bagCnt = getItemCnt(human, itemID)
- if bagCnt < itemCnt then return end
- local itemCntAdd = math.floor(saleItemCnt * itemCnt)
- delItem(human, itemID, itemCnt, "item_sale")
- addItem(human, saleItemID, itemCntAdd, "item_sale")
-
- local list = {}
- list[1] = { [1] = saleItemID, [2]= itemCntAdd }
- sendItemGetList(human, list)
- local msgRet = Msg.gc.GC_BAG_ITEM_SELL
- msgRet.id = itemID
- msgRet.cnt = itemCnt
- Msg.send(msgRet, human.fd)
- end
- -- 装备道具出售
- function equipSell(human, bagIndex)
- local equipGrid = human.db.equipBag[bagIndex]
- if not equipGrid then return end
- local itemConfig = ItemDefine.getConfig(equipGrid.id)
- if not itemConfig then return end
- if not itemConfig.price then return end
- local saleItemID = itemConfig.price[1]
- local saleItemCnt = itemConfig.price[2]
- if not saleItemCnt or saleItemCnt < 1 then return end
- EquipLogic.delEquip(human, bagIndex, "equip_sale")
- local itemCntAdd = saleItemCnt
- addItem(human, saleItemID, itemCntAdd, "equip_sale")
- sendItemGetList(human, {[1]=itemConfig.price})
- end
- -- 装备道具出售
- function equipSellByQuality(human, equipStr)
- local strTbl = Util.split(equipStr, "|")
- local equipTypeTbl = Util.split(strTbl[#strTbl], ",", true)
- local equipTypeList = {}
- for _, equipType in ipairs(equipTypeTbl) do
- if equipType == 1 then
- equipTypeList[ItemDefine.EQUIP_SUBTYPE_WEAPON] = 1
- equipTypeList[ItemDefine.EQUIP_SUBTYPE_CLOTH] = 1
- equipTypeList[ItemDefine.EQUIP_SUBTYPE_SHIPIN] = 1
- equipTypeList[ItemDefine.EQUIP_SUBTYPE_SHOES] = 1
- elseif equipType == 2 then
- equipTypeList[ItemDefine.EQUIP_SUBTYPE_RING] = 1
- equipTypeList[ItemDefine.EQUIP_SUBTYPE_AMULET] = 1
- else
- assert(false, string.format("装备类型错误, equipType = %s", equipType))
- end
- end
- local qualityStr = strTbl[1]
- local qualityList = Util.split(qualityStr, ",", true)
- local len = #qualityList
- if len <= 0 or len > 4 then return end
- local outItems = {}
- for i = 1, #qualityList do
- local quality = qualityList[i]
- for k, equipGrid in pairs(human.db.equipBag) do
- if equipGrid.quality == quality then
- local itemConfig = ItemDefine.getConfig(equipGrid.id)
- if not itemConfig then assert() end
- if not itemConfig.price then assert() end
- if equipTypeList[itemConfig.subType] then
- local saleItemID = itemConfig.price[1]
- local saleItemCnt = itemConfig.price[2]
- if not saleItemCnt or saleItemCnt < 1 then assert() end
- EquipLogic.delEquip(human, k, "equip_sale", true)
- local itemCntAdd = saleItemCnt
- addItem(human, saleItemID, itemCntAdd, "equip_sale")
- outItems[saleItemID] = outItems[saleItemID] or 0
- outItems[saleItemID] = outItems[saleItemID] + itemCntAdd
- end
- end
- end
- end
- sendItemGetList(human, outItems)
- -- 出售成功
- local msgRet = Msg.gc.GC_BAG_EQUIP_SELL_QUALITY
- Msg.send(msgRet,human.fd)
- end
- -- 道具购买查询
- function queryItemBuy(human, id)
- local config = ItemBuyExcel[id]
- if not config then return end
- local msgRet = Msg.gc.GC_ITEM_BUY_QUERY
- msgRet.id = id
- msgRet.item[0] = 1
- Grid.makeItem(msgRet.item[1], id , 1)
- msgRet.canBuy[0] = 2
- msgRet.canBuy[1] = config.cnt1
- msgRet.canBuy[2] = config.cnt2
- msgRet.need[0] = 0
- for _, item in ipairs(config.need1) do
- msgRet.need[0] = msgRet.need[0] + 1
- Grid.makeItem(msgRet.need[msgRet.need[0]], item[1], item[2])
- end
- msgRet.needTwo[0] = 0
- for _, item in ipairs(config.need2) do
- msgRet.needTwo[0] = msgRet.needTwo[0] + 1
- Grid.makeItem(msgRet.needTwo[msgRet.needTwo[0]], item[1], item[2])
- end
- --Msg.trace(msgRet)
- Msg.send(msgRet,human.fd)
- end
- -- 购买道具
- function buyItem(human, id, buyCnt, cnt)
- local config = ItemBuyExcel[id]
- if not config then return end
- local needList = nil
- if config.cnt1 == buyCnt then
- needList = config.need1
- elseif config.cnt2 == buyCnt then
- needList = config.need2
- end
- if not needList then return end
- if cnt < 1 then return end
- -- 判断消耗
- for _, item in ipairs(needList) do
- if not checkItemCnt(human, item[1], item[2] * cnt) then
- return
- end
- end
- -- 某些购买日志类型特殊
- local logType = "item_buy"
- if id == ItemDefine.ITEM_ABS_DRAW_LONGZHU_ID then
- logType = "item_buy_dragong"
- end
- -- 扣除道具
- for _, item in ipairs(needList) do
- delItem(human, item[1], item[2] * cnt, logType)
- end
- addItem(human, id, buyCnt * cnt, logType)
- Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
- local msgRet = Msg.gc.GC_ITEM_BUY
- msgRet.id = id
- Msg.send(msgRet, human.fd)
- end
- function sendCommonBuyQuery(human, itemID)
- local config = ItemComonBuyExcel[itemID]
- if not config then return end
- local msgRet = Msg.gc.GC_ITEM_COMMON_BUY_QUERY
- Grid.makeItem(msgRet.item, itemID, 1)
- msgRet.price = config.price
- Msg.send(msgRet, human.fd)
- end
- function commonBuy(human, itemID, itemCnt)
- if itemCnt < 1 then return end
- local config = ItemComonBuyExcel[itemID]
- if not config then return end
- local cost = config.price * itemCnt
- if not ObjHuman.checkRMB(human, cost) then
- return
- end
- ObjHuman.decZuanshi(human, -cost, "item_buy", itemID, itemCnt)
- addItem(human, itemID, itemCnt, "item_buy")
- local msgRet = Msg.gc.GC_ITEM_COMMON_BUY
- msgRet.itemID = itemID
- Msg.send(msgRet, human.fd)
- end
- function isDot(human)
- for itemID, itemCnt in pairs(human.db.bag) do
- local itemConfig = ItemExcel[itemID]
- if itemConfig then
- if itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN or
- itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN_SKIN then
- if itemCnt >= itemConfig.fullCnt then
- return true
- end
- end
- end
- end
- return false
- end
- -- 处理发送奖励类型为table
- function BagLogic_HandlePrizetable(tMsgItemList, list, nLen)
- if not list[1] or not list[1][1] then
- return false
- end
- local bRet = true
- for i = 1, #list do
- local items = list[i]
- for itemID, itemCnt in pairs(items) do
- if nLen >= #tMsgItemList then
- bRet = false
- break
- end
- if not ItemDefine.isEquip(itemID) then
- nLen = nLen + 1
- Grid.makeItem(tMsgItemList[nLen], itemID, itemCnt)
- end
- end
- end
- tMsgItemList[0] = nLen
- return bRet
- end
- -- 处理发送奖励为 Key-Value
- function BagLogic_HandlePrizeKeyVal(tMsgItemList, list, nLen)
- if list[1] and list[1][1] then
- return false
- end
- local bRet = true
- for itemID, itemCnt in pairs(list) do
- if cnt >= #tMsgItemList then
- bRet = false
- break
- end
- if not ItemDefine.isEquip(itemID) then
- nLen = nLen + 1
- Grid.makeItem(tMsgItemList[nLen], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
- end
- end
- tMsgItemList[0] = nLen
- return bRet
- end
- -- 外部获取需要下发的所有道具信息
- -- 主要是处理不弹窗装备的问题
- -- 返回是否发送成功
- function BagLogic_GetAllSendInfo(human, tMsgItemList, list, nType)
- local nLen = 0
- if nType ~= CommonDefine.COMMON_SEND_PRIZE_TYPE_ONLYEQUIP then
- nLen = EquipLogic.makeEquipItem(human, tMsgItemList, nLen)
- tMsgItemList[0] = nLen
- return true
- end
- local nAllLen = #tMsgItemList
- tMsgItemList[0] = 0
- nLen = EquipLogic.makeEquipItem(human, tMsgItemList, nLen)
-
- if nLen >= nAllLen then
- return false
- end
- tMsgItemList[0] = nLen
- if nil == list or nil == _G.next(list) then
- return true
- end
- -- 不同发送奖励类型的处理函数
- if CommonDefine.COMMON_SEND_PRIZE_TYPE_TABLE == nType then
- return BagLogic_HandlePrizetable(tMsgItemList, list, nLen)
- elseif CommonDefine.COMMON_SEND_PRIZE_TYPE_KEYVAL == nType then
- return BagLogic_HandlePrizeKeyVal(tMsgItemList, list, nLen)
- else
- return false
- end
- end
- -- 计算加成后的物品数量
- function calculateBonusItemCount(human, id, cnt,logType)
- --回退和重置不加成
- if logType then
- if logType == "hero_huitui" or logType == "hero_reset" then
- return cnt
- end
- end
- if id == ItemDefine.ITEM_JINBI_ID or id == ItemDefine.ITEM_GREEN_EXP_ID then
- -- 检查是否处于加成时间
- local isInBonusTime = CommonDB.GetInFireWork(human)
- if isInBonusTime == true then
- -- 应用10%加成,向下取整
- local nNewCnt = math.floor(cnt * 1.1)
- return nNewCnt
- end
- end
- -- 默认返回原数量
- return cnt
- end
|