死局随机棋盘
This commit is contained in:
parent
a6f3a64b07
commit
e7c262c34b
@ -379,8 +379,15 @@ function BattleController:enterEliminationBegin()
|
|||||||
-- 检查棋盘
|
-- 检查棋盘
|
||||||
local find, pathList = self:findAttention()
|
local find, pathList = self:findAttention()
|
||||||
if not find then -- 如果没找到,就要打乱棋盘
|
if not find then -- 如果没找到,就要打乱棋盘
|
||||||
-- todo
|
local changeInfo = self:shuffleBoard()
|
||||||
Logger.logHighlight("----- 处于无法消除状态 -----")
|
if changeInfo then
|
||||||
|
self.battleData:setGridEntitiesPosId(changeInfo)
|
||||||
|
self.battleUI:shuffleBoard(changeInfo, function()
|
||||||
|
self:enterElimination(true)
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
Logger.logHighlight("----- 处于无法消除状态 -----")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
self.attentionList = pathList
|
self.attentionList = pathList
|
||||||
-- ModuleManager.BattleManager:performWithDelayGlobal(function()
|
-- ModuleManager.BattleManager:performWithDelayGlobal(function()
|
||||||
@ -1568,37 +1575,161 @@ function BattleController:showAttention()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function BattleController:shuffleBoard()
|
function BattleController:shuffleBoard()
|
||||||
-- local posList = {}
|
local posList = {}
|
||||||
-- local gridEntityList = {}
|
local gridEntityList = {}
|
||||||
-- local elementList = {}
|
local anySkillList = {}
|
||||||
-- for posId, entity in pairs(self.battleData:getGridEnties()) do
|
local posMap = {}
|
||||||
-- table.insert(posList, posId)
|
local anySkillCount = 0
|
||||||
-- table.insert(gridEntityList, entity)
|
local gridEntityCountMap = {}
|
||||||
-- if entity:canLink() then
|
for posId, entity in pairs(self.battleData:getGridEnties()) do
|
||||||
-- table.insert(elementList, entity)
|
if not entity:isCantFallType() then
|
||||||
-- end
|
if entity:getSkillId() then
|
||||||
-- end
|
local skillEntity = self.battleData:getSkillEntityBySkillId(entity:getSkillId())
|
||||||
|
local elementType = skillEntity:getPosition()
|
||||||
|
if skillEntity:ignoreElementType() then
|
||||||
|
table.insert(anySkillList, entity)
|
||||||
|
anySkillCount = anySkillCount + 1
|
||||||
|
else
|
||||||
|
if not gridEntityList[elementType] then
|
||||||
|
gridEntityList[elementType] = {}
|
||||||
|
gridEntityCountMap[elementType] = 0
|
||||||
|
end
|
||||||
|
table.insert(gridEntityList[elementType], entity)
|
||||||
|
gridEntityCountMap[elementType] = (gridEntityCountMap[elementType] or 0) + 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local elementType = entity:getElementType()
|
||||||
|
if not gridEntityList[elementType] then
|
||||||
|
gridEntityList[elementType] = {}
|
||||||
|
end
|
||||||
|
table.insert(gridEntityList[elementType], entity)
|
||||||
|
gridEntityCountMap[elementType] = (gridEntityCountMap[elementType] or 0) + 1
|
||||||
|
end
|
||||||
|
table.insert(posList, posId)
|
||||||
|
posMap[posId] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- local needCount = self:getMinEliminationCount()
|
for elementType, list in pairs(gridEntityList) do
|
||||||
-- local tempMap = {}
|
table.sort(gridEntityList[elementType], function(a, b)
|
||||||
-- while needCount > 0 do
|
if a:getSkillId() and not b:getSkillId() then
|
||||||
-- local find = false
|
return false
|
||||||
-- for _, entity1 in ipairs(elementList) do
|
elseif not a:getSkillId() and b:getSkillId() then
|
||||||
-- if not tempMap[entity1:getPosId] then
|
return true
|
||||||
-- tempMap[entity1:getPosId] = true
|
else
|
||||||
-- for _, entity2 in ipairs(elementList) do
|
return a:getPosId() < b:getPosId()
|
||||||
-- if not tempMap[entity2:getPosId] then
|
end
|
||||||
-- if entity2: then
|
end)
|
||||||
-- -- body
|
end
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
-- end
|
local needCount = self:getMinEliminationCount()
|
||||||
-- end
|
local tempList
|
||||||
-- end
|
local find = false
|
||||||
-- if not find then
|
for elementType, list in pairs(gridEntityList) do
|
||||||
-- break
|
local count = gridEntityCountMap[elementType] or 0
|
||||||
-- end
|
if count + anySkillCount >= needCount then
|
||||||
-- end
|
local haveSkill = false
|
||||||
|
local listCount = 0
|
||||||
|
tempList = {}
|
||||||
|
find = false
|
||||||
|
for _, entity in ipairs(list) do
|
||||||
|
if entity:getSkillId() and haveSkill then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if entity:getSkillId() then
|
||||||
|
haveSkill = true
|
||||||
|
end
|
||||||
|
table.insert(tempList, entity)
|
||||||
|
listCount = listCount + 1
|
||||||
|
if listCount >= needCount then -- 普通的元素+元素技能
|
||||||
|
find = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if listCount >= needCount then -- 普通的元素+元素技能
|
||||||
|
find = true
|
||||||
|
break
|
||||||
|
elseif not haveSkill and anySkillCount > 0 then -- 普通元素 + 任意元素技能
|
||||||
|
table.insert(tempList, anySkillList[1])
|
||||||
|
listCount = listCount + 1
|
||||||
|
if listCount >= needCount then
|
||||||
|
find = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if find then
|
||||||
|
return self:shufflePos(tempList, posMap, needCount, posList)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BattleController:shufflePos(tempList, posMap, needCount, posList)
|
||||||
|
local list = {}
|
||||||
|
local count = 0
|
||||||
|
local gotPos = false
|
||||||
|
for posId, status in pairs(posMap) do
|
||||||
|
list = {}
|
||||||
|
count = 0
|
||||||
|
local findPodId = posId
|
||||||
|
local temp = {}
|
||||||
|
while true do
|
||||||
|
local aounrdList = BattleConst.GRID_OUT_LINE_POS_ID[findPodId]
|
||||||
|
if not aounrdList then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
local got = false
|
||||||
|
for id, status in pairs(aounrdList) do
|
||||||
|
if posMap[id] and not temp[id] then
|
||||||
|
table.insert(list, id)
|
||||||
|
count = count + 1
|
||||||
|
temp[id] = true
|
||||||
|
findPodId = id
|
||||||
|
got = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not got then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if count >= needCount then
|
||||||
|
gotPos = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if gotPos then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if gotPos then
|
||||||
|
local changeInfo = {}
|
||||||
|
local usedPos = {}
|
||||||
|
for index, entity in ipairs(tempList) do
|
||||||
|
changeInfo[entity:getPosId()] = list[index]
|
||||||
|
usedPos[list[index]] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local newList = {}
|
||||||
|
for index = #posList, 1, -1 do
|
||||||
|
local posId = posList[index]
|
||||||
|
if not usedPos[posId] then
|
||||||
|
table.insert(newList, posId)
|
||||||
|
else
|
||||||
|
table.remove(posList, index)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local newList2 = table.shuffle(newList)
|
||||||
|
for index, posId in ipairs(newList2) do
|
||||||
|
changeInfo[posId] = posList[index]
|
||||||
|
end
|
||||||
|
|
||||||
|
return changeInfo
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function BattleController:findAttention()
|
function BattleController:findAttention()
|
||||||
|
|||||||
@ -813,6 +813,29 @@ function BattleUI:hideGenerateSkillGridCells()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BattleUI:shuffleBoard(changeInfo, callback)
|
||||||
|
if self.shuffleBoardSeq then
|
||||||
|
self.shuffleBoardSeq:Kill()
|
||||||
|
self.shuffleBoardSeq = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
self.shuffleBoardSeq = self.root:createBindTweenSequence()
|
||||||
|
for posId, tartgetPos in pairs(changeInfo) do
|
||||||
|
local entity = DataManager.BattleData:getGridEntity(posId)
|
||||||
|
local cell = entity:getCell()
|
||||||
|
local posId = entity:getPosId()
|
||||||
|
if cell then
|
||||||
|
local pos = ModuleManager.BattleManager:getPosInfo(posId)
|
||||||
|
self.shuffleBoardSeq:Insert(0, cell:getBaseObject():getTransform():DOAnchorPos(pos, 1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.shuffleBoardSeq:AppendCallback(function()
|
||||||
|
if callback then
|
||||||
|
callback()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
function BattleUI:fallGrid(listInfo, callback)
|
function BattleUI:fallGrid(listInfo, callback)
|
||||||
self:showMask(false)
|
self:showMask(false)
|
||||||
self.fallAniCount = 0
|
self.fallAniCount = 0
|
||||||
|
|||||||
@ -275,6 +275,19 @@ function BattleData:exchangeGridEntities(posId1, posId2)
|
|||||||
self.gridEntities[posId2] = e1
|
self.gridEntities[posId2] = e1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BattleData:setGridEntitiesPosId(changeInfo)
|
||||||
|
local map = {}
|
||||||
|
for posId, targetPosId in pairs(changeInfo) do
|
||||||
|
local entity = self.gridEntities[posId]
|
||||||
|
entity:setPosId(targetPosId)
|
||||||
|
map[targetPosId] = entity
|
||||||
|
end
|
||||||
|
|
||||||
|
for posId, entity in pairs(map) do
|
||||||
|
self.gridEntities[posId] = entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function BattleData:setGridInfo(posId, gridInfo)
|
function BattleData:setGridInfo(posId, gridInfo)
|
||||||
local entity = self.gridEntities[posId]
|
local entity = self.gridEntities[posId]
|
||||||
if not entity then
|
if not entity then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user