IntoDropItemCommand.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. local IntoDropItemCommand = class('IntoDropItemCommand', framework.SimpleCommand)
  2. function IntoDropItemCommand:ctor()
  3. end
  4. function IntoDropItemCommand:execute(notification)
  5. local itemData = notification:getBody()
  6. if itemData then
  7. local function drop(dropNum)
  8. global.Facade:sendNotification(global.NoticeTable.Layer_Moved_End)
  9. local Name = itemData.Name
  10. local MakeIndex = itemData.MakeIndex
  11. LuaSendMsg(global.MsgType.MSG_CS_MAP_ITEM_DISCARD, MakeIndex, dropNum or 0, 0, 0, Name, string.len(Name))
  12. end
  13. local dropItemNum = 0
  14. local function RefreshBagItem()
  15. -- 背包中的重新刷出来
  16. local data = {
  17. dropping = {
  18. MakeIndex = itemData.MakeIndex,
  19. state = 1
  20. }
  21. }
  22. global.Facade:sendNotification(global.NoticeTable.Bag_State_Change, data)
  23. end
  24. local function RefreshBagItemQuickUse()
  25. local QuickUseProxy = global.Facade:retrieveProxy(global.ProxyTable.QuickUseProxy)
  26. local itemPos = QuickUseProxy:GetQucikUsePosByMakeIndex(itemData.MakeIndex)
  27. local data = {
  28. pos = itemPos,
  29. state = 1
  30. }
  31. global.Facade:sendNotification(global.NoticeTable.QuickUseItemRefresh, data)
  32. end
  33. local function CancelAndReset()
  34. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  35. local itemFrom = ItemManagerProxy:GetItemBelong(itemData.MakeIndex)
  36. if itemFrom == global.MMO.ITEM_FROM_BELONG_BAG then
  37. RefreshBagItem()
  38. elseif itemFrom == global.MMO.ITEM_FROM_BELONG_QUICKUSE then
  39. RefreshBagItemQuickUse()
  40. end
  41. global.Facade:sendNotification(global.NoticeTable.Layer_Moved_Cancel)
  42. end
  43. local function DropItems()
  44. local dropTips = CHECK_SERVER_OPTION(global.MMO.SERVER_DROP_TIPS)
  45. local isBind = CheckItemisBind(itemData)
  46. if isBind and dropTips == 0 then
  47. local function checkBind(atype, aData)
  48. if atype == 1 then
  49. drop(dropItemNum)
  50. else
  51. CancelAndReset()
  52. end
  53. end
  54. local data = {}
  55. data.str = string.format(GET_STRING(90020013), itemData.Name)
  56. data.callback = checkBind
  57. data.btnType = 2
  58. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
  59. else
  60. drop(dropItemNum)
  61. end
  62. end
  63. -- 随机石 回城石
  64. local ItemManagerProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemManagerProxy)
  65. local isStone = ItemManagerProxy:IsCityStone(itemData) or ItemManagerProxy:IsRandStone(itemData)
  66. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  67. if not isStone and ItemConfigProxy:CheckItemOverLap(itemData) then
  68. -- 叠加道具使用
  69. local Name = itemData.Name
  70. local MakeIndex = itemData.MakeIndex
  71. local function callback(btnType, data)
  72. local num = 0
  73. if data.editStr and tonumber(data.editStr) then
  74. num = tonumber(data.editStr)
  75. end
  76. if num > itemData.OverLap then
  77. dropItemNum = itemData.OverLap
  78. DropItems()
  79. -- global.Facade:sendNotification( global.NoticeTable.SystemTips, GET_STRING( 90020007 ) )
  80. -- CancelAndReset()
  81. -- return
  82. elseif num <= 0 then
  83. CancelAndReset()
  84. return
  85. else
  86. dropItemNum = num
  87. DropItems()
  88. end
  89. end
  90. local data = {}
  91. data.str = GET_STRING(90020009)
  92. data.callback = callback
  93. data.btnType = SL:GetMetaValue("GAME_DATA","DropCancelShow") and 2 or 1
  94. data.showEdit = true
  95. data.editParams = {
  96. inputMode = 2
  97. }
  98. global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
  99. else
  100. DropItems()
  101. end
  102. end
  103. end
  104. return IntoDropItemCommand