123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646 |
- 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
|