231 lines
6.0 KiB
Lua
231 lines
6.0 KiB
Lua
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.aroundEliminationCount = data.aroundEliminationCount or 0 -- 周围消除次数
|
|
self.skillId = data.skillId
|
|
self.linkSkillCount = data.linkSkillCount or 0 -- 任意链接技能激活次数
|
|
self.isIdle = false
|
|
self.data.isDirty = false
|
|
if self.gridType == BattleConst.GRID_TYPE.EMPTY and self.elementType == BattleConst.ELEMENT_TYPE.NONE then
|
|
self.isIdle = true
|
|
end
|
|
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,
|
|
gridType = self.gridType,
|
|
elementType = self.elementType,
|
|
aroundEliminationCount = self.aroundEliminationCount,
|
|
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.aroundEliminationCount = snapshot.aroundEliminationCount or 0 -- 周围消除次数
|
|
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: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]
|
|
local beforeGridtype = self:getGridType()
|
|
self:setGridType(gridType)
|
|
if gridType == BattleConst.GRID_TYPE.EMPTY and beforeGridtype ~= BattleConst.GRID_TYPE.ICE 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.linkSkillCount = 0
|
|
self:setDirty()
|
|
end
|
|
|
|
function BattleGridEntity:canChangeInfo()
|
|
if self:canLink() and not self:getSkillId() then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
function BattleGridEntity:canInfluenceBySkill()
|
|
if not self:isObstacleType() and not self:getSkillId() then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
function BattleGridEntity:isEmptyIdle()
|
|
if self:isEmptyType() and not self:getSkillId() 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 cfg = ModuleManager.BattleManager.SKILL_CFG[self: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
|
|
|
|
return BattleGridEntity |