BagLogic.lua 24 KB

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