BagLogic.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. ------------------------------------------------------------
  2. -- 背包
  3. -- addItem 添加道具
  4. -- delItem 删除道具
  5. -- sendItemGetList 通用道具获得界面
  6. -- checkItemCnt 检查道具数量是否足够,否则提示
  7. -- getItemCnt 返回道具数量
  8. ------------------------------------------------------------
  9. local EquipExcel = require("excel.equip").equip
  10. local ItemExcel = require("excel.item").item
  11. local FuwenExcel = require("excel.fuwen").fuwen
  12. local ItemBuyExcel = require("excel.item").buy
  13. local ItemComonBuyExcel = require("excel.item").commonBuy
  14. local Log = require("common.Log")
  15. local LogDefine = require("common.LogDefine")
  16. local Lang = require("common.Lang")
  17. local Util = require("common.Util")
  18. local ObjHuman = require("core.ObjHuman")
  19. local Msg = require("core.Msg")
  20. local Broadcast = require("broadcast.Broadcast")
  21. local Grid = require("bag.Grid")
  22. local ItemLogic = require("bag.ItemLogic")
  23. local ItemDefine = require("bag.ItemDefine")
  24. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  25. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  26. local FuwenLogic = require("fuwen.FuwenLogic")
  27. local MiddleOption = require("middle.MiddleOption")
  28. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  29. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  30. local EquipLogic = require("equip.EquipLogic")
  31. -- local YunYingLogic = require("yunying.YunYingLogic")
  32. -- local PanelDefine = require("broadcast.PanelDefine")
  33. local HeroGrowUp = require("absAct.HeroGrowUp")
  34. local CommonDefine = require("common.CommonDefine")
  35. local CommonDB = require("common.CommonDB")
  36. local ITEM_MOMENT_ADD_LIST = {}
  37. local jinbi_id=101
  38. local jinyan_id=111
  39. ADDITEM_TYPE_1 = 1 --顺序 不整合添加道具 非1 表示整合所有相同的道具数量
  40. ADDITEM_TYPE_2 = 2
  41. function updateMomentItem(type, itemID, itemCnt, quality)
  42. if type == ADDITEM_TYPE_1 then
  43. local len = #ITEM_MOMENT_ADD_LIST + 1
  44. ITEM_MOMENT_ADD_LIST[len] = {}
  45. ITEM_MOMENT_ADD_LIST[len][1] = itemID
  46. ITEM_MOMENT_ADD_LIST[len][2] = itemCnt
  47. ITEM_MOMENT_ADD_LIST[len][3] = quality
  48. else
  49. ITEM_MOMENT_ADD_LIST[itemID] = ITEM_MOMENT_ADD_LIST[itemID] or 0
  50. ITEM_MOMENT_ADD_LIST[itemID] = ITEM_MOMENT_ADD_LIST[itemID] + itemCnt
  51. end
  52. end
  53. -- 防止有报错 导致的 别的玩家 额外获得道具 在使用 通用的 添加之前 清除一次
  54. function cleanMomentItemList()
  55. Util.cleanTable(ITEM_MOMENT_ADD_LIST)
  56. end
  57. function addMomentItemList(human, logType, noSend)
  58. addItemList(human, ITEM_MOMENT_ADD_LIST, logType, noSend)
  59. cleanMomentItemList()
  60. end
  61. -- 通用道具添加 {[1] = {id, cnt}, [2] = {id,cnt}} or {[itemID] = itemCnt} 配表复杂 各自接口下自己for 添加
  62. function addItemList(human, list, logType, noSend)
  63. if not list or next(list) == nil then return end
  64. if list[1] and list[1][1] then
  65. for _, item in ipairs(list) do
  66. addItem(human, item[1], item[2], logType, noSend, item[3])
  67. end
  68. else
  69. for itemID, itemCnt in pairs(list) do
  70. addItem(human, itemID, itemCnt, logType, noSend)
  71. end
  72. end
  73. sendItemGetList(human, list, logType)
  74. end
  75. -- 增加装备,道具
  76. function addItem(human, id, cnt, logType, noSend, otherData)
  77. if cnt < 1 then return end
  78. local itemConfig = ItemDefine.getConfig(id)
  79. if not itemConfig then return end
  80. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["item"] then
  81. assert()
  82. end
  83. cnt = calculateBonusItemCount(human,id,cnt,logType)
  84. MiddleOption.addItem(human, id, cnt, logType)
  85. if handlerSpObj(human, id, cnt, logType) then
  86. print("[addItem] 不进入背包物品直接返回 id, cnt = ", id, cnt)
  87. return
  88. end
  89. if handleFuwen(human, id, cnt, logType) then
  90. print("[addItem] 符文物品不进入背包物品直接返回 id, cnt = ", id, cnt)
  91. return
  92. end
  93. -- 装备走另外的逻辑
  94. if handleEquipAdd(human, id, cnt, logType, otherData) then
  95. print("[addItem] 装备物品其他方式处理 id, cnt = ", id, cnt)
  96. return
  97. end
  98. local oldCnt = human.db.bag[id] or 0
  99. local newCnt = math.min(oldCnt + cnt, ItemDefine.BAG_ITEM_MAX_CNT)
  100. human.db.bag[id] = newCnt
  101. print("当前添加的物品数量",newCnt)
  102. if not noSend then
  103. print("当前的oldcnt",oldCnt)
  104. sendChange(human, id, oldCnt < 1)
  105. print("send charge 下发逻辑")
  106. end
  107. Log.write(Log.LOGID_OSS_ITEM, human.db._id, human.db.account, human.db.name, human.db.lv,
  108. LogDefine.DEFINE[logType] + LogDefine.TYPE["item"] , id, cnt, newCnt)
  109. -- 如果道具为公会贡献,记录到当日累计贡献中
  110. if id == ItemDefine.ITEM_UNION_COIN_ID then
  111. human.db.dailyBanggong = human.db.dailyBanggong or 0
  112. human.db.dailyBanggong = human.db.dailyBanggong + cnt
  113. human.db.totalBanggong = human.db.totalBanggong or 0
  114. human.db.totalBanggong = human.db.totalBanggong + cnt
  115. end
  116. -- 根据道具触发红点
  117. checkDotByID(human,id)
  118. return true
  119. end
  120. function checkDotByID(human,id)
  121. local itemConfig = ItemDefine.getConfig(id)
  122. local dotTb = itemConfig.dot
  123. local len = #dotTb
  124. for i = 1,len do
  125. RoleSystemLogic.onDot(human, dotTb[i])
  126. end
  127. end
  128. -- 根据id删除
  129. function delItem(human, id, cnt, logType, noSend, byId, byCnt)
  130. if cnt < 1 then return end
  131. local itemConfig = ItemExcel[id]
  132. if not itemConfig then return end
  133. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["item"] then
  134. assert()
  135. end
  136. if id == ItemDefine.ITEM_JINBI_ID then
  137. return ObjHuman.updateJinbi(human, -cnt, logType, byId, byCnt)
  138. elseif id == ItemDefine.ITEM_ZUANSHI_ID then
  139. return ObjHuman.decZuanshi(human, -cnt, logType, byId, byCnt)
  140. elseif id == ItemDefine.ITEM_FRIEND_ID then
  141. return ObjHuman.updateFriendHeart(human, -cnt, logType)
  142. end
  143. local newCnt = (human.db.bag[id] or 0) - cnt
  144. if newCnt < 0 then assert(nil) end
  145. if newCnt < 1 then
  146. newCnt = nil
  147. end
  148. human.db.bag[id] = newCnt
  149. if not noSend then
  150. sendChange(human, id)
  151. end
  152. Log.write(Log.LOGID_OSS_ITEM, human.db._id, human.db.account, human.db.name, human.db.lv,
  153. LogDefine.DEFINE[logType] + LogDefine.TYPE["item"] , id, -cnt, newCnt or 0)
  154. if itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN or
  155. itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN_SKIN then
  156. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_206)
  157. end
  158. if id == ItemDefine.ITEM_GREEN_EXP_ID then
  159. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE18, cnt)
  160. end
  161. return true
  162. end
  163. -- 获得道具数量
  164. function getItemCnt(human, id, isUse)
  165. if id == ItemDefine.ITEM_JINBI_ID and not isUse then
  166. return human.db.jinbi or 0
  167. elseif id == ItemDefine.ITEM_ZUANSHI_ID and not isUse then
  168. return human.db.zuanshi or 0
  169. elseif id == ItemDefine.ITEM_FRIEND_ID and not isUse then
  170. return human.db.friendHeart or 0
  171. end
  172. return human.db.bag[id] or 0
  173. end
  174. -- 判断道具数量
  175. function checkItemCnt(human, id, cnt)
  176. if id == ItemDefine.ITEM_ZUANSHI_ID then
  177. return ObjHuman.checkRMB(human,cnt)
  178. end
  179. if getItemCnt(human, id) < cnt then
  180. local name = ItemDefine.getValue(id,"name")
  181. return Broadcast.sendErr(human,Util.format(Lang.COMMON_NO_ITEM, name))
  182. end
  183. return true
  184. end
  185. -- 特殊不进背包的道具
  186. function handlerSpObj(human, itemID, itemCnt, logType)
  187. local itemConfig = ItemExcel[itemID]
  188. if not itemConfig then return end
  189. if itemConfig.subType ~= ItemDefine.ITEM_SUBTYPE_SPOBJ then
  190. return
  191. end
  192. local cmdstr = itemConfig.cmd and itemConfig.cmd[1]
  193. if cmdstr and ItemLogic.cmd[cmdstr] then
  194. ItemLogic.onlyuse(human, itemID, itemCnt, logType, true)
  195. -- 根据道具触发红点
  196. checkDotByID(human,itemID)
  197. end
  198. if ItemDefine.checkIsWave(LogDefine.DEFINE[logType]) then
  199. sendRoll(human, itemID, itemCnt)
  200. end
  201. return true
  202. end
  203. -- 符文
  204. function handleFuwen(human, itemID, itemCnt, logType)
  205. if not FuwenExcel[itemID] then return end
  206. FuwenLogic.add(human, itemID, itemCnt, logType)
  207. if ItemDefine.checkIsWave(LogDefine.DEFINE[logType]) then
  208. sendRoll(human, itemID, itemCnt)
  209. end
  210. return true
  211. end
  212. -- 装备增加
  213. function handleEquipAdd(human, itemID, itemCnt, logType, otherData)
  214. if not EquipExcel[itemID] then return end
  215. EquipLogic.addEquip(human, itemID, itemCnt, logType, otherData)
  216. if EquipExcel[itemID].mainType == ItemDefine.MAINTYPE_EQUIP then
  217. if EquipExcel[itemID].level == 14 then
  218. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_24,itemCnt)
  219. end
  220. end
  221. if ItemDefine.checkIsWave(LogDefine.DEFINE[logType]) then
  222. sendRoll(human, itemID, itemCnt)
  223. end
  224. return true
  225. end
  226. ---------------------------- msg --------------------------------
  227. -- 发送背包道具
  228. function sendBagList(human)
  229. local msgRet = Msg.gc.GC_BAG_LIST
  230. msgRet.list[0] = 0
  231. for itemID, itemCnt in pairs(human.db.bag) do
  232. msgRet.list[0] = msgRet.list[0] + 1
  233. local net = msgRet.list[msgRet.list[0]]
  234. Grid.makeItem(net, itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
  235. if msgRet.list[0] >= ItemDefine.PAGE_LIST_COUNT then
  236. Msg.send(msgRet, human.fd)
  237. msgRet.list[0] = 0
  238. end
  239. end
  240. if msgRet.list[0] > 0 then
  241. Msg.send(msgRet, human.fd)
  242. end
  243. end
  244. -- 改变
  245. function sendChange(human, itemID, isAdd)
  246. print("12131231进入下发逻辑")
  247. local msgRet = Msg.gc.GC_ITEM_BAG_CHANGE
  248. local itemCnt = human.db.bag[itemID] or 0
  249. msgRet.itemID = itemID
  250. msgRet.itemCnt = itemCnt
  251. msgRet.itemData[0] = 0
  252. if isAdd == true then
  253. print("下发为true")
  254. msgRet.itemData[0] = 1
  255. Grid.makeItem(msgRet.itemData[1], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
  256. end
  257. Msg.send(msgRet, human.fd)
  258. end
  259. -- 滚动
  260. function sendRoll(human, itemID, itemCnt)
  261. --[[local msgRet = Msg.gc.GC_ITEM_BAG_ROLL
  262. msgRet.itemData[0] = 1
  263. Grid.makeItem(msgRet.itemData[1], itemID, itemCnt)
  264. Msg.send(msgRet, human.fd)]]
  265. end
  266. -- 通用道具获得面板 list = {...}
  267. function sendItemGetList(human, list, logStr)
  268. if not list or not next(list) then return end
  269. if list[1] and list[1][1] then
  270. sendItemGetList1(human, list, logStr)
  271. else
  272. sendItemGetList2(human, list, logStr)
  273. end
  274. end
  275. -- 通用道具获得面板 list = {[1]={id,cnt},[2]={id2,cnt2}...}
  276. function sendItemGetList1(human, list, logStr)
  277. if not list or not next(list) then return end
  278. local msgRet = Msg.gc.GC_ITEM_GET_LIST
  279. msgRet.popupType = ItemDefine.checkIsWave(LogDefine.DEFINE[logStr]) and 1 or 0
  280. local len = math.min(#list, #msgRet.list)
  281. local cnt = 0
  282. cnt = EquipLogic.makeEquipItem(human, msgRet.list, cnt)
  283. for i=1,len do
  284. if cnt >= #msgRet.list then
  285. break
  286. end
  287. local itemID = list[i][1]
  288. local itemCnt = list[i][2]
  289. itemCnt=calculateBonusItemCount(human,itemID,itemCnt,logStr)
  290. if not ItemDefine.isEquip(itemID) then
  291. cnt = cnt + 1
  292. --Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
  293. Grid.makeItem(msgRet.list[cnt], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
  294. end
  295. end
  296. if cnt > 0 then
  297. msgRet.list[0] = cnt
  298. Msg.send(msgRet,human.fd)
  299. end
  300. end
  301. -- 通用道具获得面板2 list = {[id]=cnt,[id2]=cnt2}
  302. function sendItemGetList2(human, list, logStr)
  303. if not list or not next(list) then return end
  304. local msgRet = Msg.gc.GC_ITEM_GET_LIST
  305. msgRet.popupType = ItemDefine.checkIsWave(LogDefine.DEFINE[logStr]) and 1 or 0
  306. msgRet.list[0] = 0
  307. local cnt = 0
  308. cnt = EquipLogic.makeEquipItem(human, msgRet.list, cnt)
  309. for itemID, itemCnt in pairs(list) do
  310. if cnt >= #msgRet.list then
  311. break
  312. end
  313. itemCnt=calculateBonusItemCount(human,itemID,itemCnt,logStr)
  314. if not ItemDefine.isEquip(itemID) then
  315. cnt = cnt + 1
  316. --Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
  317. Grid.makeItem(msgRet.list[cnt], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
  318. end
  319. end
  320. --Msg.trace(msgRet)
  321. if cnt > 0 then
  322. msgRet.list[0] = cnt
  323. Msg.send(msgRet,human.fd)
  324. end
  325. end
  326. -- 通用道具获得面板2 list = {[id]=cnt,[id2]=cnt2}
  327. function sendItemGetList3(human, list, logStr)
  328. if not list or not next(list) then return end
  329. local msgRet = Msg.gc.GC_ITEM_GET_LIST
  330. msgRet.popupType = ItemDefine.checkIsWave(LogDefine.DEFINE[logStr]) and 1 or 0
  331. msgRet.list[0] = 0
  332. local cnt = 0
  333. cnt = EquipLogic.makeEquipItem(human, msgRet.list, cnt)
  334. for i = 1, #list do
  335. local items = list[i]
  336. for itemID, itemCnt in pairs(items) do
  337. if cnt >= #msgRet.list then
  338. break
  339. end
  340. if not ItemDefine.isEquip(itemID) then
  341. cnt = cnt + 1
  342. Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
  343. end
  344. end
  345. end
  346. if cnt > 0 then
  347. msgRet.list[0] = cnt
  348. Msg.send(msgRet,human.fd)
  349. end
  350. end
  351. -- 相同的道具自动叠加一起
  352. local SAME_ITEMS1 = {}
  353. local SAME_ITEMS2 = {}
  354. function sameItemTogether(list)
  355. if not list or not next(list) then return end
  356. for k in pairs(SAME_ITEMS1) do
  357. SAME_ITEMS1[k] = nil
  358. end
  359. for k in pairs(SAME_ITEMS2) do
  360. SAME_ITEMS2[k] = nil
  361. end
  362. for _, item in ipairs(list) do
  363. local itemID = item[1]
  364. local itemCnt = item[2]
  365. -- 装备符文不能叠加
  366. if not ItemDefine.isEquip(itemID) and not ItemDefine.isFuwen(itemID) then
  367. SAME_ITEMS1[itemID] = (SAME_ITEMS1[itemID] or 0) + itemCnt
  368. end
  369. end
  370. for itemID, itemCnt in pairs(SAME_ITEMS1) do
  371. SAME_ITEMS2[#SAME_ITEMS2 + 1] = {itemID, itemCnt}
  372. end
  373. return SAME_ITEMS2, SAME_ITEMS1
  374. end
  375. -- 背包道具出售
  376. function itemSell(human, itemID, itemCnt)
  377. if itemCnt < 1 then return end
  378. local itemConfig = ItemDefine.getConfig(itemID)
  379. if not itemConfig then return end
  380. if not itemConfig.price then return end
  381. local saleItemID = itemConfig.price[1]
  382. local saleItemCnt = itemConfig.price[2]
  383. if not saleItemCnt or saleItemCnt < 1 then return end -- 不能出售
  384. local bagCnt = getItemCnt(human, itemID)
  385. if bagCnt < itemCnt then return end
  386. local itemCntAdd = math.floor(saleItemCnt * itemCnt)
  387. delItem(human, itemID, itemCnt, "item_sale")
  388. addItem(human, saleItemID, itemCntAdd, "item_sale")
  389. local list = {}
  390. list[1] = { [1] = saleItemID, [2]= itemCntAdd }
  391. sendItemGetList(human, list)
  392. local msgRet = Msg.gc.GC_BAG_ITEM_SELL
  393. msgRet.id = itemID
  394. msgRet.cnt = itemCnt
  395. Msg.send(msgRet, human.fd)
  396. end
  397. -- 装备道具出售
  398. function equipSell(human, bagIndex)
  399. local equipGrid = human.db.equipBag[bagIndex]
  400. if not equipGrid then return end
  401. local itemConfig = ItemDefine.getConfig(equipGrid.id)
  402. if not itemConfig then return end
  403. if not itemConfig.price then return end
  404. local saleItemID = itemConfig.price[1]
  405. local saleItemCnt = itemConfig.price[2]
  406. if not saleItemCnt or saleItemCnt < 1 then return end
  407. EquipLogic.delEquip(human, bagIndex, "equip_sale")
  408. local itemCntAdd = saleItemCnt
  409. addItem(human, saleItemID, itemCntAdd, "equip_sale")
  410. sendItemGetList(human, {[1]=itemConfig.price})
  411. end
  412. -- 装备道具出售
  413. function equipSellByQuality(human, qualityStr)
  414. local qualityList = Util.split(qualityStr, ",", true)
  415. local len = #qualityList
  416. if len <= 0 or len > 4 then return end
  417. local outItems = {}
  418. for i = 1, #qualityList do
  419. local quality = qualityList[i]
  420. for k, equipGrid in pairs(human.db.equipBag) do
  421. if equipGrid.quality == quality then
  422. local itemConfig = ItemDefine.getConfig(equipGrid.id)
  423. if not itemConfig then assert() end
  424. if not itemConfig.price then assert() end
  425. local saleItemID = itemConfig.price[1]
  426. local saleItemCnt = itemConfig.price[2]
  427. if not saleItemCnt or saleItemCnt < 1 then assert() end
  428. EquipLogic.delEquip(human, k, "equip_sale", true)
  429. local itemCntAdd = saleItemCnt
  430. addItem(human, saleItemID, itemCntAdd, "equip_sale")
  431. outItems[saleItemID] = outItems[saleItemID] or 0
  432. outItems[saleItemID] = outItems[saleItemID] + itemCntAdd
  433. end
  434. end
  435. end
  436. sendItemGetList(human, outItems)
  437. -- 出售成功
  438. local msgRet = Msg.gc.GC_BAG_EQUIP_SELL_QUALITY
  439. Msg.send(msgRet,human.fd)
  440. end
  441. -- 道具购买查询
  442. function queryItemBuy(human, id)
  443. local config = ItemBuyExcel[id]
  444. if not config then return end
  445. local msgRet = Msg.gc.GC_ITEM_BUY_QUERY
  446. msgRet.id = id
  447. msgRet.item[0] = 1
  448. Grid.makeItem(msgRet.item[1], id , 1)
  449. msgRet.canBuy[0] = 2
  450. msgRet.canBuy[1] = config.cnt1
  451. msgRet.canBuy[2] = config.cnt2
  452. msgRet.need[0] = 0
  453. for _, item in ipairs(config.need1) do
  454. msgRet.need[0] = msgRet.need[0] + 1
  455. Grid.makeItem(msgRet.need[msgRet.need[0]], item[1], item[2])
  456. end
  457. msgRet.needTwo[0] = 0
  458. for _, item in ipairs(config.need2) do
  459. msgRet.needTwo[0] = msgRet.needTwo[0] + 1
  460. Grid.makeItem(msgRet.needTwo[msgRet.needTwo[0]], item[1], item[2])
  461. end
  462. --Msg.trace(msgRet)
  463. Msg.send(msgRet,human.fd)
  464. end
  465. -- 购买道具
  466. function buyItem(human, id, buyCnt, cnt)
  467. local config = ItemBuyExcel[id]
  468. if not config then return end
  469. local needList = nil
  470. if config.cnt1 == buyCnt then
  471. needList = config.need1
  472. elseif config.cnt2 == buyCnt then
  473. needList = config.need2
  474. end
  475. if not needList then return end
  476. if cnt < 1 then return end
  477. -- 判断消耗
  478. for _, item in ipairs(needList) do
  479. if not checkItemCnt(human, item[1], item[2] * cnt) then
  480. return
  481. end
  482. end
  483. -- 某些购买日志类型特殊
  484. local logType = "item_buy"
  485. if id == ItemDefine.ITEM_ABS_DRAW_LONGZHU_ID then
  486. logType = "item_buy_dragong"
  487. end
  488. -- 扣除道具
  489. for _, item in ipairs(needList) do
  490. delItem(human, item[1], item[2] * cnt, logType)
  491. end
  492. addItem(human, id, buyCnt * cnt, logType)
  493. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  494. local msgRet = Msg.gc.GC_ITEM_BUY
  495. msgRet.id = id
  496. Msg.send(msgRet, human.fd)
  497. end
  498. function sendCommonBuyQuery(human, itemID)
  499. local config = ItemComonBuyExcel[itemID]
  500. if not config then return end
  501. local msgRet = Msg.gc.GC_ITEM_COMMON_BUY_QUERY
  502. Grid.makeItem(msgRet.item, itemID, 1)
  503. msgRet.price = config.price
  504. Msg.send(msgRet, human.fd)
  505. end
  506. function commonBuy(human, itemID, itemCnt)
  507. if itemCnt < 1 then return end
  508. local config = ItemComonBuyExcel[itemID]
  509. if not config then return end
  510. local cost = config.price * itemCnt
  511. if not ObjHuman.checkRMB(human, cost) then
  512. return
  513. end
  514. ObjHuman.decZuanshi(human, -cost, "item_buy", itemID, itemCnt)
  515. addItem(human, itemID, itemCnt, "item_buy")
  516. local msgRet = Msg.gc.GC_ITEM_COMMON_BUY
  517. msgRet.itemID = itemID
  518. Msg.send(msgRet, human.fd)
  519. end
  520. function isDot(human)
  521. for itemID, itemCnt in pairs(human.db.bag) do
  522. local itemConfig = ItemExcel[itemID]
  523. if itemConfig then
  524. if itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN or
  525. itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN_SKIN then
  526. if itemCnt >= itemConfig.fullCnt then
  527. return true
  528. end
  529. end
  530. end
  531. end
  532. return false
  533. end
  534. -- 处理发送奖励类型为table
  535. function BagLogic_HandlePrizetable(tMsgItemList, list, nLen)
  536. if not list[1] or not list[1][1] then
  537. return false
  538. end
  539. local bRet = true
  540. for i = 1, #list do
  541. local items = list[i]
  542. for itemID, itemCnt in pairs(items) do
  543. if nLen >= #tMsgItemList then
  544. bRet = false
  545. break
  546. end
  547. if not ItemDefine.isEquip(itemID) then
  548. nLen = nLen + 1
  549. Grid.makeItem(tMsgItemList[nLen], itemID, itemCnt)
  550. end
  551. end
  552. end
  553. tMsgItemList[0] = nLen
  554. return bRet
  555. end
  556. -- 处理发送奖励为 Key-Value
  557. function BagLogic_HandlePrizeKeyVal(tMsgItemList, list, nLen)
  558. if list[1] and list[1][1] then
  559. return false
  560. end
  561. local bRet = true
  562. for itemID, itemCnt in pairs(list) do
  563. if cnt >= #tMsgItemList then
  564. bRet = false
  565. break
  566. end
  567. if not ItemDefine.isEquip(itemID) then
  568. nLen = nLen + 1
  569. Grid.makeItem(tMsgItemList[nLen], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
  570. end
  571. end
  572. tMsgItemList[0] = nLen
  573. return bRet
  574. end
  575. -- 外部获取需要下发的所有道具信息
  576. -- 主要是处理不弹窗装备的问题
  577. -- 返回是否发送成功
  578. function BagLogic_GetAllSendInfo(human, tMsgItemList, list, nType)
  579. local nLen = 0
  580. if nType ~= CommonDefine.COMMON_SEND_PRIZE_TYPE_ONLYEQUIP then
  581. nLen = EquipLogic.makeEquipItem(human, tMsgItemList, nLen)
  582. tMsgItemList[0] = nLen
  583. return true
  584. end
  585. local nAllLen = #tMsgItemList
  586. tMsgItemList[0] = 0
  587. nLen = EquipLogic.makeEquipItem(human, tMsgItemList, nLen)
  588. if nLen >= nAllLen then
  589. return false
  590. end
  591. tMsgItemList[0] = nLen
  592. if nil == list or nil == _G.next(list) then
  593. return true
  594. end
  595. -- 不同发送奖励类型的处理函数
  596. if CommonDefine.COMMON_SEND_PRIZE_TYPE_TABLE == nType then
  597. return BagLogic_HandlePrizetable(tMsgItemList, list, nLen)
  598. elseif CommonDefine.COMMON_SEND_PRIZE_TYPE_KEYVAL == nType then
  599. return BagLogic_HandlePrizeKeyVal(tMsgItemList, list, nLen)
  600. else
  601. return false
  602. end
  603. end
  604. -- 计算加成后的物品数量
  605. function calculateBonusItemCount(human, id, cnt,logType)
  606. --回退和重置不加成
  607. if logType then
  608. if logType == "hero_huitui" or logType == "hero_reset" then
  609. return cnt
  610. end
  611. end
  612. if id == ItemDefine.ITEM_JINBI_ID or id == ItemDefine.ITEM_GREEN_EXP_ID then
  613. -- 检查是否处于加成时间
  614. local isInBonusTime = CommonDB.GetInFireWork(human)
  615. if isInBonusTime == true then
  616. -- 应用10%加成,向下取整
  617. local nNewCnt = math.floor(cnt * 1.1)
  618. return nNewCnt
  619. end
  620. end
  621. -- 默认返回原数量
  622. return cnt
  623. end