PrivilegeMonth_1.lua 24 KB

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