--法灵管理 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.lv > b.lv else return a.staticId > b.staticId 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) return tonumber(config.Value) end --获取法灵增加的属性 function this.GetEquipAddPropByDid(_did) local addProp={} if _did then LogError("英雄穿戴法灵 did====".._did) 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.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) 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] 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