BagLogic.lua 22 KB

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