From e68d5a1982c4e245a24b8aa50825d9efec8230f9 Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Wed, 12 Apr 2023 16:23:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E6=A3=8B=E7=9B=98=E4=B8=8A?= =?UTF-8?q?=E7=9A=84=E6=8A=80=E8=83=BD=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/module/battle/battle_manager.lua | 44 ++++++++++--------- .../battle/controller/battle_controller.lua | 22 +++++++--- .../skill/battle_board_skill_handle.lua | 35 +++++++-------- lua/app/userdata/battle/battle_data.lua | 4 +- .../userdata/battle/battle_grid_entity.lua | 5 --- 5 files changed, 56 insertions(+), 54 deletions(-) diff --git a/lua/app/module/battle/battle_manager.lua b/lua/app/module/battle/battle_manager.lua index 799792b6..4f687608 100644 --- a/lua/app/module/battle/battle_manager.lua +++ b/lua/app/module/battle/battle_manager.lua @@ -125,20 +125,20 @@ function BattleManager:getFirstLineLastRowPosId(row, column) return self:getPosId(1 - row, column) end -function BattleManager:getAroundPosIdsByList(posId, boardrange, cludePosIdsMap) - local ids = {} +function BattleManager:getAroundPosIdsByList(posId, boardrange, cludePosIdsMap, randomExclusion) + local posIdInfos = {} for _, info in ipairs(boardrange) do - local list = self:getAroundPosIds(posId, info.type, info.range, cludePosIdsMap) - for _, posId in ipairs(list) do - table.insert(ids, posId) - cludePosIdsMap[posId] = nil + local list = self:getAroundPosIds(posId, info.type, info.range, cludePosIdsMap, randomExclusion) + for _, info in ipairs(list) do + table.insert(posIdInfos, info) + cludePosIdsMap[info.posId] = nil end end - return ids + return posIdInfos end -function BattleManager:getAroundPosIds(posId, direction, range, cludePosIdsMap) +function BattleManager:getAroundPosIds(posId, direction, range, cludePosIdsMap, randomExclusion) local rc = self:getPosRC(posId) local r = rc.r local c = rc.c @@ -148,36 +148,38 @@ function BattleManager:getAroundPosIds(posId, direction, range, cludePosIdsMap) if cludePosIdsMap then local cludePosIds = {} for posId, _ in pairs(cludePosIdsMap) do - table.insert(cludePosIds, posId) + if not randomExclusion or not randomExclusion[posId] then + table.insert(cludePosIds, posId) + end end local count = math.min(#cludePosIds, range) for i = 1, count do - table.insert(posIdList, cludePosIds[math.random(1, #cludePosIds)]) + table.insert(posIdList, {posId = cludePosIds[math.random(1, #cludePosIds)], direction = direction}) end end elseif direction == BattleConst.BOARD_RANGE_TYPE.UP then for i = r - 1, r - range, -1 do if i >= 1 then - table.insert(posIdList, self:getPosId(i, c)) + table.insert(posIdList, {posId = self:getPosId(i, c), direction = direction}) end end elseif direction == BattleConst.BOARD_RANGE_TYPE.DOWN then for i = r + 1, r + range do if i <= BattleConst.ROW_COUNT then - table.insert(posIdList, self:getPosId(i, c)) + table.insert(posIdList, {posId = self:getPosId(i, c), direction = direction}) end end elseif direction == BattleConst.BOARD_RANGE_TYPE.LEFT then for i = c - 1, c - range, -1 do if i >= 1 then - table.insert(posIdList, self:getPosId(r, i)) + table.insert(posIdList, {posId = self:getPosId(r, i), direction = direction}) end end elseif direction == BattleConst.BOARD_RANGE_TYPE.RIGHT then for i = c + 1, c + range do if i <= BattleConst.COLUMN_COUNT then - table.insert(posIdList, self:getPosId(r, i)) + table.insert(posIdList, {posId = self:getPosId(r, i), direction = direction}) end end elseif direction == BattleConst.BOARD_RANGE_TYPE.LEFT_UP then @@ -185,7 +187,7 @@ function BattleManager:getAroundPosIds(posId, direction, range, cludePosIdsMap) if i >= 1 then for j = r - 1, r - range, -1 do if j >= 1 then - table.insert(posIdList, self:getPosId(j, i)) + table.insert(posIdList, {posId = self:getPosId(j, i), direction = direction}) end end end @@ -195,7 +197,7 @@ function BattleManager:getAroundPosIds(posId, direction, range, cludePosIdsMap) if i >= 1 then for j = r + 1, r + range do if j <= BattleConst.ROW_COUNT then - table.insert(posIdList, self:getPosId(j, i)) + table.insert(posIdList, {posId = self:getPosId(j, i), direction = direction}) end end end @@ -205,7 +207,7 @@ function BattleManager:getAroundPosIds(posId, direction, range, cludePosIdsMap) if i <= BattleConst.COLUMN_COUNT then for j = r - 1, r - range, -1 do if j >= 1 then - table.insert(posIdList, self:getPosId(j, i)) + table.insert(posIdList, {posId = self:getPosId(j, i), direction = direction}) end end end @@ -215,7 +217,7 @@ function BattleManager:getAroundPosIds(posId, direction, range, cludePosIdsMap) if i <= BattleConst.COLUMN_COUNT then for j = r + 1, r + range do if j <= BattleConst.ROW_COUNT then - table.insert(posIdList, self:getPosId(j, i)) + table.insert(posIdList, {posId = self:getPosId(j, i), direction = direction}) end end end @@ -224,9 +226,9 @@ function BattleManager:getAroundPosIds(posId, direction, range, cludePosIdsMap) if cludePosIdsMap then local newList = {} - for _, posId in ipairs(posIdList) do - if cludePosIdsMap[posId] then - table.insert(newList, posId) + for _, info in ipairs(posIdList) do + if cludePosIdsMap[info.posId] then + table.insert(newList, info) end end return newList diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 9fc037d8..8276f06e 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -69,18 +69,18 @@ function BattleController:onLinkChange() end end - for posId, _ in pairs(self.battleData:getSkillInfluenceGrids()) do + for posId, info in pairs(self.battleData:getSkillInfluenceGrids()) do + local entity = self.battleData:getGridEntity(posId) if not posIdMap[posId] then posIdMap[posId] = true - local entity = self.battleData:getGridEntity(posId) if not entity:getSkillId() then local elementType = entity:getElementType() elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1 end + end - if entity:getCell() then - entity:getCell():showCircle(true) - end + if entity:getCell() and info.direction ~= BattleConst.BOARD_RANGE_TYPE.RANDOM then + entity:getCell():showCircle(true) end end @@ -737,17 +737,25 @@ function BattleController:findSkillInfluenceGrids() local girds = self.battleData:clearSkillInfluenceGrids() for posId, _ in pairs(girds) do local entity = self.battleData:getGridEntity(posId) - entity:setNeedElimination(false) + if entity:getCell() then + entity:getCell():showCircle(false) + end end local sequence = self.battleData:getGridSequence() + local sequenceEntities = {} + for _, info in ipairs(sequence) do + local entity = self.battleData:getGridEntity(info.posId) + table.insert(sequenceEntities, entity) + end + for _, info in ipairs(sequence) do local entity = self.battleData:getGridEntity(info.posId) local skillId = entity:getSkillId() if skillId then local skillEntity = self.battleData:getSkillEntityBySkillId(skillId) if skillEntity then - BATTLE_BOARD_SKILL_HANDLE.activeBoardSkill(info.posId, skillEntity, self.battleData:getGridEnties()) + BATTLE_BOARD_SKILL_HANDLE.activeBoardSkill(info.posId, skillEntity, self.battleData:getGridEnties(), sequenceEntities) end end end diff --git a/lua/app/module/battle/skill/battle_board_skill_handle.lua b/lua/app/module/battle/skill/battle_board_skill_handle.lua index a629ebaf..2757f439 100644 --- a/lua/app/module/battle/skill/battle_board_skill_handle.lua +++ b/lua/app/module/battle/skill/battle_board_skill_handle.lua @@ -5,7 +5,7 @@ local BattleBoardSkillHandle = {} local SKILL_TYPE = BattleConst.SKILL_TYPE local SKILL_METHOD_TYPE = BattleConst.SKILL_METHOD_TYPE -local function _takeElimination(posId, skillEntity, gridEntities) +local function _takeElimination(posId, skillEntity, gridEntities, sequenceEntities) local boardrange = skillEntity:getBoardRange() if boardrange then local cludePosIdsMap = {} @@ -14,16 +14,20 @@ local function _takeElimination(posId, skillEntity, gridEntities) cludePosIdsMap[posId] = true end end - local ids = ModuleManager.BattleManager:getAroundPosIdsByList(posId, boardrange, cludePosIdsMap) + local randomExclusion = {} + for _, entity in ipairs(sequenceEntities) do + randomExclusion[entity:getPosId()] = true + end + local posIdInfos = ModuleManager.BattleManager:getAroundPosIdsByList(posId, boardrange, cludePosIdsMap, randomExclusion) cludePosIdsMap = {} - for _, posId in ipairs(ids) do - cludePosIdsMap[posId] = true + for _, info in ipairs(posIdInfos) do + cludePosIdsMap[info.posId] = info end DataManager.BattleData:cacheSkillInfluenceGrids(cludePosIdsMap) end end -local function _takeChangeAround(posId, skillEntity, gridEntities) +local function _takeChangeAround(posId, skillEntity, gridEntities, sequenceEntities) local boardrange = skillEntity:getBoardRange() if boardrange then local cludePosIdsMap = {} @@ -32,9 +36,9 @@ local function _takeChangeAround(posId, skillEntity, gridEntities) cludePosIdsMap[posId] = true end end - local ids = ModuleManager.BattleManager:getAroundPosIdsByList(posId, boardrange, cludePosIdsMap) - for _, posId in ipairs(ids) do - local entity = gridEntities[posId] + local posIdInfos = ModuleManager.BattleManager:getAroundPosIdsByList(posId, boardrange, cludePosIdsMap) + for _, info in ipairs(posIdInfos) do + local entity = gridEntities[info.posId] if entity then entity:setElementType(skillEntity:getSkillTypeParameter()) end @@ -47,21 +51,14 @@ BattleBoardSkillHandle._activeBoardSkill = { [SKILL_TYPE.CHANGE_AROUND] = _takeChangeAround, } -function BattleBoardSkillHandle.activeBoardSkill(posId, skillEntity, gridEntities) +function BattleBoardSkillHandle.activeBoardSkill(posId, skillEntity, gridEntities, sequenceEntities) if not skillEntity then return end - if skillEntity:getMethond() == SKILL_METHOD_TYPE.ON_FINAL then - local func = BattleBoardSkillHandle._activeBoardSkill[skillEntity:getSkillType()] - if func then - func(posId, skillEntity, gridEntities) - end - elseif skillEntity:getMethond() == SKILL_METHOD_TYPE.ON_ENTER then - local func = BattleBoardSkillHandle._activeBoardSkill[skillEntity:getSkillType()] - if func then - func(posId, skillEntity, gridEntities) - end + local func = BattleBoardSkillHandle._activeBoardSkill[skillEntity:getSkillType()] + if func then + func(posId, skillEntity, gridEntities, sequenceEntities) end end diff --git a/lua/app/userdata/battle/battle_data.lua b/lua/app/userdata/battle/battle_data.lua index 02f3fc7b..4e42b49d 100644 --- a/lua/app/userdata/battle/battle_data.lua +++ b/lua/app/userdata/battle/battle_data.lua @@ -129,8 +129,8 @@ function BattleData:cacheSkillInfluenceGrids(grids) if not self.skillInfluenceGrids then self.skillInfluenceGrids = {} end - for posId, status in pairs(grids) do - self.skillInfluenceGrids[posId] = true + for posId, info in pairs(grids) do + self.skillInfluenceGrids[posId] = info end end diff --git a/lua/app/userdata/battle/battle_grid_entity.lua b/lua/app/userdata/battle/battle_grid_entity.lua index b1a4c957..e9d60958 100644 --- a/lua/app/userdata/battle/battle_grid_entity.lua +++ b/lua/app/userdata/battle/battle_grid_entity.lua @@ -185,11 +185,6 @@ function BattleGridEntity:isEmptyIdle() return false end -function BattleGridEntity:setNeedElimination(need) - self.needElimination = need - self:setDirty() -end - function BattleGridEntity:getNeedElimination() return self.needElimination end