BagLogic.lua 24 KB

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