158 lines
3.0 KiB
Lua
158 lines
3.0 KiB
Lua
local BattleData = class("BattleData", BaseData)
|
||
|
||
local BattleConst = GConst.BattleConst
|
||
local BATTLE_GRID_ENTITY = require "app/userdata/battle/battle_grid_entity"
|
||
|
||
local TEST_INIT = {
|
||
{1, 2},
|
||
{1, 4},
|
||
{1, 1},
|
||
{0, 4},
|
||
{0, 3},
|
||
{0, 3},
|
||
{0, 3},
|
||
{1, 4},
|
||
{1, 3},
|
||
{0, 3},
|
||
{0, 1},
|
||
{0, 4},
|
||
{0, 2},
|
||
{0, 1},
|
||
{1, 1},
|
||
{1, 4},
|
||
{1, 2},
|
||
{1, 3},
|
||
{0, 4},
|
||
{0, 4},
|
||
{1, 4},
|
||
{0, 4},
|
||
{0, 2},
|
||
{1, 4},
|
||
{0, 4},
|
||
{1, 1},
|
||
{0, 3},
|
||
{1, 2},
|
||
{0, 1},
|
||
{0, 1},
|
||
{0, 4},
|
||
{1, 4},
|
||
{0, 3},
|
||
{0, 4},
|
||
{1, 3},
|
||
{1, 1},
|
||
{0, 4},
|
||
{1, 3},
|
||
{0, 3},
|
||
{1, 2},
|
||
{1, 1},
|
||
{0, 4},
|
||
{1, 2},
|
||
{0, 4},
|
||
{0, 3},
|
||
{1, 3},
|
||
{1, 4},
|
||
{0, 4},
|
||
{0, 4},
|
||
}
|
||
|
||
function BattleData:init(data)
|
||
self:clear()
|
||
|
||
for i, info in ipairs(TEST_INIT) do
|
||
local r = 1
|
||
local c = 1
|
||
local zheng = i // BattleConst.ROW_COUNT
|
||
local yu = i % BattleConst.ROW_COUNT
|
||
if yu > 0 then
|
||
r = zheng + 1
|
||
c = yu
|
||
else
|
||
r = zheng
|
||
c = BattleConst.ROW_COUNT
|
||
end
|
||
|
||
local posId = ModuleManager.BattleManager:getPosId(r, c)
|
||
local data = {
|
||
posId = posId,
|
||
gridType = info[1],
|
||
elementType = info[2]
|
||
}
|
||
self.gridEntities[data.posId] = BATTLE_GRID_ENTITY:create(data)
|
||
end
|
||
end
|
||
|
||
function BattleData:clear()
|
||
self:clearGridSequence()
|
||
|
||
self.gridEntities = {}
|
||
end
|
||
|
||
function BattleData:getGridSequence()
|
||
return self.gridSequence
|
||
end
|
||
|
||
function BattleData:insertGridSequence(posId)
|
||
if self.gridSequenceMap[posId] then
|
||
return false
|
||
end
|
||
|
||
self.gridSequenceMap[posId] = true
|
||
table.insert(self.gridSequence, posId)
|
||
return true
|
||
end
|
||
|
||
function BattleData:removeGridSequence(posId)
|
||
if not self.gridSequenceMap[posId] then
|
||
return false
|
||
end
|
||
|
||
local count = #self.gridSequence
|
||
local lastPosId = self.gridSequence[count]
|
||
if lastPosId ~= posId then
|
||
return false
|
||
end
|
||
|
||
table.remove(self.gridSequence, count)
|
||
self.gridSequenceMap[lastPosId] = false
|
||
return true
|
||
end
|
||
|
||
function BattleData:clearGridSequence()
|
||
self.gridSequence = {} -- 格子队列
|
||
self.gridSequenceMap = {} -- 格子队列对应的map,方面查找
|
||
end
|
||
|
||
function BattleData:getGridEnties()
|
||
return self.gridEntities
|
||
end
|
||
|
||
function BattleData:getGridEntity(posId)
|
||
return self.gridEntities[posId]
|
||
end
|
||
|
||
function BattleData:exchangeGridEntities(posId1, posId2)
|
||
local e1 = self.gridEntities[posId1]
|
||
local e2 = self.gridEntities[posId2]
|
||
e1:setPosId(posId2)
|
||
e2:setPosId(posId1)
|
||
e2:setIsIdle(false)
|
||
self.gridEntities[posId1] = e2
|
||
self.gridEntities[posId2] = e1
|
||
end
|
||
|
||
function BattleData:setGridInfo(posId, gridInfo)
|
||
local entity = self.gridEntities[posId]
|
||
if not entity then
|
||
return
|
||
end
|
||
|
||
if gridInfo.gridType then
|
||
entity:setGridType(gridInfo.gridType)
|
||
end
|
||
|
||
if gridInfo.elementType then
|
||
entity:setElementType(gridInfo.elementType)
|
||
end
|
||
end
|
||
|
||
return BattleData |