ItemLogic.lua 14 KB

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