BagLogic.lua 21 KB

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