--- 经验加成道具使用 --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by zhoutao. --- DateTime: 2024/11/6 19:47 --- ExpBoost = {} --- 使用经验加成道具 ---@param actor table 角色对象 ---@param itemConfigId number 道具配置ID ---@param count number 使用数量 function ExpBoost.useExperienceBoostItem(actor, itemConfigId, count) local tableValue = ConfigDataManager.getTable("cfg_item", "id", itemConfigId) if tableValue == nil then jprint("=============================>cfg_item没有查到此道具,itemConfigId:", itemConfigId) return end local type = tonumber(tableValue[1]["type"]) local subType = tonumber(tableValue[1]["subtype"]) -- 经验药水类item特殊处理 if ItemType.DRUG == type and ItemSubType.EXP_BOOST == subType then local useParam = tableValue[1]["useparam"] if string.isNullOrEmpty(useParam) then return end local strSplit = string.split(useParam, "#") if #strSplit == 3 then local attrId = strSplit[1] local duration = strSplit[2] local buffId = strSplit[3] local attrValue = 0 local expireTime = 0 local buffValue = ConfigDataManager.getTableValue("cfg_buff", "buffvalue", "id", buffId) local buffValueSplit = string.split(buffValue, "#") if #buffValueSplit == 2 then attrValue = tonumber(buffValueSplit[2]) end for i = 1, count do local playerExpireInfo = getplaydef(actor, PlayerDefKey.player.EXP_BOOST_EXPIRE_TIME) if not table.isNullOrEmpty(playerExpireInfo) then -- 如果之前已经使用过永久的经验药水,则不做后续操作,直接return local playerExpireTime = tonumber(playerExpireInfo["expireTime"]) if playerExpireTime < 0 and tonumber(duration) < 0 then return end -- 如果之前已经使用过经验药水,则只增加时间不做加属性操作 if tonumber(duration) < 0 then expireTime = -1 else expireTime = tonumber(playerExpireTime) + tonumber(duration) * TimeUnit.MILLISECOND end else local attrMap = {} attrMap[attrId] = attrValue RoleAttr.addAndSaveRoleAttr(actor, RoleAttrKey.EXP_BOOST_ITEM_USE, attrMap) local now = getbaseinfo(actor, "now") if tonumber(duration) < 0 then expireTime = -1 else expireTime = tonumber(now) + tonumber(duration) * TimeUnit.MILLISECOND end end local expBoostInfo = {} expBoostInfo["buffId"] = buffId expBoostInfo["expireTime"] = expireTime setplaydef(actor, PlayerDefKey.player.EXP_BOOST_EXPIRE_TIME, expBoostInfo) -- 通知客户端经验收益 ExpBonus.changeBonus(actor, BonusType.EXP_DRUG_BONUS, attrValue, expireTime, buffId) -- 设置经验药水经验加成值,打怪经验展示加成值使用 setplaydef(actor, PlayerDefKey.player.EXP_BOOST_ATTR_VALUE, attrValue) local mark = getplaydef(actor, PlayerDefKey.player.EXP_BOOST_EXPIRE_MARK) if not string.isNullOrEmpty(mark) then clearintervalcall(actor, mark) end local intervalMark = intervalcalldelay(actor, expireTime - tonumber(getbaseinfo(actor, "now")), 1000, 1, "clearexpboost") setplaydef(actor, PlayerDefKey.player.EXP_BOOST_EXPIRE_MARK, intervalMark) end end end end --- 清空角色经验药水信息 ---@param actor table 角色对象 function clearexpboost(actor) local playerExpireInfo = getplaydef(actor, PlayerDefKey.player.EXP_BOOST_EXPIRE_TIME) if string.isNullOrEmpty(playerExpireInfo) then return end local buffId = playerExpireInfo["buffId"] RoleAttr.clearRoleAttrAndDB(actor, RoleAttrKey.EXP_BOOST_ITEM_USE) ExpBonus.changeBonus(actor, BonusType.EXP_DRUG_BONUS, 0, 0, buffId) setplaydef(actor, PlayerDefKey.player.EXP_BOOST_EXPIRE_TIME, nil) setplaydef(actor, PlayerDefKey.player.EXP_BOOST_ATTR_VALUE, 0) end --- 角色登录通知客户端经验药水信息 ---@param actor table 角色对象 function ExpBoost.login(play) local playerExpireInfo = getplaydef(play, PlayerDefKey.player.EXP_BOOST_EXPIRE_TIME) if string.isNullOrEmpty(playerExpireInfo) then return end local buffId = playerExpireInfo["buffId"] local expireTime = playerExpireInfo["expireTime"] local attrValue = 0 local buffValue = ConfigDataManager.getTableValue("cfg_buff", "buffvalue", "id", buffId) local buffValueSplit = string.split(buffValue, "#") if #buffValueSplit == 2 then attrValue = tonumber(buffValueSplit[2]) end ExpBonus.changeBonus(play, BonusType.EXP_DRUG_BONUS, attrValue, expireTime, buffId) end --- 检查经验药水是否过期 ---@param actor table 角色对象 function ExpBoost.expBoostExpireCheck(actor) local nowTime = getbaseinfo(actor, "now") local playerExpireInfo = getplaydef(actor, PlayerDefKey.player.EXP_BOOST_EXPIRE_TIME) if string.isNullOrEmpty(playerExpireInfo) then return end local expireTime = playerExpireInfo["expireTime"] if tonumber(nowTime) > tonumber(expireTime) then clearexpboost(actor) end end