ItemUseProxy.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. local RemoteProxy = requireProxy( "remote/RemoteProxy" )
  2. local ItemUseProxy = class( "ItemUseProxy", RemoteProxy )
  3. ItemUseProxy.NAME = global.ProxyTable.ItemUseProxy
  4. local socket = require("socket")
  5. function ItemUseProxy:ctor()
  6. self.itemCD = {}
  7. self.itemCD_Hero = {}
  8. self.itemUseCountdown = 0
  9. self.itemUseCountdown_Hero = 0
  10. ItemUseProxy.super.ctor(self)
  11. end
  12. function ItemUseProxy:UseItem(item, autoUse)
  13. if not item or next(item) == nil then
  14. return
  15. end
  16. if not CheckCanDoSomething() then
  17. return
  18. end
  19. local ItemMoveProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemMoveProxy)
  20. if item.from ~= ItemMoveProxy.ItemFrom.BAG then
  21. local BagProxy = global.Facade:retrieveProxy(global.ProxyTable.Bag)
  22. if BagProxy:GetBagCollimator() then --判断背包准星操作
  23. return
  24. end
  25. end
  26. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  27. local canUse, strList, notCheckUse = CheckItemUseNeed(item)
  28. if not canUse and not notCheckUse then
  29. for i,v in ipairs(strList) do
  30. if not v.can and not notCheckUse then
  31. local color = GUIFunction:ItemUseConditionColor(v.can)
  32. local conditionStr = string.format(GET_STRING(80049997), color, v.str)
  33. global.Facade:sendNotification(global.NoticeTable.SystemTips, conditionStr)
  34. break
  35. end
  36. end
  37. return
  38. end
  39. local isUseCd = self:CheckIsCD(item.Index)
  40. if isUseCd then
  41. return
  42. end
  43. if not self:CheckSpecialUseCondition(item) then
  44. return
  45. end
  46. local BuffProxy = global.Facade:retrieveProxy( global.ProxyTable.Buff )
  47. local ret,buffid = BuffProxy:CheckUseItemEnable( item.Index )
  48. if not ret then
  49. if buffid then
  50. local config = BuffProxy:GetConfigByID( buffid ) or {}
  51. if config.bufftitle then
  52. ShowSystemTips( config.bufftitle )
  53. end
  54. end
  55. return
  56. end
  57. if item.StdMode == 2 or item.StdMode == 3 then
  58. local MapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  59. local itemUseCd = MapProxy:GetEatItemSpeed() or 500
  60. self:IntoCD(item.Index, itemUseCd)
  61. end
  62. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  63. local Item_Type = ItemManagerProxy:GetItemSettingType()
  64. local itemType = ItemManagerProxy:GetItemType(item)
  65. if item.StdMode == 96 then
  66. itemType = Item_Type.WishBox
  67. end
  68. if itemType == Item_Type.DruaAndSomething
  69. or itemType == Item_Type.Bundle
  70. or itemType == Item_Type.Box
  71. or itemType == Item_Type.TreasureMap
  72. or itemType == Item_Type.FashionItem
  73. or itemType == Item_Type.MonsterCard
  74. or itemType == Item_Type.SomethingCanUse
  75. or itemType == Item_Type.WishBox
  76. or itemType == Item_Type.Collimator
  77. or itemType == Item_Type.NewPet then
  78. self:handleItem(item)
  79. local Name = item.Name or ""
  80. local MakeIndex = item.MakeIndex
  81. if item.StdMode == 200 and item.Shape == 0 and (ItemConfigProxy:CheckItemOverLap(item) or ItemConfigProxy:CheckItemBatch(item)) then
  82. if item.StdMode == 200 and item.Shape == 0 then
  83. autoUse = true
  84. end
  85. if autoUse then -- 自动使用 用全部
  86. local autoUseNumber = item.OverLap > 1 and item.OverLap or 1
  87. LuaSendMsg( global.MsgType.MSG_CS_USE_BAG_ITEM, MakeIndex, autoUseNumber , 0, 0, Name , string.len(Name) )
  88. else
  89. -- 叠加道具批量使用
  90. local function callback(btnType, data)
  91. if data.editStr and data.editStr ~= "" then
  92. if type(data.editStr) == "string" then
  93. local num = tonumber(data.editStr)
  94. if not num or num > item.OverLap or num <= 0 then
  95. global.Facade:sendNotification( global.NoticeTable.SystemTips, GET_STRING( 90020007 ) )
  96. return
  97. end
  98. LuaSendMsg( global.MsgType.MSG_CS_USE_BAG_ITEM, MakeIndex, num , 0, 0, Name , string.len(Name) )
  99. end
  100. end
  101. end
  102. local data = {}
  103. data.str = GET_STRING(90020006)
  104. data.callback = callback
  105. data.btnType = 2
  106. data.showEdit = true
  107. data.editParams = {
  108. inputMode = 2,
  109. str = item.OverLap
  110. }
  111. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
  112. end
  113. else
  114. if itemType == Item_Type.Bundle and ItemConfigProxy:CheckItemTreasureBox(item) then
  115. if not CheckGoldBoxCanUse() then
  116. ShowSystemTips("该系统正在使用中..")
  117. return
  118. end
  119. local data = {
  120. storage = {
  121. MakeIndex = MakeIndex,
  122. state = 0
  123. }
  124. }
  125. global.Facade:sendNotification(global.NoticeTable.Bag_State_Change, data)
  126. global.Facade:sendNotification(global.NoticeTable.Layer_Treasure_Box_Open,item)
  127. return
  128. end
  129. LuaSendMsg( global.MsgType.MSG_CS_USE_BAG_ITEM, MakeIndex, 1 , 0, 0, Name , string.len(Name) )
  130. end
  131. elseif itemType == Item_Type.SkillBook then
  132. local function callback(atype,aData)
  133. if atype == 1 then
  134. local Name = item.Name
  135. local MakeIndex = item.MakeIndex
  136. LuaSendMsg( global.MsgType.MSG_CS_USE_BAG_ITEM, MakeIndex, 0 , 0, 0, Name , string.len(Name) )
  137. end
  138. end
  139. local data = {}
  140. data.str = string.format(GET_STRING(90020001), item.Name)
  141. data.callback = callback
  142. data.btnType = 2
  143. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
  144. elseif itemType == Item_Type.Equip then
  145. local Name = item.Name
  146. local MakeIndex = item.MakeIndex
  147. local targetPos = nil
  148. -- 是否有找到合适的位置 战力对比
  149. local comparison = ItemConfigProxy:GetItemComparison(item.Index)
  150. local myPower, powerSortIndex = GUIFunction:GetEquipPower(item, {jobPower = true})
  151. local param = {jobPower = true, power = myPower, comparison = comparison, powerSortIndex = powerSortIndex}
  152. local excludePos = GUIFunction:CheckEquipExcludePos(item)
  153. local minPowerPos, onEquipMinPower, hasEquip = GUIFunction:GetMinPowerPosByStdMode(item.StdMode, param, nil, false, excludePos)
  154. if minPowerPos >= 0 and (not hasEquip or onEquipMinPower < myPower) then
  155. targetPos = minPowerPos
  156. end
  157. global.Facade:sendNotification(global.NoticeTable.Layer_Auto_Use_UnAttach, {id = MakeIndex})
  158. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.Equip)
  159. local canUseBuJuk, pos = EquipProxy:CheckBujukUse(item, targetPos)
  160. if pos then
  161. targetPos = pos
  162. else
  163. if not canUseBuJuk then
  164. return false
  165. end
  166. end
  167. local noticeName = global.NoticeTable.TakeOnRequest
  168. global.Facade:sendNotification(noticeName,
  169. {
  170. itemData = item,
  171. pos = targetPos
  172. }
  173. )
  174. end
  175. global.Facade:sendNotification(global.NoticeTable.Audio_Play, {type = global.MMO.SND_TYPE_USE_ITEM, param = item})
  176. end
  177. function ItemUseProxy:HeroUseItem(item, autoUse)
  178. if not item or next(item) == nil then
  179. return
  180. end
  181. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  182. local canUse, strList, notCheckUse = CheckItemUseNeed_Hero(item)
  183. if not canUse and not notCheckUse then
  184. for i,v in ipairs(strList) do
  185. if not v.can and not notCheckUse then
  186. local color = GUIFunction:ItemUseConditionColor(v.can)
  187. local conditionStr = string.format(GET_STRING(80049997), color, v.str)
  188. global.Facade:sendNotification(global.NoticeTable.SystemTips, conditionStr)
  189. break
  190. end
  191. end
  192. return
  193. end
  194. local isUseCd = self:CheckIsCD_Hero(item.Index)
  195. if isUseCd then
  196. return
  197. end
  198. if not self:CheckSpecialUseCondition(item) then
  199. return
  200. end
  201. if item.StdMode == 2 or item.StdMode == 3 then
  202. local MapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  203. local itemUseCd = MapProxy:GetEatItemSpeed() or 500
  204. self:IntoCD_Hero(item.Index, itemUseCd)
  205. end
  206. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  207. local Item_Type = ItemManagerProxy:GetItemSettingType()
  208. local itemType = ItemManagerProxy:GetItemType(item)
  209. if item.StdMode == 96 then
  210. itemType = Item_Type.WishBox
  211. end
  212. if itemType == Item_Type.DruaAndSomething
  213. or itemType == Item_Type.Bundle
  214. or itemType == Item_Type.Box
  215. or itemType == Item_Type.TreasureMap
  216. or itemType == Item_Type.FashionItem
  217. or itemType == Item_Type.MonsterCard
  218. or itemType == Item_Type.SomethingCanUse
  219. or itemType == Item_Type.WishBox
  220. or itemType == Item_Type.Collimator then
  221. -- self:handleItem(item)
  222. local Name = item.Name
  223. local MakeIndex = item.MakeIndex
  224. if item.StdMode == 200 and item.Shape == 0 and (ItemConfigProxy:CheckItemOverLap(item) or ItemConfigProxy:CheckItemBatch(item)) then
  225. if item.StdMode == 200 and item.Shape == 0 then
  226. autoUse = true
  227. end
  228. if autoUse then -- 自动使用 用全部
  229. local autoUseNumber = item.OverLap > 1 and item.OverLap or 1
  230. LuaSendMsg( global.MsgType.MSG_CS_USE_BAG_ITEM_HERO, MakeIndex, autoUseNumber , 0, 0, Name , string.len(Name) )
  231. else
  232. -- 叠加道具批量使用
  233. local function callback(btnType, data)
  234. if data.editStr and data.editStr ~= "" then
  235. if type(data.editStr) == "string" then
  236. local num = tonumber(data.editStr)
  237. if not num or num > item.OverLap or num <= 0 then
  238. global.Facade:sendNotification( global.NoticeTable.SystemTips, GET_STRING( 90020007 ) )
  239. return
  240. end
  241. LuaSendMsg( global.MsgType.MSG_CS_USE_BAG_ITEM_HERO, MakeIndex, num , 0, 0, Name , string.len(Name) )
  242. end
  243. end
  244. end
  245. local data = {}
  246. data.str = GET_STRING(90020006)
  247. data.callback = callback
  248. data.btnType = 2
  249. data.showEdit = true
  250. data.editParams = {
  251. inputMode = 2,
  252. str = item.OverLap
  253. }
  254. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
  255. end
  256. else
  257. if itemType == Item_Type.Bundle and ItemConfigProxy:CheckItemTreasureBox(item) then
  258. local data = {
  259. storage = {
  260. MakeIndex = MakeIndex,
  261. state = 0
  262. }
  263. }
  264. global.Facade:sendNotification(global.NoticeTable.HeroBag_State_Change, data)
  265. global.Facade:sendNotification(global.NoticeTable.Layer_Treasure_Box_Open,item)
  266. return
  267. end
  268. LuaSendMsg( global.MsgType.MSG_CS_USE_BAG_ITEM_HERO, MakeIndex, 1 , 0, 0, Name , string.len(Name) )
  269. end
  270. elseif itemType == Item_Type.SkillBook then
  271. local function callback(atype,aData)
  272. if atype == 1 then
  273. local Name = item.Name
  274. local MakeIndex = item.MakeIndex
  275. LuaSendMsg( global.MsgType.MSG_CS_USE_BAG_ITEM_HERO, MakeIndex, 0 , 0, 0, Name , string.len(Name) )
  276. end
  277. end
  278. local data = {}
  279. data.str = string.format(GET_STRING(90020001), item.Name)
  280. data.callback = callback
  281. data.btnType = 2
  282. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
  283. elseif itemType == Item_Type.Equip then
  284. local Name = item.Name
  285. local MakeIndex = item.MakeIndex
  286. local targetPos = nil
  287. -- 是否有找到合适的位置 战力对比
  288. local comparison = ItemConfigProxy:GetItemComparison(item.Index)
  289. local myPower,powerSortIndex = GUIFunction:GetEquipPower(item, {jobPower = true}, true)
  290. local param = {jobPower = true, power = myPower, comparison = comparison, powerSortIndex = powerSortIndex}
  291. local excludePos = GUIFunction:CheckEquipExcludePos(item)
  292. local minPowerPos, onEquipMinPower, hasEquip = GUIFunction:GetMinPowerPosByStdMode(item.StdMode, param, nil, true, excludePos)
  293. if minPowerPos >= 0 and (not hasEquip or onEquipMinPower < myPower) then
  294. targetPos = minPowerPos
  295. end
  296. local EquipProxy = global.Facade:retrieveProxy(global.ProxyTable.HeroEquipProxy)
  297. local canUseBuJuk, pos = EquipProxy:CheckBujukUse(item, targetPos)
  298. if pos then
  299. targetPos = pos
  300. else
  301. if not canUseBuJuk then
  302. return false
  303. end
  304. end
  305. local noticeName = global.NoticeTable.HeroTakeOnRequest
  306. global.Facade:sendNotification(noticeName,
  307. {
  308. itemData = item,
  309. pos = targetPos
  310. }
  311. )
  312. end
  313. global.Facade:sendNotification(global.NoticeTable.Audio_Play, {type = global.MMO.SND_TYPE_USE_ITEM, param = item})
  314. end
  315. function ItemUseProxy:handleItem(item)
  316. ---随机卷轴
  317. local MapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
  318. local autoProxy = global.Facade:retrieveProxy( global.ProxyTable.Auto )
  319. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  320. if ItemManagerProxy:IsRandStone(item) then
  321. autoProxy:SetRandStoneAFKFlag(true)
  322. end
  323. end
  324. function ItemUseProxy:CheckSpecialUseCondition(item)
  325. if not item or not next(item) then
  326. return
  327. end
  328. return true
  329. end
  330. function ItemUseProxy:IntoCD( index ,times)
  331. local cdtimes = times or 500
  332. if next(self.itemCD) and self.itemUseCountdown > 0 then
  333. cdtimes = math.max(cdtimes - (math.floor(socket.gettime() * 1000) - self.itemUseCountdown), 0)
  334. end
  335. self.itemUseCountdown = math.floor(socket.gettime() * 1000)
  336. self.itemCD[index] = true
  337. PerformWithDelayGlobal(function()
  338. self.itemUseCountdown = 0
  339. self.itemCD[index] = false
  340. end, cdtimes/1000)
  341. end
  342. function ItemUseProxy:CheckIsCD( index )
  343. return self.itemCD[index]
  344. end
  345. function ItemUseProxy:IntoCD_Hero( index ,times)
  346. local cdtimes = times or 500
  347. if next(self.itemCD_Hero) and self.itemUseCountdown_Hero > 0 then
  348. cdtimes = math.max(cdtimes - (math.floor(socket.gettime() * 1000) - self.itemUseCountdown_Hero), 0)
  349. end
  350. self.itemUseCountdown_Hero = math.floor(socket.gettime() * 1000)
  351. self.itemCD_Hero[index] = true
  352. PerformWithDelayGlobal(function()
  353. self.itemUseCountdown_Hero = 0
  354. self.itemCD_Hero[index] = false
  355. end, cdtimes/1000)
  356. end
  357. function ItemUseProxy:CheckIsCD_Hero( index )
  358. return self.itemCD_Hero[index]
  359. end
  360. function ItemUseProxy:onRegister()
  361. ItemUseProxy.super.onRegister(self)
  362. end
  363. return ItemUseProxy