PrivilegeMonth.lua 23 KB

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