BagLogic.lua 18 KB

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