ItemLogic.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. return true
  287. end
  288. function cmd.hatchMerge(data, human, value)
  289. return true
  290. end
  291. -----------------------------------------------------------------------------
  292. -- 仅使用道具,不扣道具
  293. function onlyuse(human, id, cnt, logType, isAuto)
  294. if cnt < 1 then return end
  295. local itemConfig = ItemDefine.getConfig(id)
  296. if not itemConfig or not itemConfig.cmd then
  297. return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CANT_USE)
  298. end
  299. local command = itemConfig.cmd
  300. local cmdName = command[1]
  301. if not cmdName or not cmd[cmdName] then
  302. return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CANT_USE)
  303. end
  304. local data = createData(id, cnt, itemConfig, logType, isAuto)
  305. while 0 < data.left do
  306. local isok = cmd[cmdName](data, human, command[2], command[3], command[4])
  307. if isok then
  308. data.left = data.left - 1
  309. else
  310. break
  311. end
  312. end
  313. return true, data.left
  314. end
  315. -- 使用并扣道具
  316. function use(human, id, cnt)
  317. if cnt < 1 then return end
  318. if id < 1 then return end
  319. local bagCnt = BagLogic.getItemCnt(human, id, true)
  320. if bagCnt < cnt then
  321. return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_NO)
  322. end
  323. local success, left = onlyuse(human, id, cnt, "item_use")
  324. if not success then
  325. return
  326. end
  327. local delCnt = cnt - left
  328. if delCnt > 0 then
  329. BagLogic.delItem(human, id, delCnt, "item_use")
  330. end
  331. end
  332. --
  333. function sendItemUse(human, id)
  334. local msgRet = Msg.gc.GC_ITEM_USE
  335. msgRet.id = id
  336. Msg.send(msgRet, human.fd)
  337. end
  338. -- 根据id获取item
  339. function sendItemDateByID(human,type,index,id,uuid)
  340. local msgRet = Msg.gc.GC_ITEM_GET_BY_ID
  341. if type == FUWEN_BAG_TYPE then
  342. -- 取出背包
  343. local bagFileds = {fuwenBag = 1}
  344. local db = nil
  345. -- 玩家在线直接取缓存
  346. local tempHuman = ObjHuman.onlineUuid[uuid]
  347. if tempHuman == nil then
  348. db = RoleDBLogic.getDb(uuid,bagFileds)
  349. else
  350. db = tempHuman.db
  351. end
  352. -- 玩家不存在,返回
  353. if db == nil then
  354. return
  355. end
  356. local fuwenGrid = db.fuwenBag[index]
  357. -- 符文背包id对不上,返回
  358. if fuwenGrid == nil or fuwenGrid.id ~= id then
  359. return
  360. end
  361. Grid.makeItem(msgRet.item,id,1,nil,fuwenGrid,index,0)
  362. elseif type == NORMAL_BAG_TYPE then
  363. Grid.makeItem(msgRet.item,id,1)
  364. elseif type == EQUIP_BAG_TYPE then
  365. -- 取出背包
  366. local bagFileds = {equipBag = 1}
  367. local db = nil
  368. -- 玩家在线直接取缓存
  369. local tempHuman = ObjHuman.onlineUuid[uuid]
  370. if tempHuman == nil then
  371. db = RoleDBLogic.getDb(uuid,bagFileds)
  372. else
  373. db = tempHuman.db
  374. end
  375. -- 玩家不存在,返回
  376. if db == nil then
  377. return
  378. end
  379. local equipGrid = db.equipBag[index]
  380. -- 符文背包id对不上,返回
  381. if equipGrid == nil or equipGrid.id ~= id then
  382. return
  383. end
  384. Grid.makeItem(msgRet.item,id,1,nil,equipGrid,index,0)
  385. end
  386. Msg.send(msgRet,human.fd)
  387. end
  388. -- 根据id获取item
  389. function sendItemData(human,itemID)
  390. local msgRet = Msg.gc.GC_ITEM_GET_BY_ITEM_ID
  391. local itemCnt = BagLogic.getItemCnt(human,itemID)
  392. Grid.makeItem(msgRet.item,itemID,itemCnt)
  393. Msg.send(msgRet,human.fd)
  394. end
  395. function itemBuyQuery(human,itemID)
  396. local config = ItemComonBuyExcel[itemID]
  397. if config == nil then
  398. return
  399. end
  400. local msgRet = Msg.gc.GC_ITEM_BUY_QUERY
  401. Grid.makeItem(msgRet.need,config.price[1],config.price[2])
  402. Grid.makeItem(msgRet.get,itemID,config.cnt)
  403. Msg.send(msgRet,human.fd)
  404. end
  405. function itemBuyDo(human,itemID,itemCnt)
  406. local msgRet = Msg.gc.GC_ITEM_BUY_DO
  407. msgRet.ret = 0
  408. local config = ItemComonBuyExcel[itemID]
  409. if config == nil then
  410. Msg.send(msgRet,human.fd)
  411. return
  412. end
  413. local needID = config.price[1]
  414. local needCnt = config.price[2] * itemCnt
  415. local costCnt = BagLogic.getItemCnt(human,needID)
  416. if costCnt < needCnt then
  417. Msg.send(msgRet,human.fd)
  418. return
  419. end
  420. BagLogic.delItem(human, needID, needCnt, "buy_item")
  421. BagLogic.cleanMomentItemList()
  422. BagLogic.updateMomentItem(1, itemID, itemCnt*config.cnt)
  423. BagLogic.addMomentItemList(human, "buy_item")
  424. msgRet.ret = 1
  425. Msg.send(msgRet,human.fd)
  426. end