From 39a2eee61adba17bfb74d14bdc58483e78752845 Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Fri, 12 May 2023 11:43:49 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=A0=BC=E5=AD=90=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E9=85=8D=E7=BD=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=A1=A8=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/config/grid_type.lua | 66 +++++++++++++ lua/app/config/grid_type.lua.meta | 10 ++ lua/app/module/battle/battle_const.lua | 43 +------- lua/app/module/battle/battle_manager.lua | 8 -- .../battle/controller/battle_controller.lua | 30 +++--- lua/app/module/gm/gm_const.lua | 6 ++ lua/app/ui/battle/battle_ui.lua | 26 ++--- lua/app/ui/battle/cell/grid_cell.lua | 2 +- .../userdata/battle/battle_grid_entity.lua | 99 +++++++++++++++++-- 9 files changed, 203 insertions(+), 87 deletions(-) create mode 100644 lua/app/config/grid_type.lua create mode 100644 lua/app/config/grid_type.lua.meta diff --git a/lua/app/config/grid_type.lua b/lua/app/config/grid_type.lua new file mode 100644 index 00000000..4c35925e --- /dev/null +++ b/lua/app/config/grid_type.lua @@ -0,0 +1,66 @@ +local grid_type = { + [0]={ + ["can_fall"]=1 + }, + [1]={ + ["icon"]="battle_hinder_4", + ["can_fall"]=0, + ["cant_link"]=1, + ["element_invalid"]=1 + }, + [2]={ + ["icon"]="stone_2", + ["next_type"]=0, + ["break_condition"]={ + 1, + 3 + }, + ["break_count"]=1, + ["cant_link"]=1, + ["element_invalid"]=1, + ["break_sfx"]="sfx_piece_za_b01" + }, + [3]={ + ["icon"]="stone_1", + ["next_type"]=2, + ["break_condition"]={ + 1, + 3 + }, + ["break_count"]=2, + ["cant_link"]=1, + ["element_invalid"]=1, + ["break_sfx"]="sfx_piece_za_b01" + }, + [4]={ + ["icon"]="vine", + ["next_type"]=0, + ["break_condition"]={ + 2, + 3 + }, + ["break_count"]=2, + ["break_sfx"]="sfx_piece_za_b03" + }, + [5]={ + ["icon"]="ice", + ["next_type"]=0, + ["break_condition"]={ + 1, + 3 + }, + ["break_count"]=1, + ["break_stay_element"]=1, + ["cant_link"]=1, + ["break_sfx"]="sfx_piece_za_b02" + }, + [6]={ + ["icon"]="ice", + ["can_fall"]=1, + ["cant_link"]=1 + } +} +local config = { +data=grid_type,count=7 +} +return config \ No newline at end of file diff --git a/lua/app/config/grid_type.lua.meta b/lua/app/config/grid_type.lua.meta new file mode 100644 index 00000000..8095e791 --- /dev/null +++ b/lua/app/config/grid_type.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: c31a614f69d4d7e4397b5b92ba1fb4d2 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/module/battle/battle_const.lua b/lua/app/module/battle/battle_const.lua index 69064439..40793fa4 100644 --- a/lua/app/module/battle/battle_const.lua +++ b/lua/app/module/battle/battle_const.lua @@ -362,47 +362,12 @@ BattleConst.GRID_TYPE = { LOCK = 6, } -BattleConst.GRID_TYPE_ICON = { - [BattleConst.GRID_TYPE.SNOW_BOX] = "stone_2", - [BattleConst.GRID_TYPE.SOLID_SNOW] = "stone_1", - [BattleConst.GRID_TYPE.VINES] = "vine", - [BattleConst.GRID_TYPE.ICE] = "ice", -} - ----- 周围格子或自己消除一次后会变成什么格子 -BattleConst.AROUND_ELIMINATION_TO_TYPE_COUNT = { - [BattleConst.GRID_TYPE.SNOW_BOX] = BattleConst.GRID_TYPE.EMPTY, - [BattleConst.GRID_TYPE.SOLID_SNOW] = BattleConst.GRID_TYPE.SNOW_BOX, - [BattleConst.GRID_TYPE.VINES] = BattleConst.GRID_TYPE.EMPTY, - [BattleConst.GRID_TYPE.ICE] = BattleConst.GRID_TYPE.EMPTY, -} - -BattleConst.ELEMENT_TYPE_INVALID = { - [BattleConst.GRID_TYPE.SNOW_BOX] = true, - [BattleConst.GRID_TYPE.SOLID_SNOW] = true, -} - -BattleConst.AROUND_BOOM_TYPE = { +BattleConst.GRID_BREAK_CONDITION = { ACOUND = 1, LINE = 2, SKILL = 3, } ----- 不可下落的格子类型 -BattleConst.CANT_FALL_GRID_TYPE = { - [BattleConst.GRID_TYPE.OBSTACLE] = true, - [BattleConst.GRID_TYPE.VINES] = true, - [BattleConst.GRID_TYPE.ICE] = true, -} - ----- 不可链接的格子类型 -BattleConst.CANT_LINK_GRID_TYPE = { - [BattleConst.GRID_TYPE.OBSTACLE] = true, - [BattleConst.GRID_TYPE.SNOW_BOX] = true, - [BattleConst.GRID_TYPE.SOLID_SNOW] = true, - [BattleConst.GRID_TYPE.ICE] = true, -} - ---- 元素类型 BattleConst.ELEMENT_TYPE = { NONE = 0, @@ -726,12 +691,6 @@ BattleConst.OUTLINE_SFX = { BattleConst.LINE_SFX = "assets/prefabs/effects/battle/sfx_piece_line_b01.prefab" BattleConst.CHANGE_ELEMENT_SFX = "assets/prefabs/effects/battle/sfx_skill_b02.prefab" -BattleConst.GRID_TYPE_BREAK_SFX = { - [BattleConst.GRID_TYPE.SNOW_BOX] = "assets/prefabs/effects/battle/sfx_piece_za_b01.prefab", - [BattleConst.GRID_TYPE.SOLID_SNOW] = "assets/prefabs/effects/battle/sfx_piece_za_b01.prefab", - [BattleConst.GRID_TYPE.VINES] = "assets/prefabs/effects/battle/sfx_piece_za_b03.prefab", - [BattleConst.GRID_TYPE.ICE] = "assets/prefabs/effects/battle/sfx_piece_za_b02.prefab", -} BattleConst.LINK_SMOKE = "assets/prefabs/effects/battle/sfx_piece_smoke_b01.prefab" return BattleConst \ No newline at end of file diff --git a/lua/app/module/battle/battle_manager.lua b/lua/app/module/battle/battle_manager.lua index eaca0ae0..5eed3db4 100644 --- a/lua/app/module/battle/battle_manager.lua +++ b/lua/app/module/battle/battle_manager.lua @@ -106,14 +106,6 @@ function BattleManager:getElementIcon(elementType) return GConst.ATLAS_PATH.BATTLE, icon end -function BattleManager:getGridTypeIcon(gridType) - local icon = GConst.BattleConst.GRID_TYPE_ICON[gridType] - if not icon then - return GConst.ATLAS_PATH.COMMON, "common_alpha" - end - return GConst.ATLAS_PATH.BATTLE, icon -end - function BattleManager:getPosId(row, column) if not BattleConst.RC_2_POS_ID[row] then BattleConst.RC_2_POS_ID[row] = {} diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 0df29d44..b52cdd01 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -892,12 +892,12 @@ function BattleController:onLinkOver() else skillPosId = info.posId end - boomGridIds[info.posId] = BattleConst.AROUND_BOOM_TYPE.LINE + boomGridIds[info.posId] = BattleConst.GRID_BREAK_CONDITION.LINE local outline = BattleConst.UP_DOWN_LEFT_RIGHT[info.posId] for _, aroundPosId in ipairs(outline) do if not boomGridIds[aroundPosId] then - boomGridIds[aroundPosId] = BattleConst.AROUND_BOOM_TYPE.ACOUND + boomGridIds[aroundPosId] = BattleConst.GRID_BREAK_CONDITION.ACOUND end end @@ -935,7 +935,7 @@ function BattleController:onLinkOver() influenceElementType[elementType] = true end else - boomGridIds[posId] = BattleConst.AROUND_BOOM_TYPE.SKILL + boomGridIds[posId] = BattleConst.GRID_BREAK_CONDITION.SKILL end end end @@ -944,17 +944,17 @@ function BattleController:onLinkOver() for posId, boomType in pairs(boomGridIds) do local entity = self.battleData:getGridEntity(posId) if entity then - local gridType = entity:getGridType() + local breakSfxName = entity:getBreakSfx() local elementTypeInvalid = entity:isElmentTypeInvalid() - if entity:addAroundEliminationCount(boomType) then - if BattleConst.GRID_TYPE_BREAK_SFX[gridType] then + if entity:tryBreakGrid(boomType) then + if breakSfxName then if not gridBreakSfxInfo then gridBreakSfxInfo = {} end - if not gridBreakSfxInfo[gridType] then - gridBreakSfxInfo[gridType] = {} + if not gridBreakSfxInfo[breakSfxName] then + gridBreakSfxInfo[breakSfxName] = {} end - table.insert(gridBreakSfxInfo[gridType], posId) + table.insert(gridBreakSfxInfo[breakSfxName], posId) end if entity:getIsIdle() then @@ -969,14 +969,14 @@ function BattleController:onLinkOver() end else if entity:getIsIdle() then - if BattleConst.GRID_TYPE_BREAK_SFX[gridType] then + if breakSfxName then if not gridBreakSfxInfo then gridBreakSfxInfo = {} end - if not gridBreakSfxInfo[gridType] then - gridBreakSfxInfo[gridType] = {} + if not gridBreakSfxInfo[breakSfxName] then + gridBreakSfxInfo[breakSfxName] = {} end - table.insert(gridBreakSfxInfo[gridType], posId) + table.insert(gridBreakSfxInfo[breakSfxName], posId) end end end @@ -985,9 +985,9 @@ function BattleController:onLinkOver() ---- 播放碎裂特效 if gridBreakSfxInfo then - for gridType, list in pairs(gridBreakSfxInfo) do + for breakSfxName, list in pairs(gridBreakSfxInfo) do for index, posId in ipairs(list) do - self.battleUI:getSfxGridBreak(gridType, index, function(obj) + self.battleUI:getSfxGridBreak(breakSfxName, index, function(obj) local pos = ModuleManager.BattleManager:getPosInfo(posId) obj:setLocalScale(38, 38, 38) obj:setLocalPosition(pos.x, pos.y, 0) diff --git a/lua/app/module/gm/gm_const.lua b/lua/app/module/gm/gm_const.lua index 62ed2290..5ab9179a 100644 --- a/lua/app/module/gm/gm_const.lua +++ b/lua/app/module/gm/gm_const.lua @@ -54,6 +54,12 @@ Example: time_diff 0]], Example: add_time_diff 1000]], type = "add_time_diff" }, + { + title = "挑战章节", + desc = [[挑战章节 type:chapter +Example: chapter 5 10 参数1 章节 参数2 波次]], + type = "chapter" + }, } return GMConst \ No newline at end of file diff --git a/lua/app/ui/battle/battle_ui.lua b/lua/app/ui/battle/battle_ui.lua index d28929cf..1646bad7 100644 --- a/lua/app/ui/battle/battle_ui.lua +++ b/lua/app/ui/battle/battle_ui.lua @@ -1457,8 +1457,8 @@ function BattleUI:hideAllSfxLine() end end -function BattleUI:getSfxGridBreak(gridType, index, func) - if not GConst.BattleConst.GRID_TYPE_BREAK_SFX[gridType] then +function BattleUI:getSfxGridBreak(breakSfxPath, index, func) + if not breakSfxPath then return end @@ -1467,21 +1467,21 @@ function BattleUI:getSfxGridBreak(gridType, index, func) if not self.root.gridBreakSfxObjs then self.root.gridBreakSfxObjs = {} end - if not self.root.gridBreakSfxObjs[gridType] then - self.root.gridBreakSfxObjs[gridType] = {} + if not self.root.gridBreakSfxObjs[breakSfxPath] then + self.root.gridBreakSfxObjs[breakSfxPath] = {} end - if self.root.gridBreakSfxObjs[gridType][index] then - if self.root.gridBreakSfxObjs[gridType][index].obj and func then - local obj = self.root.gridBreakSfxObjs[gridType][index].obj + if self.root.gridBreakSfxObjs[breakSfxPath][index] then + if self.root.gridBreakSfxObjs[breakSfxPath][index].obj and func then + local obj = self.root.gridBreakSfxObjs[breakSfxPath][index].obj obj:setActive(true) func(obj) end else - self.root.gridBreakSfxObjs[gridType][index] = { + self.root.gridBreakSfxObjs[breakSfxPath][index] = { isLoaded = true } - EffectManager:loadUIEffectAsync(GConst.BattleConst.GRID_TYPE_BREAK_SFX[gridType], self, self.gridNode, GConst.UI_EFFECT_ORDER.LEVEL1, function(obj) - self.root.gridBreakSfxObjs[gridType][index].obj = obj + EffectManager:loadUIEffectAsync(breakSfxPath, self, self.gridNode, GConst.UI_EFFECT_ORDER.LEVEL1, function(obj) + self.root.gridBreakSfxObjs[breakSfxPath][index].obj = obj if self.hidingAllSfxGridBreak then obj:setActive(false) else @@ -1498,7 +1498,7 @@ function BattleUI:hideAllSfxGridBreak() if not self.root.gridBreakSfxObjs then return end - for gridType, map in pairs(self.root.gridBreakSfxObjs) do + for breakSfxPath, map in pairs(self.root.gridBreakSfxObjs) do for index, info in pairs(map) do if info.obj then info.obj:setActive(false) @@ -1698,7 +1698,7 @@ end function BattleUI:initUISfxs() if self.root.gridBreakSfxObjs then - for gridType, map in pairs(self.root.gridBreakSfxObjs) do + for breakSfxPath, map in pairs(self.root.gridBreakSfxObjs) do for index, info in pairs(map) do if info.obj then info.obj:setActive(true) @@ -1832,7 +1832,7 @@ function BattleUI:hideAllBoardSfxs() end if self.root.gridBreakSfxObjs then - for gridType, map in pairs(self.root.gridBreakSfxObjs) do + for breakSfxPath, map in pairs(self.root.gridBreakSfxObjs) do for index, info in pairs(map) do if info.obj then info.obj:setActive(false) diff --git a/lua/app/ui/battle/cell/grid_cell.lua b/lua/app/ui/battle/cell/grid_cell.lua index b31bcb07..0a8528cd 100644 --- a/lua/app/ui/battle/cell/grid_cell.lua +++ b/lua/app/ui/battle/cell/grid_cell.lua @@ -29,7 +29,7 @@ function GridCell:refresh(gridEntity, curElement, skillPosId) if self.lastGridType ~= gridEntity:getGridType() then self.lastGridType = gridEntity:getGridType() - local atlas, icon = ModuleManager.BattleManager:getGridTypeIcon(self.lastGridType) + local atlas, icon = gridEntity:getIcon() uiMap["grid_cell.touch_node.ani_node.up_bg"]:setSprite(atlas, icon) end diff --git a/lua/app/userdata/battle/battle_grid_entity.lua b/lua/app/userdata/battle/battle_grid_entity.lua index 89d4dd8d..b24b7057 100644 --- a/lua/app/userdata/battle/battle_grid_entity.lua +++ b/lua/app/userdata/battle/battle_grid_entity.lua @@ -1,6 +1,8 @@ local BattleGridEntity = class("BattleGridEntity", BaseData) local BattleConst = GConst.BattleConst +local GRID_TYPE_CFG = ConfigManager:getConfig("grid_type") + function BattleGridEntity:ctor(data) self:clear() self.posId = data.posId or 0 @@ -9,6 +11,7 @@ function BattleGridEntity:ctor(data) self.skillId = data.skillId self.linkSkillCount = data.linkSkillCount or 0 -- 任意链接技能激活次数 self.isIdle = false + self.breakCount = 0 self.data.isDirty = false self:determineIdleStatus() end @@ -19,6 +22,7 @@ function BattleGridEntity:clear() self.skillId = nil self.linkSkillCount = 0 -- 任意链接技能激活次数 self.isIdle = false + self.breakCount = 0 self.data.isDirty = false end @@ -30,6 +34,7 @@ function BattleGridEntity:getSnapshoptInfo() isIdle = self.isIdle, skillId = self.skillId, linkSkillCount = self.linkSkillCount, + breakCount = self.breakCount, } end @@ -40,6 +45,7 @@ function BattleGridEntity:setInfoBySnapshop(snapshot) self.isIdle = snapshot.isIdle self.skillId = snapshot.skillId self.linkSkillCount = snapshot.linkSkillCount + self.breakCount = snapshot.breakCount self:setDirty() end @@ -68,7 +74,7 @@ function BattleGridEntity:getElementType(skillEntity) end function BattleGridEntity:isCantFallType() - return not self:isEmptyType() + return self:getGridTypeConfig().can_fall ~= 1 end function BattleGridEntity:isObstacleType() @@ -80,23 +86,28 @@ function BattleGridEntity:isEmptyType() end function BattleGridEntity:isElmentTypeInvalid() - return BattleConst.ELEMENT_TYPE_INVALID[self.gridType] ~= nil + return self:getGridTypeConfig().element_invalid == 1 end -function BattleGridEntity:addAroundEliminationCount(boomType) +function BattleGridEntity:tryBreakGrid(boomType) if self:getIsIdle() then self:setGridType(BattleConst.GRID_TYPE.EMPTY) return false end - local nextGridType = BattleConst.AROUND_ELIMINATION_TO_TYPE_COUNT[self.gridType] + local nextGridType = self:getNextGridType() if nextGridType then - local beforeGridtype = self:getGridType() - if beforeGridtype == BattleConst.GRID_TYPE.VINES and boomType <= BattleConst.AROUND_BOOM_TYPE.ACOUND then + if not self:canBreakByThisCondition(boomType) then return false end + self:addBreakCount(1) + if self:getBreakCount() < self:getCfgBreakCount() then + return false + end + + local breakStayElement = self:getBreakStayElement() self:setGridType(nextGridType) - if nextGridType == BattleConst.GRID_TYPE.EMPTY and beforeGridtype ~= BattleConst.GRID_TYPE.ICE then + if nextGridType == BattleConst.GRID_TYPE.EMPTY and not breakStayElement then self:setIsIdle(true) end end @@ -128,7 +139,7 @@ function BattleGridEntity:canLink() if self:getIsIdle() then return false end - return not BattleConst.CANT_LINK_GRID_TYPE[self.gridType] + return self:getGridTypeConfig().cant_link ~= 1 end function BattleGridEntity:addPath(singlePath) @@ -149,6 +160,7 @@ end function BattleGridEntity:setGridType(gridType) self.gridType = gridType + self.breakCount = 0 self:setDirty() end @@ -242,4 +254,75 @@ function BattleGridEntity:setObstacleIcon(icon) self.obstacleIcon = icon end +function BattleGridEntity:getGridTypeConfig() + if not self.gridCfg or self.lastGridType ~= self.gridType then + self.lastGridType = self.gridType + self.gridCfg = GRID_TYPE_CFG[self.lastGridType] + self.breakConditionMap = {} + if self.gridCfg.break_condition then + for _, condition in ipairs(self.gridCfg.break_condition) do + self.breakConditionMap[condition] = true + end + end + end + + return self.gridCfg +end + +function BattleGridEntity:getNextGridType() + return self:getGridTypeConfig().next_type +end + +function BattleGridEntity:getIcon() + local icon = self:getGridTypeConfig().icon + if not icon then + return GConst.ATLAS_PATH.COMMON, "common_alpha" + end + return GConst.ATLAS_PATH.BATTLE, icon +end + +function BattleGridEntity:getBreakSfx() + local sfxName = self:getGridTypeConfig().break_sfx + if not sfxName then + return + end + + if not self.cacheBreakSfxPaths then + self.cacheBreakSfxPaths = {} + end + if not self.cacheBreakSfxPaths[sfxName] then + self.cacheBreakSfxPaths[sfxName] = "assets/prefabs/effects/battle/" .. sfxName .. ".prefab" + end + return self.cacheBreakSfxPaths[sfxName] +end + +function BattleGridEntity:getBreakConditionMap() + self:getGridTypeConfig() + return self.breakConditionMap +end + +function BattleGridEntity:canBreakByThisCondition(condition) + self:getGridTypeConfig() + if not self.breakConditionMap then + return false + end + return self.breakConditionMap[condition] == true +end + +function BattleGridEntity:getBreakStayElement() + return self:getGridTypeConfig().break_stay_element == 1 +end + +function BattleGridEntity:getCfgBreakCount() + return self:getGridTypeConfig().break_count or 0 +end + +function BattleGridEntity:getBreakCount() + return self.breakCount +end + +function BattleGridEntity:addBreakCount(count) + self.breakCount = self.breakCount + count +end + return BattleGridEntity \ No newline at end of file From 9bf1f41725fe515f2f0e42447fa600b840d16717 Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Fri, 12 May 2023 17:03:14 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B6=88=E9=99=A4?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E6=96=B9=E4=BE=BF=E4=BB=A5=E5=90=8E?= =?UTF-8?q?=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../battle/controller/battle_controller.lua | 162 +++++++++--------- .../userdata/battle/battle_grid_entity.lua | 72 ++++++-- 2 files changed, 140 insertions(+), 94 deletions(-) diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index b52cdd01..3fc948d6 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -13,6 +13,7 @@ local BattleBuffHandle = require "app/module/battle/helper/battle_buff_handle" local ELIMINATION_TOUCH_EVENT = GConst.ELIMINATION_TOUCH_EVENT local BattleConst = GConst.BattleConst local BUFF_NAME_TO_ATTR = BattleConst.BUFF_NAME_TO_ATTR +local GRID_BREAK_CONDITION = BattleConst.GRID_BREAK_CONDITION -- *************各个子模块的战斗需要重写的方法 START************* function BattleController:getChapterId() @@ -99,22 +100,26 @@ function BattleController:onLinkChange() end local sequence = self.battleData:getGridSequence() - local elementTypeMap = {} - local posIdMap = {} local mainElementType - local count = 0 - for _, info in ipairs(sequence) do - posIdMap[info.posId] = true - local entity = self.battleData:getGridEntity(info.posId) + local boomGridIds = {} - if not entity:getSkillId() then - local elementType = entity:getElementType() - elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1 - mainElementType = elementType + for index, info in ipairs(sequence) do + local entity = self.battleData:getGridEntity(info.posId) + if not mainElementType then + local skillId = entity:getSkillId() + if not skillId then + mainElementType = entity:getElementType() + break + else + local skillEntity = self.battleData:getSkillEntityBySkillId(skillId) + mainElementType = entity:getElementType(skillEntity) + break + end end - count = count + 1 end + local count = #sequence + for index, info in ipairs(sequence) do local entity = self.battleData:getGridEntity(info.posId) if entity:getCell() then @@ -139,25 +144,36 @@ function BattleController:onLinkChange() entity:getCell():showAni() end end + + self:setGridBreakCondition(boomGridIds, info.posId, GRID_BREAK_CONDITION.LINE) end for posId, cell in pairs(needFalsePosMap) do cell:showHighLight(false) end - local influenceMap = {} for posId, info in pairs(self.battleData:getSkillInfluenceGrids()) do local entity = self.battleData:getGridEntity(posId) - if not influenceMap[posId] and info.direction ~= BattleConst.BOARD_RANGE_TYPE.RANDOM then - posIdMap[posId] = true - influenceMap[posId] = true - if not entity:getSkillId() then - local elementType = entity:getElementType() - elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1 - end + if info.direction ~= BattleConst.BOARD_RANGE_TYPE.RANDOM then if entity:getCell() then entity:getCell():showCircle(true) end + self:setGridBreakCondition(boomGridIds, info.posId, GRID_BREAK_CONDITION.SKILL) + end + end + + local elementTypeMap = {} + for posId, boomTypes in pairs(boomGridIds) do + local entity = self.battleData:getGridEntity(posId) + if entity then + local elementTypeInvalid = entity:isElmentTypeInvalid() + local breaked, isIdle = entity:tryBreakGrid(boomTypes, true) + if isIdle then + if not entity:getSkillId() and not elementTypeInvalid then + local elementType = entity:getElementType() + elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1 + end + end end end @@ -875,78 +891,51 @@ function BattleController:onLinkOver() end local elementTypeMap = {} - local eliminationPosIds = {} local boomGridIds = {} local lineCount = 0 local skillPosId local randomPosList for _, info in ipairs(sequence) do - if not eliminationPosIds[info.posId] then - local entity = self.battleData:getGridEntity(info.posId) - if not entity:getSkillId() then - local elementType = entity:getElementType() - elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1 - linkElementType = elementType - lineCount = lineCount + 1 - else - skillPosId = info.posId - end - boomGridIds[info.posId] = BattleConst.GRID_BREAK_CONDITION.LINE + local entity = self.battleData:getGridEntity(info.posId) + if entity:getSkillId() then + skillPosId = info.posId + else + linkElementType = entity:getElementType() + end + self:setGridBreakCondition(boomGridIds, info.posId, GRID_BREAK_CONDITION.LINE) - local outline = BattleConst.UP_DOWN_LEFT_RIGHT[info.posId] - for _, aroundPosId in ipairs(outline) do - if not boomGridIds[aroundPosId] then - boomGridIds[aroundPosId] = BattleConst.GRID_BREAK_CONDITION.ACOUND - end - end - - local entity = self.battleData:getGridEntity(info.posId) - entity:setIsIdle(true) - eliminationPosIds[info.posId] = true + local outline = BattleConst.UP_DOWN_LEFT_RIGHT[info.posId] + for _, aroundPosId in ipairs(outline) do + self:setGridBreakCondition(boomGridIds, aroundPosId, GRID_BREAK_CONDITION.ACOUND) end end + sequence = {} + for posId, info in pairs(self.battleData:getSkillInfluenceGrids()) do local entity = self.battleData:getGridEntity(posId) if not entity:getIsIdle() then if entity:isEmptyIdle() then - entity:setIsIdle(true) - if not eliminationPosIds[posId] then - eliminationPosIds[posId] = true - table.insert(sequence, {posId = posId}) - if not entity:getSkillId() then - local elementType = entity:getElementType() - elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1 - end - end if info.direction == BattleConst.BOARD_RANGE_TYPE.RANDOM then if not randomPosList then randomPosList = {} end table.insert(randomPosList, posId) end - - if not entity:getSkillId() then - local elementType = entity:getElementType() - if not influenceElementType then - influenceElementType = {} - end - influenceElementType[elementType] = true - end - else - boomGridIds[posId] = BattleConst.GRID_BREAK_CONDITION.SKILL end + self:setGridBreakCondition(boomGridIds, posId, GRID_BREAK_CONDITION.SKILL) end end local gridBreakSfxInfo - for posId, boomType in pairs(boomGridIds) do + for posId, boomTypes in pairs(boomGridIds) do local entity = self.battleData:getGridEntity(posId) if entity then local breakSfxName = entity:getBreakSfx() local elementTypeInvalid = entity:isElmentTypeInvalid() - if entity:tryBreakGrid(boomType) then + local breaked, isIdle = entity:tryBreakGrid(boomTypes) + if breaked then if breakSfxName then if not gridBreakSfxInfo then gridBreakSfxInfo = {} @@ -956,27 +945,25 @@ function BattleController:onLinkOver() end table.insert(gridBreakSfxInfo[breakSfxName], posId) end - - if entity:getIsIdle() then - if not eliminationPosIds[posId] then - eliminationPosIds[posId] = true - table.insert(sequence, {posId = posId, noAni = elementTypeInvalid}) - if not entity:getSkillId() and not elementTypeInvalid then - local elementType = entity:getElementType() - elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1 - end - end + end + if isIdle then + table.insert(sequence, {posId = posId, noAni = elementTypeInvalid}) + if not entity:getSkillId() and not elementTypeInvalid then + local elementType = entity:getElementType() + elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1 end - else - if entity:getIsIdle() then - if breakSfxName then - if not gridBreakSfxInfo then - gridBreakSfxInfo = {} + + if not entity:getSkillId() then + if boomTypes[GRID_BREAK_CONDITION.SKILL] then + local elementType = entity:getElementType() + if not influenceElementType then + influenceElementType = {} end - if not gridBreakSfxInfo[breakSfxName] then - gridBreakSfxInfo[breakSfxName] = {} - end - table.insert(gridBreakSfxInfo[breakSfxName], posId) + influenceElementType[elementType] = true + end + + if boomTypes[GRID_BREAK_CONDITION.LINE] then + lineCount = lineCount + 1 end end end @@ -1015,6 +1002,19 @@ function BattleController:onLinkOver() self.eliminateTotalCount = self.eliminateTotalCount + 1 end +function BattleController:setGridBreakCondition(gridMap, posId, condition) + if not gridMap[posId] then + gridMap[posId] = {} + gridMap[posId][condition] = true + return true + end + if gridMap[posId][condition] then + return false + end + gridMap[posId][condition] = true + return true +end + function BattleController:fillBoard(isRoundBeginCheck) local pathMap = {} local columnCount = {} diff --git a/lua/app/userdata/battle/battle_grid_entity.lua b/lua/app/userdata/battle/battle_grid_entity.lua index b24b7057..c153e6c5 100644 --- a/lua/app/userdata/battle/battle_grid_entity.lua +++ b/lua/app/userdata/battle/battle_grid_entity.lua @@ -89,30 +89,76 @@ function BattleGridEntity:isElmentTypeInvalid() return self:getGridTypeConfig().element_invalid == 1 end -function BattleGridEntity:tryBreakGrid(boomType) +---- 返回值1为true, 返回值2为是否为idle状态;返回值1为false时,没有返回值2 +function BattleGridEntity:tryBreakGrid(boomTypes, onlyCheck) if self:getIsIdle() then - self:setGridType(BattleConst.GRID_TYPE.EMPTY) + if not onlyCheck then + self:setGridType(BattleConst.GRID_TYPE.EMPTY) + end return false end local nextGridType = self:getNextGridType() if nextGridType then - if not self:canBreakByThisCondition(boomType) then + local canbreak = false + for boomType, _ in pairs(boomTypes) do + if self:canBreakByThisCondition(boomType) then + canbreak = true + break + end + end + if not canbreak then return false end - self:addBreakCount(1) - if self:getBreakCount() < self:getCfgBreakCount() then - return false - end + if not onlyCheck then + self:addBreakCount(1) + if self:getBreakCount() < self:getCfgBreakCount() then + self:setDirty() + return false + end - local breakStayElement = self:getBreakStayElement() - self:setGridType(nextGridType) - if nextGridType == BattleConst.GRID_TYPE.EMPTY and not breakStayElement then - self:setIsIdle(true) + local breakStayElement = self:getBreakStayElement() + self:setGridType(nextGridType) + if nextGridType == BattleConst.GRID_TYPE.EMPTY and not breakStayElement then + self:setIsIdle(true) + end + else + if self:getBreakCount() + 1 < self:getCfgBreakCount() then + return false + end + + local breakStayElement = self:getBreakStayElement() + if nextGridType == BattleConst.GRID_TYPE.EMPTY and not breakStayElement then + return true, true + else + return true, false + end + end + else + if self:getSkillId() then + if boomTypes[BattleConst.GRID_BREAK_CONDITION.LINE] then -- 技能破碎逻辑为,链接消除 + if not onlyCheck then + self:setIsIdle(true) + end + else + return false + end + else + if self:isEmptyIdle() and (boomTypes[BattleConst.GRID_BREAK_CONDITION.LINE] or boomTypes[BattleConst.GRID_BREAK_CONDITION.SKILL]) then -- 空类型/带技能破碎逻辑为,链接消除 置为闲置即消除 + if not onlyCheck then + self:setIsIdle(true) + end + else -- 不可破碎类型 + return false + end end end - self:setDirty() - return true + if not onlyCheck then + self:setDirty() + return true, self:getIsIdle() + else + return true, true + end end function BattleGridEntity:getPos() From 5f4b142a3fface202e083f2187b2b767fd77cc96 Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Fri, 12 May 2023 19:56:35 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E9=94=81=E5=AE=9A=E6=A0=BC=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../battle/controller/battle_controller.lua | 270 +++++++++++------- lua/app/userdata/battle/battle_data.lua | 8 + .../userdata/battle/battle_grid_entity.lua | 11 + 3 files changed, 192 insertions(+), 97 deletions(-) diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index 3fc948d6..ba0a429a 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -737,10 +737,7 @@ function BattleController:onLinkEnter(entity, posId, isVirtual) local snapshot = self.battleData:removeGridSequence(lastPosId) if snapshot then -- 如果有快照,则恢复一次 for posId, info in pairs(snapshot) do - local entity = self.battleData:getGridEntity(posId) - if entity then - entity:setInfoBySnapshop(info) - end + self.battleData:setInfoBySnapshop(posId, info) end end @@ -863,10 +860,7 @@ function BattleController:clearGridSequence() local snapshot = self.battleData:getFirstSequenceSnapshot() if snapshot then -- 如果有快照,则恢复一次 for posId, info in pairs(snapshot) do - local entity = self.battleData:getGridEntity(posId) - if entity then - entity:setInfoBySnapshop(info) - end + self.battleData:setInfoBySnapshop(posId, info) end end @@ -1821,8 +1815,8 @@ function BattleController:shuffleBoard(callback) else local resetList = {} for posId, entity in pairs(self.battleData:getGridEnties()) do - if entity:isEmptyIdle() then - table.insert(resetList, posId) + if entity:isCanFallStatus() then + table.insert(resetList, entity) end end local resetInfo = self:resetGrids(resetList) @@ -1842,7 +1836,7 @@ function BattleController:shuffleBoard(callback) self.resetGridSid = ModuleManager.BattleManager:performWithDelayGlobal(function() local count = 1 for posId, info in pairs(resetInfo) do - self.battleData:setGridInfo(posId, info) + self.battleData:setInfoBySnapshop(posId, info) self.battleUI:playChangeElementSfx(posId, count) count = count + 1 end @@ -1862,8 +1856,9 @@ function BattleController:getShuffleBoardInfo() local posMap = {} local anySkillCount = 0 local gridEntityCountMap = {} + local gridEntityCantLinkMap = {} for posId, entity in pairs(self.battleData:getGridEnties()) do - if not entity:isCantFallType() and not entity:getIsIdle() then + if entity:isCanFallStatus() then if entity:getSkillId() then local skillEntity = self.battleData:getSkillEntityBySkillId(entity:getSkillId()) local elementType = skillEntity:getPosition() @@ -1885,6 +1880,9 @@ function BattleController:getShuffleBoardInfo() end table.insert(gridEntityList[elementType], entity) gridEntityCountMap[elementType] = (gridEntityCountMap[elementType] or 0) + 1 + if not entity:canLink() then + gridEntityCantLinkMap[elementType] = (gridEntityCountMap[elementType] or 0) + 1 + end end table.insert(posList, posId) posMap[posId] = true @@ -1909,30 +1907,44 @@ function BattleController:getShuffleBoardInfo() local find = false for elementType, list in pairs(gridEntityList) do local count = gridEntityCountMap[elementType] or 0 - if count + anySkillCount >= needCount then + local cantLinkCount = gridEntityCantLinkMap[elementType] or 0 + local skillCount = 0 + if anySkillCount > 0 then + skillCount = 1 + end + if count + skillCount - cantLinkCount >= needCount then local haveSkill = false local listCount = 0 tempList = {} find = false + local add = false for _, entity in ipairs(list) do - if entity:getSkillId() and haveSkill then - break + add = false + if haveSkill then + if not entity:getSkillId() then + add = entity:canLink() + end + else + if entity:getSkillId() then + haveSkill = true + add = entity:canLink() + end end - if entity:getSkillId() then - haveSkill = true - end - table.insert(tempList, entity) - listCount = listCount + 1 - if listCount >= needCount then -- 普通的元素+元素技能 - find = true - break + if add then + table.insert(tempList, entity) + listCount = listCount + 1 + + if listCount >= needCount then -- 可连接的 普通的元素+元素技能 + find = true + break + end end end - if listCount >= needCount then -- 普通的元素+元素技能 + if listCount >= needCount then -- 可连接的 普通的元素+元素技能 find = true break - elseif not haveSkill and anySkillCount > 0 then -- 普通元素 + 任意元素技能 + elseif not haveSkill and skillCount > 0 then -- 可连接的 普通元素 + 任意元素技能 table.insert(tempList, anySkillList[1]) listCount = listCount + 1 if listCount >= needCount then @@ -1949,44 +1961,9 @@ function BattleController:getShuffleBoardInfo() 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 + local gotPos, useMap, list = self:findCanLinkPosList(posMap, needCount) - if gotPos then + if gotPos and list[1] then local changeInfo = {} local usedPos = {} local setedPos = {} @@ -2047,23 +2024,147 @@ function BattleController:findAttention() return find, pathList end +function BattleController:_dealResetGridsDataFunc(posList) + local posMap = {} + local lockElementMap = {} + local emptyCount = 0 + local keepSnapList = {} + local keepSnapSkillList = {} + local emptySnapList = {} + for _, entity in ipairs(posList) do + local posId = entity:getPosId() + posMap[posId] = entity + if entity:isEmptyIdle() then + emptyCount = emptyCount + 1 + table.insert(emptySnapList, entity:getSnapshoptInfo()) + elseif entity:isLock() and not entity:getSkillId() then + lockElementMap[entity:getElementType()] = true + emptyCount = emptyCount + 1 + local snapInfo = entity:getSnapshoptInfo() + snapInfo.gridType = BattleConst.GRID_TYPE.EMPTY + table.insert(emptySnapList, snapInfo) + else + if entity:getSkillId() then + table.insert(keepSnapSkillList, entity:getSnapshoptInfo()) + else + table.insert(keepSnapList, entity:getSnapshoptInfo()) + end + end + end + + return posMap, lockElementMap, emptyCount, keepSnapList, keepSnapSkillList, emptySnapList +end + +function BattleController:_dealResetGridsDataFunc2(useMap, emptySnapList, mainElement, backupSkill, keepSnapList, posMap, canRandomElmentList, elementCount, lockElementMap) + local resetPosInfo = {} + for posId, _ in pairs(useMap) do + local snapInfo + if emptySnapList[1] then + snapInfo = table.remove(emptySnapList) + snapInfo.elementType = mainElement + snapInfo.posId = posId + snapInfo.gridType = BattleConst.GRID_TYPE.EMPTY + else + snapInfo = backupSkill + end + resetPosInfo[posId] = snapInfo + end + + for _, snap in ipairs(emptySnapList) do + table.insert(keepSnapList, snap) + end + + keepSnapList = table.shuffle(keepSnapList) + + for posId, entity in pairs(posMap) do + if not useMap[posId] then + local snapInfo + if keepSnapList[1] then + snapInfo = table.remove(keepSnapList) + if not snapInfo.skillId or snapInfo.skillId <= 0 then + if snapInfo.gridType == BattleConst.GRID_TYPE.EMPTY then + snapInfo.elementType = canRandomElmentList[math.random(1, elementCount)] + if lockElementMap[snapInfo.elementType] then + snapInfo.gridType = BattleConst.GRID_TYPE.LOCK + end + end + end + end + + if snapInfo then + resetPosInfo[posId] = snapInfo + end + end + end + + return resetPosInfo +end + function BattleController:resetGrids(posList) local needCount = self:getMinEliminationCount() if not posList[needCount] then return end - local posMap = {} - for _, posId in ipairs(posList) do - posMap[posId] = true + local posMap, lockElementMap, emptyCount, keepSnapList, keepSnapSkillList, emptySnapList = self:_dealResetGridsDataFunc(posList) + + local canUseSkillCount = 0 + if keepSnapSkillList[1] then -- 技能可以直接链接, 不判断元素技能了 + canUseSkillCount = 1 end + + if emptyCount + canUseSkillCount < needCount then -- 格子不够 + return + end + + local backupSkill + if emptyCount < needCount then + backupSkill = table.remove(keepSnapSkillList) + end + + for _, snap in ipairs(keepSnapSkillList) do + table.insert(keepSnapList, snap) + end + + local gotPos, useMap = self:findCanLinkPosList(posMap, needCount) + if not gotPos then + return + end + + local canRandomElmentList = {} + for typeName, typeNum in pairs(BattleConst.ELEMENT_TYPE) do + if not lockElementMap[typeNum] and not self:getSealElementType()[typeNum] and self.battleData:getSkillEntityByElement(typeNum) then + table.insert(canRandomElmentList, typeNum) + end + end + + if not canRandomElmentList[1] then + return + end + + local elementCount = #canRandomElmentList + local mainElement = canRandomElmentList[math.random(1, elementCount)] + + for typeNum, _ in pairs(lockElementMap) do + table.insert(canRandomElmentList, typeNum) + elementCount = elementCount + 1 + end + + local resetPosInfo = self:_dealResetGridsDataFunc2(useMap, emptySnapList, mainElement, backupSkill, keepSnapList, posMap, canRandomElmentList, elementCount, lockElementMap) + + return resetPosInfo +end + +function BattleController:findCanLinkPosList(posMap, needCount) + local list = {} local useMap = {} - local gotPosList = false - for _, posId in ipairs(posList) do + local gotPos = false + for posId, _ in pairs(posMap) do + list = {} useMap = {} local count = 0 local findPodId = posId - gotPosList = false + gotPos = false while true do local aounrdList = BattleConst.GRID_OUT_LINE_POS_ID[findPodId] if not aounrdList then @@ -2072,6 +2173,7 @@ function BattleController:resetGrids(posList) local got = false for id, status in pairs(aounrdList) do if posMap[id] and not useMap[id] then + table.insert(list, id) count = count + 1 useMap[id] = true findPodId = id @@ -2083,43 +2185,17 @@ function BattleController:resetGrids(posList) break end if count >= needCount then - gotPosList = true + gotPos = true break end end - if gotPosList then + if gotPos then break end end - if not gotPosList then - return - end - - local canRandomElmentList = {} - for typeName, typeNum in pairs(BattleConst.ELEMENT_TYPE) do - if not self:getSealElementType()[typeNum] and self.battleData:getSkillEntityByElement(typeNum) then - table.insert(canRandomElmentList, typeNum) - end - end - - if not canRandomElmentList[1] then - return - end - - local elementCount = #canRandomElmentList - local mainElement = canRandomElmentList[math.random(1, elementCount)] - local resetPosInfo = {} - for posId, _ in pairs(posMap) do - if useMap[posId] then - resetPosInfo[posId] = {gridType = BattleConst.GRID_TYPE.EMPTY, elementType = mainElement} - else - resetPosInfo[posId] = {gridType = BattleConst.GRID_TYPE.EMPTY, elementType = canRandomElmentList[math.random(1, elementCount)]} - end - end - - return resetPosInfo + return gotPos, useMap, list end function BattleController:findLinkLine(posId, posIdMap, hadSkill, mainElementType, lineList) diff --git a/lua/app/userdata/battle/battle_data.lua b/lua/app/userdata/battle/battle_data.lua index f19b7ef7..6e65942d 100644 --- a/lua/app/userdata/battle/battle_data.lua +++ b/lua/app/userdata/battle/battle_data.lua @@ -329,6 +329,14 @@ function BattleData:setGridInfo(posId, gridInfo) entity:determineIdleStatus() end +function BattleData:setInfoBySnapshop(posId, snapInfo) + local entity = self.gridEntities[posId] + if not entity then + return + end + entity:setInfoBySnapshop(snapInfo) +end + function BattleData:getSkillEntities() return self.skillMap end diff --git a/lua/app/userdata/battle/battle_grid_entity.lua b/lua/app/userdata/battle/battle_grid_entity.lua index c153e6c5..433804f7 100644 --- a/lua/app/userdata/battle/battle_grid_entity.lua +++ b/lua/app/userdata/battle/battle_grid_entity.lua @@ -249,6 +249,17 @@ function BattleGridEntity:isNotObstacleIdle() return false end +function BattleGridEntity:isCanFallStatus() + if not self:isCantFallType() and not self:getIsIdle() then + return true + end + return false +end + +function BattleGridEntity:isLock() + return self.gridType == BattleConst.GRID_TYPE.LOCK +end + function BattleGridEntity:getNeedElimination() return self.needElimination end From 2775d669bade5ddacf59a798228864955b570396 Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Fri, 12 May 2023 20:29:30 +0800 Subject: [PATCH 4/4] =?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 --- .../battle/controller/battle_controller.lua | 1 + lua/app/userdata/battle/battle_data.lua | 27 +++++++------------ .../userdata/battle/battle_grid_entity.lua | 8 +++--- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index ba0a429a..62e685e1 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -2081,6 +2081,7 @@ function BattleController:_dealResetGridsDataFunc2(useMap, emptySnapList, mainEl local snapInfo if keepSnapList[1] then snapInfo = table.remove(keepSnapList) + snapInfo.posId = posId if not snapInfo.skillId or snapInfo.skillId <= 0 then if snapInfo.gridType == BattleConst.GRID_TYPE.EMPTY then snapInfo.elementType = canRandomElmentList[math.random(1, elementCount)] diff --git a/lua/app/userdata/battle/battle_data.lua b/lua/app/userdata/battle/battle_data.lua index 6e65942d..2b37da9f 100644 --- a/lua/app/userdata/battle/battle_data.lua +++ b/lua/app/userdata/battle/battle_data.lua @@ -127,7 +127,6 @@ function BattleData:initRogueSkills() end function BattleData:refreshBoard(board, blockIcon) - self.elementTypeMap = {} for i, info in ipairs(board) do local r = 1 local c = 1 @@ -154,9 +153,6 @@ function BattleData:refreshBoard(board, blockIcon) else self.gridEntities[data.posId] = BATTLE_GRID_ENTITY:create(data) end - if self.gridEntities[data.posId]:canLink() then - self.elementTypeMap[data.elementType] = (self.elementTypeMap[data.elementType] or 0) + 1 - end self.gridEntities[data.posId]:determineIdleStatus() self.gridEntities[data.posId]:setObstacleIcon(blockIcon) end @@ -175,13 +171,21 @@ function BattleData:clear() self:clearGridSequence() self.gridEntities = {} - self.elementTypeMap = {} -- 同元素得格子数量 self.skillMap = {} self.selectSkillMap = {} end function BattleData:getElementTypeMap() - return self.elementTypeMap + local elementTypeMap = {} + if self.gridEntities then + for posId, entity in pairs(self.gridEntities) do + if entity:canLink() then + local elementType = entity:getElementType() + elementTypeMap[elementType] = (elementTypeMap[elementType] or 0) + 1 + end + end + end + return elementTypeMap end function BattleData:getGridSequence() @@ -306,23 +310,12 @@ function BattleData:setGridInfo(posId, gridInfo) return end - if entity:canLink() then - local elementType = entity:getElementType() - self.elementTypeMap[elementType] = (self.elementTypeMap[elementType] or 0) - 1 - if self.elementTypeMap[elementType] < 0 then - self.elementTypeMap[elementType] = 0 - end - end - if gridInfo.gridType then entity:setGridType(gridInfo.gridType) end if gridInfo.elementType then entity:setElementType(gridInfo.elementType) - if entity:canLink() then - self.elementTypeMap[gridInfo.elementType] = (self.elementTypeMap[gridInfo.elementType] or 0) + 1 - end end entity:setSkilId() -- 清除skillId diff --git a/lua/app/userdata/battle/battle_grid_entity.lua b/lua/app/userdata/battle/battle_grid_entity.lua index 433804f7..3cb5a1e2 100644 --- a/lua/app/userdata/battle/battle_grid_entity.lua +++ b/lua/app/userdata/battle/battle_grid_entity.lua @@ -205,9 +205,11 @@ function BattleGridEntity:clearPath() end function BattleGridEntity:setGridType(gridType) - self.gridType = gridType - self.breakCount = 0 - self:setDirty() + if self.gridType ~= gridType then + self.gridType = gridType + self.breakCount = 0 + self:setDirty() + end end function BattleGridEntity:setElementType(elementType)