BagLogic.lua 24 KB

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