c1_lua/lua/app/module/battle/battle_manager.lua
xiekaidong ccdd6a778b 棋盘
2023-04-06 10:38:04 +08:00

100 lines
2.9 KiB
Lua

local BattleManager = class("BattleManager", BaseModule)
local BattleConst = GConst.BattleConst
local BATTLE_CONTROLLER_BASE = "app/module/battle/controller/battle_controller"
local BATTLE_CONTROLLER = {}
function BattleManager:getPosInfo(posId)
local posInfo = GConst.BattleConst.GRID_POS[posId]
if not posInfo then
local r = self:getPosRC(posId).r
local c = self:getPosRC(posId).c
local x, y
x = (c - 1) * BattleConst.GRID_STEP_H
if r > 0 then
y = (r - 1) * BattleConst.GRID_STEP_H
else
y = r * BattleConst.GRID_STEP_H
end
y = - y
GConst.BattleConst.GRID_POS[posId] = {x = x, y = y}
posInfo = GConst.BattleConst.GRID_POS[posId]
end
return posInfo
end
function BattleManager:getElementIcon(elementType)
local icon = GConst.BattleConst.ELEMENT_ICON[elementType]
if not icon then
return GConst.ATLAS_PATH.COMMON, "common_algha"
end
return GConst.ATLAS_PATH.BATTLE, icon
end
function BattleManager:getGridTypeIcon(elementType)
local icon = GConst.BattleConst.ELEMENT_ICON[elementType]
if not icon then
return GConst.ATLAS_PATH.COMMON, "common_algha"
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] = {}
end
if not BattleConst.RC_2_POS_ID[row][column] then
local posId
local rowValue = row * BattleConst.ROW_STEP
if rowValue > 0 then
posId = rowValue + column
else
posId = rowValue - column
end
BattleConst.RC_2_POS_ID[row][column] = posId
end
return BattleConst.RC_2_POS_ID[row][column]
end
function BattleManager:getLastRowPosId(row, column)
return self:getPosId(row - 1, column)
end
function BattleManager:getLastRowPosIdByPosId(posId)
local rc = self:getPosRC(posId)
return self:getPosId(rc.r - 1, rc.c)
end
function BattleManager:getPosRC(posId)
if not BattleConst.POS_ID_2_RC[posId] then
local r = posId // BattleConst.ROW_STEP
local c
if r <= 0 then
local adsPosId = math.abs(posId)
c = adsPosId % BattleConst.ROW_STEP
else
c = posId % BattleConst.ROW_STEP
end
BattleConst.POS_ID_2_RC[posId] = {r = r , c = c}
end
return BattleConst.POS_ID_2_RC[posId]
end
function BattleManager:playBattle(params, returnFunc)
if self.battleController then -- 同一时间只能有一场战斗
self:clear()
end
self.returnFunc = returnFunc
UIManager:stopCurrentBGM()
self:_play(params)
end
function BattleManager:_play(params)
local controllerPath = BATTLE_CONTROLLER[battleType] or BATTLE_CONTROLLER_BASE
self.battleController = require(controllerPath):create()
self.battleController:init(params)
end
return BattleManager