Buffer.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. Buffer = {}
  2. NOVICE_PROTECT = "T$_noviceProtect"
  3. local this = {}
  4. function Buffer.buffeffect(actor, buffCfgId, layers, casterActor)
  5. local buffConfig = ConfigDataManager.getById("cfg_buff", buffCfgId)
  6. if table.isNullOrEmpty(buffConfig) then
  7. return
  8. end
  9. local buffCountStr = buffConfig["buffcount"]
  10. -- 计算公式
  11. local buffCount = string.split(buffCountStr, "#")
  12. local buffValueStr = buffConfig["buffvalue"]
  13. local buffValueShuXian = string.split(buffValueStr, "|")
  14. local buffParamStr = buffConfig["buffparam"]
  15. local buffParamShuXian = string.split(buffParamStr, "|")
  16. --local allAttr = getallattrinfo(actor)
  17. --jprint("测试buff1",buffCountStr, buffValueStr, buffParamStr)
  18. local attr = {}
  19. for i = 1, #buffParamShuXian do
  20. local type = tonumber(buffCount[i])
  21. if type == 7 then
  22. local paramShuXian = buffParamShuXian[i]
  23. local strJinHao = string.split(paramShuXian, "#")
  24. local attrId = strJinHao[1]
  25. local attrName = attrid2name(casterActor, attrId)
  26. local strValue = buffValueShuXian[i]
  27. local value = string.split(strValue, "#")
  28. local attr1 = value[1]
  29. local rate = value[2]
  30. --local currAttr = tonumber(allAttr[attr1])
  31. local currAttr = getattrinfo(casterActor, attrid2name(attr1))
  32. local result = (currAttr * 0.0001 * rate) * layers
  33. local oldValue = attr[attrName] or 0
  34. attr[attrName] = oldValue + result
  35. --jprint("测试buff2", "i", i, "strShuXian", paramShuXian, "#buffParamShuXian", #buffParamShuXian, "attrId", attrId, "type", type, "strValue", strValue, "attr1", attr1, "rate", rate
  36. --, "currAttr",currAttr, "result", result, "attr", attrName, "layers", layers)
  37. end
  38. end
  39. for attrName, addValue in pairs(attr) do
  40. -- jprint("类型7的buff属性查看",attrName,addValue)
  41. updateattrgroup(actor, tostring(buffCfgId), attrName, addValue)
  42. end
  43. end
  44. function Buffer.bufflose(actor, buffCfgId)
  45. clearattrgroup(actor, tostring(buffCfgId))
  46. local buffId = tonumber(ConfigDataManager.getTableValue("cfg_global", "value", "id", "260004"))
  47. if buffId == buffCfgId then
  48. -- this.BiHubufflose(actor, buffCfgId)
  49. Buffer.HandleBiHu(actor, buffCfgId, 2)
  50. end
  51. end
  52. function buffertest(actor)
  53. local petActor = getactor(10942, 2056193)
  54. local tab = getallattrinfo(petActor)
  55. -- jprint("tab数据:",tab)
  56. -- jprint("petActor:",petActor)
  57. -- jprint("207011:",tab["207011"])
  58. end
  59. -- 完成任务添加buff
  60. function Buffer.taskProgressComplete(actor,taskId)
  61. local taskTable = ConfigDataManager.getTableValue("cfg_global","value","id","15001")
  62. if not taskTable then
  63. return
  64. end
  65. local taskInfo = string.split(taskTable,"#")
  66. local have = false
  67. for index, task in pairs(taskInfo) do
  68. if tonumber(task) == taskId then
  69. have = true
  70. end
  71. end
  72. local maxLevel = ConfigDataManager.getTableValue("cfg_global","value","id","15002")
  73. if have and getbaseinfo(actor,"level") < tonumber(maxLevel) then
  74. local buffCfgId = ConfigDataManager.getTableValue("cfg_global","value","id","15003")
  75. buffer(actor,buffCfgId)
  76. setplaydef(actor,NOVICE_PROTECT,true)
  77. end
  78. end
  79. function Buffer.levelUp(actor,level)
  80. local maxLevel = ConfigDataManager.getTableValue("cfg_global","value","id","15002")
  81. if tonumber(maxLevel) < level then
  82. local buffCfgId = ConfigDataManager.getTableValue("cfg_global","value","id","15003")
  83. delbuff(actor,buffCfgId)
  84. setplaydef(actor,NOVICE_PROTECT,false)
  85. end
  86. end
  87. --- 添加安全区域buff
  88. ---@param actor table 玩家对象
  89. function Buffer.safetyAreaBuff(actor)
  90. local globalVar = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.SAFETY_AREA_BUFF_CONFIG)
  91. if not globalVar or string.isNullOrEmpty(globalVar) then
  92. -- jprint("========================================>Buffer.safetyAreaBuff globalVar is nil")
  93. return
  94. end
  95. local onlineState = getbaseinfo(actor, "onlinestate")
  96. local mapId = getbaseinfo(actor, "mapid")
  97. local mapConfigId = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.SAFETY_AREA_MAP_CONFIG)
  98. if not mapConfigId or mapConfigId == "" then
  99. -- jprint("========================================>Buffer.safetyAreaBuff mapConfigId is nil")
  100. return
  101. end
  102. local splitTable = string.split(globalVar, "#")
  103. if not splitTable or not next(splitTable) then
  104. return
  105. end
  106. local mapIds = string.split(mapConfigId, "#")
  107. if insafezone(actor) and onlineState == 1 and table.getKey(mapIds, tostring(mapId)) then
  108. for _, buffCfgId in pairs(splitTable) do
  109. if not hasbuff(actor, buffCfgId) then
  110. buffer(actor, buffCfgId)
  111. end
  112. end
  113. else
  114. for _, buffCfgId in pairs(splitTable) do
  115. if hasbuff(actor, buffCfgId) then
  116. delbuff(actor, buffCfgId)
  117. --setplaydef(actor, PlayerDefKey.player.SAFETY_AREA_BUFF, false)
  118. local roleInfo = getsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO)
  119. if not roleInfo or roleInfo == "" then
  120. return
  121. end
  122. for k, v in pairs(roleInfo) do
  123. local play = v["actor"]
  124. if play:toString() == actor:toString() then
  125. table.remove(roleInfo, k)
  126. end
  127. end
  128. setsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO, roleInfo)
  129. end
  130. end
  131. end
  132. end
  133. function Buffer.onAddBuff(actor, msgData)
  134. -- msgData = {41000011,41000012 }
  135. if table.notNullOrEmpty(msgData) then
  136. -- 添加庇护buff
  137. local buffId = tonumber(ConfigDataManager.getTableValue("cfg_global", "value", "id", "260004"))
  138. local type = tonumber(msgData.type) --0 添加,1 移除
  139. if buffId == tonumber(msgData.buffCfgId) then
  140. Buffer.HandleBiHu(actor, buffId, type)
  141. return
  142. end
  143. end
  144. --幻影导师 添加buff
  145. local globalVar = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.PHANTOM_MENTOR_BUFF)
  146. local splitTable = string.split(globalVar, "#")
  147. if next(splitTable) then
  148. for _, buffCfgId in pairs(splitTable) do
  149. addbuff(actor, tonumber(buffCfgId))
  150. end
  151. end
  152. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.ADD_DOUBLE_EXP_BUFF, true)
  153. -- local buff_info = getbuffinfo(actor)
  154. -- if next(buff_info) then
  155. -- for i = 1, #buff_info do
  156. -- info(buff_info[i].buffcfgid)
  157. -- end
  158. -- end
  159. end
  160. -- 处理庇护
  161. function Buffer.HandleBiHu(actor, buffId, type)
  162. type = type or 0 --0 添加,1 移除 2 续费 3 BOSS移除
  163. local isOk = false
  164. local isEnd = false
  165. local endStr = ""
  166. local ishasBuff = hasbuff(actor, buffId)
  167. local data = API.GetTable(actor, "BIHU_DATA_INFO") or {}
  168. local cfgNum = tonumber(ConfigDataManager.getTableValue("cfg_global", "value", "id", 260005) or "20")
  169. local noNul = table.notNullOrEmpty(data)
  170. if noNul and type == 2 then
  171. type = 0
  172. end
  173. if not ishasBuff and type == 0 then
  174. local result = removeitemfrombag(actor, 10040001, cfgNum, 0, 9999, '庇护消耗')
  175. if not result then
  176. tipinfo(actor, "扣除钻石失败")
  177. endStr = "扣除钻石失败"
  178. isEnd = true
  179. end
  180. -- 不在23~8点,不享受庇护
  181. local h = TimeUtil.GetTodayHour()
  182. if h < 23 and h >= 8 then
  183. endStr = "不在庇护时间内"
  184. isEnd = true
  185. end
  186. if isEnd == false then
  187. isOk = buffer(actor, buffId)
  188. if isOk then
  189. setplayersetting(actor, 1, 1) --1 和平 5战盟
  190. data.time = data.time or getbaseinfo("nowsec")
  191. data.type = type
  192. data.cost = (data.cost or 0) + cfgNum
  193. end
  194. end
  195. elseif ishasBuff then
  196. if type == 1 then
  197. isEnd = true
  198. elseif type == 3 then
  199. endStr = "选定BOSS"
  200. isEnd = true
  201. end
  202. end
  203. if isEnd then
  204. isOk = delbuff(actor, buffId)
  205. local nowsec = getbaseinfo("nowsec")
  206. local Seconds = nowsec - (data.time or nowsec)
  207. local cost = data.cost or 0
  208. local title = "庇护结束"
  209. local str = endStr.." 庇护系统已结束!总庇护时间 %s,总消耗钻石:%s "
  210. local content =string.format(str, formatSecondsToHourMinute(Seconds), cost)
  211. sendluamsg(actor, LuaMessageIdToClient.COMMON_TIPS_PANEL, {title = title, content = content})
  212. jprint("=== 庇护结束 ===", actor, getbaseinfo(actor,"maptitle"),endStr, data.time, nowsec,cost)
  213. data = {}
  214. end
  215. API.SetTable(actor, "BIHU_DATA_INFO", data)
  216. return true
  217. end
  218. -- 秒数转换为"X时Y分"格式
  219. ---@param seconds number 秒数
  220. ---@return string 格式化时间字符串(如:"1时5分"、"0时10分")
  221. function formatSecondsToHourMinute(seconds)
  222. if not seconds or seconds <= 0 then
  223. return "0时0分"
  224. end
  225. local hours = math.floor(seconds / 3600)
  226. local minutes = math.floor((seconds % 3600) / 60)
  227. local remainingSeconds = seconds % 60
  228. return string.format("%d时%d分%d秒", hours, minutes,remainingSeconds)
  229. end
  230. --[[
  231. Buffer = {}
  232. local SKILL_TYPE = 1
  233. local ATTACK_TYPE = 2
  234. local bufferConfigMap;
  235. function Buffer.initBufferConfigMap()
  236. bufferConfigMap = {}
  237. bufferConfigMap[SKILL_TYPE] = {}
  238. bufferConfigMap[ATTACK_TYPE] = {}
  239. local bufferConfigList = ConfigDataManager.getTable("cfg_buff")
  240. for _, buffConfig in pairs(bufferConfigList) do
  241. local bufftrigger = buffConfig["bufftrigger"]
  242. if not string.isNullOrEmpty(bufftrigger) then
  243. local data = bufferConfigMap[tonumber(bufftrigger)]
  244. if data ~= nil then
  245. table.insert(data, buffConfig)
  246. end
  247. end
  248. end
  249. end
  250. function Buffer.getBufferConfigList(trigger)
  251. if bufferConfigMap == nil then
  252. Buffer.initBufferConfigMap()
  253. end
  254. return bufferConfigMap[tonumber(trigger)]
  255. end
  256. function Buffer.OnAttack(actor, targetActor)
  257. local bufferConfigs = Buffer.getBufferConfigList(ATTACK_TYPE)
  258. for _, buffConfig in ipairs(bufferConfigs) do
  259. addbuff(targetActor, buffConfig["id"], 1, actor)
  260. end
  261. end
  262. function Buffer.OnReleaseSkill(actor, targetActorlist)
  263. local bufferConfigs = Buffer.getBufferConfigList(SKILL_TYPE)
  264. for _, buffConfig in ipairs(bufferConfigs) do
  265. for _, targetActor in pairs(targetActorlist) do
  266. addbuff(targetActor, buffConfig["id"], 1, actor)
  267. end
  268. end
  269. end ]]