ItemLogic.lua 15 KB

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