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.NONE self.skillId = data.skillId self.linkSkillCount = data.linkSkillCount or 0 -- 任意链接技能激活次数 self.isIdle = false self.data.isDirty = false self:determineIdleStatus() end function BattleGridEntity:clear() self.gridType = BattleConst.GRID_TYPE.EMPTY self.elementType = BattleConst.ELEMENT_TYPE.RED self.skillId = nil self.linkSkillCount = 0 -- 任意链接技能激活次数 self.isIdle = false self.data.isDirty = false end function BattleGridEntity:getSnapshoptInfo() return { posId = self.posId, gridType = self.gridType, elementType = self.elementType, isIdle = self.isIdle, skillId = self.skillId, linkSkillCount = self.linkSkillCount, } end function BattleGridEntity:setInfoBySnapshop(snapshot) self.posId = snapshot.posId or 0 self.gridType = snapshot.gridType or BattleConst.GRID_TYPE.EMPTY self.elementType = snapshot.elementType or BattleConst.ELEMENT_TYPE.RED self.isIdle = snapshot.isIdle self.skillId = snapshot.skillId self.linkSkillCount = snapshot.linkSkillCount self:setDirty() end function BattleGridEntity:setDirty() self.data.isDirty = not self.data.isDirty end function BattleGridEntity:getPosId() return self.posId end function BattleGridEntity:setPosId(posId) self.posId = posId end function BattleGridEntity:getGridType() return self.gridType end function BattleGridEntity:getElementType(skillEntity) if skillEntity and skillEntity:getIgnoreElementType() and self.linkSkillCount <= 0 then return nil end return self.elementType end function BattleGridEntity:isCantFallType() return not self:isEmptyType() end function BattleGridEntity:isObstacleType() return self.gridType == BattleConst.GRID_TYPE.OBSTACLE end function BattleGridEntity:isEmptyType() return self.gridType == BattleConst.GRID_TYPE.EMPTY end function BattleGridEntity:isElmentTypeInvalid() return BattleConst.AROUND_ELIMINATION_TO_TYPE_COUNT[self.gridType] ~= nil end function BattleGridEntity:addAroundEliminationCount(boomType) local nextGridType = BattleConst.AROUND_ELIMINATION_TO_TYPE_COUNT[self.gridType] if nextGridType then local beforeGridtype = self:getGridType() if beforeGridtype == BattleConst.GRID_TYPE.VINES and boomType ~= BattleConst.AROUND_BOOM_TYPE.LINE then return false end self:setGridType(nextGridType) if nextGridType == BattleConst.GRID_TYPE.EMPTY and beforeGridtype ~= BattleConst.GRID_TYPE.ICE then self:setIsIdle(true) end end self:setDirty() return true end function BattleGridEntity:getPos() return ModuleManager.BattleManager:getPosInfo(self.posId) end function BattleGridEntity:setCell(cell) self.gridCell = cell end function BattleGridEntity:getCell() return self.gridCell end function BattleGridEntity:getIsIdle() return self.isIdle end function BattleGridEntity:setIsIdle(isIdle) self.isIdle = isIdle == true end function BattleGridEntity:canLink() if self:getIsIdle() then return false end return not BattleConst.CANT_LINK_GRID_TYPE[self.gridType] end function BattleGridEntity:addPath(singlePath) self:getPath() table.insert(self.pathList, singlePath) end function BattleGridEntity:getPath() if not self.pathList then self.pathList = {} end return self.pathList end function BattleGridEntity:clearPath() self.pathList = {} end function BattleGridEntity:setGridType(gridType) self.gridType = gridType self:setDirty() end function BattleGridEntity:setElementType(elementType) self.elementType = elementType self:setDirty() end function BattleGridEntity:getSkillId() if not self.skillId or self.skillId <= 0 then return end return self.skillId end function BattleGridEntity:setSkilId(skillId) self.skillId = skillId self.linkSkillCount = 0 self:setDirty() end function BattleGridEntity:canChangeInfo() if self:canLink() and not self:getSkillId() then return true end return false end function BattleGridEntity:isEmptyIdle() if self:isEmptyType() and not self:getSkillId() and not self:getIsIdle() then return true end return false end function BattleGridEntity:isNotObstacleIdle() if not self:isObstacleType() and not self:getSkillId() and not self:getIsIdle() then return true end return false end function BattleGridEntity:getNeedElimination() return self.needElimination end function BattleGridEntity:getNeedChangePos() if not self:getSkillId() then return false end local skillEntity = DataManager.BattleData:getSkillEntityBySkillId(self:getSkillId()) if not skillEntity then return false end local cfg = ModuleManager.BattleManager.SKILL_CFG[skillEntity:getSkillId()] if cfg and cfg.method == BattleConst.SKILL_METHOD_TYPE.ON_FINAL then return true end return false end function BattleGridEntity:addLinkSkillCount(count) self.linkSkillCount = self.linkSkillCount + (count or 1) end function BattleGridEntity:setLinkSkillCount(count) self.linkSkillCount = count or 0 end function BattleGridEntity:getLinkSkillCount() return self.linkSkillCount end function BattleGridEntity:determineIdleStatus() if not self.isIdle and self.gridType == BattleConst.GRID_TYPE.EMPTY and self.elementType == BattleConst.ELEMENT_TYPE.NONE then self.isIdle = true end end return BattleGridEntity