PrivilegeMonth.lua 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. ---@class PrivilegeMonthData
  2. ---@field PrivilegeTypeData table<number,PrivilegeTypeData>
  3. ---@class PrivilegeTypeData
  4. ---@field id number
  5. ---@field start_time number
  6. ---@field durationtime number 持续时长 单位小时
  7. PrivilegeMonth = {}
  8. local this = {}
  9. this.PRIVILEGE_DATA_KEY = "T$_PLAYER_MONTH_PRIVILEGE_DATA_KEY"
  10. this.PRIVILEGE_DATA_KEY_GLOBAL = "R$_PLAYER_MONTH_PRIVILEGE_DATA_KEY_GLOBAL_"
  11. this.PRIVILEGE_OVER_TIME_DATA_KEY = "T$_PLAYER_MONTH_PRIVILEGE_OVER_TIME_DATA_KEY"
  12. this.change_type = {
  13. bag = 1,
  14. warehouse = 2
  15. }
  16. PrivilegeCardType = {
  17. MONTH_CARD = 1,
  18. PRIVILEGE_CARD = 2
  19. }
  20. PrivilegeMonth.PrivilegeType = {
  21. WILD_LINE = "1", -- 野外线路
  22. QUICK_SHOP = "2", -- 随身商店
  23. MONSTER_HOOK_PROTECTION = "3", -- 小怪挂机保护
  24. BACKPACK_SPACE_INCREASE = "4", -- 背包空间增加
  25. WAREHOUSE_INCREASE = "5", -- 特权仓库增加
  26. AUTO_BUY_MEDICINE = "6", -- 自动买药
  27. SWITCHING_POINT_SCHEME = "7", -- 切换加点方案
  28. MASTER_TALENT_FREE_SWITCHING = "8", -- 大师天赋免费切换
  29. FALLING_RATE_UP = "9", -- 掉落提升
  30. EXP_ADD_RATE = "10", -- 经验提升
  31. RECYCLING_INCOME_UP = "11", -- 回收收益提升
  32. PATROL_AFK = "12", -- 巡逻挂机
  33. REMOTE_WAREHOUSE = "13", -- 远程仓库
  34. TRADE_LINE_UP_COUNT_INCREASE = "14", -- 交易行寄售货架数量增加
  35. AUTO_PICKUP = "15", -- 自动拾取
  36. AUTO_RECOVERY = "16", -- 自动回收
  37. COMBO_NUM = "17", -- 连击试炼每日次数增加
  38. TRADE_SALE = "18", -- 交易行寄售功能开启
  39. COMBO_SWEEP_IS_OPEN = "19", -- 连击副本扫荡功能开启
  40. TAX_RATE = "21", -- 调整税率
  41. STALL = "22", -- 摆摊
  42. AUTO_FIX = "23", -- 自动修理
  43. GIVE_UP = "24", -- 丢弃
  44. MAP_LINE_VIP = "25", -- 畅玩线
  45. ANCIENT_BATTLE = "26", -- 古战场2进入权限
  46. RED_FORT = "27", -- 赤色要塞活动权限
  47. KALIMA = "28", -- 卡利玛神庙活动权限
  48. }
  49. PrivilegeMonth.PrivilegeConfigMapping = {
  50. [PrivilegeMonth.PrivilegeType.EXP_ADD_RATE] = "experienceup",
  51. [PrivilegeMonth.PrivilegeType.FALLING_RATE_UP] = "dropsup",
  52. -- [PrivilegeMonth.PrivilegeType.BACKPACK_SPACE_INCREASE] = "backpackup",
  53. -- [PrivilegeMonth.PrivilegeType.WAREHOUSE_INCREASE] = "depotup",
  54. [PrivilegeMonth.PrivilegeType.RECYCLING_INCOME_UP] = "reclaimup",
  55. [PrivilegeMonth.PrivilegeType.TRADE_LINE_UP_COUNT_INCREASE] = "tradingghelvesup",
  56. [PrivilegeMonth.PrivilegeType.COMBO_NUM] = "combonum",
  57. [PrivilegeMonth.PrivilegeType.TAX_RATE] = "tax"
  58. }
  59. function PrivilegeMonth.jump(actor)
  60. -- RoleAttr.getPrivilegeAttrPointProgramme(actor)
  61. end
  62. function PrivilegeMonth.monthCardExchangePrivilege(actor, p_type)
  63. -- 暂不启用批量购买, count为1
  64. this.monthCardExchangePrivilege(actor, p_type, 1)
  65. end
  66. ---是否开启了特权
  67. ---@param privilegeType number 特权类型,PrivilegeMonth.PrivilegeType
  68. ---@return boolean, number true:已开启特权; false:未开启特权, 特权对应数值
  69. function PrivilegeMonth.hasPrivilegeType(actor, p_type)
  70. return this.hasPrivilegeType(actor, p_type)
  71. end
  72. function PrivilegeMonth.hasAnyPrivilege(actor)
  73. return this.hasAnyPrivilege(actor)
  74. end
  75. ---是否开启了特权
  76. ---@param privilegeType number 特权类型,PrivilegeMonth.PrivilegeType
  77. ---@return boolean, number true:已开启特权; false:未开启特权, 特权对应数值
  78. function PrivilegeMonth.hasPrivilege(actor, privilegeType)
  79. return this.hasPrivilege(actor, privilegeType)
  80. end
  81. function PrivilegeMonth.login(actor)
  82. this.loginCheckPrivilegeMonth(actor)
  83. this.sendPrivilegeBubbleData(actor)
  84. local is_open, rate = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.EXP_ADD_RATE)
  85. if is_open then
  86. ExpBonus.changeBonus(actor, BonusType.PRIVILEGE_EXP_BONUS, rate, 0, 0)
  87. else
  88. ExpBonus.changeBonus(actor, BonusType.PRIVILEGE_EXP_BONUS, 0, 0, 0)
  89. end
  90. end
  91. function PrivilegeMonth.sendHasPrivilege(actor, p_type)
  92. local ret = this.hasPrivilegeType(actor, p_type)
  93. sendluamsg(actor, LuaMessageIdToClient.RES_CHECK_MONTH_PRIVILEGE_IS_OPEN, ret)
  94. end
  95. function PrivilegeMonth.sendPrivilegeData(actor)
  96. local data = this.getPrivilegeData(actor)
  97. this.debug("send_privilege_data", data)
  98. sendluamsg(actor, LuaMessageIdToClient.RES_GET_MONTH_PRIVILEGE_DATA, data)
  99. end
  100. -- -------------------------------------------------------------------------- --
  101. ---@return PrivilegeMonthData
  102. function this.getPrivilegeData(actor)
  103. return getplaydef(actor, this.PRIVILEGE_DATA_KEY)
  104. end
  105. function this.setPrivilegeData(actor, data)
  106. setplaydef(actor, this.PRIVILEGE_DATA_KEY, data)
  107. end
  108. ---@return PrivilegeMonthData
  109. function this.getPrivilegeGlobalData(actor)
  110. local uid = getbaseinfo(actor, "uid")
  111. return getsysvar(this.PRIVILEGE_DATA_KEY_GLOBAL..uid)
  112. end
  113. function this.setPrivilegeGlobalData(actor, data)
  114. local uid = getbaseinfo(actor, "uid")
  115. setsysvar(this.PRIVILEGE_DATA_KEY_GLOBAL..uid, data)
  116. end
  117. function this.hasPrivilegeType(actor, p_type)
  118. local data = this.getPrivilegeData(actor)
  119. if table.isEmpty(data) then
  120. return false
  121. end
  122. ---@type PrivilegeTypeData
  123. local type_data = data[p_type]
  124. if table.isEmpty(type_data) then
  125. return false
  126. end
  127. if type_data.start_time < 1 then
  128. return false
  129. end
  130. if type_data.durationtime == -1 then
  131. return true
  132. else
  133. local now = getbaseinfo("now")
  134. local end_mills = type_data.start_time + type_data.durationtime * 60 * 60 * 1000
  135. return end_mills > tonumber(now)
  136. end
  137. end
  138. function this.hasAnyPrivilege(actor)
  139. local data = this.getPrivilegeData(actor)
  140. if table.isEmpty(data) then
  141. return false
  142. end
  143. for p_type, _ in pairs(data) do
  144. local tableValue = ConfigDataManager.getTable("cfg_privilege", "id", p_type)
  145. return not table.isNullOrEmpty(tableValue)
  146. end
  147. return false
  148. end
  149. function this.hasPrivilege(actor, privilegeType)
  150. local privilegeData = this.getPrivilegeData(actor)
  151. if table.isEmpty(privilegeData) then
  152. return false, 0
  153. end
  154. local total = 0
  155. local isFound = false
  156. for id, _ in pairs(privilegeData) do
  157. local privilegeListStr = ConfigDataManager.getTableValue("cfg_privilege", "privilegellist1", "id", id)
  158. local privilegeList = string.split(privilegeListStr, "#")
  159. if not table.isEmpty(privilegeList) and table.contains(privilegeList, privilegeType) then
  160. isFound = true
  161. local countKey = PrivilegeMonth.PrivilegeConfigMapping[privilegeType] or ""
  162. local countValueStr = ConfigDataManager.getTableValue("cfg_privilege", countKey, "id", id)
  163. local countValue = 0
  164. if string.contains(countValueStr, "#") then
  165. countValue = tonumber(string.split(countValueStr, "#")[2])
  166. else
  167. countValue = tonumber(countValueStr)
  168. end
  169. if countValue then
  170. if privilegeType == PrivilegeMonth.PrivilegeType.EXP_ADD_RATE then
  171. total = total > countValue and total or countValue
  172. elseif privilegeType == PrivilegeMonth.PrivilegeType.TAX_RATE then
  173. total = total == 0 and countValue or math.min(total, countValue)
  174. else
  175. total = total + countValue
  176. end
  177. end
  178. end
  179. end
  180. return isFound, total
  181. end
  182. function this.monthCardExchangePrivilege(actor, p_type, count)
  183. this.debug("兑换月卡特权类型:", p_type)
  184. local config_arr = ConfigDataManager.getTable("cfg_privilege", "id", p_type)
  185. if table.isEmpty(config_arr) then
  186. this.debug("未获取到配置信息", "p_type:", p_type)
  187. return
  188. end
  189. local config = config_arr[1]
  190. this.debug("config:", config)
  191. count = math.min(count, tonumber(config.maxcount))
  192. local cost_price = tonumber(config.price) * count
  193. -- 扣除月卡天数
  194. local is_suc = MonthCard.deletemonthcardtime(actor, cost_price)
  195. if not is_suc then
  196. this.debug("扣除月卡天数失败!无法继续开通特权")
  197. return
  198. end
  199. -- this.jprint("开始兑换月卡特权")
  200. local is_activation
  201. -- 获取特权数据
  202. local data = this.getPrivilegeData(actor)
  203. if table.isEmpty(data) then
  204. data = {}
  205. is_activation = true
  206. elseif this.hasPrivilegeType(actor, p_type) then
  207. is_activation = false
  208. end
  209. ---@type PrivilegeTypeData
  210. local type_data = data[p_type]
  211. if table.isEmpty(type_data) then
  212. type_data = {}
  213. type_data.id = p_type
  214. type_data.start_time = 0
  215. type_data.durationtime = 0
  216. is_activation = true
  217. else
  218. is_activation = false
  219. end
  220. local now = tonumber(getbaseinfo("now"))
  221. if type_data.start_time == 0 then
  222. type_data.start_time = now
  223. end
  224. local durationtime = tonumber(config.time) * 24 * count
  225. type_data.durationtime = type_data.durationtime + durationtime
  226. data[p_type] = type_data
  227. this.setPrivilegeData(actor, data)
  228. this.debug("激活成功, 特权数据:", data)
  229. PrivilegeMonth.sendPrivilegeData(actor)
  230. -- 定时清理玩家特权
  231. local delay_mills = type_data.durationtime * 60 * 60 * 1000
  232. this.delayClosePrivilege(actor, delay_mills, p_type)
  233. -- 开启特权功能
  234. if is_activation then
  235. this.monthPrivilegeActivation(actor, p_type)
  236. end
  237. end
  238. function this.delayClosePrivilege(actor, delay_mills, p_type)
  239. -- this.jprint("---- " .. tostring(delay_mills / 1000) .. "秒后清理玩家特权 ----")
  240. intervalcalldelay(actor, delay_mills, 1000, 1, "timeoutmonthprivilegeclear", p_type)
  241. end
  242. function timeoutmonthprivilegeclear(actor, p_type)
  243. this.debug("---- 开始清理特权 ----", "p_type:", p_type)
  244. local rid = actor:toString()
  245. -- this.jprint("rid: " .. tostring(rid))
  246. local is_has = this.hasPrivilegeType(actor, p_type)
  247. if is_has then
  248. -- this.jprint("玩家特权未到期,不处理清理逻辑")
  249. return
  250. end
  251. local data = this.getPrivilegeData(actor)
  252. data[p_type] = nil
  253. this.setPrivilegeData(actor, data)
  254. this.setPrivilegeBubbleTime(actor, p_type, getbaseinfo("now"))
  255. this.monthPrivilegeClose(actor, p_type)
  256. -- 移除加成
  257. local is_open, rate = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.EXP_ADD_RATE)
  258. if not is_open then
  259. RoleAttr.clearRoleAttrAndDB(actor, RoleAttrKey.PRIVILEGE_EXP_BOOST)
  260. ExpBonus.changeBonus(actor, BonusType.PRIVILEGE_EXP_BONUS, 0, 0, 0)
  261. else
  262. -- 加成信息变化修改
  263. if data then
  264. if is_open then
  265. RoleAttr.clearRoleAttrAndDB(actor, RoleAttrKey.PRIVILEGE_EXP_BOOST)
  266. RoleAttr.addAndSaveRoleAttr(actor, RoleAttrKey.PRIVILEGE_EXP_BOOST, {
  267. [this.getExpBoostAttrId(p_type)] = rate
  268. })
  269. ExpBonus.changeBonus(actor, BonusType.PRIVILEGE_EXP_BONUS, rate, 0, 0)
  270. end
  271. end
  272. end
  273. this.debug("---- 清理特权完成 ----")
  274. sendluamsg(actor, LuaMessageIdToClient.RES_MONTH_PRIVILEGE_TIME_OUT, p_type)
  275. end
  276. function this.loginCheckPrivilegeMonth(actor)
  277. this.checkPrivilegeGlobalData(actor)
  278. -- 登录时检查特权是否过期 未则开启定时任务
  279. local data = this.getPrivilegeData(actor)
  280. if table.isEmpty(data) then
  281. return
  282. end
  283. for k, v in pairs(data) do
  284. if v.start_time < 1 then
  285. goto continue
  286. end
  287. local now = getbaseinfo("now")
  288. local end_mills = v.start_time + v.durationtime * 60 * 60 * 1000
  289. local delay_mills = end_mills - tonumber(now)
  290. this.debug("玩家特权结束时间: ", end_mills, "now:", now, "delay_mills:", delay_mills)
  291. delay_mills = math.max(delay_mills, 1000)
  292. this.delayClosePrivilege(actor, delay_mills, k)
  293. ::continue::
  294. end
  295. end
  296. -- 登录时检查全局特权,如果该角色没有,就将该特权赋予该角色
  297. function this.checkPrivilegeGlobalData(actor)
  298. local data = this.getPrivilegeData(actor)
  299. local data_global = this.getPrivilegeGlobalData(actor)
  300. if data_global == nil then
  301. return
  302. end
  303. local hasChange = false
  304. local hasGlobalChange = false
  305. for k, type_data in pairs(data_global) do
  306. if this.hasPrivilegeType(actor, k) then
  307. goto continue
  308. end
  309. if type_data.start_time < 1 then
  310. hasGlobalChange = true
  311. data_global[k] = nil
  312. goto continue
  313. end
  314. if type_data.durationtime > 0 then
  315. local now = getbaseinfo("now")
  316. local end_mills = type_data.start_time + type_data.durationtime * 60 * 60 * 1000
  317. if end_mills <= tonumber(now) then
  318. hasGlobalChange = true
  319. data_global[k] = nil
  320. goto continue
  321. end
  322. end
  323. if data == nil then
  324. data = {}
  325. end
  326. data[k] = type_data
  327. this.setPrivilegeData(actor, data)
  328. hasChange = true
  329. ::continue::
  330. end
  331. if hasChange then
  332. PrivilegeMonth.sendPrivilegeData(actor)
  333. end
  334. if hasGlobalChange then
  335. this.setPrivilegeGlobalData(actor, data_global)
  336. end
  337. end
  338. function this.monthPrivilegeActivation(actor, p_type)
  339. this.addFallRate(actor, p_type)
  340. this.changeCapacity(actor, this.change_type.bag, true, p_type)
  341. this.changeCapacity(actor, this.change_type.warehouse, true, p_type)
  342. this.changeComboCount(actor, true, p_type)
  343. end
  344. function this.monthPrivilegeClose(actor, p_type)
  345. local is_has = PrivilegeMonth.hasPrivilegeType(actor, p_type)
  346. if not is_has then
  347. this.closeAutoBuyMedicine(actor)
  348. this.clearFallRate(actor, p_type)
  349. this.changeCapacity(actor, this.change_type.bag, false, p_type)
  350. this.changeCapacity(actor, this.change_type.warehouse, false, p_type)
  351. this.changeComboCount(actor, false, p_type)
  352. end
  353. end
  354. function this.closeAutoBuyMedicine(actor)
  355. local autoBuyPotion = getplaydef(actor, "T$autoBuyPotion") or {}
  356. local isOn = autoBuyPotion["on"] or 0
  357. if isOn == 0 then
  358. return
  359. end
  360. AutoBuyPotionScript.openOrCloseAutoBuyPotion(actor)
  361. end
  362. function this.addFallRate(actor, p_type)
  363. local attr_str = ConfigDataManager.getTableValue("cfg_privilege", "dropsup", "id", p_type)
  364. if attr_str and attr_str ~= "" then
  365. local drop_tbl = string.split(attr_str, "#")
  366. this.debug("drop_tbl:", drop_tbl, "attr_str", attr_str)
  367. local attr_map = {}
  368. attr_map[tonumber(drop_tbl[1])] = tonumber(drop_tbl[2])
  369. RoleAttr.addAndSaveRoleAttr(actor, RoleAttrKey.PRIVILEGE_MONTH_DROP_RATE, attr_map)
  370. end
  371. end
  372. function this.clearFallRate(actor, p_type)
  373. local attr_str = ConfigDataManager.getTableValue("cfg_privilege", "dropsup", "id", p_type)
  374. if attr_str and attr_str ~= "" then
  375. local drop_tbl = string.split(attr_str, "#")
  376. this.debug("drop_tbl:", drop_tbl, "attr_str", attr_str)
  377. local attr_map = {}
  378. attr_map[tonumber(drop_tbl[1])] = tonumber(drop_tbl[2])
  379. RoleAttr.reduceAndSaveRoleAttr(actor, RoleAttrKey.PRIVILEGE_MONTH_DROP_RATE, attr_map)
  380. end
  381. end
  382. function this.changeCapacity(actor, capacity_type, is_add, p_type)
  383. local is_open, _ = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.BACKPACK_SPACE_INCREASE)
  384. if not is_open and is_add then
  385. this.debug("特权未开启,无法扩容")
  386. return
  387. end
  388. -- 定义内置函数, 执行全局函数
  389. local function handleCapacityChange(action, pages, grids)
  390. if pages then
  391. for _, page in pairs(pages) do
  392. action(actor, page)
  393. end
  394. else
  395. action(actor, grids)
  396. end
  397. end
  398. local action, pages, grids
  399. if capacity_type == this.change_type.bag then
  400. grids = ConfigDataManager.getTableValue("cfg_privilege", "backpackup", "id", p_type)
  401. this.debug("----grids-----", grids, p_type)
  402. action = is_add and unlockbaggridcount or lockbaggridcount
  403. elseif capacity_type == this.change_type.warehouse then
  404. local config = ConfigDataManager.getById("cfg_privilege", p_type)
  405. if table.isEmpty(config) then
  406. return
  407. end
  408. pages = string.split(config.depotup, "#")
  409. action = is_add and unlockstoregridcount or lockstoregridcount
  410. end
  411. if grids and grids ~= "" then
  412. handleCapacityChange(action, pages, grids)
  413. end
  414. end
  415. --- 改变连击副本次数
  416. --- @param actor table 玩家对象
  417. --- @param isAdd boolean 是否增加
  418. --- @param p_type number 特权类型
  419. function this.changeComboCount(actor, isAdd, p_type)
  420. local comboNum = ConfigDataManager.getTableValue("cfg_privilege", "comboNum", "id", p_type)
  421. if comboNum and comboNum ~= "" then
  422. if isAdd then
  423. addleftcountofactivity(actor, DuplicateType.COMBO_TEST, comboNum)
  424. ComboTest.setComboTestAddCount(actor)
  425. else
  426. local comboCount = getleftcountofactivity(actor, DuplicateType.COMBO_TEST)
  427. if comboCount and comboCount > 0 then
  428. comboNum = comboCount - comboNum > 0 and comboCount - comboNum or comboCount
  429. reduceactivitytimes(actor, DuplicateType.COMBO_TEST, comboNum)
  430. ComboTest.setComboTestAddCount(actor)
  431. end
  432. end
  433. end
  434. end
  435. ---- 特权过期气泡
  436. function this.sendPrivilegeBubbleData(actor)
  437. local data = this.getPrivilegeBubbleData(actor)
  438. if table.isEmpty(data) then
  439. return
  440. end
  441. sendluamsg(actor, LuaMessageIdToClient.RES_PRIVILEGE_MONTH_BUBBLE_DATA, data)
  442. end
  443. function this.getPrivilegeBubbleData(actor)
  444. return getplaydef(actor, this.PRIVILEGE_OVER_TIME_DATA_KEY)
  445. end
  446. function this.setPrivilegeBubbleTime(actor, p_type, time)
  447. local data = this.getPrivilegeBubbleData(actor)
  448. if table.isEmpty(data) then
  449. data = {}
  450. end
  451. data[p_type] = time
  452. setplaydef(actor, this.PRIVILEGE_OVER_TIME_DATA_KEY, data)
  453. end
  454. ---------------------------- 日志打印 -----------------------------
  455. this.log_open = false
  456. function this.debug(...)
  457. if not this.log_open then
  458. return
  459. end
  460. gameDebug.print(...)
  461. end
  462. function this.jprint(param)
  463. if not this.log_open then
  464. return
  465. end
  466. if param == nil then
  467. param = "error! 输出内容为空. nil"
  468. end
  469. jprint(param)
  470. end
  471. function this.loginfo(actor, param)
  472. if not this.log_open then
  473. return
  474. end
  475. if param == nil then
  476. param = "error! 日志输出内容为空. nil"
  477. end
  478. jprint(param)
  479. info(actor, param)
  480. end
  481. this.gm_open = true
  482. function l_privilege_month_add_bag_count(actor, p_type)
  483. if not this.gm_open then
  484. return
  485. end
  486. this.changeCapacity(actor, this.change_type.bag, true, p_type)
  487. end
  488. function l_privilege_month_close_bag_count(actor, p_type)
  489. if not this.gm_open then
  490. return
  491. end
  492. this.changeCapacity(actor, this.change_type.bag, false, p_type)
  493. end
  494. function this.checkIsNew(data, mintType)
  495. local tableValuesByMinType = ConfigDataManager.getTable("cfg_privilege", "mintype", mintType)
  496. for _, v in pairs(tableValuesByMinType) do
  497. local id = tonumber(v["id"])
  498. if data[id] then
  499. return true
  500. end
  501. end
  502. return false
  503. end
  504. --- 使用特权卡
  505. ---@param actor table 角色对象
  506. ---@param itemConfigId number 道具配置ID
  507. ---@param count number 使用数量
  508. function PrivilegeMonth.usePrivilegeCard(actor, itemConfigId, count)
  509. local tableValues = ConfigDataManager.getTable("cfg_privilege", "type", PrivilegeCardType.PRIVILEGE_CARD)
  510. local p_type = 0
  511. local p_minType = 0;
  512. local config = {}
  513. for _, v in pairs(tableValues) do
  514. if tonumber(v.item) == tonumber(itemConfigId) then
  515. p_type = tonumber(v.id)
  516. p_minType = tonumber(v.mintype)
  517. config = v
  518. break
  519. end
  520. end
  521. if p_type <= 0 then
  522. return
  523. end
  524. local is_activation = false
  525. -- 获取特权数据
  526. local data = this.getPrivilegeData(actor)
  527. if table.isEmpty(data) then
  528. data = {}
  529. is_activation = true
  530. elseif this.hasPrivilegeType(actor, p_type) then
  531. is_activation = false
  532. end
  533. local is_new = false
  534. local tmp_p_type = p_type
  535. -- 判断之前是否有使用同类型的特权卡
  536. -- if tmp_p_type == PrivilegeCardId.SILVER1 or tmp_p_type == PrivilegeCardId.SILVER2 or p_type == PrivilegeCardId.SILVER3 or p_type == PrivilegeCardId.SILVER4 then
  537. -- is_new = data[PrivilegeCardId.SILVER1] or data[PrivilegeCardId.SILVER2] or data[PrivilegeCardId.SILVER3] or data[PrivilegeCardId.SILVER4]
  538. -- tmp_p_type = PrivilegeCardId.SILVER1
  539. -- end
  540. --
  541. -- if tmp_p_type == PrivilegeCardId.GOLD1 or tmp_p_type == PrivilegeCardId.GOLD2 then
  542. -- is_new = data[PrivilegeCardId.GOLD1] or data[PrivilegeCardId.GOLD2]
  543. -- tmp_p_type = PrivilegeCardId.GOLD1
  544. -- end
  545. --
  546. -- if tmp_p_type == PrivilegeCardId.DIAMOND1 or tmp_p_type == PrivilegeCardId.DIAMOND2 then
  547. -- is_new = data[PrivilegeCardId.DIAMOND1] or data[PrivilegeCardId.DIAMOND2]
  548. -- tmp_p_type = PrivilegeCardId.DIAMOND1
  549. -- end
  550. if p_minType == PrivilegeCardMinType.SILVER then
  551. tmp_p_type = PrivilegeCardId.SILVER1
  552. elseif p_minType == PrivilegeCardMinType.GOLD then
  553. tmp_p_type = PrivilegeCardId.GOLD1
  554. elseif p_minType == PrivilegeCardMinType.DIAMOND then
  555. tmp_p_type = PrivilegeCardId.DIAMOND1
  556. elseif p_minType == PrivilegeCardMinType.ENJOY then
  557. tmp_p_type = PrivilegeCardId.ENJOY1
  558. elseif p_minType == PrivilegeCardMinType.RECOVERY then
  559. local id = ConfigDataManager.getTableValue("cfg_privilege", "id", "mintype", p_minType)
  560. if string.isNullOrEmpty(id) then
  561. error("该类型特权卡暂时未实现", tmp_p_type, p_minType)
  562. return
  563. end
  564. tmp_p_type = tonumber(id)
  565. else
  566. local id = ConfigDataManager.getTableValue("cfg_privilege", "id", "mintype", p_minType)
  567. if string.isNullOrEmpty(id) then
  568. error("该类型特权卡暂时未实现", tmp_p_type, p_minType)
  569. return
  570. end
  571. tmp_p_type = tonumber(id)
  572. end
  573. is_new = this.checkIsNew(data, p_minType)
  574. -- jprint("特权卡信息", tmp_p_type, p_minType, is_new)
  575. ---@type PrivilegeTypeData
  576. local type_data = data[tmp_p_type]
  577. if table.isEmpty(type_data) then
  578. type_data = {}
  579. type_data.id = tmp_p_type
  580. type_data.start_time = 0
  581. type_data.durationtime = 0
  582. is_activation = true
  583. else
  584. is_activation = false
  585. end
  586. local now = tonumber(getbaseinfo("now"))
  587. if type_data.start_time == 0 then
  588. type_data.start_time = now
  589. end
  590. local configTime = config.time
  591. if not string.isNullOrEmpty(configTime) then
  592. configTime = configTime / 60 / 24
  593. local durationtime = configTime * 24 * count
  594. type_data.durationtime = type_data.durationtime + durationtime
  595. -- 定时清理玩家特权
  596. local delay_mills = type_data.durationtime * 60 * 60 * 1000
  597. this.delayClosePrivilege(actor, delay_mills, tmp_p_type)
  598. else
  599. type_data.durationtime = -1
  600. end
  601. data[tmp_p_type] = type_data
  602. this.setPrivilegeData(actor, data)
  603. this.debug("激活成功, 特权数据:", data)
  604. PrivilegeMonth.sendPrivilegeData(actor)
  605. -- 账号通用数据记录
  606. if config.accountaccess ~= nil and tonumber(config.accountaccess) > 0 then
  607. this.setPrivilegeGlobalData(actor, data)
  608. end
  609. -- 开启特权功能
  610. if is_activation then
  611. this.monthPrivilegeActivation(actor, tmp_p_type)
  612. -- 如果之前没有使用此特权卡则增加特权BOSS挑战次数
  613. -- local type
  614. -- if tmp_p_type == PrivilegeCardId.SILVER1 then
  615. -- type = PrivilegeBossCountType.SILVER_CARD
  616. -- elseif tmp_p_type == PrivilegeCardId.GOLD1 then
  617. -- type = PrivilegeBossCountType.GOLD_CARD
  618. -- elseif tmp_p_type == PrivilegeCardId.DIAMOND1 then
  619. -- type = PrivilegeBossCountType.DIAMOND_CARD
  620. -- elseif tmp_p_type == PrivilegeCardId.ENJOY1 then
  621. -- type = PrivilegeBossCountType.ENJOY_CARD
  622. -- end
  623. -- if type then
  624. -- PrivilegeBoss.addCount(targetActor, type)
  625. -- end
  626. -- 白银特权任务
  627. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.ACTIVATE_SILVER_PRIVILEGE)
  628. end
  629. if not is_new then
  630. sendluamsg(actor, LuaMessageIdToClient.RES_PRIVILEGE_CARD_ACTIVATION, tmp_p_type)
  631. -- 发送经验加成信息
  632. local is_open, rate = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.EXP_ADD_RATE)
  633. if is_open then
  634. local attrId = this.getExpBoostAttrId(tmp_p_type)
  635. local attrMap = {
  636. [attrId] = rate
  637. }
  638. RoleAttr.clearRoleAttrAndDB(actor, RoleAttrKey.PRIVILEGE_EXP_BOOST)
  639. RoleAttr.addAndSaveRoleAttr(actor, RoleAttrKey.PRIVILEGE_EXP_BOOST, attrMap)
  640. ExpBonus.changeBonus(actor, BonusType.PRIVILEGE_EXP_BONUS, rate, 0, 0)
  641. end
  642. end
  643. Platform.monthPrivilegeActivation(actor, p_type)
  644. end
  645. ---是否激活白银特权
  646. function PrivilegeMonth.hasSilverPrivilege(actor)
  647. if PrivilegeMonth.hasPrivilegeType(actor, PrivilegeCardId.SILVER1) or
  648. PrivilegeMonth.hasPrivilegeType(actor, PrivilegeCardId.SILVER2) or
  649. PrivilegeMonth.hasPrivilegeType(actor, PrivilegeCardId.SILVER3) or
  650. PrivilegeMonth.hasPrivilegeType(actor, PrivilegeCardId.SILVER4) then
  651. return true;
  652. end
  653. return false;
  654. end
  655. ---是否激活畅玩特权
  656. function PrivilegeMonth.hasEnjoyPrivilege(actor)
  657. if PrivilegeMonth.hasPrivilegeType(actor, PrivilegeCardId.ENJOY1) or
  658. PrivilegeMonth.hasPrivilegeType(actor, PrivilegeCardId.ENJOY2) then
  659. return true;
  660. end
  661. return false;
  662. end
  663. function this.getExpBoostAttrId(p_type)
  664. local countKey = PrivilegeMonth.PrivilegeConfigMapping[PrivilegeMonth.PrivilegeType.EXP_ADD_RATE]
  665. local countValueStr = ConfigDataManager.getTableValue("cfg_privilege", countKey, "id", p_type)
  666. local split = string.split(countValueStr, "#")
  667. -- return tonumber(split[1])
  668. return 325012
  669. end