PrivilegeMonth.lua 23 KB

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