From 5de785f28e49e884ea7da864b261d4ff1b24e387 Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Tue, 20 Jun 2023 11:35:23 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/module/battle/battle_manager.lua | 48 ++++++++++-------------- 1 file changed, 20 insertions(+), 28 deletions(-) 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