Buffer.lua 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. Buffer = {}
  2. NOVICE_PROTECT = "T$_noviceProtect"
  3. function Buffer.buffeffect(actor, buffCfgId, layers)
  4. local buffConfig = ConfigDataManager.getById("cfg_buff", buffCfgId)
  5. if table.isNullOrEmpty(buffConfig) then
  6. return
  7. end
  8. local buffCountStr = buffConfig["buffcount"]
  9. -- 计算公式
  10. local buffCount = string.split(buffCountStr, "#")
  11. local buffValueStr = buffConfig["buffvalue"]
  12. local buffValueShuXian = string.split(buffValueStr, "|")
  13. local buffParamStr = buffConfig["buffparam"]
  14. local buffParamShuXian = string.split(buffParamStr, "|")
  15. --local allAttr = getallattrinfo(actor)
  16. --jprint("测试buff1",buffCountStr, buffValueStr, buffParamStr)
  17. local attr = {}
  18. for i = 1, #buffParamShuXian do
  19. local type = tonumber(buffCount[i])
  20. if type == 7 then
  21. local paramShuXian = buffParamShuXian[i]
  22. local strJinHao = string.split(paramShuXian, "#")
  23. local attrId = strJinHao[1]
  24. local attrName = attrid2name(actor, attrId)
  25. local strValue = buffValueShuXian[i]
  26. local value = string.split(strValue, "#")
  27. local attr1 = value[1]
  28. local rate = value[2]
  29. --local currAttr = tonumber(allAttr[attr1])
  30. local currAttr = getattrinfo(actor, attrid2name(attr1))
  31. local result = (currAttr * 0.0001 * rate) * layers
  32. local oldValue = attr[attrName] or 0
  33. attr[attrName] = oldValue + result
  34. --jprint("测试buff2", "i", i, "strShuXian", paramShuXian, "#buffParamShuXian", #buffParamShuXian, "attrId", attrId, "type", type, "strValue", strValue, "attr1", attr1, "rate", rate
  35. --, "currAttr",currAttr, "result", result, "attr", attrName, "layers", layers)
  36. end
  37. end
  38. for attrName, addValue in pairs(attr) do
  39. jprint("类型7的buff属性查看",attrName,addValue)
  40. updateattrgroup(actor, tostring(buffCfgId), attrName, addValue)
  41. end
  42. end
  43. function Buffer.bufflose(actor, buffCfgId)
  44. clearattrgroup(actor, tostring(buffCfgId))
  45. end
  46. function buffertest(actor)
  47. local petActor = getactor(10942, 2056193)
  48. local tab = getallattrinfo(petActor)
  49. jprint("tab数据:",tab)
  50. jprint("petActor:",petActor)
  51. jprint("207011:",tab["207011"])
  52. end
  53. -- 完成任务添加buff
  54. function Buffer.taskProgressComplete(actor,taskId)
  55. local taskTable = ConfigDataManager.getTableValue("cfg_global","value","id","15001")
  56. if not taskTable then
  57. return
  58. end
  59. local taskInfo = string.split(taskTable,"#")
  60. local have = false
  61. for index, task in pairs(taskInfo) do
  62. if tonumber(task) == taskId then
  63. have = true
  64. end
  65. end
  66. local maxLevel = ConfigDataManager.getTableValue("cfg_global","value","id","15002")
  67. if have and getbaseinfo(actor,"level") < tonumber(maxLevel) then
  68. local buffCfgId = ConfigDataManager.getTableValue("cfg_global","value","id","15003")
  69. buffer(actor,buffCfgId)
  70. setplaydef(actor,NOVICE_PROTECT,true)
  71. end
  72. end
  73. function Buffer.levelUp(actor,level)
  74. local maxLevel = ConfigDataManager.getTableValue("cfg_global","value","id","15002")
  75. if tonumber(maxLevel) < level then
  76. local buffCfgId = ConfigDataManager.getTableValue("cfg_global","value","id","15003")
  77. delbuff(actor,buffCfgId)
  78. setplaydef(actor,NOVICE_PROTECT,false)
  79. end
  80. end
  81. --- 添加安全区域buff
  82. ---@param actor table 玩家对象
  83. function Buffer.safetyAreaBuff(actor)
  84. local globalVar = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.SAFETY_AREA_BUFF_CONFIG)
  85. if not globalVar or string.isNullOrEmpty(globalVar) then
  86. jprint("========================================>Buffer.safetyAreaBuff globalVar is nil")
  87. return
  88. end
  89. local onlineState = getbaseinfo(actor, "onlinestate")
  90. local mapId = getbaseinfo(actor, "mapid")
  91. local mapConfigId = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.SAFETY_AREA_MAP_CONFIG)
  92. if not mapConfigId or mapConfigId == "" then
  93. jprint("========================================>Buffer.safetyAreaBuff mapConfigId is nil")
  94. return
  95. end
  96. local splitTable = string.split(globalVar, "#")
  97. if not splitTable or not next(splitTable) then
  98. return
  99. end
  100. local mapIds = string.split(mapConfigId, "#")
  101. if insafezone(actor) and onlineState == 1 and table.getKey(mapIds, tostring(mapId)) then
  102. for _, buffCfgId in pairs(splitTable) do
  103. if not hasbuff(actor, buffCfgId) then
  104. buffer(actor, buffCfgId)
  105. end
  106. end
  107. else
  108. for _, buffCfgId in pairs(splitTable) do
  109. if hasbuff(actor, buffCfgId) then
  110. delbuff(actor, buffCfgId)
  111. --setplaydef(actor, PlayerDefKey.player.SAFETY_AREA_BUFF, false)
  112. local roleInfo = getsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO)
  113. if not roleInfo or roleInfo == "" then
  114. return
  115. end
  116. for k, v in pairs(roleInfo) do
  117. local play = v["actor"]
  118. if play:toString() == actor:toString() then
  119. table.remove(roleInfo, k)
  120. end
  121. end
  122. setsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO, roleInfo)
  123. end
  124. end
  125. end
  126. end
  127. --[[
  128. Buffer = {}
  129. local SKILL_TYPE = 1
  130. local ATTACK_TYPE = 2
  131. local bufferConfigMap;
  132. function Buffer.initBufferConfigMap()
  133. bufferConfigMap = {}
  134. bufferConfigMap[SKILL_TYPE] = {}
  135. bufferConfigMap[ATTACK_TYPE] = {}
  136. local bufferConfigList = ConfigDataManager.getTable("cfg_buff")
  137. for _, buffConfig in pairs(bufferConfigList) do
  138. local bufftrigger = buffConfig["bufftrigger"]
  139. if not string.isNullOrEmpty(bufftrigger) then
  140. local data = bufferConfigMap[tonumber(bufftrigger)]
  141. if data ~= nil then
  142. table.insert(data, buffConfig)
  143. end
  144. end
  145. end
  146. end
  147. function Buffer.getBufferConfigList(trigger)
  148. if bufferConfigMap == nil then
  149. Buffer.initBufferConfigMap()
  150. end
  151. return bufferConfigMap[tonumber(trigger)]
  152. end
  153. function Buffer.OnAttack(actor, targetActor)
  154. local bufferConfigs = Buffer.getBufferConfigList(ATTACK_TYPE)
  155. for _, buffConfig in ipairs(bufferConfigs) do
  156. addbuff(targetActor, buffConfig["id"], 1, actor)
  157. end
  158. end
  159. function Buffer.OnReleaseSkill(actor, targetActorlist)
  160. local bufferConfigs = Buffer.getBufferConfigList(SKILL_TYPE)
  161. for _, buffConfig in ipairs(bufferConfigs) do
  162. for _, targetActor in pairs(targetActorlist) do
  163. addbuff(targetActor, buffConfig["id"], 1, actor)
  164. end
  165. end
  166. end ]]