BubblePoint.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. local this = {}
  2. --玩家秒钟心跳
  3. function SecondHeartBP(actor)
  4. OnlineBP(actor)
  5. end
  6. --在线泡点
  7. function OnlineBP(actor)
  8. local nowMillis = getbaseinfo(actor, "now")
  9. if CheckExpConditionBP(actor) == false then
  10. return
  11. end
  12. local lastBPMillis = getplaydef(actor, "@lastBPMillis")
  13. lastBPMillis = tonumber(lastBPMillis)
  14. if lastBPMillis == nil or lastBPMillis <= 0 then
  15. setplaydef(actor, "@lastBPMillis", nowMillis)
  16. return
  17. end
  18. --间隔时间
  19. local level = getbaseinfo(actor, "level")
  20. local expInterval = ConfigDataManager.getTableValue("cfg_bubble_point", "expInterval", "id", level)
  21. if expInterval == nil or expInterval == "" then
  22. -- error("找不到cfg_bubble_point配置,id:"..level)
  23. return
  24. end
  25. expInterval = tonumber(expInterval) * 1000
  26. local subSec = nowMillis - lastBPMillis
  27. if subSec < expInterval then
  28. return
  29. end
  30. --满足条件,1.发放经验,2.发包给客户端,3.设置上次时间为当前时间
  31. setplaydef(actor, "@lastBPMillis", nowMillis)
  32. local expConfig = ConfigDataManager.getTableValue("cfg_bubble_point", "exp", "id", level)
  33. local itemMap = string.toIntIntMap(expConfig, "#", "|")
  34. -- 泡点经验加成
  35. -- itemMap = this.rateAddExpValue(actor, itemMap)
  36. if table.isEmpty(itemMap) then
  37. return
  38. end
  39. additemmaptobag(actor, itemMap, 0, 1)
  40. end
  41. function this.rateAddExpValue(actor, itemMap)
  42. if table.isEmpty(itemMap) then
  43. return
  44. end
  45. -- 过滤掉值小于1的配置
  46. local exp_map = {}
  47. -- 特权/VIP加成 已改为走属性加成
  48. local rate = 0
  49. -- local rate = this.calculatorPrivilegeExpRate(actor) / 100
  50. for k, v in pairs(itemMap) do
  51. local final_v = string.tonumber(v)
  52. if final_v < 1 then
  53. goto continue
  54. end
  55. final_v = final_v * (1 + rate / 100)
  56. exp_map[k] = final_v
  57. ::continue::
  58. end
  59. return exp_map
  60. end
  61. --获取经验事件
  62. function bubblePointGetExp(actor, exp, fromType, expAddRate)
  63. if fromType ~= 1 and fromType ~= 2 then
  64. return
  65. end
  66. -- 内置经验加成算法与外置不同,覆盖内置倍率逻辑
  67. expAddRate = 0
  68. -- vip与特权卡的经验加成没有走角色加属性的方式,所以此处单独处理经验加成百分比展示问题
  69. expAddRate = expAddRate + this.calculatorPrivilegeExpRate(actor)
  70. -- 获取经验药水加成值
  71. local expBoostAttrValue = getplaydef(actor, PlayerDefKey.player.EXP_BOOST_ATTR_VALUE)
  72. if expBoostAttrValue then
  73. expAddRate = expAddRate + expBoostAttrValue
  74. end
  75. local sendData = {
  76. exp = exp,
  77. expAddRate = expAddRate,
  78. fromType= fromType --1泡点,2杀怪
  79. }
  80. sendluamsg(actor, LuaMessageIdToClient.BOBBLE_POINT_SHOW, sendData)
  81. end
  82. function this.calculatorPrivilegeExpRate(actor)
  83. -- 杀怪经验加成值取各个功能模块的加成值之和
  84. local expAddRate = 0
  85. -- 判断是否开启了vip经验加成
  86. local vipOpen, vipRate = VipGiftPack.hasPrivilege(actor, VipPrivilege.Type.exp)
  87. if vipOpen then
  88. local vipRateArr = string.split(vipRate, "#")
  89. expAddRate = expAddRate + string.tonumber(vipRateArr[2])
  90. end
  91. -- 判断是否开启了特权经验加成
  92. local privilegeOpen, privilegeRate = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.EXP_ADD_RATE)
  93. if privilegeOpen then
  94. expAddRate = expAddRate + privilegeRate
  95. end
  96. return expAddRate
  97. end
  98. --检查经验泡点条件
  99. function CheckExpConditionBP(actor)
  100. --检查是否在线
  101. local isOffLine = isofflineplay(actor)
  102. if isOffLine == true then
  103. return false
  104. end
  105. --检查等级限制
  106. local level = getbaseinfo(actor, "level")
  107. level = tonumber(level)
  108. local configLevel = ConfigDataManager.getTableValue("cfg_bubble_point", "expLevelLimit", "id", level)
  109. if configLevel == nil or configLevel == "" then
  110. -- error("找不到cfg_bubble_point配置,id:"..level)
  111. return false
  112. end
  113. local levelTable = string.split(configLevel, "#")
  114. local minLevel = tonumber(levelTable[1])
  115. local maxLevel = tonumber(levelTable[2])
  116. if level < minLevel or level > maxLevel then
  117. return false
  118. end
  119. --检查区域
  120. local mapId = getbaseinfo(actor, "map")
  121. local safeArea = getbaseinfo(actor, "safearea")
  122. local configString = ConfigDataManager.getTableValue("cfg_bubble_point", "expMap", "id", level)
  123. local configMap = string.toIntIntMap(configString, "#", "|")
  124. local checkArea = false
  125. for key, value in pairs(configMap) do
  126. mapId = tonumber(mapId)
  127. key = tonumber(key)
  128. value = tonumber(value)
  129. if mapId == key then
  130. if value == 3 then
  131. checkArea = true
  132. elseif value == 2 and safeArea == false then
  133. checkArea = true
  134. elseif value == 1 and safeArea == true then
  135. checkArea = true
  136. end
  137. end
  138. end
  139. if checkArea == false then
  140. return false
  141. end
  142. return true
  143. end