diff --git a/lua/app/module/battle/controller/battle_controller_pvp.lua b/lua/app/module/battle/controller/battle_controller_pvp.lua index 1aaf255f..ae51e29a 100644 --- a/lua/app/module/battle/controller/battle_controller_pvp.lua +++ b/lua/app/module/battle/controller/battle_controller_pvp.lua @@ -251,7 +251,13 @@ end function BattleControllerPVP:checkDefBoard() if self:getCurActionSide() == SIDE_DEF then - local path = board_heler:findPvpLinkOptimalSolution(self, self:getAtkMinRow(), 1) + local elementTypeCoefficient = {} + local teamEntity = self.battleData:getDefTeam() + local members = teamEntity:getAllMembers() + for k, v in pairs(members) do + elementTypeCoefficient[v:getMatchType()] = v:getAtk() + end + local path = board_heler:findPvpLinkOptimalSolution(self, self:getAtkMinRow(), 1, elementTypeCoefficient) if path and #path >= self:getMinEliminationCount() then if self.showCheckDefBoardSeq then self.showCheckDefBoardSeq:Kill() diff --git a/lua/app/module/battle/helper/board_helper.lua b/lua/app/module/battle/helper/board_helper.lua index 851864f5..c8bccddd 100644 --- a/lua/app/module/battle/helper/board_helper.lua +++ b/lua/app/module/battle/helper/board_helper.lua @@ -21,7 +21,7 @@ function BoardHelper:recycleedEmptyTable(emptyTable) end end -function BoardHelper:findPvpLinkOptimalSolution(battleController, startRow, endRow) +function BoardHelper:findPvpLinkOptimalSolution(battleController, startRow, endRow, elementTypeCoefficient) local battleData = battleController.battleData local gridMap = BoardHelper:getEmptyTable() local gridEntities = BoardHelper:getEmptyTable() @@ -43,6 +43,11 @@ function BoardHelper:findPvpLinkOptimalSolution(battleController, startRow, endR local maxPath local maxPathCount = 0 + local newHaveSkill = false + local lastMainElementType + if not elementTypeCoefficient then + elementTypeCoefficient = BoardHelper:getEmptyTable() + end for _, posId in pairs(gridEntities) do local entity = gridMap[posId] local mainElementType @@ -50,15 +55,33 @@ function BoardHelper:findPvpLinkOptimalSolution(battleController, startRow, endR mainElementType = entity:getElementType() local tree = BoardHelper:getEmptyTable() self:getCanlinkTree(posId, gridMap, tree, mainElementType) - + local checked = BoardHelper:getEmptyTable() local haveSkill = false - local path = self:findMaxPath(posId, tree, checked, haveSkill, gridMap) + local path, getSkill = self:findMaxPath(posId, tree, checked, haveSkill, gridMap) local count = #path - if count > maxPathCount then + if getSkill and not newHaveSkill then maxPath = path maxPathCount = count + newHaveSkill = getSkill + lastMainElementType = mainElementType + else + local curCoefficient = elementTypeCoefficient[mainElementType] or 0 + local lastCoefficient = elementTypeCoefficient[lastMainElementType] or 0 + if not getSkill and newHaveSkill then + BoardHelper:recycleedEmptyTable(path) + else + if count * curCoefficient > maxPathCount * lastCoefficient then + maxPath = path + maxPathCount = count + newHaveSkill = getSkill + lastMainElementType = mainElementType + else + BoardHelper:recycleedEmptyTable(path) + end + end end + for posId, info in pairs(tree) do BoardHelper:recycleedEmptyTable(info) end @@ -67,6 +90,7 @@ function BoardHelper:findPvpLinkOptimalSolution(battleController, startRow, endR end end + BoardHelper:recycleedEmptyTable(elementTypeCoefficient) BoardHelper:recycleedEmptyTable(gridMap) return maxPath