ItemLogic.lua 13 KB

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