c1_lua/lua/app/module/battle/battle_manager.lua
2023-04-06 18:32:04 +08:00

91 lines
2.8 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 offsetC = c - BattleConst.HALF_COLUMN_COUNT
local offsetR = BattleConst.HALF_ROW_COUNT - r
local info = {x = offsetC * BattleConst.GRID_STEP_H, y = offsetR * BattleConst.GRID_STEP_H}
GConst.BattleConst.GRID_POS[posId] = info
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
rowValue = rowValue + BattleConst.ROW_STEP
posId = rowValue - column
end
BattleConst.RC_2_POS_ID[row][column] = posId
end
return BattleConst.RC_2_POS_ID[row][column]
end
function BattleManager:getFirstLineLastRowPosId(row, column)
return self:getPosId(1 - row, column)
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