diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index d65d50f..d281341 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -596,7 +596,7 @@ function RolePlugin.bind(Role) -- end end - function Role:getHeroActiveRelation(heros) + function Role:getHeroActiveRelationData(heros) local relations = {} for _, id in pairs(heros or {}) do local hero = self.heros[id] @@ -605,20 +605,42 @@ function RolePlugin.bind(Role) relations[job] = (relations[job] or 0) + 1 end end - if not next(relations) then return {} end - local result = {} + if not next(relations) then return nil end + + local curData = nil for _, data in pairs(csvdb["unit_relationCsv"]) do - local ok = true - for typ, count in pairs(data.relation:toNumMap()) do - if (relations[typ] or 0) < count then - ok = false + local had = {} + local isDone = true + for _, count in pairs(data.relation:toArray(true, "=")) do + local find = false + for camp, _count in pairs(relations) do + if count == _count and not had[camp] then + had[camp] = true + find = true + break + end end - end - if ok then - for attr, value in pairs(data.effect:toNumMap()) do - result[AttsEnumEx[attr]] = (result[AttsEnumEx[attr]] or 0) + value + if not find then + isDone = false + break end end + if isDone then + curData = data + break + end + end + return curData + end + + function Role:getHeroActiveRelation(heros) + local data = self:getHeroActiveRelationData(heros) + local result = {} + if not data then + return result + end + for attr, value in pairs(data.effect:toNumMap()) do + result[AttsEnumEx[attr]] = (result[AttsEnumEx[attr]] or 0) + value end return result end -- libgit2 0.21.2