BagLogic.lua 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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. if not ItemDefine.isEquip(itemID) then
  285. cnt = cnt + 1
  286. --Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
  287. Grid.makeItem(msgRet.list[cnt], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
  288. end
  289. end
  290. if cnt > 0 then
  291. msgRet.list[0] = cnt
  292. Msg.send(msgRet,human.fd)
  293. end
  294. end
  295. -- 通用道具获得面板2 list = {[id]=cnt,[id2]=cnt2}
  296. function sendItemGetList2(human, list, logStr)
  297. if not list or not next(list) then return end
  298. local msgRet = Msg.gc.GC_ITEM_GET_LIST
  299. msgRet.popupType = ItemDefine.checkIsWave(LogDefine.DEFINE[logStr]) and 1 or 0
  300. msgRet.list[0] = 0
  301. local cnt = 0
  302. cnt = EquipLogic.makeEquipItem(human, msgRet.list, cnt)
  303. for itemID, itemCnt in pairs(list) do
  304. if cnt >= #msgRet.list then
  305. break
  306. end
  307. if not ItemDefine.isEquip(itemID) then
  308. cnt = cnt + 1
  309. --Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
  310. Grid.makeItem(msgRet.list[cnt], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
  311. end
  312. end
  313. --Msg.trace(msgRet)
  314. if cnt > 0 then
  315. msgRet.list[0] = cnt
  316. Msg.send(msgRet,human.fd)
  317. end
  318. end
  319. -- 通用道具获得面板2 list = {[id]=cnt,[id2]=cnt2}
  320. function sendItemGetList3(human, list, logStr)
  321. if not list or not next(list) then return end
  322. local msgRet = Msg.gc.GC_ITEM_GET_LIST
  323. msgRet.popupType = ItemDefine.checkIsWave(LogDefine.DEFINE[logStr]) and 1 or 0
  324. msgRet.list[0] = 0
  325. local cnt = 0
  326. cnt = EquipLogic.makeEquipItem(human, msgRet.list, cnt)
  327. for i = 1, #list do
  328. local items = list[i]
  329. for itemID, itemCnt in pairs(items) do
  330. if cnt >= #msgRet.list then
  331. break
  332. end
  333. if not ItemDefine.isEquip(itemID) then
  334. cnt = cnt + 1
  335. Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
  336. end
  337. end
  338. end
  339. if cnt > 0 then
  340. msgRet.list[0] = cnt
  341. Msg.send(msgRet,human.fd)
  342. end
  343. end
  344. -- 相同的道具自动叠加一起
  345. local SAME_ITEMS1 = {}
  346. local SAME_ITEMS2 = {}
  347. function sameItemTogether(list)
  348. if not list or not next(list) then return end
  349. for k in pairs(SAME_ITEMS1) do
  350. SAME_ITEMS1[k] = nil
  351. end
  352. for k in pairs(SAME_ITEMS2) do
  353. SAME_ITEMS2[k] = nil
  354. end
  355. for _, item in ipairs(list) do
  356. local itemID = item[1]
  357. local itemCnt = item[2]
  358. -- 装备符文不能叠加
  359. if not ItemDefine.isEquip(itemID) and not ItemDefine.isFuwen(itemID) then
  360. SAME_ITEMS1[itemID] = (SAME_ITEMS1[itemID] or 0) + itemCnt
  361. end
  362. end
  363. for itemID, itemCnt in pairs(SAME_ITEMS1) do
  364. SAME_ITEMS2[#SAME_ITEMS2 + 1] = {itemID, itemCnt}
  365. end
  366. return SAME_ITEMS2, SAME_ITEMS1
  367. end
  368. -- 背包道具出售
  369. function itemSell(human, itemID, itemCnt)
  370. if itemCnt < 1 then return end
  371. local itemConfig = ItemDefine.getConfig(itemID)
  372. if not itemConfig then return end
  373. if not itemConfig.price then return end
  374. local saleItemID = itemConfig.price[1]
  375. local saleItemCnt = itemConfig.price[2]
  376. if not saleItemCnt or saleItemCnt < 1 then return end -- 不能出售
  377. local bagCnt = getItemCnt(human, itemID)
  378. if bagCnt < itemCnt then return end
  379. local itemCntAdd = math.floor(saleItemCnt * itemCnt)
  380. delItem(human, itemID, itemCnt, "item_sale")
  381. addItem(human, saleItemID, itemCntAdd, "item_sale")
  382. local list = {}
  383. list[1] = { [1] = saleItemID, [2]= itemCntAdd }
  384. sendItemGetList(human, list)
  385. local msgRet = Msg.gc.GC_BAG_ITEM_SELL
  386. msgRet.id = itemID
  387. msgRet.cnt = itemCnt
  388. Msg.send(msgRet, human.fd)
  389. end
  390. -- 装备道具出售
  391. function equipSell(human, bagIndex)
  392. local equipGrid = human.db.equipBag[bagIndex]
  393. if not equipGrid then return end
  394. local itemConfig = ItemDefine.getConfig(equipGrid.id)
  395. if not itemConfig then return end
  396. if not itemConfig.price then return end
  397. local saleItemID = itemConfig.price[1]
  398. local saleItemCnt = itemConfig.price[2]
  399. if not saleItemCnt or saleItemCnt < 1 then return end
  400. EquipLogic.delEquip(human, bagIndex, "equip_sale")
  401. local itemCntAdd = saleItemCnt
  402. addItem(human, saleItemID, itemCntAdd, "equip_sale")
  403. sendItemGetList(human, {[1]=itemConfig.price})
  404. end
  405. -- 装备道具出售
  406. function equipSellByQuality(human, qualityStr)
  407. local qualityList = Util.split(qualityStr, ",", true)
  408. local len = #qualityList
  409. if len <= 0 or len > 4 then return end
  410. local outItems = {}
  411. for i = 1, #qualityList do
  412. local quality = qualityList[i]
  413. for k, equipGrid in pairs(human.db.equipBag) do
  414. if equipGrid.quality == quality then
  415. local itemConfig = ItemDefine.getConfig(equipGrid.id)
  416. if not itemConfig then assert() end
  417. if not itemConfig.price then assert() end
  418. local saleItemID = itemConfig.price[1]
  419. local saleItemCnt = itemConfig.price[2]
  420. if not saleItemCnt or saleItemCnt < 1 then assert() end
  421. EquipLogic.delEquip(human, k, "equip_sale", true)
  422. local itemCntAdd = saleItemCnt
  423. addItem(human, saleItemID, itemCntAdd, "equip_sale")
  424. outItems[saleItemID] = outItems[saleItemID] or 0
  425. outItems[saleItemID] = outItems[saleItemID] + itemCntAdd
  426. end
  427. end
  428. end
  429. sendItemGetList(human, outItems)
  430. -- 出售成功
  431. local msgRet = Msg.gc.GC_BAG_EQUIP_SELL_QUALITY
  432. Msg.send(msgRet,human.fd)
  433. end
  434. -- 道具购买查询
  435. function queryItemBuy(human, id)
  436. local config = ItemBuyExcel[id]
  437. if not config then return end
  438. local msgRet = Msg.gc.GC_ITEM_BUY_QUERY
  439. msgRet.id = id
  440. msgRet.item[0] = 1
  441. Grid.makeItem(msgRet.item[1], id , 1)
  442. msgRet.canBuy[0] = 2
  443. msgRet.canBuy[1] = config.cnt1
  444. msgRet.canBuy[2] = config.cnt2
  445. msgRet.need[0] = 0
  446. for _, item in ipairs(config.need1) do
  447. msgRet.need[0] = msgRet.need[0] + 1
  448. Grid.makeItem(msgRet.need[msgRet.need[0]], item[1], item[2])
  449. end
  450. msgRet.needTwo[0] = 0
  451. for _, item in ipairs(config.need2) do
  452. msgRet.needTwo[0] = msgRet.needTwo[0] + 1
  453. Grid.makeItem(msgRet.needTwo[msgRet.needTwo[0]], item[1], item[2])
  454. end
  455. --Msg.trace(msgRet)
  456. Msg.send(msgRet,human.fd)
  457. end
  458. -- 购买道具
  459. function buyItem(human, id, buyCnt, cnt)
  460. local config = ItemBuyExcel[id]
  461. if not config then return end
  462. local needList = nil
  463. if config.cnt1 == buyCnt then
  464. needList = config.need1
  465. elseif config.cnt2 == buyCnt then
  466. needList = config.need2
  467. end
  468. if not needList then return end
  469. if cnt < 1 then return end
  470. -- 判断消耗
  471. for _, item in ipairs(needList) do
  472. if not checkItemCnt(human, item[1], item[2] * cnt) then
  473. return
  474. end
  475. end
  476. -- 某些购买日志类型特殊
  477. local logType = "item_buy"
  478. if id == ItemDefine.ITEM_ABS_DRAW_LONGZHU_ID then
  479. logType = "item_buy_dragong"
  480. end
  481. -- 扣除道具
  482. for _, item in ipairs(needList) do
  483. delItem(human, item[1], item[2] * cnt, logType)
  484. end
  485. addItem(human, id, buyCnt * cnt, logType)
  486. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  487. local msgRet = Msg.gc.GC_ITEM_BUY
  488. msgRet.id = id
  489. Msg.send(msgRet, human.fd)
  490. end
  491. function sendCommonBuyQuery(human, itemID)
  492. local config = ItemComonBuyExcel[itemID]
  493. if not config then return end
  494. local msgRet = Msg.gc.GC_ITEM_COMMON_BUY_QUERY
  495. Grid.makeItem(msgRet.item, itemID, 1)
  496. msgRet.price = config.price
  497. Msg.send(msgRet, human.fd)
  498. end
  499. function commonBuy(human, itemID, itemCnt)
  500. if itemCnt < 1 then return end
  501. local config = ItemComonBuyExcel[itemID]
  502. if not config then return end
  503. local cost = config.price * itemCnt
  504. if not ObjHuman.checkRMB(human, cost) then
  505. return
  506. end
  507. ObjHuman.decZuanshi(human, -cost, "item_buy", itemID, itemCnt)
  508. addItem(human, itemID, itemCnt, "item_buy")
  509. local msgRet = Msg.gc.GC_ITEM_COMMON_BUY
  510. msgRet.itemID = itemID
  511. Msg.send(msgRet, human.fd)
  512. end
  513. function isDot(human)
  514. for itemID, itemCnt in pairs(human.db.bag) do
  515. local itemConfig = ItemExcel[itemID]
  516. if itemConfig then
  517. if itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN or
  518. itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN_SKIN then
  519. if itemCnt >= itemConfig.fullCnt then
  520. return true
  521. end
  522. end
  523. end
  524. end
  525. return false
  526. end
  527. -- 处理发送奖励类型为table
  528. function BagLogic_HandlePrizetable(tMsgItemList, list, nLen)
  529. if not list[1] or not list[1][1] then
  530. return false
  531. end
  532. local bRet = true
  533. for i = 1, #list do
  534. local items = list[i]
  535. for itemID, itemCnt in pairs(items) do
  536. if nLen >= #tMsgItemList then
  537. bRet = false
  538. break
  539. end
  540. if not ItemDefine.isEquip(itemID) then
  541. nLen = nLen + 1
  542. Grid.makeItem(tMsgItemList[nLen], itemID, itemCnt)
  543. end
  544. end
  545. end
  546. tMsgItemList[0] = nLen
  547. return bRet
  548. end
  549. -- 处理发送奖励为 Key-Value
  550. function BagLogic_HandlePrizeKeyVal(tMsgItemList, list, nLen)
  551. if list[1] and list[1][1] then
  552. return false
  553. end
  554. local bRet = true
  555. for itemID, itemCnt in pairs(list) do
  556. if cnt >= #tMsgItemList then
  557. bRet = false
  558. break
  559. end
  560. if not ItemDefine.isEquip(itemID) then
  561. nLen = nLen + 1
  562. Grid.makeItem(tMsgItemList[nLen], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
  563. end
  564. end
  565. tMsgItemList[0] = nLen
  566. return bRet
  567. end
  568. -- 外部获取需要下发的所有道具信息
  569. -- 主要是处理不弹窗装备的问题
  570. -- 返回是否发送成功
  571. function BagLogic_GetAllSendInfo(human, tMsgItemList, list, nType)
  572. local nLen = 0
  573. if nType ~= CommonDefine.COMMON_SEND_PRIZE_TYPE_ONLYEQUIP then
  574. nLen = EquipLogic.makeEquipItem(human, tMsgItemList, nLen)
  575. tMsgItemList[0] = nLen
  576. return true
  577. end
  578. local nAllLen = #tMsgItemList
  579. tMsgItemList[0] = 0
  580. nLen = EquipLogic.makeEquipItem(human, tMsgItemList, nLen)
  581. if nLen >= nAllLen then
  582. return false
  583. end
  584. tMsgItemList[0] = nLen
  585. if nil == list or nil == _G.next(list) then
  586. return true
  587. end
  588. -- 不同发送奖励类型的处理函数
  589. if CommonDefine.COMMON_SEND_PRIZE_TYPE_TABLE == nType then
  590. return BagLogic_HandlePrizetable(tMsgItemList, list, nLen)
  591. elseif CommonDefine.COMMON_SEND_PRIZE_TYPE_KEYVAL == nType then
  592. return BagLogic_HandlePrizeKeyVal(tMsgItemList, list, nLen)
  593. else
  594. return false
  595. end
  596. end
  597. -- 计算加成后的物品数量
  598. function calculateBonusItemCount(human, id, cnt)
  599. -- 检查是否是金币(101)或经验(111)道具
  600. if id == jinbi_id or id == jinyan_id then
  601. -- 检查是否处于加成时间
  602. local isInBonusTime = CommonDB.GetInFireWork(human)
  603. if isInBonusTime==true then
  604. -- 应用10%加成,向下取整
  605. return math.floor(cnt * 1.1)
  606. end
  607. end
  608. -- 默认返回原数量
  609. return cnt
  610. end