157 lines
3.9 KiB
Lua
157 lines
3.9 KiB
Lua
local BattleGridEntity = class("BattleGridEntity", BaseData)
|
|
local BattleConst = GConst.BattleConst
|
|
|
|
function BattleGridEntity:ctor(data)
|
|
self.posId = data.posId or 0
|
|
self.gridType = data.gridType or BattleConst.GRID_TYPE.EMPTY
|
|
self.elementType = data.elementType or BattleConst.ELEMENT_TYPE.RED
|
|
self.aroundEliminationCount = data.aroundEliminationCount or 0 -- 周围消除次数
|
|
self.skillId = data.skillId
|
|
self.isIdle = false
|
|
self.data.isDirty = false
|
|
end
|
|
|
|
function BattleGridEntity:getSnapshoptInfo()
|
|
return {
|
|
posId = self.posId,
|
|
gridType = self.gridType,
|
|
elementType = self.elementType,
|
|
aroundEliminationCount = self.aroundEliminationCount,
|
|
isIdle = self.isIdle,
|
|
skillId = self.skillId,
|
|
}
|
|
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.aroundEliminationCount = snapshot.aroundEliminationCount or 0 -- 周围消除次数
|
|
self.isIdle = snapshot.isIdle
|
|
self.skillId = snapshot.skillId
|
|
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()
|
|
return self.elementType
|
|
end
|
|
|
|
function BattleGridEntity:isCantFallType()
|
|
return BattleConst.CANT_FALL_GRID_TYPE[self.gridType] or false
|
|
end
|
|
|
|
function BattleGridEntity:isObstacleType()
|
|
return self.gridType == BattleConst.GRID_TYPE.OBSTACLE
|
|
end
|
|
|
|
function BattleGridEntity:getAroundEliminationCount()
|
|
return self.aroundEliminationCount
|
|
end
|
|
|
|
function BattleGridEntity:addAroundEliminationCount(count)
|
|
count = count or 1
|
|
self.aroundEliminationCount = self.aroundEliminationCount + count
|
|
local gridTypeList = BattleConst.AROUND_ELIMINATION_TO_TYPE_COUNT[self.gridType]
|
|
if gridTypeList and gridTypeList[self.aroundEliminationCount] then
|
|
local gridType = gridTypeList[self.aroundEliminationCount]
|
|
self:setGridType(gridType)
|
|
if gridType == BattleConst.GRID_TYPE.EMPTY then
|
|
self:setIsIdle(true)
|
|
end
|
|
end
|
|
self:setDirty()
|
|
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
|
|
if self.isIdle then
|
|
self.aroundEliminationCount = 0
|
|
end
|
|
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.aroundEliminationCount = 0
|
|
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:setDirty()
|
|
end
|
|
|
|
function BattleGridEntity:canChangeInfo()
|
|
if self:canLink() and not self:getSkillId() then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
return BattleGridEntity |