diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 1be6f5b5..a5e18c10 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -134,10 +134,10 @@ end function BattleController:onLinkChange() self.battleUI:hideAllSfxLine() - local needFalsePosMap = {} + self.linkChangeNeedFalsePosMap = table.clearOrCreate(self.linkChangeNeedFalsePosMap) for posId, entity in pairs(self.battleData:getGridEnties()) do if entity:getCell() then - needFalsePosMap[posId] = entity:getCell() + self.linkChangeNeedFalsePosMap[posId] = entity:getCell() end end @@ -162,8 +162,8 @@ function BattleController:onLinkChange() if entity:getCell() then entity:getCell():showHighLight(true, mainElementType, self.battleUI) end - if needFalsePosMap[info.posId] then - needFalsePosMap[info.posId] = nil + if self.linkChangeNeedFalsePosMap[info.posId] then + self.linkChangeNeedFalsePosMap[info.posId] = nil end if index < count then local nextPosId = sequence[index + 1].posId @@ -183,7 +183,7 @@ function BattleController:onLinkChange() end end - for posId, cell in pairs(needFalsePosMap) do + for posId, cell in pairs(self.linkChangeNeedFalsePosMap) do cell:showHighLight(false) end @@ -982,58 +982,58 @@ function BattleController:calculateCurElimination(onlyCheck) if skillId then skillEntity = self.battleData:getSkillEntityBySkillId(skillId) end - local breakedMap = {} - local boomGridIds = {} - local sequenceMap = {} + self.breakedMap = table.clearOrCreate(self.breakedMap) + self.boomGridIds = table.clearOrCreate(self.boomGridIds) + self.sequenceMap = table.clearOrCreate(self.sequenceMap) + self.aniSequence = table.clearOrCreate(self.aniSequence) for idx, info in ipairs(sequence) do - sequenceMap[info.posId] = idx + self.sequenceMap[info.posId] = idx end local time = 0 local skillTime = BattleConst.SKILL_ELIMINATION_TIME - local aniSequence = {} for idx, info in ipairs(sequence) do local posId = info.posId - self:dealGridBreak(posId, GRID_BREAK_CONDITION.LINE, time, breakedMap, sequenceMap, aniSequence, boomGridIds, onlyCheck) + self:dealGridBreak(posId, GRID_BREAK_CONDITION.LINE, time, self.breakedMap, self.sequenceMap, self.aniSequence, self.boomGridIds, onlyCheck) time = time + BattleConst.ELIMINATION_INTERVAL end local randomPosList, influenceElementTypeMap - for i, info in ipairs(aniSequence) do + for i, info in ipairs(self.aniSequence) do if info.isSkill then - randomPosList, influenceElementTypeMap = self:dealSkillElement(info.timeIdx + skillTime, breakedMap, sequenceMap, aniSequence, boomGridIds, onlyCheck) - local aniUnit = aniSequence[i] + randomPosList, influenceElementTypeMap = self:dealSkillElement(info.timeIdx + skillTime, self.breakedMap, self.sequenceMap, self.aniSequence, self.boomGridIds, onlyCheck) + local aniUnit = self.aniSequence[i] aniUnit.rangeList = skillEntity:getBoardRange() aniUnit.randomPosList = randomPosList break end end - local lineCount = 0 - local elementTypeMap = {} + self.elementTypeMap = table.clearOrCreate(self.elementTypeMap) + self.effectGridMap = table.clearOrCreate(self.effectGridMap) local linkElementType + local lineCount = 0 local gridEntities = self.battleData:getGridEnties() - local effectGridMap = {} - for _, info in ipairs(aniSequence) do + for _, info in ipairs(self.aniSequence) do local entity = gridEntities[info.posId] local elementType = entity:getElementType() if not info.noAni and info.isIdle then if not info.isSkill then if not entity:isElmentTypeInvalid() then - elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1 + self.elementTypeMap[elementType] = (self.elementTypeMap[elementType] or 0) + 1 end - if boomGridIds[info.posId] and boomGridIds[info.posId][GRID_BREAK_CONDITION.LINE] then + if self.boomGridIds[info.posId] and self.boomGridIds[info.posId][GRID_BREAK_CONDITION.LINE] then lineCount = lineCount + 1 linkElementType = elementType end end end if entity:getEffectType() and info.isIdle then - effectGridMap[info.posId] = true + self.effectGridMap[info.posId] = true end end - return aniSequence, influenceElementTypeMap, lineCount, elementTypeMap, linkElementType, effectGridMap + return self.aniSequence, influenceElementTypeMap, lineCount, self.elementTypeMap, linkElementType, self.effectGridMap end function BattleController:dealGridBreak(posId, condition, time, breakedMap, sequenceMap, aniSequence, gridMap, onlyCheck) @@ -1081,7 +1081,7 @@ function BattleController:dealGridBreak(posId, condition, time, breakedMap, sequ if entity:getEffectType() then local succ, list = BATTLE_GRID_EFFECT_HANDLE.gridEffectOn(posId, gridEntities, BattleConst.GRID_EFFECT_TRIGGER_TYPE.ON_GRID_BREAK, self, onlyCheck) if list then - aniUnit.aniPosList = {} + aniUnit.aniPosList = table.clearOrCreate(aniUnit.aniPosList) aniUnit.overCallback = aniUnit.callback aniUnit.callback = nil for index, id in ipairs(list) do @@ -1173,15 +1173,15 @@ function BattleController:tryShowSelectSkillComp(needDelay, onlyCommonSkill) end function BattleController:fillBoard(isRoundBeginCheck) - local pathMap = {} - local columnCount = {} - local gridMap = {} + self.fillBoardPathMap = table.clearOrCreate(self.fillBoardPathMap) + self.fillColumnCount = table.clearOrCreate(self.fillColumnCount) + self.fillGridMap = table.clearOrCreate(self.fillGridMap) for c = 1, BattleConst.COLUMN_COUNT do for r = BattleConst.ROW_COUNT, 1, -1 do local posId = ModuleManager.BattleManager:getPosId(r, c) local entity = self.battleData:getGridEntity(posId) if entity:getIsIdle() then - self:fillThisPos(posId, columnCount, gridMap) + self:fillThisPos(posId, self.fillColumnCount, self.fillGridMap) end end end @@ -1189,7 +1189,7 @@ function BattleController:fillBoard(isRoundBeginCheck) while true do local find = false for c = 1, BattleConst.COLUMN_COUNT do - local list = gridMap[c] + local list = self.fillGridMap[c] if list and list[1] then -- 此列有需要填充的元素 local entity = table.remove(list, 1) if entity then @@ -1209,13 +1209,13 @@ function BattleController:fillBoard(isRoundBeginCheck) local posId = ModuleManager.BattleManager:getPosId(r, c) local entity = self.battleData:getGridEntity(posId) if #entity:getPath() > 0 then - pathMap[posId] = entity:getPath() + self.fillBoardPathMap[posId] = entity:getPath() entity:clearPath() end end end - self.battleUI:fallGrid(pathMap, isRoundBeginCheck, function() + self.battleUI:fallGrid(self.fillBoardPathMap, isRoundBeginCheck, function() self:onFillBoardOver(isRoundBeginCheck) end) end @@ -1333,24 +1333,24 @@ function BattleController:popBoardCacheSkill(callback) local skillList, skillCount = self.battleData:getCacheBoardSkill() self.battleData:clearCacheBoardSkill() if self.battleUI and skillCount > 0 then - local posidList = {} + self.popSkillPosIdList = table.clearOrCreate(self.popSkillPosIdList) for posId, entity in pairs(self.battleData:getGridEnties()) do if entity:isEmptyIdle() and not entity:getIsIdle() then - table.insert(posidList, posId) + table.insert(self.popSkillPosIdList, posId) end end - posidList = table.shuffle(posidList) - local newSkillId = {} + self.popSkillPosIdList = table.shuffle(self.popSkillPosIdList) + self.popNewSkillId = table.shuffle(self.popNewSkillId) for index, info in ipairs(skillList) do - if posidList[1] then - newSkillId[index] = info - newSkillId[index].posId = table.remove(posidList) + if self.popSkillPosIdList[1] then + self.popNewSkillId[index] = info + self.popNewSkillId[index].posId = table.remove(self.popSkillPosIdList) else break end end - self.battleUI:cacheSkillAni(newSkillId, true, callback) + self.battleUI:cacheSkillAni(self.popNewSkillId, true, callback) else if callback then callback() @@ -1359,18 +1359,18 @@ function BattleController:popBoardCacheSkill(callback) end function BattleController:generateSkill(callback) - local map = {} - local excludeMap = {} + self.generateSkillMap = table.clearOrCreate(self.generateSkillMap) + self.generateExcludeMap = table.clearOrCreate(self.generateExcludeMap) for _, skillEntity in pairs(self.battleData:getSkillEntities()) do if skillEntity:getEnergyEnough() then - local list = self:getSkillElementList(skillEntity:getPosition(), 1, true, excludeMap) + local list = self:getSkillElementList(skillEntity:getPosition(), 1, true, self.generateExcludeMap) if list[1] then - map[skillEntity:getPosition()] = + self.generateSkillMap[skillEntity:getPosition()] = { skillId = skillEntity:getSkillId(), posId = list[1] } - excludeMap[list[1]] = true + self.generateExcludeMap[list[1]] = true end end end @@ -1382,8 +1382,8 @@ function BattleController:generateSkill(callback) return end - self.battleUI:generateSkillAni(map, function() - for elementType, info in pairs(map) do + self.battleUI:generateSkillAni(self.generateSkillMap, function() + for elementType, info in pairs(self.generateSkillMap) do self:setGridSkillId(info.posId, info.skillId) end @@ -1409,28 +1409,28 @@ function BattleController:generateGridType(skillTypeParameter, monsterPos) return end - local list = {} + self.generateGridTypeList = table.clearOrCreate(self.generateGridTypeList) local count = 0 for posId, entity in pairs(self.battleData:getGridEnties()) do if entity:isEmptyIdle() then - table.insert(list, entity) + table.insert(self.generateGridTypeList, entity) count = count + 1 end end - list = table.shuffle(list) + self.generateGridTypeList = table.shuffle(self.generateGridTypeList) if count > 0 then - local map = {} + self.generateGridTypeMap = table.clearOrCreate(self.generateGridTypeMap) local minCount = math.min(skillTypeParameter[2], count) for i = minCount, 1, -1 do - local entity = table.remove(list, math.random(1, i)) - map[entity:getPosId()] = { + local entity = table.remove(self.generateGridTypeList, math.random(1, i)) + self.generateGridTypeMap[entity:getPosId()] = { gridType = skillTypeParameter[1], elementType = entity:getElementType() } end - self.battleUI:showMonsterSkillAni(map, monsterPos, function() - for posId, info in pairs(map) do + self.battleUI:showMonsterSkillAni(self.generateGridTypeMap, monsterPos, function() + for posId, info in pairs(self.generateGridTypeMap) do self.battleData:setGridInfo(posId, info) end end) @@ -1438,49 +1438,55 @@ function BattleController:generateGridType(skillTypeParameter, monsterPos) end function BattleController:lockElement(lcokElementType, isUnlock) - local elementTypeMap = {} - local list - local lockElementMap + if not self.lockElementElementTypeMap then + self.lockElementElementTypeMap = table.clearOrCreate(self.lockElementElementTypeMap) + else + for k, v in pairs(self.lockElementElementTypeMap) do + self.lockElementElementTypeMap[k] = table.clearOrCreate(self.lockElementElementTypeMap[k]) + end + end + if not self.lockElementMap then + self.lockElementMap = table.clearOrCreate(self.lockElementMap) + else + for k, v in pairs(self.lockElementMap) do + self.lockElementMap[k] = table.clearOrCreate(self.lockElementMap[k]) + end + end + self.lockElementList = table.clearOrCreate(self.lockElementList) local locked = false for posId, entity in pairs(self.battleData:getGridEnties()) do local elementType = entity:getElementType() if not isUnlock then if entity:isEmptyIdle() then - if not elementTypeMap[elementType] then - elementTypeMap[elementType] = {} + local elementTypeMapUnit = self.lockElementElementTypeMap[elementType] + if not elementTypeMapUnit or not elementTypeMapUnit[1] then + self.lockElementElementTypeMap[elementType] = table.clearOrCreate(self.lockElementElementTypeMap[elementType]) + elementTypeMapUnit = self.lockElementElementTypeMap[elementType] if not isUnlock then - if not list then - list = {} - end - table.insert(list, elementType) + table.insert(self.lockElementList, elementType) end end - table.insert(elementTypeMap[elementType], posId) + table.insert(elementTypeMapUnit, posId) end if entity:isLock() then locked = true end else if entity:isLock() then - if not lockElementMap then - lockElementMap = {} + if not self.lockElementMap[elementType] then + self.lockElementMap[elementType] = table.clearOrCreate(self.lockElementMap[elementType]) end - if not lockElementMap[elementType] then - lockElementMap[elementType] = {} - end - table.insert(lockElementMap[elementType], posId) + table.insert(self.lockElementMap[elementType], posId) end end end if isUnlock then - if lockElementMap then - for elementType, list in pairs(lockElementMap) do - self.battleData:cacheLockElement(elementType, nil) - for _, posId in ipairs(list) do - self.battleData:setGridType(posId, BattleConst.GRID_TYPE.EMPTY) - end + for elementType, list in pairs(self.lockElementMap) do + self.battleData:cacheLockElement(elementType, nil) + for _, posId in ipairs(list) do + self.battleData:setGridType(posId, BattleConst.GRID_TYPE.EMPTY) end end else @@ -1489,13 +1495,13 @@ function BattleController:lockElement(lcokElementType, isUnlock) end local elementType = lcokElementType if elementType == BattleConst.ELEMENT_TYPE.NONE then - if not list or not list[1] then + if not self.lockElementList[1] then return end - elementType = list[math.random(1, #list)] + elementType = self.lockElementList[math.random(1, #self.lockElementList)] end self.battleData:cacheLockElement(elementType, true) - local list = elementTypeMap[elementType] + local list = self.lockElementElementTypeMap[elementType] if list then for _, posId in ipairs(list) do self.battleData:setGridType(posId, BattleConst.GRID_TYPE.LOCK) @@ -1505,14 +1511,14 @@ function BattleController:lockElement(lcokElementType, isUnlock) end function BattleController:getSkillElementList(elementType, count, useAlternate, excludeMap) - local result = {} + self.getSkillElementListResult = table.clearOrCreate(self.getSkillElementListResult) local gridEntities = self.battleData:getGridEnties() if not gridEntities then - return result + return self.getSkillElementListResult end - local sameElementList = {} - local alternateList = {} + self.getSkillElementListSameElementList = table.clearOrCreate(self.getSkillElementListSameElementList) + self.getSkillElementListAlternateList = table.clearOrCreate(self.getSkillElementListAlternateList) local addCount = 0 for row = 1, BattleConst.ROW_COUNT do @@ -1521,48 +1527,48 @@ function BattleController:getSkillElementList(elementType, count, useAlternate, local entity = gridEntities[posId] if entity and entity:canChangeInfo() and not excludeMap[posId] then if entity:getElementType() == elementType then - table.insert(sameElementList, posId) + table.insert(self.getSkillElementListSameElementList, posId) else - table.insert(alternateList, posId) + table.insert(self.getSkillElementListAlternateList, posId) end end end local remainCount = count - addCount if remainCount <= 0 then - return result + return self.getSkillElementListResult end for i = 1, remainCount do - if not sameElementList[i] then + if not self.getSkillElementListSameElementList[i] then break end - table.insert(result, table.remove(sameElementList, math.random(1, #sameElementList))) + table.insert(self.getSkillElementListResult, table.remove(self.getSkillElementListSameElementList, math.random(1, #self.getSkillElementListSameElementList))) addCount = addCount + 1 if addCount >= count then - return result + return self.getSkillElementListResult end end if addCount < count and useAlternate then for i = 1, count - addCount do - if not alternateList[1] then + if not self.getSkillElementListAlternateList[1] then break end - table.insert(result, table.remove(alternateList, math.random(1, #alternateList))) + table.insert(self.getSkillElementListResult, table.remove(self.getSkillElementListAlternateList, math.random(1, #self.getSkillElementListAlternateList))) addCount = addCount + 1 if addCount >= count then - return result + return self.getSkillElementListResult end end end if addCount >= count then - return result + return self.getSkillElementListResult end end - return result + return self.getSkillElementListResult end ---- 从一个点直接遍历所有相关的路径 @@ -1641,21 +1647,21 @@ function BattleController:getRandomGridInfo() elementType = table.remove(fixedRandomList, 1) else local map = self.battleData:getElementTypeMap() - local indexs = {} - local typeList = {} + self.getRandomGridInfoIndexs = table.clearOrCreate(self.getRandomGridInfoIndexs) + self.getRandomGridInfoTypeList = table.clearOrCreate(self.getRandomGridInfoTypeList) for typeName, typeNum in pairs(BattleConst.ELEMENT_TYPE) do if not self:getSealElementType()[typeNum] and self.battleData:getSkillEntityByElement(typeNum) then local weight = ((map[typeNum] or 0) + 1) * BattleConst.ELEMENT_WIGHT if weight > BattleConst.MAX_ELEMENT_WIGHT then weight = BattleConst.MAX_ELEMENT_WIGHT end - table.insert(indexs, weight) - table.insert(typeList, typeNum) + table.insert(self.getRandomGridInfoIndexs, weight) + table.insert(self.getRandomGridInfoTypeList, typeNum) end end - local index = GFunc.getRandomIndex(indexs) - elementType = typeList[index] + local index = GFunc.getRandomIndex(self.getRandomGridInfoIndexs) + elementType = self.getRandomGridInfoTypeList[index] end return {gridType = gridType, elementType = elementType} @@ -1671,10 +1677,10 @@ function BattleController:findSkillInfluenceGrids() end local sequence = self.battleData:getGridSequence() - local sequenceEntities = {} + self.skillInfluenceGridsSequenceEntities = table.clearOrCreate(self.skillInfluenceGridsSequenceEntities) for _, info in ipairs(sequence) do local entity = self.battleData:getGridEntity(info.posId) - table.insert(sequenceEntities, entity) + table.insert(self.skillInfluenceGridsSequenceEntities, entity) end for _, info in ipairs(sequence) do @@ -1683,7 +1689,7 @@ function BattleController:findSkillInfluenceGrids() if skillId then local skillEntity = self.battleData:getSkillEntityBySkillId(skillId) if skillEntity then - BATTLE_BOARD_SKILL_HANDLE.activeBoardSkill(info.posId, skillEntity, self.battleData:getGridEnties(), sequenceEntities, self) + BATTLE_BOARD_SKILL_HANDLE.activeBoardSkill(info.posId, skillEntity, self.battleData:getGridEnties(), self.skillInfluenceGridsSequenceEntities, self) end end end @@ -1696,14 +1702,13 @@ function BattleController:getRandomSkillList(getCount, onlyCommonSkill, excludeM end getCount = getCount or BattleConst.SKILL_SELECT_COUNT - local result = {} + self.randomSkillList = table.clearOrCreate(self.randomSkillList) + self.randomSkillMap = table.clearOrCreate(self.randomSkillMap) + self.randomSkillNewSkillPool = table.clearOrCreate(self.randomSkillNewSkillPool) + self.randomSkillSkillWeight = table.clearOrCreate(self.randomSkillSkillWeight) local cfg = ConfigManager:getConfig("skill_rogue") local skillPool = self.battleData:getSkillPool() - local map = {} - local count = 0 - local newSkillPool = {} - local skillWeight = {} if not onlyCommonSkill then for elementType, list in pairs(skillPool) do -- 先遍历一下未解锁的技能 @@ -1711,12 +1716,12 @@ function BattleController:getRandomSkillList(getCount, onlyCommonSkill, excludeM local skillEntity = self.battleData:getSkillEntityByElement(elementType) if skillEntity then local skillId = skillEntity:getUnlockId() - if skillId and not map[skillId] then + if skillId and not self.randomSkillMap[skillId] then local skillCfg = cfg[skillId] - table.insert(newSkillPool, skillId) - table.insert(skillWeight, skillCfg.weight) + table.insert(self.randomSkillNewSkillPool, skillId) + table.insert(self.randomSkillSkillWeight, skillCfg.weight) count = count + 1 - map[skillId] = true + self.randomSkillMap[skillId] = true end end end @@ -1724,19 +1729,19 @@ function BattleController:getRandomSkillList(getCount, onlyCommonSkill, excludeM if count >= 3 then -- 如果未解锁的技能大于等于3,则直接返回三个解锁技能 for i = 1, 3 do - local index = GFunc.getRandomIndex(skillWeight) - local skillId = table.remove(newSkillPool, index) - table.remove(skillWeight, index) + local index = GFunc.getRandomIndex(self.randomSkillSkillWeight) + local skillId = table.remove(self.randomSkillNewSkillPool, index) + table.remove(self.randomSkillSkillWeight, index) count = count - 1 - table.insert(result, skillId) + table.insert(self.randomSkillList, skillId) end - return table.shuffle(result) + return table.shuffle(self.randomSkillList) end if excludeMap then for skillId, _ in pairs(excludeMap) do - map[skillId] = true + self.randomSkillMap[skillId] = true end end @@ -1746,11 +1751,11 @@ function BattleController:getRandomSkillList(getCount, onlyCommonSkill, excludeM local skillCfg = cfg[skillId] if skillCfg and (not skillCfg.limit_times or self.battleData:getSkillCount(skillId) < skillCfg.limit_times) then - if not map[skillId] and (not skillCfg.unlock or self.battleData:getSkillCount(skillCfg.unlock) > 0) then - table.insert(newSkillPool, skillId) - table.insert(skillWeight, skillCfg.weight) + if not self.randomSkillMap[skillId] and (not skillCfg.unlock or self.battleData:getSkillCount(skillCfg.unlock) > 0) then + table.insert(self.randomSkillNewSkillPool, skillId) + table.insert(self.randomSkillSkillWeight, skillCfg.weight) count = count + 1 - map[skillId] = true + self.randomSkillMap[skillId] = true end end end @@ -1758,11 +1763,11 @@ function BattleController:getRandomSkillList(getCount, onlyCommonSkill, excludeM end if count > 0 then - local index = GFunc.getRandomIndex(skillWeight) - local skillId = table.remove(newSkillPool, index) - table.remove(skillWeight, index) + local index = GFunc.getRandomIndex(self.randomSkillSkillWeight) + local skillId = table.remove(self.randomSkillNewSkillPool, index) + table.remove(self.randomSkillSkillWeight, index) count = count - 1 - table.insert(result, skillId) + table.insert(self.randomSkillList, skillId) getCount = getCount - 1 end end @@ -1771,9 +1776,9 @@ function BattleController:getRandomSkillList(getCount, onlyCommonSkill, excludeM if not self:getNotInvolvedSkills()[skillId] then if info.universal then if not info.limit_times or self.battleData:getSkillCount(skillId) < info.limit_times then - if not map[skillId] then - table.insert(newSkillPool, skillId) - table.insert(skillWeight, info.weight) + if not self.randomSkillMap[skillId] then + table.insert(self.randomSkillNewSkillPool, skillId) + table.insert(self.randomSkillSkillWeight, info.weight) count = count + 1 end end @@ -1782,17 +1787,17 @@ function BattleController:getRandomSkillList(getCount, onlyCommonSkill, excludeM end for i = 1, getCount do - local index = GFunc.getRandomIndex(skillWeight) - local skillId = table.remove(newSkillPool, index) - table.remove(skillWeight, index) + local index = GFunc.getRandomIndex(self.randomSkillSkillWeight) + local skillId = table.remove(self.randomSkillNewSkillPool, index) + table.remove(self.randomSkillSkillWeight, index) count = count - 1 - table.insert(result, skillId) + table.insert(self.randomSkillList, skillId) if count <= 0 then break end end - result = table.shuffle(result) + local result = table.shuffle(self.randomSkillList) return result end @@ -1835,10 +1840,10 @@ function BattleController:selectSKillNextToStep() end function BattleController:changeElementType(count, elementType) - local map = {} + self.changeElementTypeMap = table.clearOrCreate(self.changeElementTypeMap) for _, entity in pairs(self.battleData:getGridEnties()) do if entity:canChangeInfo() and entity:getElementType() ~= elementType then - map[entity] = elementType + self.changeElementTypeMap[entity] = elementType count = count - 1 if count <= 0 then break @@ -1846,7 +1851,7 @@ function BattleController:changeElementType(count, elementType) end end - self:changeElementTypeByMap(map) + self:changeElementTypeByMap(self.changeElementTypeMap) end function BattleController:changeElementTypeByMap(changeMap) @@ -1872,12 +1877,12 @@ function BattleController:killGrids(posIdList) end function BattleController:killRowOrColumn(infoList) - local map = {} + self.killRowOrColumnMap = table.clearOrCreate(self.killRowOrColumnMap) for _, info in ipairs(infoList) do if info.posList then for i, posId in ipairs(info.posList) do - if not map[posId] then - map[posId] = true + if not self.killRowOrColumnMap[posId] then + self.killRowOrColumnMap[posId] = true local entity = DataManager.BattleData:getGridEntity(posId) entity:setIsIdle(true) end @@ -1945,13 +1950,13 @@ function BattleController:shuffleBoard(callback) self.battleData:setGridEntitiesPosId(changeInfo) self.battleUI:shuffleBoard(changeInfo, callback) else - local resetList = {} + self.resetList = table.clearOrCreate(self.resetList) for posId, entity in pairs(self.battleData:getGridEnties()) do if entity:isCanFallStatus() then - table.insert(resetList, entity) + table.insert(self.resetList, entity) end end - local resetInfo = self:resetGrids(resetList) + local resetInfo = self:resetGrids(self.resetList) if not resetInfo then if EDITOR_MODE then Logger.logHighlight("----- 处于无法消除状态 -----") @@ -1982,47 +1987,52 @@ function BattleController:shuffleBoard(callback) end function BattleController:getShuffleBoardInfo() - local posList = {} - local gridEntityList = {} - local anySkillList = {} - local posMap = {} + self.shuffleBoardPosList = table.clearOrCreate(self.shuffleBoardPosList) + self.shuffleBoardAnySkillList = table.clearOrCreate(self.shuffleBoardAnySkillList) + self.shuffleBoardPosMap = table.clearOrCreate(self.shuffleBoardPosMap) + self.shuffleBoardCountMap = table.clearOrCreate(self.shuffleBoardCountMap) + self.shuffleBoardCantLinkMap = table.clearOrCreate(self.shuffleBoardCantLinkMap) + if not self.shuffleBoardList then + self.shuffleBoardList = table.clearOrCreate(self.shuffleBoardList) + else + for elementType, _ in pairs(self.shuffleBoardList) do + self.shuffleBoardList[elementType] = table.clearOrCreate(self.shuffleBoardList[elementType]) + end + end local anySkillCount = 0 - local gridEntityCountMap = {} - local gridEntityCantLinkMap = {} for posId, entity in pairs(self.battleData:getGridEnties()) do if entity:isCanFallStatus() then if entity:getSkillId() then local skillEntity = self.battleData:getSkillEntityBySkillId(entity:getSkillId()) local elementType = skillEntity:getPosition() if skillEntity:getIgnoreElementType() then - table.insert(anySkillList, entity) + table.insert(self.shuffleBoardAnySkillList, entity) anySkillCount = anySkillCount + 1 else - if not gridEntityList[elementType] then - gridEntityList[elementType] = {} - gridEntityCountMap[elementType] = 0 + if not self.shuffleBoardList[elementType] then + self.shuffleBoardList[elementType] = table.clearOrCreate(self.shuffleBoardList[elementType]) end - table.insert(gridEntityList[elementType], entity) - gridEntityCountMap[elementType] = (gridEntityCountMap[elementType] or 0) + 1 + table.insert(self.shuffleBoardList[elementType], entity) + self.shuffleBoardCountMap[elementType] = (self.shuffleBoardCountMap[elementType] or 0) + 1 end else local elementType = entity:getElementType() - if not gridEntityList[elementType] then - gridEntityList[elementType] = {} + if not self.shuffleBoardList[elementType] then + self.shuffleBoardList[elementType] = table.clearOrCreate(self.shuffleBoardList[elementType]) end - table.insert(gridEntityList[elementType], entity) - gridEntityCountMap[elementType] = (gridEntityCountMap[elementType] or 0) + 1 + table.insert(self.shuffleBoardList[elementType], entity) + self.shuffleBoardCountMap[elementType] = (self.shuffleBoardCountMap[elementType] or 0) + 1 if not entity:canLink() then - gridEntityCantLinkMap[elementType] = (gridEntityCountMap[elementType] or 0) + 1 + self.shuffleBoardCantLinkMap[elementType] = (self.shuffleBoardCantLinkMap[elementType] or 0) + 1 end end - table.insert(posList, posId) - posMap[posId] = true + table.insert(self.shuffleBoardPosList, posId) + self.shuffleBoardPosMap[posId] = true end end - for elementType, list in pairs(gridEntityList) do - table.sort(gridEntityList[elementType], function(a, b) + for elementType, list in pairs(self.shuffleBoardList) do + table.sort(self.shuffleBoardList[elementType], function(a, b) if a:getSkillId() and not b:getSkillId() then return false elseif not a:getSkillId() and b:getSkillId() then @@ -2035,11 +2045,10 @@ function BattleController:getShuffleBoardInfo() local needCount = self:getMinEliminationCount() - local tempList local find = false - for elementType, list in pairs(gridEntityList) do - local count = gridEntityCountMap[elementType] or 0 - local cantLinkCount = gridEntityCantLinkMap[elementType] or 0 + for elementType, list in pairs(self.shuffleBoardList) do + local count = self.shuffleBoardCountMap[elementType] or 0 + local cantLinkCount = self.shuffleBoardCantLinkMap[elementType] or 0 local skillCount = 0 if anySkillCount > 0 then skillCount = 1 @@ -2047,7 +2056,7 @@ function BattleController:getShuffleBoardInfo() if count + skillCount - cantLinkCount >= needCount then local haveSkill = false local listCount = 0 - tempList = {} + self.shuffleBoardTempList = table.clearOrCreate(self.shuffleBoardList) find = false local add = false for _, entity in ipairs(list) do @@ -2063,7 +2072,7 @@ function BattleController:getShuffleBoardInfo() add = entity:canLink() end if add then - table.insert(tempList, entity) + table.insert(self.shuffleBoardTempList, entity) listCount = listCount + 1 if listCount >= needCount then -- 可连接的 普通的元素+元素技能 @@ -2077,7 +2086,7 @@ function BattleController:getShuffleBoardInfo() find = true break elseif not haveSkill and skillCount > 0 then -- 可连接的 普通元素 + 任意元素技能 - table.insert(tempList, anySkillList[1]) + table.insert(self.shuffleBoardTempList, self.shuffleBoardAnySkillList[1]) listCount = listCount + 1 if listCount >= needCount then find = true @@ -2088,7 +2097,7 @@ function BattleController:getShuffleBoardInfo() end if find then - return self:shufflePos(tempList, posMap, needCount, posList) + return self:shufflePos(self.shuffleBoardTempList, self.shuffleBoardPosMap, needCount, self.shuffleBoardPosList) end end @@ -2096,53 +2105,51 @@ function BattleController:shufflePos(tempList, posMap, needCount, posList) local gotPos, useMap, list = self:findCanLinkPosList(posMap, needCount) if gotPos and list[1] then - local changeInfo = {} - local usedPos = {} - local setedPos = {} + self.shufflePosInfo = table.clearOrCreate(self.shufflePosInfo) + self.shufflerPosUsedPos = table.clearOrCreate(self.shufflerPosUsedPos) + self.shufflerSetedPos = table.clearOrCreate(self.shufflerSetedPos) for index, entity in ipairs(tempList) do - changeInfo[entity:getPosId()] = list[index] - usedPos[list[index]] = true - setedPos[entity:getPosId()] = true + self.shufflePosInfo[entity:getPosId()] = list[index] + self.shufflerPosUsedPos[list[index]] = true + self.shufflerSetedPos[entity:getPosId()] = true end - local newList = {} - local newList2 = {} + self.shufflePosList1 = table.clearOrCreate(self.shufflePosList1) + self.shufflePosList2 = table.clearOrCreate(self.shufflePosList2) for index = #posList, 1, -1 do local posId = posList[index] - if not usedPos[posId] then - table.insert(newList2, posId) + if not self.shufflerPosUsedPos[posId] then + table.insert(self.shufflePosList2, posId) end - if not setedPos[posId] then - table.insert(newList, posId) + if not self.shufflerSetedPos[posId] then + table.insert(self.shufflePosList1, posId) end end - newList2 = table.shuffle(newList2) - for index, posId in ipairs(newList) do - if not newList2[index] then + self.shufflePosList2 = table.shuffle(self.shufflePosList2) + for index, posId in ipairs(self.shufflePosList1) do + if not self.shufflePosList2[index] then break end - changeInfo[posId] = newList2[index] + self.shufflePosInfo[posId] = self.shufflePosList2[index] end - return changeInfo + return self.shufflePosInfo end end function BattleController:findAttention() local find = false - local posIdMap = {} - local pathList for r = 1, GConst.BattleConst.ROW_COUNT do for c = 1, GConst.BattleConst.COLUMN_COUNT do local posId = ModuleManager.BattleManager:getPosId(r, c) local gridEntity = self.battleData:getGridEntity(posId) local mainElementType = gridEntity:getElementType() if gridEntity:canChangeInfo() then - pathList = {} - posIdMap = {} - self:findLinkLine(posId, posIdMap, false, mainElementType, pathList) - if table.nums(pathList) >= self:getMinEliminationCount() then + self.findAttentionPathList = table.clearOrCreate(self.findAttentionPathList) + self.findAttentionPosIdMap = table.clearOrCreate(self.findAttentionPosIdMap) + self:findLinkLine(posId, self.findAttentionPosIdMap, false, mainElementType, self.findAttentionPathList) + if table.nums(self.findAttentionPathList) >= self:getMinEliminationCount() then find = true break end @@ -2153,42 +2160,42 @@ function BattleController:findAttention() end end - return find, pathList + return find, self.findAttentionPathList end function BattleController:_dealResetGridsDataFunc(posList) - local posMap = {} - local lockElementMap = {} + self.dealResetFunc1PosMap = table.clearOrCreate(self.dealResetFunc1PosMap) + self.dealResetFunc1LockElementMap = table.clearOrCreate(self.dealResetFunc1LockElementMap) + self.dealResetFunc1KeepSnapList = table.clearOrCreate(self.dealResetFunc1KeepSnapList) + self.dealResetFunc1KeepSnapSkillList = table.clearOrCreate(self.dealResetFunc1KeepSnapSkillList) + self.dealResetFunc1EmptySnapList = table.clearOrCreate(self.dealResetFunc1EmptySnapList) local emptyCount = 0 - local keepSnapList = {} - local keepSnapSkillList = {} - local emptySnapList = {} for _, entity in ipairs(posList) do local posId = entity:getPosId() - posMap[posId] = entity + self.dealResetFunc1PosMap[posId] = entity if entity:isEmptyIdle() then emptyCount = emptyCount + 1 - table.insert(emptySnapList, entity:getSnapshoptInfo()) + table.insert(self.dealResetFunc1EmptySnapList, entity:getSnapshoptInfo()) elseif entity:isLock() and not entity:getSkillId() then - lockElementMap[entity:getElementType()] = true + self.dealResetFunc1LockElementMap[entity:getElementType()] = true emptyCount = emptyCount + 1 local snapInfo = entity:getSnapshoptInfo() snapInfo.gridType = BattleConst.GRID_TYPE.EMPTY - table.insert(emptySnapList, snapInfo) + table.insert(self.dealResetFunc1EmptySnapList, snapInfo) else if entity:getSkillId() then - table.insert(keepSnapSkillList, entity:getSnapshoptInfo()) + table.insert(self.dealResetFunc1KeepSnapSkillList, entity:getSnapshoptInfo()) else - table.insert(keepSnapList, entity:getSnapshoptInfo()) + table.insert(self.dealResetFunc1KeepSnapList, entity:getSnapshoptInfo()) end end end - return posMap, lockElementMap, emptyCount, keepSnapList, keepSnapSkillList, emptySnapList + return self.dealResetFunc1PosMap, self.dealResetFunc1LockElementMap, emptyCount, self.dealResetFunc1KeepSnapList, self.dealResetFunc1KeepSnapSkillList, self.dealResetFunc1EmptySnapList end function BattleController:_dealResetGridsDataFunc2(useMap, emptySnapList, mainElement, backupSkill, keepSnapList, posMap, canRandomElmentList, elementCount, lockElementMap) - local resetPosInfo = {} + self.dealResetFunc2ResetPosInfo = table.clearOrCreate(self.dealResetFunc2ResetPosInfo) for posId, _ in pairs(useMap) do local snapInfo if emptySnapList[1] then @@ -2199,7 +2206,7 @@ function BattleController:_dealResetGridsDataFunc2(useMap, emptySnapList, mainEl else snapInfo = backupSkill end - resetPosInfo[posId] = snapInfo + self.dealResetFunc2ResetPosInfo[posId] = snapInfo end for _, snap in ipairs(emptySnapList) do @@ -2225,12 +2232,12 @@ function BattleController:_dealResetGridsDataFunc2(useMap, emptySnapList, mainEl end if snapInfo then - resetPosInfo[posId] = snapInfo + self.dealResetFunc2ResetPosInfo[posId] = snapInfo end end end - return resetPosInfo + return self.dealResetFunc2ResetPosInfo end function BattleController:resetGrids(posList) @@ -2264,13 +2271,7 @@ function BattleController:resetGrids(posList) return end - if not self.canRandomElmentList then - self.canRandomElmentList = {} - end - - for i = #self.canRandomElmentList, 1, -1 do - table.remove(self.canRandomElmentList) - end + self.canRandomElmentList = table.clearOrCreate(self.canRandomElmentList) local elementCount = 0 for typeName, typeNum in pairs(BattleConst.ELEMENT_TYPE) do @@ -2297,12 +2298,12 @@ function BattleController:resetGrids(posList) end function BattleController:findCanLinkPosList(posMap, needCount) - local list = {} - local useMap = {} + self.findCanLinkList = table.clearOrCreate(self.findCanLinkList) + self.findCanUseMap = table.clearOrCreate(self.findCanUseMap) local gotPos = false for posId, _ in pairs(posMap) do - list = {} - useMap = {} + table.clear(self.findCanLinkList) + table.clear(self.findCanUseMap) local count = 0 local findPodId = posId gotPos = false @@ -2313,10 +2314,10 @@ function BattleController:findCanLinkPosList(posMap, needCount) end local got = false for id, status in pairs(aounrdList) do - if posMap[id] and not useMap[id] then - table.insert(list, id) + if posMap[id] and not self.findCanUseMap[id] then + table.insert(self.findCanLinkList, id) count = count + 1 - useMap[id] = true + self.findCanUseMap[id] = true findPodId = id got = true break @@ -2336,7 +2337,7 @@ function BattleController:findCanLinkPosList(posMap, needCount) end end - return gotPos, useMap, list + return gotPos, self.findCanUseMap, self.findCanLinkList end function BattleController:findLinkLine(posId, posIdMap, hadSkill, mainElementType, lineList) diff --git a/lua/app/ui/battle/battle_ui.lua b/lua/app/ui/battle/battle_ui.lua index 44e3bf3c..da0d5305 100644 --- a/lua/app/ui/battle/battle_ui.lua +++ b/lua/app/ui/battle/battle_ui.lua @@ -1762,7 +1762,7 @@ function BattleUI:playSkillLineSfx(posId, boradRangeList, randomPosList) end end - if randomPosList then + if randomPosList and randomPosList[1] then local count = math.min(#randomPosList, 5) -- 特效最多5个 self.skillLightSfxs.point:setAnchoredPosition(pos.x, pos.y) self.skillLightSfxs.point:setActive(true)