miduo_client/Assets/ManagedResources/~Lua/Modules/Guild/Skill/FaLingManager.lua

380 lines
14 KiB
Lua

--法灵管理
FaLingManager = {}
local this = FaLingManager
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local equipConfig = ConfigManager.GetConfig(ConfigName.EquipConfig)
function this.Initialize()
--所有法灵数据
this.allEquipData = {}
--所有作为庇护法灵的id列表
this.allBlessIds = {}
end
--初始化所有数据
function this.InitAllEquipData(_list)
for i = 1, #_list do
local data = this.initSingleData(_list[i])
--LogError("data.did======================="..data.did)
this.allEquipData[data.did] = data
if data.belongHero ~= nil and data.belongHero ~= "" then
--LogError("计算当前英雄的法灵添加的属性================="..data.belongHero)
HeroPropManager.SetDirtyByType(data.belongHero, Hero_Prop_Type.Talisman)
end
end
--LogError("法灵 this.allEquipData len=========================="..#this.allEquipData)
end
--初始化单个法灵数据
function this.initSingleData(_data)
local data = {}
data.did = _data.id
data.staticId = _data.equipId
data.lv = _data.exp
data.itemConfig = itemConfig[data.staticId]
data.frame = GetQuantityImageByquality(data.itemConfig.Quantity)
data.icon = GetResourcePath(data.itemConfig.ResourceID)
--LogError("_data.heroId=====================".._data.heroId)
data.belongHero = _data.heroId
data.bless = {}
if _data.bless and #_data.bless > 0 then
for i = 1, #_data.bless do
local single = this.initSingleData(_data.bless[i])
--data.bless[single.did]=single
table.insert(data.bless, single)
--LogError("护佑id======================="..single.did.." 被忽悠的法灵"..data.itemConfig.Name.." "..data.lv)
table.insert(this.allBlessIds, single.did)
end
end
return data
end
--获取所有没有庇护的法灵,没有穿戴的法灵
function this.GetAllEquipDataNoBless()
local list = {}
for k, v in pairs(this.allEquipData) do
if CheckListIsContainValue1(this.allBlessIds, k) == false and (v.belongHero == nil or v.belongHero == "") then
table.insert(list, v)
end
end
table.sort(list, function(a, b)
if a.lv == b.lv then
return a.lv > b.lv
else
return a.staticId > b.staticId
end
end)
return list
end
--获取升级升星需要的材料
function this.GetAllUpListNoBless(_id)
local list = {}
for k, v in pairs(this.allEquipData) do
if CheckListIsContainValue1(this.allBlessIds, k) == false and (v.belongHero == nil or v.belongHero == "") and v.staticId == _id then
table.insert(list, v)
end
end
table.sort(list, function(a, b)
if a.lv == b.lv then
return a.lv > b.lv
else
return a.staticId > b.staticId
end
end)
return list
end
--获取可以护佑法灵集合
function this.GetCanBlessEquipList()
local list = {}
local canLv = this.GetBlessOpenLv()
for k, v in pairs(this.allEquipData) do
if CheckListIsContainValue1(this.allBlessIds, k) == false and (v.belongHero == nil or v.belongHero == "") and v.lv >= canLv then
table.insert(list, v)
end
end
table.sort(list, function(a, b)
if a.lv == b.lv then
return a.staticId > b.staticId
else
return a.lv > b.lv
end
end)
return list
end
--检测法灵护佑红点
function this.CheckEquipBlessRedPoint(_did)
local data = this.allEquipData[_did]
if data then
if data.lv < this.GetBlessOpenLv() then
return false
end
if data.bless and #data.bless == this.GetBlessEquipNum() then
return false
end
if data then
local list = this.GetCanBlessEquipList()
if #list > 0 then
return true
end
end
end
return false
end
--检测法灵强化红点
function this.CheckEquipStrongRedPoint(_did)
local data = this.allEquipData[_did]
if data then
local isEnough = false
--检测法宝能否升级
local config = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.EquipTalismana, "TalismanaId", data.staticId,
"Level", data.lv)
if config then
local cost = config.RankupBasicMaterial
local coinNum = 0
local selectMat = {}
if #cost > 0 then
isEnough = true
for i = 1, #cost do
local id = cost[i][1]
local list = {}
local bagNum = 0
if id == 0 then
id = data.staticId
list = FaLingManager.GetAllUpListNoBless(id)
if #selectMat == 0 then
for j = 1, #list do
if #selectMat < cost[i][2] and list[j].lv == 0 then
table.insert(selectMat, list[j].did)
end
end
end
bagNum = #selectMat
else
bagNum = BagManager.GetItemCountById(cost[i][1])
end
--LogError("bagnum============================"..bagNum)
if cost[i][2] > bagNum then
isEnough = false
end
end
end
end
if isEnough then
return isEnough
end
end
return false
end
--获取护佑开启等级
function this.GetBlessOpenLv()
local config = ConfigManager.GetConfigData(ConfigName.SpecialConfig, 166)
return tonumber(config.Value)
end
--获取护佑增加属性
function this.GetBlessEquipAddPro()
local config = ConfigManager.GetConfigData(ConfigName.SpecialConfig, 167)
return tonumber(config.Value)
end
--获取护佑法宝数量
function this.GetBlessEquipNum()
local config = ConfigManager.GetConfigData(ConfigName.SpecialConfig, 168)
local num = 0
local strs = string.split(config.Value, "|")
for i = 1, #strs do
local data = string.split(strs[i], "#")
local waveNum = tonumber(data[1])
if MonsterCampManager.GetFourElementTotalWave() >= waveNum then
num = tonumber(data[2])
end
end
return num
end
--获取法灵增加的属性
function this.GetEquipAddPropByDid(_did)
local addProp = {}
if this.allEquipData[_did] then
local data = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.EquipTalismana, "TalismanaId",
this.allEquipData[_did].staticId, "Level", this.allEquipData[_did].lv)
if data then
if data.Property and #data.Property > 0 then
for i = 1, #data.Property do
local key = data.Property[i][1]
local value = data.Property[i][2]
if addProp[key] then
addProp[key] = addProp[key] + value
else
addProp[key] = value
end
--LogError("法灵add key================"..key.." value==========="..value)
end
end
if this.allEquipData[_did].bless and #this.allEquipData[_did].bless > 0 then
local add = this.GetBlessEquipAddPro() / 10000
for i = 1, #this.allEquipData[_did].bless do
if this.allEquipData[this.allEquipData[_did].bless[i].did] then
--LogError("============英雄穿戴护佑1:" ..
--tostring(this.allEquipData[_did].bless[i].did) .. "/" .. tostring(_did))
local equip = this.allEquipData[this.allEquipData[_did].bless[i].did]
local data = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.EquipTalismana, "TalismanaId",
equip.staticId, "Level", equip.lv)
if data then
if data.Property and #data.Property > 0 then
for i = 1, #data.Property do
local key = data.Property[i][1]
local value = data.Property[i][2]
value = math.floor(value * add)
if addProp[key] then
addProp[key] = addProp[key] + value
else
addProp[key] = value
end
LogError("法灵add key================" .. key .. " value===========" .. value .. "/" .. tostring(add))
end
end
end
end
end
end
end
end
--[[
if this.allEquipData[_did] then
local data = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.EquipTalismana, "TalismanaId",
this.allEquipData[_did].staticId, "Level", this.allEquipData[_did].lv)
if data then
local blessNum = #this.allEquipData[_did].bless
local add = this.GetBlessEquipAddPro() * blessNum
if data.Property and #data.Property > 0 then
for i = 1, #data.Property do
local key = data.Property[i][1]
local value = data.Property[i][2]
value = value + add
addProp[key] = value
--LogError("法灵add key================"..key.." value==========="..value)
end
end
end
end
]]
return addProp
end
function this.GetEquipAddSkill(_did)
if not this.allEquipData[_did] then
return {}
end
local staticId = this.allEquipData[_did].staticId
local lvList = ConfigManager.TryGetAllConfigsDataByKey(ConfigName.EquipTalismana, "TalismanaId", staticId)
local lv = this.allEquipData[_did].lv
local skillList = {}
local curHeroData = nil
if this.allEquipData[_did].belongHero then
curHeroData = HeroManager.GetSingleHeroData(this.allEquipData[_did].belongHero)
end
local curStar = 0
for i = 1, #lvList do
if lvList[i].ShowSkill and #lvList[i].ShowSkill > 0 and tonumber(lvList[i].ShowSkill[1]) ~= nil then
local type = lvList[i].ShowSkill[1]
if type == 0 then
if lv >= lvList[i].Level then
table.insert(skillList, lvList[i].ShowSkill[3])
end
elseif type == 1 then
if lv >= lvList[i].Level and curHeroData and curHeroData.heroConfig.Profession == lvList[i].ShowSkill[2] then
table.insert(skillList, lvList[i].ShowSkill[3])
end
elseif type == 2 then
--LogError("lv=========="..lv.." lvList[i].Level=="..lvList[i].Level.." self.curHeroData.staticId=="..self.curHeroData.staticId.." lvList[i].ShowSkill[2]=="..lvList[i].ShowSkill[2])
if lv >= lvList[i].Level and curHeroData and curHeroData.heroConfig.Id == lvList[i].ShowSkill[2] then
table.insert(skillList, lvList[i].ShowSkill[3])
end
end
end
end
return skillList
end
function this.SetEquipBelongHero(_did, _heroId)
if this.allEquipData[_did] then
this.allEquipData[_did].belongHero = _heroId
end
end
--设置法灵等级
function this.SetEquipLv(_did, _lv)
if this.allEquipData[_did] then
this.allEquipData[_did].lv = _lv
end
end
--
function this.AddEquipToList(_data)
local single = this.initSingleData(_data)
if PlayerManager.handBook[6] and CheckListIsContainValue1(PlayerManager.handBook[6], single.staticId) == false then
table.insert(PlayerManager.handBook[6], single.staticId)
TianShuMiJuanManger.CheckFetterStatus(6)
end
this.allEquipData[single.did] = single
end
function this.RemoveEquip(_did)
if this.allEquipData[_did] then
this.allEquipData[_did] = nil
end
end
--获取所有没有庇护的法灵
function this.GetAllEquipData()
return this.allEquipData
end
--获取法灵数据
function this.GetEquipDataByDid(_did)
--LogError("_did=========================".._did)
if this.allEquipData[_did] then
return this.allEquipData[_did]
else
-- LogError("_did=========================".._did)
end
return nil
end
--设置法灵的庇护法灵
function this.SetEquipBlessEquip(_did, _blessId)
if this.allEquipData[_did] and this.allEquipData[_blessId] then
if #this.allEquipData[_blessId].bless > 0 then
LogError("作为庇护的法灵已有庇护")
return
end
--[_blessId]=this.allEquipData[_blessId]
--LogError("建立护佑关系--------------------------------")
table.insert(this.allEquipData[_did].bless, this.allEquipData[_blessId])
table.insert(this.allBlessIds, _blessId)
end
end
--移除法灵的庇护法灵
function this.RemoveEquipBlessEquip(_did, _blessId)
if this.allEquipData[_did] and this.allEquipData[_blessId] then
--table.removebyvalue(this.allEquipData[_did].bless,this.allEquipData[_blessId])
for k, v in pairs(this.allEquipData[_did].bless) do
if v.did == _blessId then
table.removebyvalue(this.allEquipData[_did].bless, v)
end
end
table.removebyvalue(this.allBlessIds, _blessId)
end
end
return this