ItemLogic.lua 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. ----------------------------------------------------------
  2. -- 道具使用
  3. ----------------------------------------------------------
  4. local Lang = require("common.Lang")
  5. local Msg = require("core.Msg")
  6. local ObjHuman = require("core.ObjHuman")
  7. local Grid = require("bag.Grid")
  8. local ItemDefine = require("bag.ItemDefine")
  9. local BagLogic = require("bag.BagLogic")
  10. local BoxLogic = require("bag.BoxLogic")
  11. local Broadcast = require("broadcast.Broadcast")
  12. local FundLogic = require("present.FundLogic")
  13. local SuperFundLogic = require("present.SuperFundLogic")
  14. local TopupLogic = require("topup.TopupLogic")
  15. local VipLogic = require("vip.VipLogic")
  16. local RoleHeadLogic = require("role.RoleHeadLogic")
  17. local BarTaskLogic = require("bar.BarTaskLogic")
  18. local YjTreasureLogic = require("yjTreasure.YjTreasureLogic")
  19. local ItemComonBuyExcel = require("excel.item").commonBuy
  20. local UnionLogic = require("union.UnionLogic")
  21. local RoleDBLogic = require("role.RoleDBLogic")
  22. local EquipLogic = require("equip.EquipLogic")
  23. local FuwenGrid = require("fuwen.FuwenGrid")
  24. local Util = require("common.Util")
  25. local XingYaoGongMing = require("xingYaoMen.XingYaoGongMing")
  26. local DropExchangeLogic = require("absAct.DropExchangeLogic")
  27. local HeroGrowUp = require("absAct.HeroGrowUp")
  28. local BuyExcel = require("excel.buy")
  29. local LostTempleLogic = require("lostTemple.lostTempleLogic")
  30. local BattleLogic = require("battle.BattleLogic")
  31. local HeroSkinLogic = require("present.HeroSkinLogic")
  32. local TreasureChestLogic = require("treasurechest.TreasureChestLogic")
  33. local CommerceMiddle = require("serverCommerce.ServerCommerceManager")
  34. cmd = {}
  35. FUWEN_BAG_TYPE = 1
  36. NORMAL_BAG_TYPE = 2
  37. EQUIP_BAG_TYPE = 3
  38. -- 所使用道具的相关信息
  39. local function createData(id, cnt, itemConfig, logType, isAuto)
  40. local data = {}
  41. data.id = id -- 道具id
  42. data.cnt = cnt -- 使用道具数量
  43. data.left = cnt -- 剩余要使用的数量
  44. data.config = itemConfig -- 道具配置
  45. data.logType = logType -- 日志类型
  46. data.isAuto = isAuto -- 是否自动使用
  47. return data
  48. end
  49. -- 金币
  50. function cmd.jinbi(data, human, value)
  51. if data.left < 1 then return end
  52. local sumJinbi = value * data.left
  53. data.left = 0
  54. ObjHuman.updateJinbi(human, sumJinbi, data.logType)
  55. end
  56. -- 钻石
  57. function cmd.zuanshi(data, human, value)
  58. if data.left < 1 then return end
  59. local sumZuanshi = value * data.left
  60. data.left = 0
  61. ObjHuman.addZuanshi(human, sumZuanshi, data.logType)
  62. end
  63. -- 经验
  64. function cmd.exp(data, human, value)
  65. if data.left < 1 then return end
  66. local sumExp = value * data.left
  67. data.left = 0
  68. ObjHuman.addExp(human, sumExp)
  69. end
  70. -- 自选宝箱
  71. function cmd.box(data, human, list)
  72. BoxLogic.sendBoxList(human, list)
  73. end
  74. -- 随机宝箱
  75. function cmd.boxRand(data, human, list)
  76. if data.left < 1 then return end
  77. local itemLen = list and #list or 0
  78. if itemLen < 1 then
  79. return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CONFIG)
  80. end
  81. local weightSum = 0
  82. for i = 1, itemLen do
  83. local weight = list[i][3]
  84. weightSum = weightSum + weight
  85. end
  86. if weightSum < 1 then
  87. return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CONFIG)
  88. end
  89. -- 检测数量
  90. local equipCnt = 0
  91. local fuWenCnt = 0
  92. BagLogic.cleanMomentItemList()
  93. local mathRandom = math.random
  94. for i = 1, data.left do
  95. local r = mathRandom(1, weightSum)
  96. for j = 1, itemLen do
  97. local itemID = list[j][1]
  98. local itemCnt = list[j][2]
  99. local weight = list[j][3]
  100. local quality = list[j][4]
  101. if r <= weight then
  102. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, itemID, itemCnt, quality)
  103. -- 计算装备数量
  104. if ItemDefine.isEquip(itemID) then
  105. equipCnt = equipCnt + itemCnt
  106. end
  107. if ItemDefine.isFuwen(itemID) then
  108. fuWenCnt = fuWenCnt + itemCnt
  109. end
  110. break
  111. end
  112. r = r - weight
  113. end
  114. end
  115. -- 检测装备背包空间
  116. if not EquipLogic.checkEmptyCnt(human, equipCnt) then
  117. BagLogic.cleanMomentItemList()
  118. return
  119. end
  120. if not FuwenGrid.checkEmptyCnt(human, fuWenCnt) then
  121. BagLogic.cleanMomentItemList()
  122. return
  123. end
  124. data.left = 0
  125. BagLogic.addMomentItemList(human, "useBox", true)
  126. end
  127. -- 固定箱子
  128. function cmd.boxAll(data, human, list)
  129. if data.left < 1 then return end
  130. local cnt = data.left
  131. local oustList = {}
  132. local len = 0
  133. local equipCnt = 0
  134. local fuWenCnt = 0
  135. for i = 1, #list do
  136. local itemID = list[i][1]
  137. local itemCnt = list[i][2] * cnt
  138. local quality = list[i][3]
  139. oustList[i] = {}
  140. oustList[i][1] = itemID
  141. oustList[i][2] = itemCnt
  142. oustList[i][3] = quality
  143. -- 计算装备数量
  144. if ItemDefine.isEquip(itemID) then
  145. equipCnt = equipCnt + itemCnt
  146. end
  147. if ItemDefine.isFuwen(itemID) then
  148. fuWenCnt = fuWenCnt + itemCnt
  149. end
  150. end
  151. -- 检测装备背包空间
  152. if not EquipLogic.checkEmptyCnt(human, equipCnt) then
  153. return
  154. end
  155. if not FuwenGrid.checkEmptyCnt(human, fuWenCnt) then
  156. return
  157. end
  158. data.left = 0
  159. BagLogic.addItemList(human, oustList, "useBox")
  160. end
  161. -- 获得称号
  162. function cmd.chenghao(data, human)
  163. RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_4, data.config.icon)
  164. return true
  165. end
  166. -- 头像
  167. function cmd.head(data, human)
  168. RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_1, data.config.icon)
  169. return true
  170. end
  171. -- 头像框
  172. function cmd.headFrame(data, human)
  173. RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_2, data.config.icon)
  174. return true
  175. end
  176. -- 小基金/大基金
  177. function cmd.superfund(data, human, ftype)
  178. SuperFundLogic.buySuperFund(human, ftype)
  179. return true
  180. end
  181. -- 钻石基金
  182. function cmd.fundbuy(data, human, ftype)
  183. FundLogic.fundBuy(human, ftype)
  184. return true
  185. end
  186. -- 扫荡特权
  187. function cmd.tequanmopup(data, human, day)
  188. local time = os.time()
  189. if human.db.tequanMopup and human.db.tequanMopup > time then
  190. time = human.db.tequanMopup
  191. end
  192. human.db.tequanMopup = time + day * 86400
  193. return true
  194. end
  195. -- 民生/悬赏高级特权
  196. function cmd.tequanbar1(data, human)
  197. BarTaskLogic.activateBarVip(human, 1)
  198. return true
  199. end
  200. -- 民生/悬赏豪华特权
  201. function cmd.tequanbar2(data, human)
  202. BarTaskLogic.activateBarVip(human, 2)
  203. return true
  204. end
  205. -- 模拟充值
  206. function cmd.chargemoney(data, human, value, noAddYb)
  207. if data.left < 1 then return end
  208. local price = value * data.left
  209. data.left = 0
  210. TopupLogic.clacTopupAcount(human, price)
  211. if noAddYb ~= 1 then
  212. VipLogic.addExp(human, price*10)
  213. ObjHuman.addZuanshi(human, price*10, data.logType)
  214. end
  215. end
  216. -- 大月卡
  217. function cmd.fundbig(data, human)
  218. return true
  219. end
  220. -- 小月卡
  221. function cmd.fundsmall(data, human)
  222. return true
  223. end
  224. -- 友情值
  225. function cmd.friendheart(data, human, value)
  226. if data.left < 1 then return end
  227. local sum = data.left * value
  228. data.left = 0
  229. ObjHuman.updateFriendHeart(human, sum, data.logType)
  230. end
  231. -- vip经验
  232. function cmd.vipexp(data, human, value)
  233. if data.left < 1 then return end
  234. local sum = data.left * value
  235. data.left = 0
  236. VipLogic.addExp(human, sum)
  237. end
  238. --民生任务 情报值
  239. function cmd.qingbao(data, human, value)
  240. if data.left < 1 then return end
  241. local sum = value * data.left
  242. data.left = 0
  243. BarTaskLogic.addBarQingBao(human,sum)
  244. end
  245. --遗迹探宝
  246. function cmd.yjtreasureYJ(data, human, yaojiType)
  247. YjTreasureLogic.yjYaoJiAdd(human,data.left,yaojiType)
  248. end
  249. --遗迹探宝
  250. function cmd.heroGrowUp(data, human)
  251. HeroGrowUp.addJifen(human, data.cnt)
  252. end
  253. function cmd.guildexp(data, human, value)
  254. if data.left < 1 then return end
  255. local sum = value * data.left
  256. data.left = 0
  257. UnionLogic.addUnionExpByItem(human, sum)
  258. end
  259. function cmd.absDrop(data, human, value)
  260. if data.left < 1 then return end
  261. local sum = data.left * value
  262. data.left = 0
  263. DropExchangeLogic.addJifen(human, sum)
  264. end
  265. function cmd.zhigou(data, human, value)
  266. if data.left < 1 then return end
  267. local buyConf = BuyExcel.buy[value]
  268. if not buyConf then
  269. return
  270. end
  271. local msg = {}
  272. msg.logintype = 2
  273. msg.openid = "oCD-L5RxAtfRe8-aiezdY-Ccla5U"
  274. msg.openkey = "VsBJf2DKah7QhzU5xuzLNA=="
  275. msg.yuanbao = buyConf.CN * 10
  276. msg.buyID = value
  277. msg.account = human.db.account
  278. msg.transaction_id = "transaction_id1"
  279. msg.pf = "android"
  280. msg.money = buyConf.CN
  281. require("platform.ApiLogic").CHARGE_CODE_HIS = {}
  282. require("AdminLogic").adminFunction.tencentPay(msg)
  283. end
  284. function cmd.lostRevice(data, human, value)
  285. if data.left < 1 then return end
  286. LostTempleLogic.lostTempleRevice(human)
  287. return true
  288. end
  289. function cmd.mergeHero(data, human, value)
  290. if data.left < 1 then return end
  291. return true
  292. end
  293. function cmd.hatchMerge(data, human, value)
  294. if data.left < 1 then return end
  295. return true
  296. -- human.db.mergeInfo = human.db.mergeInfo or {}
  297. -- human.db.mergeInfo.endTime = human.db.mergeInfo.endTime or 0
  298. -- if human.db.mergeInfo.endTime > 0 then
  299. -- local itemSpeedTime = (60 * 5 * data.cnt)
  300. -- local hatchTime = human.db.mergeInfo.endTime - itemSpeedTime - os.time()
  301. -- if hatchTime <= 0 then
  302. -- human.db.mergeInfo.endTime = 0
  303. -- return true
  304. -- else
  305. -- human.db.mergeInfo.endTime = human.db.mergeInfo.endTime - itemSpeedTime
  306. -- return true
  307. -- end
  308. -- end
  309. -- return false
  310. end
  311. -- 使用增加主线关卡扫荡次数道具
  312. function cmd.AddFreeMopup(data, human)
  313. if 0 >= data.left then
  314. return false
  315. end
  316. BattleLogic.BattleLogic_AddMopup(human, data.id, data.cnt)
  317. -- 把剩余数量改成0,才能消耗
  318. data.left = 0
  319. end
  320. -- 使用皮肤道具
  321. function cmd.UseSkinItem(data, human, nMoney)
  322. if 0 >= data.left then
  323. return false
  324. end
  325. HeroSkinLogic.SendSkinInfoByMoney(human, nMoney, data.id)
  326. end
  327. function cmd.treasurechestadd(data, human)
  328. if 0 >= data.left then
  329. return
  330. end
  331. TreasureChestLogic.TreasureChestLogic_AddItem(human, data.id, data.cnt)
  332. end
  333. function cmd.UseYanHua(data,human)
  334. if 0>=data.cnt then
  335. return
  336. end
  337. TopupLogic.Addtime(human,data.cnt)
  338. data.left = 0
  339. end
  340. function cmd.AddServerCommerPoint(data, human)
  341. if 0 >= data.left then
  342. return
  343. end
  344. CommerceMiddle.CommerceMiddle_AddTaskPoint(human, data.cnt)
  345. end
  346. -- 激活皮肤
  347. function cmd.activateSkin(data, human, skinId)
  348. if 0>=data.cnt then
  349. return
  350. end
  351. return HeroSkinLogic.ActivateSkinByBox(human, skinId)
  352. end
  353. -----------------------------------------------------------------------------
  354. -- 仅使用道具,不扣道具
  355. function onlyuse(human, id, cnt, logType, isAuto)
  356. if cnt < 1 then return end
  357. local itemConfig = ItemDefine.getConfig(id)
  358. if not itemConfig or not itemConfig.cmd then
  359. return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CANT_USE)
  360. end
  361. local command = itemConfig.cmd
  362. local cmdName = command[1]
  363. if not cmdName or not cmd[cmdName] then
  364. return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CANT_USE)
  365. end
  366. local data = createData(id, cnt, itemConfig, logType, isAuto)
  367. while 0 < data.left do
  368. local isok = cmd[cmdName](data, human, command[2], command[3], command[4])
  369. if isok then
  370. data.left = data.left - 1
  371. else
  372. break
  373. end
  374. end
  375. return true, data.left
  376. end
  377. -- 使用并扣道具
  378. function use(human, id, cnt)
  379. if cnt < 1 then return end
  380. if id < 1 then return end
  381. local bagCnt = BagLogic.getItemCnt(human, id, true)
  382. if bagCnt < cnt then
  383. return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  384. end
  385. local success, left = onlyuse(human, id, cnt, "item_use")
  386. if not success then
  387. return
  388. end
  389. local delCnt = cnt - left
  390. if delCnt > 0 then
  391. BagLogic.delItem(human, id, delCnt, "item_use")
  392. end
  393. end
  394. --
  395. function sendItemUse(human, id)
  396. local msgRet = Msg.gc.GC_ITEM_USE
  397. msgRet.id = id
  398. Msg.send(msgRet, human.fd)
  399. end
  400. -- 根据id获取item
  401. function sendItemDateByID(human,type,index,id,uuid)
  402. local msgRet = Msg.gc.GC_ITEM_GET_BY_ID
  403. if type == FUWEN_BAG_TYPE then
  404. -- 取出背包
  405. local bagFileds = {fuwenBag = 1}
  406. local db = nil
  407. -- 玩家在线直接取缓存
  408. local tempHuman = ObjHuman.onlineUuid[uuid]
  409. if tempHuman == nil then
  410. db = RoleDBLogic.getDb(uuid,bagFileds)
  411. else
  412. db = tempHuman.db
  413. end
  414. -- 玩家不存在,返回
  415. if db == nil then
  416. return
  417. end
  418. local fuwenGrid = db.fuwenBag[index]
  419. -- 符文背包id对不上,返回
  420. if fuwenGrid == nil or fuwenGrid.id ~= id then
  421. return
  422. end
  423. Grid.makeItem(msgRet.item,id,1,nil,fuwenGrid,index,0)
  424. elseif type == NORMAL_BAG_TYPE then
  425. Grid.makeItem(msgRet.item,id,1)
  426. elseif type == EQUIP_BAG_TYPE then
  427. -- 取出背包
  428. local bagFileds = {equipBag = 1}
  429. local db = nil
  430. -- 玩家在线直接取缓存
  431. local tempHuman = ObjHuman.onlineUuid[uuid]
  432. if tempHuman == nil then
  433. db = RoleDBLogic.getDb(uuid,bagFileds)
  434. else
  435. db = tempHuman.db
  436. end
  437. -- 玩家不存在,返回
  438. if db == nil then
  439. return
  440. end
  441. local equipGrid = db.equipBag[index]
  442. -- 符文背包id对不上,返回
  443. if equipGrid == nil or equipGrid.id ~= id then
  444. return
  445. end
  446. Grid.makeItem(msgRet.item,id,1,nil,equipGrid,index,0)
  447. end
  448. Msg.send(msgRet,human.fd)
  449. end
  450. -- 根据id获取item
  451. function sendItemData(human,itemID)
  452. local msgRet = Msg.gc.GC_ITEM_GET_BY_ITEM_ID
  453. local itemCnt = BagLogic.getItemCnt(human,itemID)
  454. Grid.makeItem(msgRet.item,itemID,itemCnt)
  455. Msg.send(msgRet,human.fd)
  456. end
  457. function itemBuyQuery(human,itemID)
  458. local config = ItemComonBuyExcel[itemID]
  459. if config == nil then
  460. return
  461. end
  462. local msgRet = Msg.gc.GC_ITEM_BUY_QUERY
  463. Grid.makeItem(msgRet.need,config.price[1],config.price[2])
  464. Grid.makeItem(msgRet.get,itemID,config.cnt)
  465. Msg.send(msgRet,human.fd)
  466. end
  467. function itemBuyDo(human,itemID,itemCnt)
  468. local msgRet = Msg.gc.GC_ITEM_BUY_DO
  469. msgRet.ret = 0
  470. local config = ItemComonBuyExcel[itemID]
  471. if config == nil then
  472. Msg.send(msgRet,human.fd)
  473. return
  474. end
  475. local needID = config.price[1]
  476. local needCnt = config.price[2] * itemCnt
  477. local costCnt = BagLogic.getItemCnt(human,needID)
  478. if costCnt < needCnt then
  479. Msg.send(msgRet,human.fd)
  480. return
  481. end
  482. BagLogic.delItem(human, needID, needCnt, "buy_item")
  483. BagLogic.cleanMomentItemList()
  484. BagLogic.updateMomentItem(1, itemID, itemCnt*config.cnt)
  485. BagLogic.addMomentItemList(human, "buy_item")
  486. msgRet.ret = 1
  487. Msg.send(msgRet,human.fd)
  488. end