From cbad76a7d9f4b4f0458ad01074436e9af0b7a90b Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Wed, 12 Apr 2023 21:03:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=80=E8=83=BD=E5=9B=9E=E6=94=B6=E5=92=8C?= =?UTF-8?q?=E5=90=90=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/config/chapter_board.lua | 1 - lua/app/module/battle/battle_const.lua | 98 ++++++------ .../battle/controller/battle_controller.lua | 67 ++++++-- lua/app/ui/battle/battle_ui.lua | 143 ++++++++++++++++++ lua/app/userdata/battle/battle_data.lua | 10 ++ .../userdata/battle/battle_grid_entity.lua | 11 ++ 6 files changed, 266 insertions(+), 64 deletions(-) diff --git a/lua/app/config/chapter_board.lua b/lua/app/config/chapter_board.lua index 1eccc5e3..065ffc0a 100644 --- a/lua/app/config/chapter_board.lua +++ b/lua/app/config/chapter_board.lua @@ -825,7 +825,6 @@ local chapter_board = { } }, ["control_element"]={ - 0 } }, [5]={ diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index e55cf3e6..3e649690 100644 --- a/lua/app/module/battle/battle_const.lua +++ b/lua/app/module/battle/battle_const.lua @@ -5,7 +5,7 @@ BattleConst.COLUMN_COUNT = 7 BattleConst.HALF_ROW_COUNT = 4 -- 计算偏移 math.ceil(ROW_COUNT / 2) BattleConst.HALF_COLUMN_COUNT = 4 -- 计算偏移 math.ceil(COLUMN_COUNT / 2) BattleConst.ELIMINATION_MIN_COUNT = 2 -BattleConst.GRID_STEP_H = 97 +BattleConst.GRID_STEP_H = 94 BattleConst.ROW_STEP = 10 BattleConst.ONE_STEP_TIME = 0.2 BattleConst.ELEMENT_TYPE_COUNT = 5 @@ -102,55 +102,55 @@ BattleConst.RC_2_POS_ID = {} ---- 格子位置 BattleConst.GRID_POS = { - [11] = {x = -291, y = 291}, - [12] = {x = -194, y = 291}, - [13] = {x = -97, y = 291}, - [14] = {x = 0, y = 291}, - [15] = {x = 97, y = 291}, - [16] = {x = 194, y = 291}, - [17] = {x = 291, y = 291}, - [21] = {x = -291, y = 194}, - [22] = {x = -194, y = 194}, - [23] = {x = -97, y = 194}, - [24] = {x = 0, y = 194}, - [25] = {x = 97, y = 194}, - [26] = {x = 194, y = 194}, - [27] = {x = 291, y = 194}, - [31] = {x = -291, y = 97}, - [32] = {x = -194, y = 97}, - [33] = {x = -97, y = 97}, - [34] = {x = 0, y = 97}, - [35] = {x = 97, y = 97}, - [36] = {x = 194, y = 97}, - [37] = {x = 291, y = 97}, - [41] = {x = -291, y = 0}, - [42] = {x = -194, y = 0}, - [43] = {x = -97, y = 0}, + [11] = {x = -282, y = 282}, + [12] = {x = -188, y = 282}, + [13] = {x = -94, y = 282}, + [14] = {x = 0, y = 282}, + [15] = {x = 94, y = 282}, + [16] = {x = 188, y = 282}, + [17] = {x = 282, y = 282}, + [21] = {x = -282, y = 188}, + [22] = {x = -188, y = 188}, + [23] = {x = -94, y = 188}, + [24] = {x = 0, y = 188}, + [25] = {x = 94, y = 188}, + [26] = {x = 188, y = 188}, + [27] = {x = 282, y = 188}, + [31] = {x = -282, y = 94}, + [32] = {x = -188, y = 94}, + [33] = {x = -94, y = 94}, + [34] = {x = 0, y = 94}, + [35] = {x = 94, y = 94}, + [36] = {x = 188, y = 94}, + [37] = {x = 282, y = 94}, + [41] = {x = -282, y = 0}, + [42] = {x = -188, y = 0}, + [43] = {x = -94, y = 0}, [44] = {x = 0, y = 0}, - [45] = {x = 97, y = 0}, - [46] = {x = 194, y = 0}, - [47] = {x = 291, y = 0}, - [51] = {x = -291, y = -97}, - [52] = {x = -194, y = -97}, - [53] = {x = -97, y = -97}, - [54] = {x = 0, y = -97}, - [55] = {x = 97, y = -97}, - [56] = {x = 194, y = -97}, - [57] = {x = 291, y = -97}, - [61] = {x = -291, y = -194}, - [62] = {x = -194, y = -194}, - [63] = {x = -97, y = -194}, - [64] = {x = 0, y = -194}, - [65] = {x = 97, y = -194}, - [66] = {x = 194, y = -194}, - [67] = {x = 291, y = -194}, - [71] = {x = -291, y = -291}, - [72] = {x = -194, y = -291}, - [73] = {x = -97, y = -291}, - [74] = {x = 0, y = -291}, - [75] = {x = 97, y = -291}, - [76] = {x = 194, y = -291}, - [77] = {x = 291, y = -291}, + [45] = {x = 94, y = 0}, + [46] = {x = 188, y = 0}, + [47] = {x = 282, y = 0}, + [51] = {x = -282, y = -94}, + [52] = {x = -188, y = -94}, + [53] = {x = -94, y = -94}, + [54] = {x = 0, y = -94}, + [55] = {x = 94, y = -94}, + [56] = {x = 188, y = -94}, + [57] = {x = 282, y = -94}, + [61] = {x = -282, y = -188}, + [62] = {x = -188, y = -188}, + [63] = {x = -94, y = -188}, + [64] = {x = 0, y = -188}, + [65] = {x = 94, y = -188}, + [66] = {x = 188, y = -188}, + [67] = {x = 282, y = -188}, + [71] = {x = -282, y = -282}, + [72] = {x = -188, y = -282}, + [73] = {x = -94, y = -282}, + [74] = {x = 0, y = -282}, + [75] = {x = 94, y = -282}, + [76] = {x = 188, y = -282}, + [77] = {x = 282, y = -282}, } ---- 每个格子外围一格距离的格子 diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 8276f06e..b9aa1d8a 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -241,8 +241,8 @@ function BattleController:onTouchEvent(eventType, posId) if lastEntity:getNeedChangePos() and not entity:getNeedChangePos() then -- 需要移动到队列末尾 local lastSkillId = lastEntity:getSkillId() local skillId = entity:getSkillId() - lastEntity:setSkilId(skillId) - entity:setSkilId(lastSkillId) + self:setGridSkillId(lastPosId, skillId) + self:setGridSkillId(posId, lastSkillId) end local newElementType = elementType or lastElementType @@ -433,6 +433,7 @@ function BattleController:fillBoard() -- local gridType = list[math.random(1, 4)] -- self:generateGridType(gridType) -- ModuleManager.BattleManager:showSelectSkillUI(self:getRandomSkillList()) + -- self:generateBoard() end) end @@ -493,7 +494,8 @@ function BattleController:generateInstructions(skillEntity, elementType, influen if elementTypeCount > 0 then table.insert(instructions, { name = BattleConst.INSTRUCTION_NAME.GENERAL_ATTACK, - count = elementTypeCount + count = elementTypeCount, + skillMatch = elementType }) end @@ -527,10 +529,42 @@ function BattleController:generateBoard() return end - self.curBoardIndex = (self.curBoardIndex or 0) + 1 - local board = boardList[self.curBoardIndex] - self.battleData:refreshBoard(board) - self.battleUI:initGridCell() + local skillCount = 0 + local skillList = {} + for posId, entity in pairs(self.battleData:getGridEnties()) do + if entity:getSkillId() then + table.insert(skillList, {skillId = entity:getSkillId(), posId = posId}) + skillCount = skillCount + 1 + end + end + + self.battleUI:cacheSkillAni(skillList, false, function() + self.curBoardIndex = (self.curBoardIndex or 0) + 1 + local board = boardList[self.curBoardIndex] + self.battleData:refreshBoard(board) + self.battleUI:initGridCell() + + if skillCount > 0 then + local posidList = {} + for posId, entity in pairs(self.battleData:getGridEnties()) do + if entity:isEmptyIdle() then + table.insert(posidList, posId) + end + end + + posidList = table.shuffle(posidList) + local newSkillId = {} + for index, info in ipairs(skillList) do + if posidList[1] then + newSkillId[index] = info + newSkillId[index].posId = table.remove(posidList) + else + break + end + end + self.battleUI:cacheSkillAni(newSkillId, true) + end + end) end function BattleController:generateSkill() @@ -544,13 +578,18 @@ function BattleController:generateSkill() for elementType, skillId in pairs(map) do local list = self:getSkillElementList(elementType, 1, true) for _, posId in ipairs(list) do - local entity = self.battleData:getGridEntity(posId) - if entity then - entity:setSkilId(skillId) - if entity:getElementType() ~= elementType then - entity:setElementType(elementType) - end - end + self:setGridSkillId(posId, skillId) + end + end +end + +function BattleController:setGridSkillId(posId, skillId) + local entity = self.battleData:getGridEntity(posId) + if entity then + entity:setSkilId(skillId) + local skillEntity = self.battleData:getSkillEntityBySkillId(skillId) + if skillEntity and entity:getElementType() ~= skillEntity:getPosition() then + entity:setElementType(skillEntity:getPosition()) end end end diff --git a/lua/app/ui/battle/battle_ui.lua b/lua/app/ui/battle/battle_ui.lua index 9adeea41..b6999c04 100644 --- a/lua/app/ui/battle/battle_ui.lua +++ b/lua/app/ui/battle/battle_ui.lua @@ -25,6 +25,9 @@ function BattleUI:_display() self.boardMask2D = uiMap["battle_ui.bg_2.board_node"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_RECT_MASK_2D) self.boardMask = uiMap["battle_ui.bg_2.board_mask"] self.boardMask:setVisible(false) + self.boardCacheNode = uiMap["battle_ui.bg_2.board_cache_node"] + self.boardCacheNode:setVisible(false) + self.boardCacheBox = uiMap["battle_ui.bg_2.board_cache_node.skill_box"] self:initSkill() self:initBattlefield() end @@ -264,4 +267,144 @@ function BattleUI:fallGrid(listInfo, callback) end end +function BattleUI:cacheSkillAni(skillInfo, isPop, callback) + local skillInfoCount = #skillInfo + if skillInfoCount <= 0 then + if callback then + callback() + end + return + end + + self:disableUITouch() + + if not self.root.skillAniGridEntities then + self.root.skillAniGridEntities = {} + end + + for _, entity in ipairs(self.root.skillAniGridEntities) do + local cell = entity:getCell() + if cell then + cell:getBaseObject():setAnchoredPositionX(DEFAULT_X) -- 放到屏幕外 + end + end + + local gridEntityCount = #self.root.skillAniGridEntities + if gridEntityCount < skillInfoCount then + for i = gridEntityCount, skillInfoCount do + CellManager:loadCellAsync(GRID_CELL_PATH, GRID_CELL, self.boardCacheNode, function(cell) + cell:getBaseObject():setAnchoredPositionX(DEFAULT_X) -- 初始化时放到屏幕外 + local entity = DataManager.BattleData:getNewGridEntity() + entity:setCell(cell) + table.insert(self.root.skillAniGridEntities, entity) + if i == skillInfoCount then + if isPop then + self:doCachePopAni(skillInfo, callback) + else + self:doCacheAni(skillInfo, callback) + end + end + end) + end + else + if isPop then + self:doCachePopAni(skillInfo, callback) + else + self:doCacheAni(skillInfo, callback) + end + end +end + +function BattleUI:doCacheAni(skillInfo, callback) + if self.cacheSkillAniSeq then + self.cacheSkillAniSeq:Kill() + self.cacheSkillAniSeq = nil + end + + if not self.root.skillAniGridEntities then + if callback then + callback() + end + return + end + + self.boardCacheNode:setVisible(true) + + self.cacheSkillAniSeq = self.root:createBindTweenSequence() + for index, info in ipairs(skillInfo) do + local entity = self.root.skillAniGridEntities[index] + if entity then + entity:setSkilId(info.skillId) + local pos = ModuleManager.BattleManager:getPosInfo(info.posId) + local cell = entity:getCell() + if cell then + cell:refresh(entity) + local obj = cell:getBaseObject() + self.cacheSkillAniSeq:InsertCallback(0.5 * (index - 1), function() + obj:setAnchoredPosition(pos.x, pos.y) + local gridEntity = DataManager.BattleData:getGridEntity(info.posId) + if gridEntity and gridEntity:getCell() then + gridEntity:getCell():getBaseObject():setAnchoredPositionX(DEFAULT_X) -- 放到屏幕外 + end + end) + + self.cacheSkillAniSeq:Insert(0.5 * (index - 1) + 0.02, obj:getTransform():DOAnchorPos(BF.Vector2(0, 656), 0.5)) + end + end + end + self.cacheSkillAniSeq:AppendCallback(function() + self.boardCacheNode:setVisible(false) + self:enableUITouch() + if callback then + callback() + end + end) +end + +function BattleUI:doCachePopAni(skillInfo, callback) + if self.cacheSkillAniSeq then + self.cacheSkillAniSeq:Kill() + self.cacheSkillAniSeq = nil + end + + if not self.root.skillAniGridEntities then + if callback then + callback() + end + return + end + + self.boardCacheNode:setVisible(true) + self.cacheSkillAniSeq = self.root:createBindTweenSequence() + for index, info in ipairs(skillInfo) do + local entity = self.root.skillAniGridEntities[index] + if entity then + entity:setSkilId(info.skillId) + local pos = ModuleManager.BattleManager:getPosInfo(info.posId) + local cell = entity:getCell() + if cell then + cell:refresh(entity) + local obj = cell:getBaseObject() + self.cacheSkillAniSeq:InsertCallback(0.5 * (index - 1), function() + obj:setAnchoredPosition(0, 656) + end) + + self.cacheSkillAniSeq:Insert(0.5 * (index - 1) + 0.02, obj:getTransform():DOAnchorPos(pos, 0.5)) + self.cacheSkillAniSeq:InsertCallback(0.5 * (index - 1) + 0.52, function() + if self.battleController then + self.battleController:setGridSkillId(info.posId, info.skillId) + end + end) + end + end + end + self.cacheSkillAniSeq:AppendCallback(function() + self.boardCacheNode:setVisible(false) + self:enableUITouch() + if callback then + callback() + end + end) +end + return BattleUI \ No newline at end of file diff --git a/lua/app/userdata/battle/battle_data.lua b/lua/app/userdata/battle/battle_data.lua index 4e42b49d..1279218e 100644 --- a/lua/app/userdata/battle/battle_data.lua +++ b/lua/app/userdata/battle/battle_data.lua @@ -56,6 +56,7 @@ function BattleData:refreshBoard(board) elementType = info[2] } if self.gridEntities[data.posId] then + self.gridEntities[data.posId]:clear() self.gridEntities[data.posId]:setGridType(data.gridType) self.gridEntities[data.posId]:setElementType(data.elementType) else @@ -67,6 +68,15 @@ function BattleData:refreshBoard(board) end end +function BattleData:getNewGridEntity(posId, gridType, elementType) + local data = { + posId = posId or 0, + gridType = gridType or BattleConst.GRID_TYPE.EMPTY, + elementType = elementType or BattleConst.ELEMENT_TYPE.RED + } + return BATTLE_GRID_ENTITY:create(data) +end + function BattleData:clear() self:clearGridSequence() diff --git a/lua/app/userdata/battle/battle_grid_entity.lua b/lua/app/userdata/battle/battle_grid_entity.lua index e9d60958..0cf95b1e 100644 --- a/lua/app/userdata/battle/battle_grid_entity.lua +++ b/lua/app/userdata/battle/battle_grid_entity.lua @@ -2,6 +2,7 @@ local BattleGridEntity = class("BattleGridEntity", BaseData) local BattleConst = GConst.BattleConst function BattleGridEntity:ctor(data) + self:clear() self.posId = data.posId or 0 self.gridType = data.gridType or BattleConst.GRID_TYPE.EMPTY self.elementType = data.elementType or BattleConst.ELEMENT_TYPE.RED @@ -12,6 +13,16 @@ function BattleGridEntity:ctor(data) self.data.isDirty = false end +function BattleGridEntity:clear() + self.gridType = BattleConst.GRID_TYPE.EMPTY + self.elementType = BattleConst.ELEMENT_TYPE.RED + self.aroundEliminationCount = 0 -- 周围消除次数 + self.skillId = nil + self.linkSkillCount = 0 -- 任意链接技能激活次数 + self.isIdle = false + self.data.isDirty = false +end + function BattleGridEntity:getSnapshoptInfo() return { posId = self.posId,