BagLogic.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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 ITEM_MOMENT_ADD_LIST = {}
  35. ADDITEM_TYPE_1 = 1 --顺序 不整合添加道具 非1 表示整合所有相同的道具数量
  36. ADDITEM_TYPE_2 = 2
  37. function updateMomentItem(type, itemID, itemCnt, quality)
  38. if type == ADDITEM_TYPE_1 then
  39. local len = #ITEM_MOMENT_ADD_LIST + 1
  40. ITEM_MOMENT_ADD_LIST[len] = {}
  41. ITEM_MOMENT_ADD_LIST[len][1] = itemID
  42. ITEM_MOMENT_ADD_LIST[len][2] = itemCnt
  43. ITEM_MOMENT_ADD_LIST[len][3] = quality
  44. else
  45. ITEM_MOMENT_ADD_LIST[itemID] = ITEM_MOMENT_ADD_LIST[itemID] or 0
  46. ITEM_MOMENT_ADD_LIST[itemID] = ITEM_MOMENT_ADD_LIST[itemID] + itemCnt
  47. end
  48. end
  49. -- 防止有报错 导致的 别的玩家 额外获得道具 在使用 通用的 添加之前 清除一次
  50. function cleanMomentItemList()
  51. Util.cleanTable(ITEM_MOMENT_ADD_LIST)
  52. end
  53. function addMomentItemList(human, logType, noSend)
  54. addItemList(human, ITEM_MOMENT_ADD_LIST, logType, noSend)
  55. cleanMomentItemList()
  56. end
  57. -- 通用道具添加 {[1] = {id, cnt}, [2] = {id,cnt}} or {[itemID] = itemCnt} 配表复杂 各自接口下自己for 添加
  58. function addItemList(human, list, logType, noSend)
  59. if not list or next(list) == nil then return end
  60. if list[1] and list[1][1] then
  61. for _, item in ipairs(list) do
  62. addItem(human, item[1], item[2], logType, noSend, item[3])
  63. end
  64. else
  65. for itemID, itemCnt in pairs(list) do
  66. addItem(human, itemID, itemCnt, logType, noSend)
  67. end
  68. end
  69. sendItemGetList(human, list, logType)
  70. end
  71. -- 增加装备,道具
  72. function addItem(human, id, cnt, logType, noSend, otherData)
  73. if cnt < 1 then return end
  74. local itemConfig = ItemDefine.getConfig(id)
  75. if not itemConfig then return end
  76. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["item"] then
  77. assert()
  78. end
  79. MiddleOption.addItem(human, id, cnt, logType)
  80. if handlerSpObj(human, id, cnt, logType) then
  81. print("[addItem] 不进入背包物品直接返回 id, cnt = ", id, cnt)
  82. return
  83. end
  84. if handleFuwen(human, id, cnt, logType) then
  85. print("[addItem] 符文物品不进入背包物品直接返回 id, cnt = ", id, cnt)
  86. return
  87. end
  88. -- 装备走另外的逻辑
  89. if handleEquipAdd(human, id, cnt, logType, otherData) then
  90. print("[addItem] 装备物品其他方式处理 id, cnt = ", id, cnt)
  91. return
  92. end
  93. local oldCnt = human.db.bag[id] or 0
  94. local newCnt = math.min(oldCnt + cnt, ItemDefine.BAG_ITEM_MAX_CNT)
  95. human.db.bag[id] = newCnt
  96. if not noSend then
  97. sendChange(human, id, oldCnt < 1)
  98. end
  99. Log.write(Log.LOGID_OSS_ITEM, human.db._id, human.db.account, human.db.name, human.db.lv,
  100. LogDefine.DEFINE[logType] + LogDefine.TYPE["item"] , id, cnt, newCnt)
  101. -- 如果道具为公会贡献,记录到当日累计贡献中
  102. if id == ItemDefine.ITEM_UNION_COIN_ID then
  103. human.db.dailyBanggong = human.db.dailyBanggong or 0
  104. human.db.dailyBanggong = human.db.dailyBanggong + cnt
  105. human.db.totalBanggong = human.db.totalBanggong or 0
  106. human.db.totalBanggong = human.db.totalBanggong + cnt
  107. end
  108. -- 根据道具触发红点
  109. checkDotByID(human,id)
  110. return true
  111. end
  112. function checkDotByID(human,id)
  113. local itemConfig = ItemDefine.getConfig(id)
  114. local dotTb = itemConfig.dot
  115. local len = #dotTb
  116. for i = 1,len do
  117. RoleSystemLogic.onDot(human, dotTb[i])
  118. end
  119. end
  120. -- 根据id删除
  121. function delItem(human, id, cnt, logType, noSend, byId, byCnt)
  122. if cnt < 1 then return end
  123. local itemConfig = ItemExcel[id]
  124. if not itemConfig then return end
  125. if not LogDefine.DEFINE[logType] or not LogDefine.TYPE["item"] then
  126. assert()
  127. end
  128. if id == ItemDefine.ITEM_JINBI_ID then
  129. return ObjHuman.updateJinbi(human, -cnt, logType, byId, byCnt)
  130. elseif id == ItemDefine.ITEM_ZUANSHI_ID then
  131. return ObjHuman.decZuanshi(human, -cnt, logType, byId, byCnt)
  132. elseif id == ItemDefine.ITEM_FRIEND_ID then
  133. return ObjHuman.updateFriendHeart(human, -cnt, logType)
  134. end
  135. local newCnt = (human.db.bag[id] or 0) - cnt
  136. if newCnt < 0 then assert(nil) end
  137. if newCnt < 1 then
  138. newCnt = nil
  139. end
  140. human.db.bag[id] = newCnt
  141. if not noSend then
  142. sendChange(human, id)
  143. end
  144. Log.write(Log.LOGID_OSS_ITEM, human.db._id, human.db.account, human.db.name, human.db.lv,
  145. LogDefine.DEFINE[logType] + LogDefine.TYPE["item"] , id, -cnt, newCnt or 0)
  146. if itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN or
  147. itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN_SKIN then
  148. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_206)
  149. end
  150. if id == ItemDefine.ITEM_GREEN_EXP_ID then
  151. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE18, cnt)
  152. end
  153. return true
  154. end
  155. -- 获得道具数量
  156. function getItemCnt(human, id, isUse)
  157. if id == ItemDefine.ITEM_JINBI_ID and not isUse then
  158. return human.db.jinbi or 0
  159. elseif id == ItemDefine.ITEM_ZUANSHI_ID and not isUse then
  160. return human.db.zuanshi or 0
  161. elseif id == ItemDefine.ITEM_FRIEND_ID and not isUse then
  162. return human.db.friendHeart or 0
  163. end
  164. return human.db.bag[id] or 0
  165. end
  166. -- 判断道具数量
  167. function checkItemCnt(human, id, cnt)
  168. if id == ItemDefine.ITEM_ZUANSHI_ID then
  169. return ObjHuman.checkRMB(human,cnt)
  170. end
  171. if getItemCnt(human, id) < cnt then
  172. local name = ItemDefine.getValue(id,"name")
  173. return Broadcast.sendErr(human,Util.format(Lang.COMMON_NO_ITEM, name))
  174. end
  175. return true
  176. end
  177. -- 特殊不进背包的道具
  178. function handlerSpObj(human, itemID, itemCnt, logType)
  179. local itemConfig = ItemExcel[itemID]
  180. if not itemConfig then return end
  181. if itemConfig.subType ~= ItemDefine.ITEM_SUBTYPE_SPOBJ then
  182. return
  183. end
  184. local cmdstr = itemConfig.cmd and itemConfig.cmd[1]
  185. if cmdstr and ItemLogic.cmd[cmdstr] then
  186. ItemLogic.onlyuse(human, itemID, itemCnt, logType, true)
  187. -- 根据道具触发红点
  188. checkDotByID(human,itemID)
  189. end
  190. if ItemDefine.checkIsWave(LogDefine.DEFINE[logType]) then
  191. sendRoll(human, itemID, itemCnt)
  192. end
  193. return true
  194. end
  195. -- 符文
  196. function handleFuwen(human, itemID, itemCnt, logType)
  197. if not FuwenExcel[itemID] then return end
  198. FuwenLogic.add(human, itemID, itemCnt, logType)
  199. if ItemDefine.checkIsWave(LogDefine.DEFINE[logType]) then
  200. sendRoll(human, itemID, itemCnt)
  201. end
  202. return true
  203. end
  204. -- 装备增加
  205. function handleEquipAdd(human, itemID, itemCnt, logType, otherData)
  206. if not EquipExcel[itemID] then return end
  207. EquipLogic.addEquip(human, itemID, itemCnt, logType, otherData)
  208. if EquipExcel[itemID].mainType == ItemDefine.MAINTYPE_EQUIP then
  209. if EquipExcel[itemID].level == 14 then
  210. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_24,itemCnt)
  211. end
  212. end
  213. if ItemDefine.checkIsWave(LogDefine.DEFINE[logType]) then
  214. sendRoll(human, itemID, itemCnt)
  215. end
  216. return true
  217. end
  218. ---------------------------- msg --------------------------------
  219. -- 发送背包道具
  220. function sendBagList(human)
  221. local msgRet = Msg.gc.GC_BAG_LIST
  222. msgRet.list[0] = 0
  223. for itemID, itemCnt in pairs(human.db.bag) do
  224. msgRet.list[0] = msgRet.list[0] + 1
  225. local net = msgRet.list[msgRet.list[0]]
  226. Grid.makeItem(net, itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
  227. if msgRet.list[0] >= ItemDefine.PAGE_LIST_COUNT then
  228. Msg.send(msgRet, human.fd)
  229. msgRet.list[0] = 0
  230. end
  231. end
  232. if msgRet.list[0] > 0 then
  233. Msg.send(msgRet, human.fd)
  234. end
  235. end
  236. -- 改变
  237. function sendChange(human, itemID, isAdd)
  238. local msgRet = Msg.gc.GC_ITEM_BAG_CHANGE
  239. local itemCnt = human.db.bag[itemID] or 0
  240. msgRet.itemID = itemID
  241. msgRet.itemCnt = itemCnt
  242. msgRet.itemData[0] = 0
  243. if isAdd == true then
  244. msgRet.itemData[0] = 1
  245. Grid.makeItem(msgRet.itemData[1], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
  246. end
  247. Msg.send(msgRet, human.fd)
  248. end
  249. -- 滚动
  250. function sendRoll(human, itemID, itemCnt)
  251. --[[local msgRet = Msg.gc.GC_ITEM_BAG_ROLL
  252. msgRet.itemData[0] = 1
  253. Grid.makeItem(msgRet.itemData[1], itemID, itemCnt)
  254. Msg.send(msgRet, human.fd)]]
  255. end
  256. -- 通用道具获得面板 list = {...}
  257. function sendItemGetList(human, list, logStr)
  258. if not list or not next(list) then return end
  259. if list[1] and list[1][1] then
  260. sendItemGetList1(human, list, logStr)
  261. else
  262. sendItemGetList2(human, list, logStr)
  263. end
  264. end
  265. -- 通用道具获得面板 list = {[1]={id,cnt},[2]={id2,cnt2}...}
  266. function sendItemGetList1(human, list, logStr)
  267. if not list or not next(list) then return end
  268. local msgRet = Msg.gc.GC_ITEM_GET_LIST
  269. msgRet.popupType = ItemDefine.checkIsWave(LogDefine.DEFINE[logStr]) and 1 or 0
  270. local len = math.min(#list, #msgRet.list)
  271. local cnt = 0
  272. cnt = EquipLogic.makeEquipItem(human, msgRet.list, cnt)
  273. for i=1,len do
  274. if cnt >= #msgRet.list then
  275. break
  276. end
  277. local itemID = list[i][1]
  278. local itemCnt = list[i][2]
  279. if not ItemDefine.isEquip(itemID) then
  280. cnt = cnt + 1
  281. --Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
  282. Grid.makeItem(msgRet.list[cnt], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
  283. end
  284. end
  285. if cnt > 0 then
  286. msgRet.list[0] = cnt
  287. Msg.send(msgRet,human.fd)
  288. end
  289. end
  290. -- 通用道具获得面板2 list = {[id]=cnt,[id2]=cnt2}
  291. function sendItemGetList2(human, list, logStr)
  292. if not list or not next(list) then return end
  293. local msgRet = Msg.gc.GC_ITEM_GET_LIST
  294. msgRet.popupType = ItemDefine.checkIsWave(LogDefine.DEFINE[logStr]) and 1 or 0
  295. msgRet.list[0] = 0
  296. local cnt = 0
  297. cnt = EquipLogic.makeEquipItem(human, msgRet.list, cnt)
  298. for itemID, itemCnt in pairs(list) do
  299. if cnt >= #msgRet.list then
  300. break
  301. end
  302. if not ItemDefine.isEquip(itemID) then
  303. cnt = cnt + 1
  304. --Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
  305. Grid.makeItem(msgRet.list[cnt], itemID, itemCnt, nil,nil,nil, Grid.getOpflagAtBag(itemID))
  306. end
  307. end
  308. --Msg.trace(msgRet)
  309. if cnt > 0 then
  310. msgRet.list[0] = cnt
  311. Msg.send(msgRet,human.fd)
  312. end
  313. end
  314. -- 通用道具获得面板2 list = {[id]=cnt,[id2]=cnt2}
  315. function sendItemGetList3(human, list, logStr)
  316. if not list or not next(list) then return end
  317. local msgRet = Msg.gc.GC_ITEM_GET_LIST
  318. msgRet.popupType = ItemDefine.checkIsWave(LogDefine.DEFINE[logStr]) and 1 or 0
  319. msgRet.list[0] = 0
  320. local cnt = 0
  321. cnt = EquipLogic.makeEquipItem(human, msgRet.list, cnt)
  322. for i = 1, #list do
  323. local items = list[i]
  324. for itemID, itemCnt in pairs(items) do
  325. if cnt >= #msgRet.list then
  326. break
  327. end
  328. if not ItemDefine.isEquip(itemID) then
  329. cnt = cnt + 1
  330. Grid.makeItem(msgRet.list[cnt], itemID, itemCnt)
  331. end
  332. end
  333. end
  334. if cnt > 0 then
  335. msgRet.list[0] = cnt
  336. Msg.send(msgRet,human.fd)
  337. end
  338. end
  339. -- 相同的道具自动叠加一起
  340. local SAME_ITEMS1 = {}
  341. local SAME_ITEMS2 = {}
  342. function sameItemTogether(list)
  343. if not list or not next(list) then return end
  344. for k in pairs(SAME_ITEMS1) do
  345. SAME_ITEMS1[k] = nil
  346. end
  347. for k in pairs(SAME_ITEMS2) do
  348. SAME_ITEMS2[k] = nil
  349. end
  350. for _, item in ipairs(list) do
  351. local itemID = item[1]
  352. local itemCnt = item[2]
  353. -- 装备符文不能叠加
  354. if not ItemDefine.isEquip(itemID) and not ItemDefine.isFuwen(itemID) then
  355. SAME_ITEMS1[itemID] = (SAME_ITEMS1[itemID] or 0) + itemCnt
  356. end
  357. end
  358. for itemID, itemCnt in pairs(SAME_ITEMS1) do
  359. SAME_ITEMS2[#SAME_ITEMS2 + 1] = {itemID, itemCnt}
  360. end
  361. return SAME_ITEMS2, SAME_ITEMS1
  362. end
  363. -- 背包道具出售
  364. function itemSell(human, itemID, itemCnt)
  365. if itemCnt < 1 then return end
  366. local itemConfig = ItemDefine.getConfig(itemID)
  367. if not itemConfig then return end
  368. if not itemConfig.price then return end
  369. local saleItemID = itemConfig.price[1]
  370. local saleItemCnt = itemConfig.price[2]
  371. if not saleItemCnt or saleItemCnt < 1 then return end -- 不能出售
  372. local bagCnt = getItemCnt(human, itemID)
  373. if bagCnt < itemCnt then return end
  374. local itemCntAdd = math.floor(saleItemCnt * itemCnt)
  375. delItem(human, itemID, itemCnt, "item_sale")
  376. addItem(human, saleItemID, itemCntAdd, "item_sale")
  377. local list = {}
  378. list[1] = { [1] = saleItemID, [2]= itemCntAdd }
  379. sendItemGetList(human, list)
  380. local msgRet = Msg.gc.GC_BAG_ITEM_SELL
  381. msgRet.id = itemID
  382. msgRet.cnt = itemCnt
  383. Msg.send(msgRet, human.fd)
  384. end
  385. -- 装备道具出售
  386. function equipSell(human, bagIndex)
  387. local equipGrid = human.db.equipBag[bagIndex]
  388. if not equipGrid then return end
  389. local itemConfig = ItemDefine.getConfig(equipGrid.id)
  390. if not itemConfig then return end
  391. if not itemConfig.price then return end
  392. local saleItemID = itemConfig.price[1]
  393. local saleItemCnt = itemConfig.price[2]
  394. if not saleItemCnt or saleItemCnt < 1 then return end
  395. EquipLogic.delEquip(human, bagIndex, "equip_sale")
  396. local itemCntAdd = saleItemCnt
  397. addItem(human, saleItemID, itemCntAdd, "equip_sale")
  398. sendItemGetList(human, {[1]=itemConfig.price})
  399. end
  400. -- 装备道具出售
  401. function equipSellByQuality(human, qualityStr)
  402. local qualityList = Util.split(qualityStr, ",", true)
  403. local len = #qualityList
  404. if len <= 0 or len > 4 then return end
  405. local outItems = {}
  406. for i = 1, #qualityList do
  407. local quality = qualityList[i]
  408. for k, equipGrid in pairs(human.db.equipBag) do
  409. if equipGrid.quality == quality then
  410. local itemConfig = ItemDefine.getConfig(equipGrid.id)
  411. if not itemConfig then assert() end
  412. if not itemConfig.price then assert() end
  413. local saleItemID = itemConfig.price[1]
  414. local saleItemCnt = itemConfig.price[2]
  415. if not saleItemCnt or saleItemCnt < 1 then assert() end
  416. EquipLogic.delEquip(human, k, "equip_sale", true)
  417. local itemCntAdd = saleItemCnt
  418. addItem(human, saleItemID, itemCntAdd, "equip_sale")
  419. outItems[saleItemID] = outItems[saleItemID] or 0
  420. outItems[saleItemID] = outItems[saleItemID] + itemCntAdd
  421. end
  422. end
  423. end
  424. sendItemGetList(human, outItems)
  425. -- 出售成功
  426. local msgRet = Msg.gc.GC_BAG_EQUIP_SELL_QUALITY
  427. Msg.send(msgRet,human.fd)
  428. end
  429. -- 道具购买查询
  430. function queryItemBuy(human, id)
  431. local config = ItemBuyExcel[id]
  432. if not config then return end
  433. local msgRet = Msg.gc.GC_ITEM_BUY_QUERY
  434. msgRet.id = id
  435. msgRet.item[0] = 1
  436. Grid.makeItem(msgRet.item[1], id , 1)
  437. msgRet.canBuy[0] = 2
  438. msgRet.canBuy[1] = config.cnt1
  439. msgRet.canBuy[2] = config.cnt2
  440. msgRet.need[0] = 0
  441. for _, item in ipairs(config.need1) do
  442. msgRet.need[0] = msgRet.need[0] + 1
  443. Grid.makeItem(msgRet.need[msgRet.need[0]], item[1], item[2])
  444. end
  445. msgRet.needTwo[0] = 0
  446. for _, item in ipairs(config.need2) do
  447. msgRet.needTwo[0] = msgRet.needTwo[0] + 1
  448. Grid.makeItem(msgRet.needTwo[msgRet.needTwo[0]], item[1], item[2])
  449. end
  450. --Msg.trace(msgRet)
  451. Msg.send(msgRet,human.fd)
  452. end
  453. -- 购买道具
  454. function buyItem(human, id, buyCnt, cnt)
  455. local config = ItemBuyExcel[id]
  456. if not config then return end
  457. local needList = nil
  458. if config.cnt1 == buyCnt then
  459. needList = config.need1
  460. elseif config.cnt2 == buyCnt then
  461. needList = config.need2
  462. end
  463. if not needList then return end
  464. if cnt < 1 then return end
  465. -- 判断消耗
  466. for _, item in ipairs(needList) do
  467. if not checkItemCnt(human, item[1], item[2] * cnt) then
  468. return
  469. end
  470. end
  471. -- 某些购买日志类型特殊
  472. local logType = "item_buy"
  473. if id == ItemDefine.ITEM_ABS_DRAW_LONGZHU_ID then
  474. logType = "item_buy_dragong"
  475. end
  476. -- 扣除道具
  477. for _, item in ipairs(needList) do
  478. delItem(human, item[1], item[2] * cnt, logType)
  479. end
  480. addItem(human, id, buyCnt * cnt, logType)
  481. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  482. local msgRet = Msg.gc.GC_ITEM_BUY
  483. msgRet.id = id
  484. Msg.send(msgRet, human.fd)
  485. end
  486. function sendCommonBuyQuery(human, itemID)
  487. local config = ItemComonBuyExcel[itemID]
  488. if not config then return end
  489. local msgRet = Msg.gc.GC_ITEM_COMMON_BUY_QUERY
  490. Grid.makeItem(msgRet.item, itemID, 1)
  491. msgRet.price = config.price
  492. Msg.send(msgRet, human.fd)
  493. end
  494. function commonBuy(human, itemID, itemCnt)
  495. if itemCnt < 1 then return end
  496. local config = ItemComonBuyExcel[itemID]
  497. if not config then return end
  498. local cost = config.price * itemCnt
  499. if not ObjHuman.checkRMB(human, cost) then
  500. return
  501. end
  502. ObjHuman.decZuanshi(human, -cost, "item_buy", itemID, itemCnt)
  503. addItem(human, itemID, itemCnt, "item_buy")
  504. local msgRet = Msg.gc.GC_ITEM_COMMON_BUY
  505. msgRet.itemID = itemID
  506. Msg.send(msgRet, human.fd)
  507. end
  508. function isDot(human)
  509. for itemID, itemCnt in pairs(human.db.bag) do
  510. local itemConfig = ItemExcel[itemID]
  511. if itemConfig then
  512. if itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN or
  513. itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN_SKIN then
  514. if itemCnt >= itemConfig.fullCnt then
  515. return true
  516. end
  517. end
  518. end
  519. end
  520. return false
  521. end