KLTradeSalesPanel.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. ---@class GoodsData
  2. ---@field number number @上架数量
  3. ---@field capacity number @总容量
  4. ---@field allgoods
  5. ---@class KLTradeSalesPanel:UIKmlLuaPanelBase
  6. ---@field view KLTradeSalesPanelView
  7. ---@field itemPanelList KLTradeSalesItem[]
  8. local KLTradeSalesPanel = class(UIKmlLuaPanelBase)
  9. local this = KLTradeSalesPanel
  10. ---创建时调用一次
  11. function this:Init()
  12. self.itemPanelList = {}
  13. end
  14. ---注册UI事件和服务器消息
  15. function this:RegistEvents()
  16. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_TRADE_MY_SHELVES, self.RES_TRADE_MY_SHELVES, self)
  17. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_TRADE_LISTING_GOODS, self.RES_TRADE_LISTING_GOODS, self)
  18. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_TRADE_OFF_GOODS, self.RES_TRADE_OFF_GOODS, self)
  19. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_STALL_INFO, self.RES_STALL_INFO, self)
  20. SL:RegisterLUAEvent(LUA_EVENT_BAG_CHANGE_AFTER, self.RefreshBag, self)
  21. GUI:AddOnClickEvent(self.view.StallButton, self, self.StallButtonOnclick)
  22. GUI:AddOnClickEvent(self.view.stall_btn_chat, self, self.stall_btn_chat_OnClick)
  23. GUI:AddOnClickEvent(self.view.stall_btn_walk, self, self.stall_btn_walk_OnClick)
  24. end
  25. ---创建或者刷新界面数据时调用
  26. function this:Refresh()
  27. if not self.bagItem then
  28. GUI:UIPanel_Open("dev/outui/Trade/Panel/KLTradeBag/KLTradeBagPanel", self.view.root, _, {
  29. --itemList = self:ShowItem(),
  30. --id = EBagShowType.EquipAdd,
  31. --forbidCount = SL:GetMetaValue("BAG_FORBID_COUNT"),
  32. --hor = self.maxHor,
  33. --vet = self.maxVet,
  34. canDrag = false,
  35. --forbidClickCallback = self.forbidClick,
  36. itemClick = self.ClickItem,
  37. callBackUI = self,
  38. itemList = self:ShowItem(),
  39. x = 370,
  40. y = -30
  41. }, false, function(bagItem)
  42. self.bagItem = bagItem
  43. self:RefreshUI()
  44. end)
  45. else
  46. self:RefreshUI()
  47. end
  48. end
  49. function this:RefreshUI()
  50. for _, v in pairs(self.itemPanelList) do
  51. v:Remove()
  52. end
  53. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_TRADE_MY_SHELVES)
  54. self.bagItem:RefreshItem(self:ShowItem())
  55. end
  56. function this:RefreshBag()
  57. self.bagItem:RefreshItem(self:ShowItem())
  58. end
  59. ---@param message GoodsData
  60. function this:RES_TRADE_MY_SHELVES(_, message)
  61. self.message = message
  62. local capacity = message.capacity or SL:GetConfig("cfg_global", 8001, "id").value
  63. local allCapacity = capacity
  64. if capacity < table.count(message.allgoods) then
  65. capacity = table.count(message.allgoods)
  66. end
  67. GUI:Text_setString(self.view.TradeSales_title,
  68. "寄售货架(" .. tostring(table.count(message.allgoods)) .. "/" .. tostring(allCapacity) .. ")")
  69. --self.isCapacity = table.count(message.allgoods) < capacity and true or false
  70. self:CreateItem(capacity)
  71. self:ShowGoodsInfo(message.allgoods)
  72. end
  73. function this:RES_TRADE_OFF_GOODS(_, message)
  74. if message then
  75. self:RefreshUI()
  76. end
  77. end
  78. function this:RES_TRADE_LISTING_GOODS(_, message)
  79. if message then
  80. self:RefreshUI()
  81. end
  82. end
  83. function this:ShowItem()
  84. local data = {}
  85. local bagItemTabl = SL:GetMetaValue("BAG_DATA")[1]
  86. if bagItemTabl then
  87. for i, v in pairs(bagItemTabl) do
  88. if v.bind == false and SL:HasConfigTwoKeys("cfg_stall", v.cfgId, 4, "id", "way") then
  89. local is_add = true
  90. --判断有没有强化追加再生过,有的话不可交易
  91. local strengthen = EquipFunc.GetEquipStrengthLevel(v)
  92. if is_add and strengthen > 0 then
  93. is_add = false
  94. end
  95. local appLevel = EquipFunc.GetEquipAppendLevel(v)
  96. if is_add and appLevel > 0 then
  97. is_add = false
  98. end
  99. local regenerateToAttr = SL:GetEquipValue(EMetaVarGetKey.EQUIP_REGENERATE_ATTR, "bag", v.cfgId, v.id)
  100. if is_add and regenerateToAttr and table.count(regenerateToAttr) > 0 then
  101. is_add = false
  102. end
  103. if is_add then
  104. table.insert(data, v)
  105. end
  106. --table.insert(self.bagItems, v.id)
  107. end
  108. end
  109. end
  110. ---月卡或者日卡生效
  111. if SL:HasConfigTwoKeys("cfg_stall", EMonthType.MonthCardTime, 4, "id", "way") and InfoManager.monthCardInfo.MonthCardTimeTotal > (SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME) + 86400000) then
  112. ---月卡时间特殊处理
  113. if InfoManager.monthCardInfo.IsGetDailyCard or InfoManager.monthCardInfo.IsGetMonthCard then
  114. local MonthTimeData = {
  115. bind = false,
  116. id = EMonthType.MonthCardTime,
  117. cfgId = EMonthType.MonthCardTime,
  118. count = 1,
  119. endTime = 0,
  120. itemExtInfo = nil,
  121. gmExtInfo = nil,
  122. correctId = 0,
  123. luaExtData = ""
  124. }
  125. table.insert(data, MonthTimeData)
  126. end
  127. end
  128. --货币特殊处理
  129. for _, id in pairs(MUEResourceType) do
  130. if SL:HasConfigTwoKeys("cfg_stall", id, 4, "id", "way") then
  131. local coinCount = SL:GetMetaValue(EMetaVarGetKey.MONEY, id)
  132. if coinCount > 0 then
  133. local coinData = {
  134. cfgId = id,
  135. count = coinCount,
  136. itemExtInfo = nil,
  137. luaExtData = ""
  138. }
  139. table.insert(data, coinData)
  140. end
  141. end
  142. end
  143. return self:SortItemList(data)
  144. end
  145. function this:CreateItem(capacity)
  146. for i = table.count(self.itemPanelList), capacity - 1 do
  147. ---@type KLTradeSalesItem
  148. local item = GUI:UIPanel_Open("dev/outui/Trade/Item/KLTradeSales/KLTradeSalesItem", self.view.sales_grid, self,
  149. nil, true)
  150. table.insert(self.itemPanelList, item)
  151. end
  152. GUI:SetScrollView_scrollpos(self.view.sales_scroll, 0)
  153. end
  154. ---@param data Allgoods[]
  155. function this:ShowGoodsInfo(data)
  156. if not data then
  157. return
  158. end
  159. for i, v in pairs(data) do
  160. if not self.itemPanelList[tonumber(i)] then
  161. return
  162. end
  163. if not self.itemPanelList[tonumber(i)]:IsGoods() then
  164. ---@type KLTradeGoodsItemData
  165. --local goods = {}
  166. --goods["itemname"] = v.item
  167. --goods["count"] = v.count
  168. --goods.price = math.floor(v.price / v.count)
  169. --goods.time = v.time and v.time or 0
  170. --goods.itemcfgid = v.cfgid
  171. --goods.cointype = v.cointype
  172. --goods.itemid = v.itemid
  173. --goods.timename = "公示时间:"
  174. --goods.type = 1
  175. --goods["itemname"] = v.itemname
  176. --goods["count"] = v.count
  177. --goods.price = math.floor(v.totalprice / v.count)
  178. --goods.totalprice
  179. --goods.time = v.time and v.time or 0
  180. --goods.itemcfgid = v.itemcfgid
  181. --goods.cointype = v.cointype
  182. --goods.itemid = v.itemid
  183. --goods.timename = "公示时间:"
  184. --goods.type = 1
  185. self.itemPanelList[tonumber(i)]:UpdateUI(v)
  186. end
  187. end
  188. end
  189. function this:ClickItem(itemControl, itemData)
  190. local itemInfo = SL:GetItemInfoByItemId(itemData.id)
  191. SL:OpenTips(_, itemData.cfgId, itemData.id, _, itemInfo)
  192. GUI:UIPanel_Open("dev/outui/Trade/Panel/KLSalesTips/KLSalesTipsPanel", _, _,
  193. { cfgId = itemData.cfgId, id = itemData.id, index = SL:GetBagIndex(itemData.id), capacity = self.isCapacity, IsNeedOffsetXPos = 0 })
  194. end
  195. function this:Tick()
  196. end
  197. function this:Close()
  198. GUI:UIPanel_Close("dev/outui/Trade/Panel/KLTradeBag/KLTradeBagPanel")
  199. end
  200. ---@param itemList CommonProtos.Item[]
  201. ---@return CommonProtos.Item[]
  202. function this:SortItemList(itemList)
  203. local bag_str = SL:GetConfig("cfg_global", 6).value
  204. local bag_tbl = string.split(bag_str, '#')
  205. local bag_hor = tonumber(bag_tbl[1])
  206. local bag_vet = tonumber(bag_tbl[2])
  207. local use_cell_dict = {}
  208. local sortItemList = {}
  209. local cfg_id, now_hor, now_vet, is_put, hold_vet, hole_hor, item, now_hold_hor, now_judge_hor, now_hold_vet, now_judge_vet, now_cell_index
  210. local max_hor = bag_hor + 20
  211. for _, v in pairs(itemList) do
  212. cfg_id = v.cfgId
  213. now_hor = 1
  214. while now_hor <= max_hor do
  215. now_vet = 1
  216. while now_vet <= bag_vet do
  217. is_put = true
  218. ---@type cfg_item_column
  219. item = SL:GetConfig("cfg_item", cfg_id)
  220. hold_vet = item.holdGrid[1]
  221. hole_hor = item.holdGrid[2]
  222. now_hold_hor = 0
  223. if item.id == MUEResourceType.MiracleCurrency then
  224. hole_hor = 2
  225. hold_vet = 2
  226. end
  227. if hole_hor == nil then
  228. hole_hor = 1
  229. end
  230. if hold_vet == nil then
  231. hold_vet = 1
  232. end
  233. while now_hold_hor < hole_hor do
  234. now_judge_hor = now_hor + now_hold_hor
  235. now_hold_vet = 0
  236. while now_hold_vet < hold_vet do
  237. now_judge_vet = now_vet + now_hold_vet
  238. now_cell_index = now_judge_hor * 100 + now_judge_vet
  239. if use_cell_dict[now_cell_index] or now_judge_vet > bag_vet then
  240. is_put = false
  241. break
  242. end
  243. now_hold_vet = now_hold_vet + 1
  244. end
  245. if not is_put then
  246. break
  247. end
  248. now_hold_hor = now_hold_hor + 1
  249. end
  250. if is_put then
  251. break
  252. end
  253. now_vet = now_vet + 1
  254. end
  255. if is_put then
  256. break
  257. end
  258. now_hor = now_hor + 1
  259. end
  260. local now_index = now_hor * 100 + now_vet
  261. sortItemList[now_index] = v
  262. now_hold_hor = 0
  263. while now_hold_hor < hole_hor do
  264. now_hold_vet = 0
  265. local now_hold_judge_hor = now_hor + now_hold_hor
  266. while now_hold_vet < hold_vet do
  267. local now_hold_judge_vet = now_vet + now_hold_vet
  268. now_cell_index = now_hold_judge_hor * 100 + now_hold_judge_vet
  269. use_cell_dict[now_cell_index] = true
  270. now_hold_vet = now_hold_vet + 1
  271. end
  272. now_hold_hor = now_hold_hor + 1
  273. end
  274. end
  275. return sortItemList
  276. end
  277. function this:StallButtonOnclick()
  278. if not InfoManager.monthCardInfo:IsHaveMonthCardRights("stall") then
  279. SL:TipMessage(SL:GetConfig('cfg_string', 278).text, 1, NoticeType.NoticeMid) --"开通月卡后可使用交易行功能",
  280. return
  281. end
  282. GUI:UIPanel_Open("dev/outui/Stall/Panel/KLOpenStall/KLOpenStallPanel")
  283. end
  284. function this:RES_STALL_INFO(_, message)
  285. if message.mapId then
  286. local endTime = message.endTime
  287. local current_time = Time.GetServerTime()
  288. current_time = math.floor(current_time / 1000)
  289. local last_time = endTime - current_time
  290. GUI:SetControl_time(self.view.stall_time, last_time)
  291. GUI:setVisible(self.view.StallView, true)
  292. GUI:setVisible(self.view.StallButton, false)
  293. self.stall_data = message
  294. else
  295. GUI:setVisible(self.view.StallView, false)
  296. GUI:setVisible(self.view.StallButton, true)
  297. end
  298. end
  299. function this:stall_btn_chat_OnClick()
  300. if not self.stall_data then
  301. return
  302. end
  303. GUI:UIPanel_Open("dev/outui/Stall/Panel/KLChatStall/KLChatStallPanel", nil, nil,
  304. { data = self.message, pos = self.stall_data })
  305. end
  306. function this:stall_btn_walk_OnClick()
  307. if not self.stall_data then
  308. return
  309. end
  310. local map_id = self.stall_data.mapId
  311. local serverType = SL:GetConfig("cfg_map_info", map_id, "id").serverType
  312. if serverType == 2 then
  313. if not self:CrossServerStall() then
  314. return
  315. end
  316. local mapId1 = SL:GetMetaValue(EMetaVarGetKey.MAP_ID)
  317. if mapId1 == self.stall_data.mapId then
  318. SL:Pathfinding(self.stall_data.mapId, self.stall_data.line, self.stall_data.pointX, self.stall_data.pointY)
  319. else
  320. SL.Scene:SetTransMapMoveToPointCallbackFunc(function()
  321. if not self.stall_data then
  322. SL.Scene:SetTransMapMoveToPointCallbackFunc()
  323. return
  324. end
  325. local mapId = SL:GetMetaValue(EMetaVarGetKey.MAP_ID)
  326. if mapId ~= self.stall_data.mapId then
  327. SL.Scene:SetTransMapMoveToPointCallbackFunc()
  328. return
  329. end
  330. SL:Pathfinding(self.stall_data.mapId, self.stall_data.line, self.stall_data.pointX,
  331. self.stall_data.pointY)
  332. end)
  333. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_GOTO_CROSS_MAP, {})
  334. end
  335. else
  336. SL:Pathfinding(self.stall_data.mapId, self.stall_data.line, self.stall_data.pointX, self.stall_data.pointY)
  337. end
  338. GUI:UIPanel_Close("dev/outui/Trade/Panel/KLTradeMain/KLTradeMainPanel")
  339. SL.ShowMainPanel()
  340. end
  341. function this:CrossServerStall()
  342. local cond, message = InfoManager.godsDescendInfo.CheckActivityConditionMapId(20001)
  343. if not cond then
  344. SL:TipMessage(message, 1, NoticeType.NoticeMid)
  345. end
  346. return cond
  347. end
  348. function this:IsHavePrivilege()
  349. if InfoManager.monthCardInfo.IsGetMonthCard or InfoManager.monthCardInfo.IsGetDailyCard then
  350. --有月卡或是日卡
  351. return true
  352. end
  353. return false
  354. end
  355. return this