PrivilegeCardManager.lua 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  1. ---@class PrivilegeCardManager
  2. PrivilegeCardManager = {}
  3. local this = PrivilegeCardManager
  4. function this.Init()
  5. this.RegistEvents()
  6. this.all_info = {}
  7. this.auto_buy_drug = 0
  8. local cfg = SL:GetConfigTable('cfg_free_buff')
  9. local one_num = 1
  10. if cfg then
  11. for k, v in pairs(cfg) do
  12. if v.autoPick then
  13. one_num = v.autoPick[1]
  14. break
  15. end
  16. end
  17. end
  18. SL:StartFastPickUp(3,1,50)
  19. -- ---@type cfg_privilege_column
  20. -- this.goldCfg = SL:GetConfig("cfg_privilege", 1)
  21. -- ---@type cfg_privilege_column
  22. -- this.diamondCfg = SL:GetConfig("cfg_privilege", 2)
  23. this.goldPrivilege = false
  24. this.diamondPrivilege = false
  25. this.all_pricilege_id = {}
  26. this.message = {}
  27. end
  28. function this.RegistEvents()
  29. SL:RegisterLUAEvent(LUA_EVENT_LOGIN_MAP, this.LoginReq)
  30. SL:RegisterLUAEvent(LUA_EVENT_ONHOOK_STATE_CHANGE,this.LUA_EVENT_ONHOOK_STATE_CHANGE)
  31. SL:RegisterLUAEvent(LUA_EVENT_DROPITEM_OUT_OF_VIEW,this.LUA_EVENT_DROPITEM_OUT_OF_VIEW)
  32. SL:RegisterLUAEvent(LUA_EVENT_MAIN_PLAYER_REVIVE,this.LUA_EVENT_MAIN_PLAYER_REVIVE)
  33. SL:RegisterLUAEvent(LUA_EVENT_PICK_UP_SETTING_CHANGE,this.LUA_EVENT_PICK_UP_SETTING_CHANGE)
  34. SL:RegisterLuaNetMsg(LuaMessageIdToClient.SET_AUTO_BUY_POTION_RESULT,this.ResSetAutoBuy)
  35. SL:RegisterLuaNetMsg(LuaMessageIdToClient.CURRENT_AUTO_BUY_POTION_RESULT,this.AutoBuyStatus)
  36. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_PRIVILEGE_RESULT,this.ResAllPrivilegeCardInfo)
  37. SL:RegisterLuaNetMsg(LuaMessageIdToClient.PRIVILEGE_INFO_TIP,this.ResCardChange)
  38. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GET_MONTH_PRIVILEGE_DATA,this.RES_GET_MONTH_PRIVILEGE_DATA)
  39. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_PRIVILEGE_CARD_ACTIVATION,this.RES_PRIVILEGE_CARD_ACTIVATION)
  40. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GET_ROLE_ATTR_POINT_PROGRAMME, this.RES_GET_ROLE_ATTR_POINT_PROGRAMME)
  41. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_CHANGE_ROLE_ATTR_POINT_PROGRAMME, this.RES_CHANGE_ROLE_ATTR_POINT_PROGRAMME)
  42. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_MONTH_PRIVILEGE_TIME_OUT, this.RES_MONTH_PRIVILEGE_TIME_OUT)
  43. SL:RegisterLuaNetMsg(LuaMessageIdToClient.TRIPLE_INCOME_INFO, this.TRIPLE_INCOME_INFO)
  44. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_PRIVILEGE_MONTH_BUBBLE_DATA, this.RES_PRIVILEGE_MONTH_BUBBLE_DATA)
  45. SL:RegisterLuaNetMsg(MessageDef.ResMonsterStatusChangeMessage, this.ResMonsterStatusChangeMessage)
  46. end
  47. function this.Update()
  48. ---特权巡逻挂机,击杀黄金boss后捡完装备,去下一家
  49. if this.checkHaveDrop then
  50. local data = SL:GetMetaValue(EMetaVarGetKey.GET_MONSTER_DROP_ITEM_LIST)
  51. if type(data) == "table" and next(data) then
  52. this.checkHaveDrop = false
  53. this.LUA_EVENT_DROPITEM_OUT_OF_VIEW()
  54. else
  55. this.checkHaveDrop = false
  56. this:GetThisMapGoldBossAttack()
  57. end
  58. end
  59. if this.is_wait_req then
  60. if this.check_req_time + 100 < Time.GetServerTime() then
  61. local panel = GUI:GetUI("dev/ui/MainUI/Panel/KLUIPlayerInfo/KLUIPlayerInfoPanel")
  62. if panel then
  63. this.is_wait_req = false
  64. this.REQ_GET_MONTH_PRIVILEGE_DATA()
  65. end
  66. end
  67. end
  68. end
  69. function this.UnRegistEvents()
  70. SL:UnRegisterLUAEvent(LUA_EVENT_LOGIN_MAP,this.LoginReq)
  71. end
  72. function this.Reset()
  73. if this.scheduleId then
  74. SL:UnSchedule(this.scheduleId)
  75. this.scheduleId = nil
  76. end
  77. this.UnRegistEvents()
  78. end
  79. function this:LoginReq()
  80. this.all_info = {}
  81. this.pickupType = {}
  82. this.hideDiamondPopover = false
  83. this.hideGoldPopover = false
  84. this.startFindWay = false
  85. this.finishFindWay = false
  86. this.onHookType = EOnHookType.Situ
  87. this.goldPrivilegeStopTime = nil
  88. this.diamondPrivilegeStopTime = nil
  89. --this.ReqPrivilegeCardAllInfo()
  90. local panel = GUI:GetUI("dev/ui/MainUI/Panel/KLUIPlayerInfo/KLUIPlayerInfoPanel")
  91. if panel then
  92. this.is_wait_req = false
  93. this.REQ_GET_MONTH_PRIVILEGE_DATA()
  94. else
  95. this.is_wait_req = true
  96. this.check_req_time = Time.GetServerTime()
  97. end
  98. --特权功能请求买药状态
  99. --this.ReqAutoBuyStatus()
  100. end
  101. ---请求设置自动吃药
  102. function this.ReqAutoBuyDrug()
  103. SL:SendLuaNetMsg(LuaMessageIdToSever.OPEN_OR_CLOSE_AUTO_BUY_POTION, {})
  104. end
  105. ---请求设置自动吃药回包
  106. function this.ResSetAutoBuy(_id,message)
  107. --SL:LogError("ResSetAutoBuy")
  108. this.auto_buy_drug = message.isOn
  109. SL:onLUAEvent(LUA_EVENT_AUTO_BUY_POTION_RESULT, {})
  110. end
  111. --获得当前自动购买药水状态
  112. function this.ReqAutoBuyStatus()
  113. SL:SendLuaNetMsg(LuaMessageIdToSever.GET_CURRENT_AUTO_BUY_POTION, {})
  114. end
  115. --获得当前自动购买药水状态回包
  116. function this.AutoBuyStatus(_id,message)
  117. --SL:LogError(message.isOn)
  118. this.auto_buy_drug = message.isOn
  119. if this.AutoBuyIsOpen() then
  120. if not this.isautoPotion() then
  121. this.ReqAutoBuyDrug()
  122. end
  123. end
  124. end
  125. function this.AutoBuyIsOpen()
  126. if this.auto_buy_drug and this.auto_buy_drug == 1 then
  127. return true
  128. end
  129. return false
  130. end
  131. ---获取已有的特权信息
  132. function this.ReqPrivilegeCardAllInfo()
  133. SL:SendLuaNetMsg(LuaMessageIdToSever.GET_PRIVILEGES, {})
  134. end
  135. function this.LUA_EVENT_MAIN_PLAYER_REVIVE()
  136. this.REQ_GET_MONTH_PRIVILEGE_DATA()
  137. end
  138. function this:LUA_EVENT_PICK_UP_SETTING_CHANGE()
  139. this.pickupType = SL:GetMetaValue(EMetaVarGetKey.GET_ATUO_PICKUP_ITEM)
  140. end
  141. ---获取已有的特权信息
  142. function this.REQ_GET_MONTH_PRIVILEGE_DATA()
  143. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_GET_MONTH_PRIVILEGE_DATA, {})
  144. end
  145. ---获取特权项结果
  146. function this.ResAllPrivilegeCardInfo(_id,message)
  147. --SL:LogError(message)
  148. this.all_info = message
  149. this.ReqAutoBuyStatus()
  150. this.UpdateData()
  151. end
  152. function this.ResCardChange(_id,message)
  153. if message.withstore then
  154. this.all_info.withstore = "0"
  155. end
  156. if message.withwarehouse then
  157. this.all_info.withwarehouse = "0"
  158. end
  159. if message.autopotion then
  160. this.all_info.autopotion = "0"
  161. end
  162. if message.autorecovery then
  163. this.all_info.autorecovery = "0"
  164. end
  165. if message.autopick then
  166. this.all_info.autopick = "0"
  167. end
  168. this.ReqAutoBuyStatus()
  169. this.UpdateData()
  170. end
  171. -- ---@param message table<number,PrivilegeTypeData>
  172. -- ---@class PrivilegeTypeData
  173. -- ---@field id number
  174. -- ---@field start_time number
  175. -- ---@field durationtime number 持续时长 单位小时
  176. -- ---@field timerid number
  177. -- function this.RES_GET_MONTH_PRIVILEGE_DATA(_, message)
  178. -- SL:LogTable(message,true)
  179. -- --判断激活特权特殊展示
  180. -- local showType = 0
  181. -- if message then
  182. -- for i, v in pairs(message) do
  183. -- if v.id == 1 and not this.goldPrivilege then
  184. -- --新激活黄金特权开启自动买药
  185. -- this.ReqAutoBuyDrug()
  186. -- showType = 1
  187. -- end
  188. -- if v.id == 2 and not this.diamondPrivilege then
  189. -- showType = 2
  190. -- end
  191. -- end
  192. -- end
  193. -- --刷新特权信息
  194. -- this.goldPrivilege = false
  195. -- this.goldServerInfo = nil
  196. -- this.diamondPrivilege = false
  197. -- this.diamondServerInfo = nil
  198. -- if message then
  199. -- for _, v in pairs(message) do
  200. -- if v.id == 1 then
  201. -- local time = v.start_time + v.durationtime * 3600000
  202. -- if time > Time.GetServerTime() then
  203. -- this.goldPrivilege = true
  204. -- this.goldServerInfo = v
  205. -- this.goldServerInfo["stop_time"] = time
  206. -- end
  207. -- end
  208. -- if v.id == 2 then
  209. -- local time = v.start_time + v.durationtime * 3600000
  210. -- if time > Time.GetServerTime() then
  211. -- this.diamondPrivilege = true
  212. -- this.diamondServerInfo = v
  213. -- this.diamondServerInfo["stop_time"] = time
  214. -- end
  215. -- end
  216. -- end
  217. -- end
  218. -- SL:onLUAEvent(LUA_EVENT_PRIVILEGE_INFO_CHANGE, showType)
  219. -- this.CheckPriviegeBoss()
  220. -- end
  221. ---@param message table<number,PrivilegeTypeData>
  222. ---@class PrivilegeTypeData
  223. ---@field id number
  224. ---@field start_time number
  225. ---@field durationtime number 持续时长 单位小时
  226. ---@field timerid number
  227. function this.RES_GET_MONTH_PRIVILEGE_DATA(_, message)
  228. --SL:LogTable(message,true)
  229. --判断激活特权特殊展示
  230. local is_drug = false
  231. local is_pick_up = false
  232. local is_recovery = false
  233. --刷新特权信息
  234. this.goldPrivilege = false
  235. this.goldServerInfo = nil
  236. this.diamondPrivilege = false
  237. this.diamondServerInfo = nil
  238. this.message = message
  239. this.all_pricilege_id = {}
  240. if message then
  241. for _, v in pairs(message) do
  242. local time = v.start_time + v.durationtime * 3600000
  243. if time > Time.GetServerTime() or v.durationtime == -1 then
  244. local tab = SL:GetConfig("cfg_privilege",v.id)
  245. local PrivilegelList = tab.PrivilegelList
  246. for ii, one_id in ipairs(PrivilegelList) do
  247. if not table.contains(this.all_pricilege_id,one_id) then
  248. table.insert(this.all_pricilege_id,one_id)
  249. end
  250. end
  251. local myId = SL:GetMetaValue("MAIN_ACTOR_ID")
  252. local buff_id = tab.buff
  253. local _buffText = SL:GetConfig("cfg_buff",buff_id).buffText
  254. --local buffChangeData = {{cfgId = 30000001,endTime = time}}
  255. if v.durationtime == -1 then
  256. time = v.durationtime
  257. end
  258. local fuffData = {updateType=0,buff={buffTbl={showIcon="aa"},cfgId=buff_id,endTime=time,buffText=_buffText},roleId=myId}
  259. --SL:LogTable(fuffData,true)
  260. SL:onLUAEvent(LUA_EVENT_BUFFCHANHE, fuffData)
  261. end
  262. end
  263. end
  264. if not this.isautoPick() then
  265. local is_open = SL:GetPlayerAutoPickIsOpen()
  266. if is_open then
  267. --去掉勾选自动范围拾取
  268. SL:SetPlayerAutoPick(false)
  269. SL:SendPlayerAutoPickChange(false)
  270. end
  271. end
  272. if not this.isautoRecovery() then
  273. --去掉勾选自动回收
  274. SL:SendPlayerAutoRecoverChange(false)
  275. end
  276. --SL:LogTable(this.all_pricilege_id,true)
  277. this.CheckPriviegeBoss()
  278. this.ReqAutoBuyStatus()
  279. end
  280. function this.RES_PRIVILEGE_CARD_ACTIVATION(_, message)
  281. if message then
  282. local id = tonumber(message)
  283. local PrivilegelList = SL:GetConfig("cfg_privilege",id).PrivilegelList
  284. if table.contains(PrivilegelList,6) and not not table.contains(this.all_pricilege_id,6) then
  285. --新激特权开启自动买药
  286. if not this.AutoBuyIsOpen() then
  287. this.ReqAutoBuyDrug()
  288. end
  289. end
  290. if table.contains(PrivilegelList,16) and not not table.contains(this.all_pricilege_id,16) then
  291. --新激活特权开启自动范围拾取
  292. local is_open = SL:GetPlayerAutoPickIsOpen()
  293. if not is_open then
  294. ---设置一下数据
  295. SL:SetPlayerAutoPick(true)
  296. ---发给服务器
  297. SL:SendPlayerAutoPickChange(true)
  298. end
  299. end
  300. if table.contains(PrivilegelList,17) and not not table.contains(this.all_pricilege_id,17) then
  301. --新激活特权开启自动回收
  302. local is_open = SL:GetPlayerAutoRecoverIsOpen()
  303. if not is_open then
  304. ---发给服务器
  305. SL:SendPlayerAutoRecoverChange(true)
  306. end
  307. end
  308. end
  309. end
  310. function this.HavePriviege()
  311. if this.all_pricilege_id and #this.all_pricilege_id > 0 then
  312. return true
  313. end
  314. return false
  315. end
  316. ---@class freeSwitchAttrPointData
  317. ---@field id number
  318. ---@field attr table
  319. ---@field name string
  320. ---@param message RoleAttrProgrammeData
  321. ---@class RoleAttrProgrammeData
  322. ---@field current number 当前方案
  323. ---@field FreeSwitchAttrPointData table<number,freeSwitchAttrPointData>
  324. function this.RES_GET_ROLE_ATTR_POINT_PROGRAMME(_, message)
  325. if message then
  326. this.currentAttrType = message.current or 1
  327. this.freeFirstSwitchInfo = message.freeSwitchAttrPointData and message.freeSwitchAttrPointData["1"] or nil
  328. this.freeSecondSwitchInfo = message.freeSwitchAttrPointData and message.freeSwitchAttrPointData["2"] or nil
  329. else
  330. this.currentAttrType = 1
  331. this.freeFirstSwitchInfo = nil
  332. this.freeSecondSwitchInfo = nil
  333. end
  334. end
  335. function this.RES_CHANGE_ROLE_ATTR_POINT_PROGRAMME(_, message)
  336. this.currentAttrType = message
  337. end
  338. ---特权到期
  339. -- function this.RES_MONTH_PRIVILEGE_TIME_OUT(_, message)
  340. -- if message then
  341. -- if message == 1 then
  342. -- this.goldPrivilege = false
  343. -- this.goldServerInfo = nil
  344. -- else
  345. -- this.diamondPrivilege = false
  346. -- this.diamondServerInfo = nil
  347. -- end
  348. -- end
  349. -- SL:onLUAEvent(LUA_EVENT_PRIVILEGE_INFO_CHANGE)
  350. -- end
  351. function this.RES_MONTH_PRIVILEGE_TIME_OUT(_, message)
  352. if message then
  353. if not this.message[tostring(message)] then
  354. return
  355. end
  356. local data = this.message[tostring(message)]
  357. local tab = SL:GetConfig("cfg_privilege",data.id)
  358. local time = data.start_time + data.durationtime * 3600000
  359. local myId = SL:GetMetaValue("MAIN_ACTOR_ID")
  360. local buff_id = tab.buff
  361. local _buffText = SL:GetConfig("cfg_buff",buff_id).buffText
  362. local fuffData = {updateType=1,buff={buffTbl={showIcon="aa"},cfgId=buff_id,endTime=time,buffText=_buffText},roleId=myId}
  363. SL:onLUAEvent(LUA_EVENT_BUFFCHANHE, fuffData)
  364. this.message[tostring(message)] = nil
  365. this.all_pricilege_id = {}
  366. if this.message then
  367. for _, v in pairs(this.message) do
  368. local time = v.start_time + v.durationtime * 3600000
  369. if time > Time.GetServerTime() then
  370. local PrivilegelList = SL:GetConfig("cfg_privilege",v.id).PrivilegelList
  371. for ii, one_id in ipairs(PrivilegelList) do
  372. if not table.contains(this.all_pricilege_id,one_id) then
  373. table.insert(this.all_pricilege_id,one_id)
  374. end
  375. end
  376. end
  377. end
  378. end
  379. end
  380. if not this.isautoPick() then
  381. local is_open = SL:GetPlayerAutoPickIsOpen()
  382. if is_open then
  383. --去掉勾选自动范围拾取
  384. SL:SetPlayerAutoPick(false)
  385. SL:SendPlayerAutoPickChange(false)
  386. end
  387. end
  388. if not this.isautoRecovery() then
  389. --去掉勾选自动回收
  390. SL:SendPlayerAutoRecoverChange(false)
  391. end
  392. this.ReqAutoBuyStatus()
  393. SL:onLUAEvent(LUA_EVENT_PRIVILEGE_INFO_CHANGE)
  394. end
  395. function this.TRIPLE_INCOME_INFO(_, message)
  396. if this.scheduleId then
  397. SL:UnSchedule(this.scheduleId)
  398. this.scheduleId = nil
  399. end
  400. if message then
  401. this.tripleEarningsInfo = message
  402. if this.tripleEarningsInfo.effectSec > 0 then
  403. this.scheduleId = SL:ScheduleOnce(this.tripleEarningsInfo.effectSec, function()
  404. SL:SendLuaNetMsg(LuaMessageIdToSever.TRIPLE_INCOME_PANEL)
  405. end)
  406. end
  407. end
  408. SL:onLUAEvent(LUA_EVENT_PRIVILEGE_INFO_CHANGE)
  409. end
  410. function this.RES_PRIVILEGE_MONTH_BUBBLE_DATA(_, message)
  411. for i, v in pairs(message) do
  412. if i == "1" then
  413. this.goldPrivilegeStopTime = v
  414. elseif i == "2" then
  415. this.diamondPrivilegeStopTime = v
  416. end
  417. end
  418. end
  419. function this.SetHideGoldPopover(state)
  420. this.hideGoldPopover = state
  421. end
  422. function this.SetHideDiamondPopover(state)
  423. this.hideDiamondPopover = state
  424. end
  425. function this.GetGoldPrivilegePopoverState()
  426. if this.hideGoldPopover then
  427. return false
  428. end
  429. if this.goldPrivilege then
  430. local gold_stop_time = SL:GetConfig("cfg_global", 14001).value
  431. local remind_time = this.goldServerInfo.stop_time - Time.GetServerTime()
  432. if remind_time < gold_stop_time * 3600000 then
  433. return true
  434. end
  435. else
  436. local gold_stop_day = SL:GetConfig("cfg_global", 14002).value
  437. if this.goldPrivilegeStopTime then
  438. local gold_stop_time = Time.GetServerTime() - this.goldPrivilegeStopTime
  439. if gold_stop_time < gold_stop_day * 3600000 then
  440. return true
  441. end
  442. end
  443. end
  444. return false
  445. end
  446. function this.GetDiamondPrivilegePopoverState()
  447. if this.hideDiamondPopover then
  448. return false
  449. end
  450. if this.diamondPrivilege then
  451. local diamond_stop_time = SL:GetConfig("cfg_global", 14001).value
  452. local remind_time = this.diamondServerInfo.stop_time - Time.GetServerTime()
  453. if remind_time < diamond_stop_time * 3600000 then
  454. return true
  455. end
  456. else
  457. local diamond_stop_day = SL:GetConfig("cfg_global", 14002).value
  458. if this.diamondPrivilegeStopTime then
  459. local diamond_stop_time = Time.GetServerTime() - this.diamondPrivilegeStopTime
  460. if diamond_stop_time < diamond_stop_day * 3600000 then
  461. return true
  462. end
  463. end
  464. end
  465. return false
  466. end
  467. function this.GetCurrentAttrPointPlan()
  468. if this.currentAttrType == 1 then
  469. return this.freeFirstSwitchInfo and this.freeFirstSwitchInfo.attr or nil
  470. else
  471. return this.freeSecondSwitchInfo and this.freeSecondSwitchInfo.attr or nil
  472. end
  473. end
  474. ---返回毫秒值
  475. function this.GetPrivilegeRemainTime(type)
  476. if type == 1 then
  477. if this.goldPrivilege then
  478. local totalTime = this.goldServerInfo.start_time + this.goldServerInfo.durationtime * 3600000
  479. local now = Time.GetServerTime()
  480. return totalTime - now
  481. else
  482. return 0
  483. end
  484. elseif type == 2 then
  485. if this.diamondPrivilege then
  486. local totalTime = this.diamondServerInfo.start_time + this.diamondServerInfo.durationtime * 3600000
  487. local now = Time.GetServerTime()
  488. return totalTime - now
  489. else
  490. return 0
  491. end
  492. end
  493. end
  494. function this.SendMessageSetFreeAttrInfo(id, attr, name)
  495. local info
  496. if not id then
  497. id = this.currentAttrType
  498. end
  499. if id == 1 then
  500. info = this.freeFirstSwitchInfo or {}
  501. else
  502. info = this.freeSecondSwitchInfo or {}
  503. end
  504. local message = {}
  505. message["id"] = id
  506. if attr then
  507. message["attr"] = attr
  508. else
  509. message["attr"] = info.attr or {}
  510. end
  511. if name then
  512. message["name"] = name
  513. else
  514. message["name"] = info.name
  515. end
  516. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_SET_ROLE_ATTR_POINT_PROGRAMME, message)
  517. end
  518. function this.ClearPrivilegeCardAllInfo()
  519. this.all_info = {}
  520. this.auto_buy_drug = 0
  521. end
  522. ---刷新特权的时候如果某个特权没了,要把勾选取消掉
  523. function this.UpdateData()
  524. if not this.isautoPick() then
  525. --自动拾取勾选修改
  526. SL:SetPlayerAutoPick(false)
  527. SL:SendPlayerAutoPickChange(false)
  528. end
  529. if not this.isautoRecovery() then
  530. --修改回收
  531. SL:SendPlayerAutoRecoverChange(false)
  532. end
  533. if this.isautoPick() then
  534. local strList = string.split(this.all_info.autopick,'#')
  535. local num = tonumber(strList[1])
  536. local speed = tonumber(strList[2])
  537. SL:StartFastPickUp(num,1,30*speed)
  538. end
  539. end
  540. -- function this.SendMU()
  541. -- SL:SendLuaNetMsg(LuaMessageIdToSever.RECRUIT_INFO_REQ, {id=10002})
  542. -- end
  543. ---是否拥有开启随身商店特权
  544. function this.iswithStore()
  545. --if this.all_info.withstore and this.all_info.withstore ~= "" and this.all_info.withstore ~= "0" then
  546. -- return true
  547. --end
  548. --return false
  549. --return this.goldPrivilege
  550. if not this.all_pricilege_id then
  551. return false
  552. end
  553. return table.contains(this.all_pricilege_id,2)
  554. end
  555. ---是否拥有开启随身仓库特权
  556. function this.iswithWarehouse()
  557. --if this.all_info.withwarehouse and this.all_info.withwarehouse ~= "" and this.all_info.withwarehouse ~= "0" then
  558. -- return true
  559. --end
  560. --return false
  561. --return this.diamondPrivilege
  562. if not this.all_pricilege_id then
  563. return false
  564. end
  565. return table.contains(this.all_pricilege_id,13)
  566. end
  567. ---是否拥有开启自动买药特权
  568. function this.isautoPotion()
  569. --if this.all_info.autopotion and this.all_info.autopotion ~= "" and this.all_info.autopotion ~= "0" then
  570. -- return true
  571. --end
  572. --return false
  573. --return this.goldPrivilege
  574. if not this.all_pricilege_id then
  575. return false
  576. end
  577. return table.contains(this.all_pricilege_id,6)
  578. end
  579. ---是否拥有开启自动回收特权
  580. function this.isautoRecovery()
  581. -- if this.all_info.autorecovery and this.all_info.autorecovery ~= "" and this.all_info.autorecovery ~= "0" then
  582. -- return true
  583. -- end
  584. -- return false
  585. if not this.all_pricilege_id then
  586. return false
  587. end
  588. return table.contains(this.all_pricilege_id,17)
  589. end
  590. ---是否拥有开启自动拾取
  591. function this.isautoPick()
  592. -- if this.all_info.autopick and this.all_info.autopick ~= "" and this.all_info.autopick ~= "0" then
  593. -- return true
  594. -- end
  595. -- return false
  596. if not this.all_pricilege_id then
  597. return false
  598. end
  599. return table.contains(this.all_pricilege_id,16)
  600. end
  601. ---是否拥有交易行寄售特权
  602. function this.isSalesAdd()
  603. if not this.all_pricilege_id then
  604. return false
  605. end
  606. return table.contains(this.all_pricilege_id,19)
  607. end
  608. ---是否拥有扫荡特权
  609. function this.isSaoDangOpen()
  610. if not this.all_pricilege_id then
  611. return false
  612. end
  613. return table.contains(this.all_pricilege_id,20)
  614. end
  615. function this.FreeSwitchAttrPoint()
  616. return this.goldPrivilege
  617. end
  618. ---获取激活特权需要展示的背包行数
  619. function this.GetBagCanShowRow(row)
  620. -- row = row or 0
  621. -- local lockRow = this.GetLockGridRowWithoutPrivilege()
  622. -- local increaseRow, gridNum = this.GetBagIncreaseRowCount()
  623. -- if gridNum == this.goldCfg.backpackUp + this.diamondCfg.backpackUp then
  624. -- return increaseRow, 0
  625. -- else
  626. -- ---获取背包道具最大占用格子数
  627. -- local maxItemRow = 0
  628. -- local bagItemList = SL:GetMetaValue("BAG_DATA")[1]
  629. -- for i, v in pairs(bagItemList) do
  630. -- local holdGrid = SL:GetConfig("cfg_item", v.cfgId).holdGrid
  631. -- local itemRow = holdGrid[2] + math.modf(i / 100) - 1
  632. -- if itemRow > maxItemRow then
  633. -- maxItemRow = itemRow
  634. -- end
  635. -- end
  636. -- if maxItemRow > increaseRow + row - lockRow then
  637. -- return maxItemRow - row + lockRow, maxItemRow - increaseRow - row + lockRow
  638. -- else
  639. -- return increaseRow, 0
  640. -- end
  641. -- end
  642. end
  643. function this.GetLockGridRowWithoutPrivilege()
  644. local lockGrid = SL:GetMetaValue("BAG_FORBID_COUNT")
  645. local privilegeGrid = this.GetBagSiftLockGridNum()
  646. local num = (lockGrid - privilegeGrid) / 8
  647. if num > 0 then
  648. ---有非特权格子未解锁
  649. return math.floor(num)
  650. end
  651. ---非特权格子全解锁
  652. return 0
  653. end
  654. ---返回未解锁特权需要隐藏的格子数
  655. function this.GetBagSiftLockGridNum()
  656. --local num = 0
  657. --if not this.goldPrivilege then
  658. -- num = num + this.goldCfg.backpackUp
  659. --end
  660. --if not this.diamondPrivilege then
  661. -- num = num + this.diamondCfg.backpackUp
  662. --end
  663. --return num
  664. return 0
  665. end
  666. ---返回未开启特权减少的背包行数
  667. function this.GetBagIncreaseRowCount()
  668. local bag_info = string.split(SL:GetConfig("cfg_global", 6).value, '#')
  669. local maxVet = tonumber(bag_info[2])
  670. local num = 0
  671. local girdNum = 0
  672. if this.goldPrivilege then
  673. num = num + this.goldCfg.backpackUp / maxVet
  674. girdNum = girdNum + this.goldCfg.backpackUp
  675. end
  676. if this.diamondPrivilege then
  677. num = num + this.diamondCfg.backpackUp / maxVet
  678. girdNum = girdNum + this.diamondCfg.backpackUp
  679. end
  680. return math.floor(num), girdNum
  681. end
  682. ---返回特权增加特权仓库页数
  683. function this.GetDepotUp()
  684. local num = 0
  685. if this.goldPrivilege then
  686. num = num + #this.goldCfg.DepotUp
  687. end
  688. if this.diamondPrivilege then
  689. num = num + #this.diamondCfg.DepotUp
  690. end
  691. return num
  692. end
  693. ---返回交易行增加数量
  694. function this.GetTradingShelvesUp()
  695. local num = 0
  696. if this.goldPrivilege then
  697. num = num + this.goldCfg.TradingGhelvesUp
  698. end
  699. if this.diamondPrivilege then
  700. num = num + this.diamondCfg.TradingGhelvesUp
  701. end
  702. return num
  703. end
  704. ---返回经验提升
  705. function this.GetExperienceUp()
  706. local num = 0
  707. if this.goldPrivilege then
  708. num = this.goldCfg.ExperienceUp
  709. end
  710. if this.diamondPrivilege then
  711. num = this.diamondCfg.ExperienceUp
  712. end
  713. return num
  714. end
  715. ---返回掉落提升
  716. function this.GetDropsUp()
  717. local num = 0
  718. if this.goldPrivilege then
  719. num = num + (this.goldCfg.DropsUp[2] / 100)
  720. end
  721. if this.diamondPrivilege then
  722. num = num + (this.diamondCfg.DropsUp[2] / 100)
  723. end
  724. return num
  725. end
  726. ---返回回收收益提升
  727. function this.GetReclaimUp()
  728. local num = 0
  729. if this.goldPrivilege then
  730. num = num + this.goldCfg.reclaimUp
  731. end
  732. if this.diamondPrivilege then
  733. num = num + this.diamondCfg.reclaimUp
  734. end
  735. return num
  736. end
  737. function this.GetFreeSwitchAttrPoint()
  738. --return this.goldPrivilege
  739. if not this.all_pricilege_id then
  740. return false
  741. end
  742. return table.contains(this.all_pricilege_id,7)
  743. end
  744. function this.CheckPriviegeBoss()
  745. if this.goldPrivilege then
  746. this.SendPriviegeBoss(1)
  747. end
  748. if this.diamondPrivilege then
  749. this.SendPriviegeBoss(2)
  750. end
  751. end
  752. ---通知特权boss
  753. ---@param value 活动类型 1—黄金特权卡 2—钻石特权卡 3—月卡 4-日卡
  754. function this.SendPriviegeBoss(value)
  755. SL:SendLuaNetMsg(LuaMessageIdToSever.PRIVILEGE_BOSS_COUNT_INIT,value)
  756. end
  757. function this.isAutoPatrolOnHook()
  758. --return this.diamondPrivilege
  759. if not this.all_pricilege_id then
  760. return false
  761. end
  762. return table.contains(this.all_pricilege_id,12)
  763. end
  764. ---@param state number @1.挂机中, 2.暂停挂机, 3.停止挂机
  765. function this.LUA_EVENT_ONHOOK_STATE_CHANGE(_, state)
  766. if this.onHookType == EOnHookType.Patrol then
  767. if state == EAutoOnHookStatus.OnHooking then
  768. this.patrolOnHookState = true
  769. elseif state == EAutoOnHookStatus.PauseOnHook then
  770. if this.startFindWay then
  771. this.patrolOnHookState = false
  772. this.startFindWay = false
  773. end
  774. if this.finishFindWay then
  775. this.finishFindWay = false
  776. this.patrolOnHookState = false
  777. end
  778. elseif state == EAutoOnHookStatus.StopOnHook then
  779. if this.startFindWay then
  780. this.patrolOnHookState = false
  781. this.startFindWay = false
  782. end
  783. if this.finishFindWay then
  784. this.finishFindWay = false
  785. this.patrolOnHookState = false
  786. end
  787. end
  788. end
  789. end
  790. ---道具是否捡完可以继续巡逻
  791. function this.LUA_EVENT_DROPITEM_OUT_OF_VIEW()
  792. if this.patrolOnHookState then
  793. local bagFull = false
  794. local data = SL:GetMetaValue(EMetaVarGetKey.GET_MONSTER_DROP_ITEM_LIST)
  795. for i, v in pairs(data) do
  796. if v.isMeCanPickUp then
  797. ---勾选自动拾取组才进行判断
  798. if this.pickupType and this.pickupType[v.tbl.pickgroup[1]] then
  799. if SL:CanPutToBag(v.tbl.id, 1) then
  800. return false
  801. else
  802. bagFull = true
  803. end
  804. end
  805. end
  806. end
  807. if bagFull then
  808. SL:TipMessage(SL:GetConfig('cfg_string',30001).text,1, NoticeType.NoticeMid)
  809. ---@type KLUISystemLeftPanel
  810. local ui = GUI:GetUI("dev/ui/MainUI/Panel/KLUISystemLeft/KLUISystemLeftPanel")
  811. if ui then
  812. ui:OnClickAutoHookIconContainerBtn_2()
  813. end
  814. else
  815. this:GetThisMapGoldBossAttack()
  816. end
  817. end
  818. end
  819. function this.ResMonsterStatusChangeMessage(_, message)
  820. if this.patrolOnHookState then
  821. if message.monsterId == this.attackGoldBossId and message.status == 0 then
  822. ---把掉落物刷新出来
  823. SL:ScheduleOnce(1, function()
  824. this.checkHaveDrop = true
  825. end)
  826. elseif this.readyFindMonster then
  827. if message.status == 1 and this.allGoldMonsterTbl[message.configId] then
  828. ---等待1秒让怪物数据后台更新
  829. SL:ScheduleOnce(1, function()
  830. this:GetThisMapGoldBossAttack()
  831. end)
  832. end
  833. end
  834. end
  835. end
  836. function this:RefreshPatrolHookState(state)
  837. if state then
  838. this:GetThisMapGoldBossList()
  839. end
  840. end
  841. ---缓存所有黄金boss
  842. function this:GetAllMapGoldBossList()
  843. this.allGoldMonsterTbl = {}
  844. ---@type cfg_monster_column[]
  845. local cfg_monster = SL:GetConfigTable("cfg_monster")
  846. for i, v in pairs(cfg_monster) do
  847. if v.type == 2 then
  848. this.allGoldMonsterTbl[v.id] = v
  849. end
  850. end
  851. end
  852. function this.IsCanOnHookCheck()
  853. if SL:GetMetaValue(EMetaVarGetKey.GET_IS_SAFEAREA) then
  854. --SL:TipMessage(EAutoFightErrorTip.SafeArea, 1, NoticeType.NoticeMid)
  855. return false
  856. else
  857. return true
  858. end
  859. end
  860. ---开始巡逻挂机
  861. function this.StartPatrolOnHook()
  862. this.patrolOnHookState = false
  863. ---是否安全区等检测
  864. if this.IsCanOnHookCheck() then
  865. this.patrolOnHookState = true
  866. this.stopPatrol = false
  867. end
  868. this.pickupType = SL:GetMetaValue(EMetaVarGetKey.GET_ATUO_PICKUP_ITEM)
  869. return this.patrolOnHookState
  870. end
  871. function this.StopPatrolOnHook()
  872. this.patrolOnHookState = false
  873. --中途退出寻路标签,回调不自动打怪
  874. this.stopPatrol = true
  875. SL:Me_StopMove(true, true)
  876. end
  877. ---获取当前地图存活黄金boss前往击杀
  878. function this:GetThisMapGoldBossAttack()
  879. if not this.patrolOnHookState then
  880. return
  881. end
  882. this.readyFindMonster = false
  883. if not this.allGoldMonsterTbl or not next(this.allGoldMonsterTbl) then
  884. self:GetAllMapGoldBossList()
  885. end
  886. ---获取所有怪
  887. local mapGoldMonsterTbl = {}
  888. local allMonster = SL:GetMetaValue(EMetaVarGetKey.MAP_GET_MONSTERS)
  889. for i, v in pairs(allMonster) do
  890. if this.allGoldMonsterTbl[v.configId] and v.status == 1 then
  891. mapGoldMonsterTbl[#mapGoldMonsterTbl + 1] = v
  892. end
  893. end
  894. ---没有黄金怪
  895. if #mapGoldMonsterTbl == 0 then
  896. SL:TipMessage( SL:GetConfig("cfg_string",443).text ,1, NoticeType.NoticeMid )
  897. ---地图没有黄金怪标识
  898. this.readyFindMonster = true
  899. return true
  900. end
  901. ---找直线距离最近的
  902. local playerPos = SL:GetMetaValue(EMetaVarGetKey.MAP_PLAYER_POS)
  903. local attackGoldBossDistance = 99999
  904. local monsterId = 0
  905. local x,y
  906. for i, v in ipairs(mapGoldMonsterTbl) do
  907. local distance = math.abs(playerPos.x - v.pointX) + math.abs(playerPos.z - v.pointY)
  908. if distance < attackGoldBossDistance then
  909. attackGoldBossDistance = distance
  910. monsterId = v.configId
  911. x = v.pointX
  912. y = v.pointY
  913. this.attackGoldBossId = v.monsterId
  914. end
  915. end
  916. ---生成快捷指令
  917. ---@type cfg_mapMove_column[]
  918. local cfg_mapMove = SL:GetConfigTable("cfg_mapMove")
  919. local mapMoveId
  920. for i, v in pairs(cfg_mapMove) do
  921. if v.mapID == SL:GetMetaValue(EMetaVarGetKey.MAP_ID) then
  922. mapMoveId = v.id
  923. break
  924. end
  925. end
  926. local param = {}
  927. param[1] = "moveTo"
  928. param[2] = mapMoveId
  929. param[3] = x
  930. param[4] = y
  931. ---是否到达寻路终点,用于是否处于巡逻挂机判断
  932. this.finishFindWay = false
  933. local moveToArriveCallBack = function()
  934. if not this.stopPatrol then
  935. --AutoFightManager.StartAutoFight(false, true, monsterId)
  936. if not SL:GetMetaValue(EMetaVarGetKey.GET_IS_SAFEAREA) then
  937. SL:StartOnHook(false, true, monsterId)
  938. end
  939. end
  940. this.stopPatrol = false
  941. this.startFindWay = false
  942. this.finishFindWay = true
  943. end
  944. this.startFindWay = false
  945. SL:ShortcutDO(param,nil,nil,moveToArriveCallBack)
  946. ---是否开始寻路,用于是否处于巡逻挂机判断
  947. this.startFindWay = true
  948. end
  949. return this