BagLogic.lua 24 KB

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