BagLogic.lua 23 KB

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