ItemLogic.lua 14 KB

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