EquipGem = {} function gemtest(actor, msgData) -- local a = {} -- a.schemepos = 1 -- a.idxOfBag = 10102 -- a.idxOfEquip = 65538 -- EquipGem.schemeInfo(actor,msgData) -- EquipGem.putOnGemOrSlabstone(actor,a) -- EquipGem.takeOffGemOrSlabstone(actor,a) -- EquipGem.schemeSwitch(actor,a) end -- 萤石方案详情 function EquipGem.schemeInfo(actor, msgData) local gemScheme = getGemscheme(actor) sendluamsg(actor, LuaMessageIdToClient.RES_GEM_SCHEME, gemScheme) end -- 萤石方案镶嵌宝石或者石板 function EquipGem.putOnGemOrSlabstone(actor, msgData) local idx = msgData.idxOfBag local idxOfEquip = msgData.idxOfEquip local pos = idxOfEquip local wearBar = nil if idx < 10000 then tipinfo(actor, "找不到物品") return end local gem = getbagiteminfo(actor, idx) -- 判断镶嵌的是宝石还是石板 有wearBar的是宝石 if tonumber(idxOfEquip) > 0xFFFF then wearBar = gameequip.wearBar(idxOfEquip) pos = gameequip.pos(idxOfEquip) end if not gem then tipinfo(actor, "找不到物品") return end local gemId = gem.cfgid if not cellVerify(actor, gemId, idxOfEquip) then return end if not removeitembyidxlist(actor, { [idx] = 1 },9999,'荧石') then tipinfo(actor, "移除物品失败") return end local gemScheme = getGemscheme(actor) local schemepos = gemScheme.cur local schemeData = gemScheme.data[schemepos] local part = schemeData.scheme[pos] if part == nil then schemeData.scheme[pos] = {} part = schemeData.scheme[pos] part.active = true end -- 判断镶嵌的是宝石还是石板 if wearBar ~= nil then if part.gems == nil then part.gems = {} end local filledGem = part.gems[wearBar] if filledGem then additemtobag(actor, tonumber(filledGem), 1,0,9999,'荧石') end part.gems[wearBar] = gemId else if part.stone then additemtobag(actor, tonumber(part.stone), 1,0,9999,'荧石') end part.stone = gemId end setplaydef(actor, "T$gemscheme", gemScheme) updateAttr(actor, gemScheme) sendluamsg(actor, LuaMessageIdToClient.RES_GEM_CURRENT_SCHEME, schemeData) -- 刷新任务进度 EquipGem.flushGemTask(actor) end -- 萤石方案里卸载宝石或者石板 function EquipGem.takeOffGemOrSlabstone(actor, msgData) local idxOfEquip = msgData.idxOfEquip local pos = idxOfEquip local wearBar = nil -- 判断镶嵌的是宝石还是石板 有wearBar的是宝石 if idxOfEquip > 0xFFFF then wearBar = gameequip.wearBar(idxOfEquip) pos = gameequip.pos(idxOfEquip) end local gemScheme = getGemscheme(actor) local schemepos = gemScheme.cur local schemeData = gemScheme.data[schemepos] local part = schemeData.scheme[pos] if part == nil then schemeData.scheme[pos] = {} part = schemeData.scheme[pos] end -- 判断镶嵌的是宝石还是石板 if wearBar ~= nil then if part.gems == nil then part.gems = {} end local filledGem = part.gems[wearBar] if filledGem then additemtobag(actor, tonumber(filledGem), 1,0,9999,'荧石') else tipinfo(actor, "找不到物品") return end part.gems[wearBar] = nil else if part.stone then additemtobag(actor, tonumber(part.stone), 1,0,9999,'荧石') else tipinfo(actor, "找不到物品") return end part.stone = nil end setplaydef(actor, "T$gemscheme", gemScheme) updateAttr(actor, gemScheme) sendluamsg(actor, LuaMessageIdToClient.RES_GEM_CURRENT_SCHEME, schemeData) EquipGem.flushGemTask(actor) end -- 萤石方案切换 function EquipGem.schemeSwitch(actor, msgData) local schemepos = msgData.schemepos local gemScheme = getGemscheme(actor) local scheme = gemScheme.data[schemepos] if scheme == nil then tipinfo(actor, "找不到方案") return end local oldpos = gemScheme.cur local oldscheme = gemScheme.data[oldpos] if oldscheme == nil then tipinfo(actor, "找不到方案") return end if gemScheme.cur == schemepos then tipinfo(actor, "方案已激活") return end -- 老方案的宝石全部返回背包 -- if oldscheme.scheme then -- for _,part in pairs(oldscheme.scheme) do -- if part.gems then -- for _, gemId in pairs(part.gems) do -- additemtobag(actor, tonumber(gemId), 1) -- end -- end -- if part.stone then -- additemtobag(actor, tonumber(part.stone), 1) -- end -- end -- end -- 新方案的宝石从背包里扣除 不够扣移除宝石 -- if scheme.scheme then -- for _,part in pairs(scheme.scheme) do -- if part.gems then -- local removes = {} -- for key, gemId in pairs(part.gems) do -- if not removeitemfrombag(actor, tonumber(gemId), 1) then -- --记录宝石不足的遍历后移除 -- table.insert(removes, gemId) -- end -- end -- for _, key in pairs(removes) do -- part.gems[key] = nil -- end -- end -- if part.stone then -- if not removeitemfrombag(actor, tonumber(part.stone), 1) then -- part.stone = nil -- end -- end -- end -- end oldscheme.active = false scheme.active = true gemScheme.cur = schemepos setplaydef(actor, "T$gemscheme", gemScheme) updateAttr(actor, gemScheme) sendluamsg(actor, LuaMessageIdToClient.RES_GEM_CURRENT_SCHEME, scheme) EquipGem.flushGemTask(actor) end -- 刷新镶嵌宝石任务进度 function EquipGem.flushGemTask(actor) TaskHandler.TriggerTaskGoal(actor, TaskTargetType.INLAID_GEMSTONES) end function EquipGem.getAllGemCount(actor) local final_count = 0 local gem_info = getGemscheme(actor) local scheme_info = gem_info.data[gem_info.cur].scheme if table.isEmpty(scheme_info) then return final_count end for _, info in pairs(scheme_info) do if info.active then local value = table.isEmpty(info.gems) and 0 or #info.gems final_count = final_count + value end end return final_count end -- 装备是否生效影响 萤石方案属性 是否失效 function EquipGem.schemeEffectByBoolean(actor, map, effect) local gemScheme = getGemscheme(actor) local cur = gemScheme.cur -- local scheme = gemScheme.data[gemScheme.cur] for schemeIndex, scheme in pairs(gemScheme.data) do local update = false for _, pos in pairs(map) do local data = scheme.scheme[pos] if data and data.active ~= effect then data.active = effect update = true end end -- 当前方案某装备激活,更新对应属性 local isCur = (cur == schemeIndex) if update and isCur then updateAttr(actor, gemScheme) end setplaydef(actor, "T$gemscheme", gemScheme) -- 测试看数据 sendluamsg(actor,LuaMessageIdToClient.RES_GEM_SCHEME,gemScheme) end end function EquipGem.getOtherGemScheme(actor, msgData) local rid = msgData.rid if not rid then return end local player = getactor(actor, rid) if not player then return end local gemScheme = getGemscheme(player) if actor:toString() ~= player:toString() then gemScheme.rid = rid end sendluamsg(actor, LuaMessageIdToClient.RES_GEM_SCHEME, gemScheme) end -- 更新萤石方案属性 function updateAttr(actor, gemScheme) local cur = gemScheme.cur local gemScheme = gemScheme.data[cur] local allattr = {} local suit = {} for _, data in pairs(gemScheme.scheme) do if data.active == true then local stoneId = data.stone local attrUp = nil if stoneId then -- 石板属性 local stoneAtt = string.getAttrByStr(ConfigDataManager.getTableValue("cfg_equip_stoneBoard", "stoneAtt", "id", stoneId)) table.mergeAdd(allattr, stoneAtt) attrUp = string.getAttrByStr(ConfigDataManager.getTableValue("cfg_equip_stoneBoard", "stoneAtt2", "id", stoneId)) end -- 萤石属性 if data.gems then for _, gemId in pairs(data.gems) do local gemAtt = string.getAttrByStr(ConfigDataManager.getTableValue("cfg_equip_gem", "gemAtt", "id", gemId)) local lr = string.LR(ConfigDataManager.getTableValue("cfg_equip_gem", "gemBelong", "id", gemId)) -- 萤石属性增强 if (attrUp ~= nil and attrUp[lr.left] ~= nil) then gemAtt = attrUpByPc(gemAtt, attrUp[lr.left]) end suit[lr.left] = (suit[lr.left] and suit[lr.left] or 0) + tonumber(lr.right) table.mergeAdd(allattr, gemAtt) end end end end -- 萤石套装属性 local suitConfigs = ConfigDataManager.getList("cfg_equip_gemSuit") local suitAttr = {} local activeSuitConfig = {} for k, v in pairs(suit) do for _, config in pairs(suitConfigs) do local lr = string.LR(config.gemcondition) if k == lr.left and v >= tonumber(lr.right) then if activeSuitConfig[k] == nil or tonumber(lr.right) > tonumber(string.LR(activeSuitConfig[k].gemcondition).right) then activeSuitConfig[k] = config end end end end -- 学习套装技能 -- for k, config in pairs(activeSuitConfig) do -- table.mergeAdd(suitAttr,string.getAttrByStr(config.suitatt)) 暂时无属性不加成套装属性 -- local lr = string.LR(config.skill) -- levelupskill(actor,lr.left,lr.right) -- print("套装id:"..config.id.." 套装类型:"..k) -- print("学习技能id:"..lr.left.." 技能等级:"..lr.right) -- end table.mergeAdd(allattr, suitAttr) local activeIds = {} for _, config in pairs(activeSuitConfig) do table.insert(activeIds, config.id) end -- setplaydef(actor, "T$gemSuitConfig", activeSuitConfig) setplaydef(actor, "T$gemSuitConfig", activeIds) -- 测试看数据 sendluamsg(actor,LuaMessageIdToClient.RES_GEM_SCHEME,{["总属性"]= allattr}) addrolekmlattributes(actor, "gemscheme", allattr) end function attrUpByPc(attr_map, attr_up) attr = {} for key, value in pairs(attr_map) do attr[key] = math.ceil(value * (1 + attr_up / 10000.0)) end return attr end function cellVerify(actor, itemid, idxOfEquip) -- 判断镶嵌的是宝石还是石板 if idxOfEquip > 0xFFFF then local reqWearBar = gameequip.wearBar(idxOfEquip) local reqPos = gameequip.pos(idxOfEquip) local configPos = ConfigDataManager.getTableValue("cfg_equip_gem", "wearbarPos", "id", itemid) local configWearbar = ConfigDataManager.getTableValue("cfg_equip_gem", "wearbar", "id", itemid) if not string.contains(configWearbar, reqWearBar) or not string.contains(configPos, reqPos) then tipinfo(actor, "该位置无法镶嵌") return false end else local reqPos = idxOfEquip local configPos = ConfigDataManager.getTableValue("cfg_equip_stoneBoard", "pos", "id", itemid) if not string.contains(configPos, reqPos) then tipinfo(actor, "该位置无法镶嵌") return false end end return true end function getGemscheme(actor) local playData = getplaydef(actor, "T$gemscheme") if playData == nil then playData = gemschemeInit(actor) end return playData; end function gemschemeInit(actor) local gemScheme = {} gemScheme.data = {} for i = 1, 2, 1 do local scheme = {} scheme.pos = i scheme.scheme = {} if i == 1 then scheme.active = true gemScheme.cur = i else scheme.active = false end table.insert(gemScheme.data, scheme.pos, scheme) end setplaydef(actor, "T$gemscheme", gemScheme) return gemScheme end -- =======套装属性相关======= function EquipGem.getConfigByAttr(configs, attrName) for _, cfg in pairs(configs) do local value = cfg[string.lower(attrName)] if value and value ~= "" then -- lg(value) return cfg end end return nil end function EquipGem.getConfigByIdAndAttr(activeIds, attrName) if not activeIds then return nil end for _, id in ipairs(activeIds) do local config = ConfigDataManager.getById("cfg_equip_gemsuit", id) if not config then return nil end local value = config[string.lower(attrName)] if value ~= "" and value ~= nil then return config end end return nil end function EquipGem.dataAndType(actor, attrName) local data = getplaydef(actor, "T$gemSuitConfig") or {} if table.isNullOrEmpty(data) then return nil end local dataType = 0 for _, v in pairs(data) do if type(v) == "string" then dataType = 2 break elseif type(v) == "table" then dataType = 1 break end end if dataType == 0 then return nil elseif dataType == 1 then data = EquipGem.getConfigByAttr(data, attrName) return data else data = EquipGem.getConfigByIdAndAttr(data, attrName) return data end end function EquipGem.updateAttrGroup(actor, groupName, attrName, value) updateattrgroup(actor, groupName, attrName, value) end function EquipGem.sendHpChangeMessage(actor, recovery, target) sendluamsg(actor, LuaMessageIdToClient.RES_GEM_RECOVERY_HP_INFO, { text = recovery, hurtType = 118, targetId = target:toString() }) end function EquipGem.selectRate(probability) local randomNum = math.random() return randomNum <= probability end function EquipGem.parseConfigValue(valueStr) local valueArr = string.splitByAll(valueStr, "#") local probability = tonumber(valueArr[1]) / 10000 local ratio = tonumber(valueArr[2]) / 10000 return probability, ratio end -- 检查时间 function EquipGem.checkSpeedTime(actor, config) local timeInfo = getplaydef(actor, "@gemSpeedTimeInfo") if not timeInfo then return 0 end local speedBonus = config["anispeedbonus"] local lastingtime = tonumber(string.splitByAll(speedBonus, "#")[3]) local cd = tonumber(string.splitByAll(speedBonus, "#")[4]) local nowSec = getbaseinfo(actor, "nowsec") local useTime = timeInfo["useTime"] or 0 if nowSec - useTime <= lastingtime then return 1 elseif nowSec - useTime > lastingtime and nowSec - useTime < lastingtime + cd then return 2 else return 3 end end function EquipGem.checkRecoveryHpTime(actor, config) local useTime = getplaydef(actor, "@gemHpRecoveryTime") if not useTime then return true end local beAttackRecover = config["beattackrecover"] local cd = tonumber(string.splitByAll(beAttackRecover, "#")[3]) if not cd or cd == "" then return true end local nowSec = getbaseinfo(actor, "nowsec") if nowSec - useTime <= cd then return false end return true end function EquipGem.handleGemAttrs(caster, target, targetHurt, casterType, targetType) local hurt = EquipGem.setGemAttrs(caster, "damageRate", targetHurt) if casterType == MapObjectType.PLAYER and targetType == MapObjectType.PLAYER then hurt = EquipGem.setGemAttrs(target, "damageAbsorb", hurt) end return hurt end -- 设置宝石伤害增减 function EquipGem.setGemAttrs(actor, attrName, hurt) local config = EquipGem.dataAndType(actor,attrName) -- lg("伤害增减:",attrName, config) if not config then return hurt end local probability, ratio = EquipGem.parseConfigValue(config[string.lower(attrName)]) if EquipGem.selectRate(probability) then if attrName == "damageRate" then hurt = hurt * (1 + ratio) elseif attrName == "damageAbsorb" then hurt = hurt * (1 - ratio) end end return hurt end -- 设置宝石恢复 function EquipGem.setGemRecovery(actor, fightParam) local hurt = fightParam["targethurt"] local casterType = fightParam["castertype"] local targetType = fightParam["targettype"] if casterType == MapObjectType.PLAYER and targetType == MapObjectType.PLAYER then local config = EquipGem.dataAndType(actor,"beattackrecover") -- lg("恢复:", config) if not config then return end if not EquipGem.checkRecoveryHpTime(actor, config) then return end local probability, ratio = EquipGem.parseConfigValue(config["beattackrecover"]) if EquipGem.selectRate(probability) then local recovery = math.ceil(hurt * ratio) local currHp = getbaseinfo(actor, "hp") local fixHp = recovery + currHp sethp(actor, fixHp) -- local caster = fightParam["caster"] EquipGem.sendHpChangeMessage(actor, recovery, actor) -- local nearPlayers = getnarplayer(actor) -- for _, playInfo in ipairs(nearPlayers) do -- local play = playInfo["luaplayer"] -- if play:toString() ~= actor:toString() then -- EquipGem.sendHpChangeMessage(play, recovery, actor) -- end -- end setplaydef(actor, "@gemHpRecoveryTime", getbaseinfo(actor, "nowsec")) end end end -- 设置速度加成 function EquipGem.setSpeedBonus(actor) local config = EquipGem.dataAndType(actor,"anispeedbonus") -- lg("速度:", config) local timeInfo = getplaydef(actor, "@gemSpeedTimeInfo") if not config and not timeInfo then return elseif not config and timeInfo then local configId = timeInfo["cfgId"] config = ConfigDataManager.getById("cfg_equip_gemSuit", configId) end if not config then return end local nowSec = getbaseinfo(actor, "nowsec") local configId = tonumber(config["id"]) local probability, ratio = EquipGem.parseConfigValue(config["anispeedbonus"]) local value = getattrinfo(actor, "AniSpeedBonus") local id = attrname2id("AniSpeedBonus") local remarks = tonumber(ConfigDataManager.getTableValue("cfg_att_info", "remarks", "id", id)) -- lg(value) if timeInfo then local preCfgId = timeInfo["cfgId"] local preConfig = ConfigDataManager.getById("cfg_equip_gemSuit", preCfgId) local stage = EquipGem.checkSpeedTime(actor, preConfig) if stage == 1 then -- lg(1) return elseif stage == 2 then -- lg(2) EquipGem.updateAttrGroup(actor, "gemSuitAttr", "AniSpeedBonus", 0) elseif stage == 3 then -- lg(3) if EquipGem.selectRate(probability) then local num = value * ratio if remarks == 2 then num = num * 10000 < 0 and 0 or num * 10000 end -- lg("攻击速度选中:", num) EquipGem.updateAttrGroup(actor, "gemSuitAttr", "AniSpeedBonus", num) setplaydef(actor, "@gemSpeedTimeInfo", { useTime = nowSec, cfgId = configId }) end end else if EquipGem.selectRate(probability) then -- lg(0) local num = value * ratio if remarks == 2 then num = num * 10000 < 0 and 0 or num * 10000 end EquipGem.updateAttrGroup(actor, "gemSuitAttr", "AniSpeedBonus", num) setplaydef(actor, "@gemSpeedTimeInfo", { useTime = nowSec, cfgId = configId }) end end -- lg(getattrinfo(actor, "AniSpeedBonus")) -- lg("====================================") end function testgem(actor, hurt) hurt = EquipGem.setGemAttrs(actor, "damageRate", hurt) hurt = EquipGem.setGemAttrs(actor, "damageAbsorb", hurt) lg(hurt) end