require("operation.SourceOperate")
|
|
require("operation.NowOperate")
|
|
require("operation.NowOperateNop")
|
|
require("operation.SourceOperateCrossSceneAction")
|
|
|
|
require("operation.SourceOperateMove")
|
|
require("operation.NowOperateMove")
|
|
require("operation.SourceOperateJump")
|
|
require("operation.NowOperateJump")
|
|
|
|
require("operation.SourceOperateTargetAction")
|
|
require("operation.NowOperateTargetMove")
|
|
|
|
|
|
OperateManager = OperateManager or BaseClass()
|
|
local OperateManager = OperateManager
|
|
local rawget = rawget
|
|
local GlobalEventSystem = GlobalEventSystem
|
|
OperateManager.OperateType = {
|
|
Unknown = 0,
|
|
Move = 1,
|
|
Attack = 2,
|
|
Skill = 3,
|
|
}
|
|
OperateManager.SourceOperateType =
|
|
{
|
|
Unknown = 1,
|
|
Move = 2,
|
|
CrossScene = 3,
|
|
TargetAction = 4,
|
|
}
|
|
|
|
function OperateManager:__init()
|
|
OperateManager.Instance = self
|
|
self.source_oper = false
|
|
self.now_oper = false
|
|
|
|
self.enter_playing_handle = nil
|
|
self.quit_playing_handle = nil
|
|
|
|
--当前阶段是否需要运行
|
|
self.need_run = false
|
|
|
|
--最小移动周期
|
|
self.min_move_tip_time = 0.3
|
|
|
|
self.jump_point_obj = nil --跳点对象
|
|
|
|
--注册相关事件
|
|
self:RegisterEvents()
|
|
|
|
--添加到Runner中以便每帧执行Update
|
|
Runner.Instance:AddLateRunObj(self, 1)
|
|
|
|
-- 当前寻路点
|
|
self.current_target_pos = co.Vector2(0,0)
|
|
|
|
self.pokemon_source_oper_list = false
|
|
self.pokemon_now_oper_list = {}
|
|
end
|
|
|
|
function OperateManager:RegisterEvents( )
|
|
local enter_playing_callback = function ( )
|
|
self.need_run = true
|
|
end
|
|
|
|
local quit_playing_callback = function ( )
|
|
self.need_run = false
|
|
end
|
|
self.enter_playing_handle =
|
|
EventSystem.Bind(GlobalEventSystem,SceneManager.START, enter_playing_callback)
|
|
|
|
self.quit_playing_handle =
|
|
EventSystem.Bind(GlobalEventSystem,SceneManager.DISPOSE, quit_playing_callback)
|
|
end
|
|
|
|
|
|
function OperateManager:DeleteMe()
|
|
EventSystem.UnBind(GlobalEventSystem,self.enter_playing_handle)
|
|
EventSystem.UnBind(GlobalEventSystem,self.quit_playing_handle)
|
|
end
|
|
|
|
function OperateManager:LateUpdate(now_time, elapse_time)
|
|
if not self.need_run then
|
|
return
|
|
end
|
|
|
|
if self.pokemon_source_oper_list then
|
|
if TableSize(self.pokemon_source_oper_list) > 0 then
|
|
local source_oper
|
|
local now_oper
|
|
local source_delete_list = {}
|
|
for pokemon_id,source_oper in pairs(self.pokemon_source_oper_list) do
|
|
now_oper = self.pokemon_now_oper_list[pokemon_id]
|
|
if not now_oper then
|
|
if source_oper:IsFinish() then
|
|
source_oper:DeleteMe()
|
|
source_oper = nil
|
|
source_delete_list[pokemon_id] = true
|
|
else
|
|
self.pokemon_now_oper_list[pokemon_id] = source_oper:GetOper()
|
|
end
|
|
else
|
|
if now_oper:Excute(elapse_time) then
|
|
now_oper:DeleteMe()
|
|
now_oper = nil
|
|
self.pokemon_now_oper_list[pokemon_id] = nil
|
|
end
|
|
end
|
|
end
|
|
|
|
for pokemon_id,_ in pairs(source_delete_list) do
|
|
self.pokemon_source_oper_list[pokemon_id] = nil
|
|
end
|
|
end
|
|
end
|
|
|
|
if self.source_oper then
|
|
if not self.now_oper then
|
|
if self.source_oper:IsFinish() then
|
|
local next_target = self.source_oper:GetNextTarget()
|
|
local cross_scene = self.source_oper:GetCrossScene()
|
|
self.source_oper:DeleteMe()
|
|
self.source_oper = false
|
|
|
|
if next_target then
|
|
-- print("next_target------------:", next_target.target.x, next_target.target.y)
|
|
self:StartMoveAction(next_target.target,next_target.func,next_target.arg)
|
|
end
|
|
|
|
if cross_scene then
|
|
self:StartCrossSceneAction(cross_scene.id, cross_scene.pos, cross_scene.change_scene_callback, cross_scene.action_func, cross_scene.arg_list)
|
|
end
|
|
else
|
|
self.now_oper = self.source_oper:GetOper() or false
|
|
end
|
|
end
|
|
end
|
|
|
|
if self.now_oper then
|
|
if self.now_oper:Excute(elapse_time) then
|
|
if self.now_oper then
|
|
self.now_oper:DeleteMe()
|
|
self.now_oper = false
|
|
end
|
|
end
|
|
return
|
|
end
|
|
|
|
end
|
|
|
|
--clear_now_scene 跨场景寻路的过程中清掉当前场景的操作包
|
|
function OperateManager:ClearSrcOper(clear_now_scene)
|
|
if clear_now_scene and self.source_oper and self.source_oper.type == OperateManager.SourceOperateType.CrossScene then
|
|
self.source_oper:ClearNowMoveSrcOper()
|
|
else
|
|
if self.source_oper then
|
|
-- if self.source_oper.BeforeDelete then
|
|
-- self.source_oper:BeforeDelete()
|
|
-- end
|
|
self.source_oper:DeleteMe()
|
|
end
|
|
self.source_oper = false
|
|
end
|
|
|
|
|
|
if self.now_oper then
|
|
self.now_oper:DeleteMe()
|
|
self.now_oper = false
|
|
end
|
|
if AutoFightManager:getInstance().auto_find_way_state then
|
|
EventSystem.Fire(GlobalEventSystem,SceneEventType.CLEAR_SRC_OPERATE)
|
|
end
|
|
end
|
|
|
|
function OperateManager:IsNoOperWork(owner_key)
|
|
return not self.source_oper and not self.now_oper
|
|
end
|
|
|
|
function OperateManager:GetNowSrcOper()
|
|
return self.source_oper
|
|
end
|
|
|
|
--由摇杆触发,停止移动
|
|
--is_fire_evt 返回is_fire_evt,有些地方执行了这个方法,又触发FINDWAY_ENDED
|
|
function OperateManager:StopMove(clear_now_scene)
|
|
local main_role = Scene.Instance:GetMainRole()
|
|
if main_role == nil then
|
|
return
|
|
end
|
|
local is_fire_evt = false
|
|
main_role:WaitForNextMove()
|
|
self:ClearSrcOper(clear_now_scene)
|
|
if not self.source_oper then
|
|
is_fire_evt = true
|
|
EventSystem.Fire(GlobalEventSystem,EventName.FINDWAY_ENDED)
|
|
end
|
|
return is_fire_evt
|
|
end
|
|
|
|
function OperateManager:IsNearJumpArea( point )
|
|
|
|
local check = function(x_a,y_a)
|
|
local cur_pos_x = point.x + x_a
|
|
local cur_pos_y = point.y + y_a
|
|
local is_jump = SceneManager:getInstance():IsAreaType(cur_pos_x,cur_pos_y, AreaDataIndex.JumpType)
|
|
if is_jump then
|
|
return true
|
|
end
|
|
end
|
|
|
|
if check(0,0) or check(1,0) or check(0,1) or check(-1,0) or check(0,-1) or check(1,-1) or check(1,1) or check(-1,1) or check(-1,-1) then
|
|
return true
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
function OperateManager:CheckJumpAction( now_pair,path_list,action_func,arg_list,cross_scene )
|
|
if EnglineVersion and AppConst_EnglineVer >= 4 then
|
|
local end_pos = path_list[#path_list].end_point
|
|
local end_is_block = SceneManager:getInstance():IsBlockXY(end_pos.x, end_pos.y)
|
|
if end_is_block then
|
|
return
|
|
end
|
|
|
|
local posx,posy = Scene.Instance:GetMainRole():GetLogicPos()
|
|
if self:IsNearJumpArea(co.TableXY(posx,posy)) then
|
|
for i=1, now_pair -2, 1 do
|
|
table.remove(path_list,1)
|
|
end
|
|
local try_jump = function()
|
|
OperateManager.Instance:StartJumpAction(path_list,action_func,arg_list,cross_scene)
|
|
end
|
|
TimerQuest.AddDelayQuest(GlobalTimerQuest, try_jump,0.1)
|
|
end
|
|
end
|
|
end
|
|
|
|
function OperateManager:CurSourceOper()
|
|
local after_jump_data = nil
|
|
local oper_type = nil
|
|
if self.source_oper then
|
|
oper_type = self.source_oper.type
|
|
if oper_type == OperateManager.SourceOperateType.CrossScene then
|
|
after_jump_data = {
|
|
self.source_oper.target_scene_id,
|
|
self.source_oper.target_scene_pos,
|
|
self.source_oper.change_scene_callback,
|
|
self.source_oper.action_func,
|
|
self.source_oper.arg_list,
|
|
}
|
|
|
|
elseif oper_type == OperateManager.SourceOperateType.Move then
|
|
-- PrintTable(self.source_oper.end_pos)
|
|
local pos_x,pos_y = Scene.Instance:GetMainRole():GetLogicPos()
|
|
if self.source_oper.end_pos.x and self.source_oper.end_pos.y then
|
|
-- local is_near = GameMath.IsPointNear(pos_x, pos_y, self.source_oper.end_pos.x, self.source_oper.end_pos.y, 0)
|
|
-- if not is_near then
|
|
after_jump_data = {
|
|
self.source_oper.end_pos,
|
|
self.source_oper.action_func,
|
|
self.source_oper.arg_list,
|
|
}
|
|
-- end
|
|
end
|
|
end
|
|
self:ClearSrcOper()
|
|
end
|
|
|
|
return after_jump_data,oper_type
|
|
end
|
|
|
|
--以下均接受逻辑坐标
|
|
|
|
-- function OperateManager:StartJumpPointAction( jump_point_obj )
|
|
-- self.jump_point_obj = jump_point_obj
|
|
-- if self.jump_point_obj == nil then return end
|
|
|
|
-- local play_action = function()
|
|
-- if self.jump_point_obj then
|
|
-- self.jump_point_obj:DoJump()
|
|
-- end
|
|
-- end
|
|
|
|
-- local onMainRoleJumpEnd = function()
|
|
-- if self.jump_point_obj and self.jump_point_obj:JumpFinish() then
|
|
-- if self.after_jump_event then
|
|
-- GlobalEventSystem:UnBind(self.after_jump_event)
|
|
-- end
|
|
-- self.jump_point_obj = nil
|
|
-- else
|
|
-- GlobalTimerQuest:AddDelayQuest(play_action,0.1)
|
|
-- end
|
|
-- GlobalEventSystem:Fire(EventName.JUMP_POINT_END)
|
|
-- end
|
|
|
|
-- local after_jump_data,oper_type = self:CurSourceOper()
|
|
-- if after_jump_data then
|
|
-- local onMainRoleJumpEnd = function()
|
|
-- if self.jump_point_obj and self.jump_point_obj:JumpFinish() then
|
|
-- if oper_type == OperateManager.SourceOperateType.Move then
|
|
-- local end_pos = after_jump_data[1]
|
|
-- if not SceneManager:getInstance():IsAreaType(end_pos.x,end_pos.y, AreaDataIndex.JumpType) then
|
|
-- -- print("------StartJumpPointAction-------:", after_jump_data[1].x,after_jump_data[1].y)
|
|
-- self:StartMoveAction(after_jump_data[1],after_jump_data[2],after_jump_data[3])
|
|
-- end
|
|
-- else
|
|
-- self:StartCrossSceneAction(after_jump_data[1], after_jump_data[2], after_jump_data[3], after_jump_data[4], after_jump_data[5])
|
|
-- end
|
|
-- if self.after_jump_event then
|
|
-- GlobalEventSystem:UnBind(self.after_jump_event)
|
|
-- end
|
|
-- self.jump_point_obj = nil
|
|
-- else
|
|
-- GlobalTimerQuest:AddDelayQuest(play_action,0.1)
|
|
-- end
|
|
-- end
|
|
-- self.after_jump_event = GlobalEventSystem:Bind(SceneEventType.MAIN_ROLE_JUMP_END, onMainRoleJumpEnd)
|
|
-- else
|
|
-- self.after_jump_event = GlobalEventSystem:Bind(SceneEventType.MAIN_ROLE_JUMP_END, onMainRoleJumpEnd)
|
|
-- end
|
|
-- if self.jump_point_obj then
|
|
-- self.jump_point_obj:DoJump()
|
|
-- end
|
|
-- end
|
|
|
|
|
|
function OperateManager:JumpEndHandler()
|
|
if self.jump_end_not_continue then
|
|
self:ClearSrcOper()
|
|
GlobalEventSystem:Fire(EventName.FINDWAY_ENDED)
|
|
self.jump_end_not_continue = false
|
|
return
|
|
end
|
|
local after_jump_data,oper_type = self:CurSourceOper()
|
|
print("--------------JumpEndHandler------------:", after_jump_data)
|
|
if after_jump_data then
|
|
if oper_type == OperateManager.SourceOperateType.Move then
|
|
local end_pos = after_jump_data[1]
|
|
if not SceneManager:getInstance():IsAreaType(end_pos.x,end_pos.y, AreaDataIndex.JumpType) then
|
|
print("------------跳完后继续寻路----------")
|
|
|
|
--优化,如果是跳跃才能到达的点,mapview算出的是目标点范围一个点,而不是最近的,这里重新计算
|
|
-- if after_jump_data[3] and after_jump_data[3][1] and after_jump_data[3][2] then
|
|
-- Scene.Instance:MainRoleMove(after_jump_data[3][1],after_jump_data[3][2],after_jump_data[2])
|
|
-- else
|
|
self:StartMoveAction(after_jump_data[1],after_jump_data[2],after_jump_data[3])
|
|
-- end
|
|
end
|
|
else
|
|
self:StartCrossSceneAction(after_jump_data[1], after_jump_data[2], after_jump_data[3], after_jump_data[4], after_jump_data[5])
|
|
end
|
|
end
|
|
end
|
|
|
|
function OperateManager:StartMoveAction(end_pos, action_func, ...)
|
|
self:ClearSrcOper()
|
|
self.source_oper = SourceOperateMove.New(end_pos, action_func, {...})
|
|
end
|
|
|
|
function OperateManager:StartJumpAction(path_list, action_func, arg_list,cross_scene)
|
|
self:ClearSrcOper()
|
|
|
|
self.source_oper = SourceOperateJump.New(path_list, action_func, arg_list,cross_scene)
|
|
end
|
|
|
|
function OperateManager:StartInitedMoveAction(path, action_func, ...)
|
|
self:ClearSrcOper()
|
|
|
|
self.source_oper = SourceOperateMove.New(nil, action_func, {...})
|
|
self.source_oper:SetPathList(path)
|
|
end
|
|
|
|
|
|
--[[@
|
|
功能: 开始执行一个TargetAction操作(靠近目标,执行对应动作)
|
|
参数:
|
|
target_compress_id 目标的压缩ID int32
|
|
range 范围 numeric
|
|
action_func 动作函数 function
|
|
action_period_func 动作周期函数,获取执行动作的周期 function
|
|
action_end_func 结束动作的条件 function
|
|
clear_func 清理函数 function
|
|
scene_obj:场景对象
|
|
返回值:
|
|
无
|
|
其它: 无
|
|
作者: deadline
|
|
]]
|
|
|
|
function OperateManager:StartTargetAction(target_compress_id, range, action_func, action_period_func, action_end_func, clear_func,scene_obj)
|
|
-- print("OperateManager:ClearSrcOper 9")
|
|
self:ClearSrcOper()
|
|
self.source_oper = SourceOperateTargetAction.New(target_compress_id, range, action_func, action_period_func, action_end_func, clear_func,scene_obj)
|
|
return true
|
|
end
|
|
|
|
|
|
function OperateManager:StartPokemonTargetAction(target_compress_id, range, action_func, action_period_func, action_end_func, clear_func,scene_obj,pokemon_id)
|
|
self.pokemon_source_oper_list = self.pokemon_source_oper_list or {}
|
|
self:ClearPokemonSrcOper(pokemon_id)
|
|
self.pokemon_source_oper_list[pokemon_id] = SourceOperateTargetAction.New(target_compress_id, range, action_func, action_period_func, action_end_func, clear_func,scene_obj)
|
|
return true
|
|
end
|
|
|
|
--clear_now_scene 跨场景寻路的过程中清掉当前场景的操作包
|
|
function OperateManager:ClearPokemonSrcOper(pokemon_id)
|
|
local source_oper = self.pokemon_source_oper_list[pokemon_id]
|
|
if source_oper then
|
|
source_oper:DeleteMe()
|
|
source_oper = nil
|
|
self.pokemon_source_oper_list[pokemon_id] = nil
|
|
end
|
|
|
|
local now_oper = self.pokemon_now_oper_list[pokemon_id]
|
|
if now_oper then
|
|
now_oper:DeleteMe()
|
|
now_oper = nil
|
|
self.pokemon_now_oper_list[pokemon_id] = nil
|
|
end
|
|
end
|
|
|
|
|
|
--clear_now_scene 跨场景寻路的过程中清掉当前场景的操作包
|
|
function OperateManager:ClearAllPokemonSrcOper()
|
|
if TableSize(self.pokemon_source_oper_list) > 0 then
|
|
for pokemon_id,_ in pairs(self.pokemon_source_oper_list) do
|
|
local source_oper = self.pokemon_source_oper_list[pokemon_id]
|
|
if source_oper then
|
|
source_oper:DeleteMe()
|
|
source_oper = nil
|
|
end
|
|
|
|
local now_oper = self.pokemon_now_oper_list[pokemon_id]
|
|
if now_oper then
|
|
now_oper:DeleteMe()
|
|
now_oper = nil
|
|
end
|
|
end
|
|
end
|
|
|
|
self.pokemon_source_oper_list = {}
|
|
self.pokemon_now_oper_list = {}
|
|
end
|
|
|
|
|
|
|
|
function OperateManager:StartCrossSceneAction(scene_id, end_pos, change_scene_callback, action_func, ...)
|
|
self:ClearSrcOper()
|
|
self.source_oper = SourceOperateCrossSceneAction.New(scene_id,
|
|
end_pos, change_scene_callback, action_func, {...})
|
|
|
|
return true
|
|
end
|