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. local SkinLogic = require("skin.SkinLogic")
  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.skinGen(data,human,skinId)
  287. if data.left < 1 then return end
  288. SkinLogic.skinUnlock(human,skinId)
  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