Buffer = {} NOVICE_PROTECT = "T$_noviceProtect" local this = {} function Buffer.buffeffect(actor, buffCfgId, layers, casterActor) local buffConfig = ConfigDataManager.getById("cfg_buff", buffCfgId) if table.isNullOrEmpty(buffConfig) then return end local buffCountStr = buffConfig["buffcount"] -- 计算公式 local buffCount = string.split(buffCountStr, "#") local buffValueStr = buffConfig["buffvalue"] local buffValueShuXian = string.split(buffValueStr, "|") local buffParamStr = buffConfig["buffparam"] local buffParamShuXian = string.split(buffParamStr, "|") --local allAttr = getallattrinfo(actor) --jprint("测试buff1",buffCountStr, buffValueStr, buffParamStr) local attr = {} for i = 1, #buffParamShuXian do local type = tonumber(buffCount[i]) if type == 7 then local paramShuXian = buffParamShuXian[i] local strJinHao = string.split(paramShuXian, "#") local attrId = strJinHao[1] local attrName = attrid2name(casterActor, attrId) local strValue = buffValueShuXian[i] local value = string.split(strValue, "#") local attr1 = value[1] local rate = value[2] --local currAttr = tonumber(allAttr[attr1]) local currAttr = getattrinfo(casterActor, attrid2name(attr1)) local result = (currAttr * 0.0001 * rate) * layers local oldValue = attr[attrName] or 0 attr[attrName] = oldValue + result --jprint("测试buff2", "i", i, "strShuXian", paramShuXian, "#buffParamShuXian", #buffParamShuXian, "attrId", attrId, "type", type, "strValue", strValue, "attr1", attr1, "rate", rate --, "currAttr",currAttr, "result", result, "attr", attrName, "layers", layers) end end for attrName, addValue in pairs(attr) do -- jprint("类型7的buff属性查看",attrName,addValue) updateattrgroup(actor, tostring(buffCfgId), attrName, addValue) end end function Buffer.bufflose(actor, buffCfgId) clearattrgroup(actor, tostring(buffCfgId)) local buffId = tonumber(ConfigDataManager.getTableValue("cfg_global", "value", "id", "260004")) if buffId == buffCfgId then -- this.BiHubufflose(actor, buffCfgId) Buffer.HandleBiHu(actor, buffCfgId, 2) end end function buffertest(actor) local petActor = getactor(10942, 2056193) local tab = getallattrinfo(petActor) -- jprint("tab数据:",tab) -- jprint("petActor:",petActor) -- jprint("207011:",tab["207011"]) end -- 完成任务添加buff function Buffer.taskProgressComplete(actor,taskId) local taskTable = ConfigDataManager.getTableValue("cfg_global","value","id","15001") if not taskTable then return end local taskInfo = string.split(taskTable,"#") local have = false for index, task in pairs(taskInfo) do if tonumber(task) == taskId then have = true end end local maxLevel = ConfigDataManager.getTableValue("cfg_global","value","id","15002") if have and getbaseinfo(actor,"level") < tonumber(maxLevel) then local buffCfgId = ConfigDataManager.getTableValue("cfg_global","value","id","15003") buffer(actor,buffCfgId) setplaydef(actor,NOVICE_PROTECT,true) end end function Buffer.levelUp(actor,level) local maxLevel = ConfigDataManager.getTableValue("cfg_global","value","id","15002") if tonumber(maxLevel) < level then local buffCfgId = ConfigDataManager.getTableValue("cfg_global","value","id","15003") delbuff(actor,buffCfgId) setplaydef(actor,NOVICE_PROTECT,false) end end --- 添加安全区域buff ---@param actor table 玩家对象 function Buffer.safetyAreaBuff(actor) local globalVar = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.SAFETY_AREA_BUFF_CONFIG) if not globalVar or string.isNullOrEmpty(globalVar) then -- jprint("========================================>Buffer.safetyAreaBuff globalVar is nil") return end local onlineState = getbaseinfo(actor, "onlinestate") local mapId = getbaseinfo(actor, "mapid") local mapConfigId = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.SAFETY_AREA_MAP_CONFIG) if not mapConfigId or mapConfigId == "" then -- jprint("========================================>Buffer.safetyAreaBuff mapConfigId is nil") return end local splitTable = string.split(globalVar, "#") if not splitTable or not next(splitTable) then return end local mapIds = string.split(mapConfigId, "#") if insafezone(actor) and onlineState == 1 and table.getKey(mapIds, tostring(mapId)) then for _, buffCfgId in pairs(splitTable) do if not hasbuff(actor, buffCfgId) then buffer(actor, buffCfgId) end end else for _, buffCfgId in pairs(splitTable) do if hasbuff(actor, buffCfgId) then delbuff(actor, buffCfgId) --setplaydef(actor, PlayerDefKey.player.SAFETY_AREA_BUFF, false) local roleInfo = getsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO) if not roleInfo or roleInfo == "" then return end for k, v in pairs(roleInfo) do local play = v["actor"] if play:toString() == actor:toString() then table.remove(roleInfo, k) end end setsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO, roleInfo) end end end end function Buffer.onAddBuff(actor, msgData) -- msgData = {41000011,41000012 } if table.notNullOrEmpty(msgData) then -- 添加庇护buff local buffId = tonumber(ConfigDataManager.getTableValue("cfg_global", "value", "id", "260004")) local type = tonumber(msgData.type) --0 添加,1 移除 if buffId == tonumber(msgData.buffCfgId) then Buffer.HandleBiHu(actor, buffId, type) return end end --幻影导师 添加buff local globalVar = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.PHANTOM_MENTOR_BUFF) local splitTable = string.split(globalVar, "#") if next(splitTable) then for _, buffCfgId in pairs(splitTable) do addbuff(actor, tonumber(buffCfgId)) end end TaskHandler.TriggerTaskGoal(actor, TaskTargetType.ADD_DOUBLE_EXP_BUFF, true) -- local buff_info = getbuffinfo(actor) -- if next(buff_info) then -- for i = 1, #buff_info do -- info(buff_info[i].buffcfgid) -- end -- end end -- 处理庇护 function Buffer.HandleBiHu(actor, buffId, type) type = type or 0 --0 添加,1 移除 2 续费 3 BOSS移除 local isOk = false local isEnd = false local endStr = "" local ishasBuff = hasbuff(actor, buffId) local data = API.GetTable(actor, "BIHU_DATA_INFO") or {} local cfgNum = tonumber(ConfigDataManager.getTableValue("cfg_global", "value", "id", 260005) or "20") local noNul = table.notNullOrEmpty(data) if noNul and type == 2 then type = 0 end if not ishasBuff and type == 0 then local result = removeitemfrombag(actor, 10040001, cfgNum, 0, 9999, '庇护消耗') if not result then tipinfo(actor, "扣除钻石失败") endStr = "扣除钻石失败" isEnd = true end -- 不在23~8点,不享受庇护 local h = TimeUtil.GetTodayHour() if h < 23 and h >= 8 then endStr = "不在庇护时间内" isEnd = true end if isEnd == false then isOk = buffer(actor, buffId) if isOk then setplayersetting(actor, 1, 1) --1 和平 5战盟 data.time = data.time or getbaseinfo("nowsec") data.type = type data.cost = (data.cost or 0) + cfgNum end end elseif ishasBuff then if type == 1 then isEnd = true elseif type == 3 then endStr = "选定BOSS" isEnd = true end end if isEnd then isOk = delbuff(actor, buffId) local nowsec = getbaseinfo("nowsec") local Seconds = nowsec - (data.time or nowsec) local cost = data.cost or 0 local title = "庇护结束" local str = endStr.." 庇护系统已结束!总庇护时间 %s,总消耗钻石:%s " local content =string.format(str, formatSecondsToHourMinute(Seconds), cost) sendluamsg(actor, LuaMessageIdToClient.COMMON_TIPS_PANEL, {title = title, content = content}) jprint("=== 庇护结束 ===", actor, getbaseinfo(actor,"maptitle"),endStr, data.time, nowsec,cost) data = {} end API.SetTable(actor, "BIHU_DATA_INFO", data) return true end -- 秒数转换为"X时Y分"格式 ---@param seconds number 秒数 ---@return string 格式化时间字符串(如:"1时5分"、"0时10分") function formatSecondsToHourMinute(seconds) if not seconds or seconds <= 0 then return "0时0分" end local hours = math.floor(seconds / 3600) local minutes = math.floor((seconds % 3600) / 60) local remainingSeconds = seconds % 60 return string.format("%d时%d分%d秒", hours, minutes,remainingSeconds) end --[[ Buffer = {} local SKILL_TYPE = 1 local ATTACK_TYPE = 2 local bufferConfigMap; function Buffer.initBufferConfigMap() bufferConfigMap = {} bufferConfigMap[SKILL_TYPE] = {} bufferConfigMap[ATTACK_TYPE] = {} local bufferConfigList = ConfigDataManager.getTable("cfg_buff") for _, buffConfig in pairs(bufferConfigList) do local bufftrigger = buffConfig["bufftrigger"] if not string.isNullOrEmpty(bufftrigger) then local data = bufferConfigMap[tonumber(bufftrigger)] if data ~= nil then table.insert(data, buffConfig) end end end end function Buffer.getBufferConfigList(trigger) if bufferConfigMap == nil then Buffer.initBufferConfigMap() end return bufferConfigMap[tonumber(trigger)] end function Buffer.OnAttack(actor, targetActor) local bufferConfigs = Buffer.getBufferConfigList(ATTACK_TYPE) for _, buffConfig in ipairs(bufferConfigs) do addbuff(targetActor, buffConfig["id"], 1, actor) end end function Buffer.OnReleaseSkill(actor, targetActorlist) local bufferConfigs = Buffer.getBufferConfigList(SKILL_TYPE) for _, buffConfig in ipairs(bufferConfigs) do for _, targetActor in pairs(targetActorlist) do addbuff(targetActor, buffConfig["id"], 1, actor) end end end ]]