diff --git a/lua/app/module/battle/battle_manager.lua b/lua/app/module/battle/battle_manager.lua index 0935f870..ef4960dc 100644 --- a/lua/app/module/battle/battle_manager.lua +++ b/lua/app/module/battle/battle_manager.lua @@ -219,43 +219,35 @@ function BattleManager:getAroundPosIds(posId, direction, range, cludePosIdsMap, end end elseif direction == BattleConst.BOARD_RANGE_TYPE.LEFT_UP then - for i = c - 1, c - range, -1 do - if i >= 1 then - for j = r - 1, r - range, -1 do - if j >= 1 then - table.insert(posIdList, {posId = self:getPosId(j, i), direction = direction}) - end - end + for i = 1, range do + local newR = r - i + local newC = c - i + if newR >= 1 and newC >= 1 then + table.insert(posIdList, {posId = self:getPosId(newR, newC), direction = direction}) end end elseif direction == BattleConst.BOARD_RANGE_TYPE.LEFT_DOWN then - for i = c - 1, c - range, -1 do - if i >= 1 then - for j = r + 1, r + range do - if j <= BattleConst.ROW_COUNT then - table.insert(posIdList, {posId = self:getPosId(j, i), direction = direction}) - end - end + for i = 1, range do + local newR = r + i + local newC = c - i + if newR <= BattleConst.ROW_COUNT and newC >= 1 then + table.insert(posIdList, {posId = self:getPosId(newR, newC), direction = direction}) end end elseif direction == BattleConst.BOARD_RANGE_TYPE.RIGHT_UP then - for i = c + 1, c + range do - if i <= BattleConst.COLUMN_COUNT then - for j = r - 1, r - range, -1 do - if j >= 1 then - table.insert(posIdList, {posId = self:getPosId(j, i), direction = direction}) - end - end + for i = 1, range do + local newR = r - i + local newC = c + i + if newR >= 1 and newC <= BattleConst.COLUMN_COUNT then + table.insert(posIdList, {posId = self:getPosId(newR, newC), direction = direction}) end end elseif direction == BattleConst.BOARD_RANGE_TYPE.RIGHT_DOWN then - for i = c + 1, c + range do - if i <= BattleConst.COLUMN_COUNT then - for j = r + 1, r + range do - if j <= BattleConst.ROW_COUNT then - table.insert(posIdList, {posId = self:getPosId(j, i), direction = direction}) - end - end + for i = 1, range do + local newR = r + i + local newC = c + i + if newR <= BattleConst.ROW_COUNT and newC <= BattleConst.COLUMN_COUNT then + table.insert(posIdList, {posId = self:getPosId(newR, newC), direction = direction}) end end end