require("game.proto.500.Require500")
|
|
require("game.escort.EscortModel")
|
|
require("game.escort.EscortConst")
|
|
require("game.escort.EscortMainView")
|
|
require("game.escort.EscortItem")--主界面的item
|
|
require("game.escort.EscortResultView")--结算界面
|
|
require("game.escort.EscortStageResultView")--一阶段结算界面
|
|
require("game.escort.EscortSceneView")--场景界面
|
|
|
|
EscortController = EscortController or BaseClass(BaseController)
|
|
|
|
function EscortController:__init()
|
|
EscortController.Instance = self
|
|
self.model = EscortModel:getInstance()
|
|
self:InitEvent()
|
|
self:RegisterAllProtocals()
|
|
end
|
|
|
|
function EscortController:InitEvent()
|
|
local function onRequestHandler(...)
|
|
local args_list = {...}
|
|
self.igonre_once = false
|
|
if args_list[1] == 50010 or args_list[1] == 50003 or args_list[1] == 50001 or args_list[1] == 50002 then
|
|
self:SendFmtToGame(args_list[1], "c", args_list[2])
|
|
else
|
|
self:SendFmtToGame(args_list[1])
|
|
end
|
|
end
|
|
self.model:Bind(EscortConst.REQUEST_SCMD_EVENT, onRequestHandler)
|
|
|
|
local function gameStartHandler()
|
|
if GetModuleIsOpen(500) then
|
|
self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50000)
|
|
end
|
|
end
|
|
GlobalEventSystem:Bind(EventName.GAME_START, gameStartHandler)
|
|
GlobalEventSystem:Bind(EventName.CHANE_DAY, gameStartHandler)
|
|
|
|
local function show_left()
|
|
self.model:SetEscortSceneLeftHideState(false)
|
|
end
|
|
GlobalEventSystem:Bind(EventName.FINISHED_COM_DIALOGUE_SHOW_ANIM, show_left)
|
|
|
|
local function onOpenEscortView(show)
|
|
if show then
|
|
if self.EscortMainView == nil then
|
|
self.EscortMainView = EscortMainView.New()
|
|
end
|
|
self.EscortMainView:Open()
|
|
else
|
|
if self.EscortMainView and self.EscortMainView:HasOpen() then
|
|
self.EscortMainView:Close()
|
|
end
|
|
end
|
|
end
|
|
GlobalEventSystem:Bind(EscortConst.OPEN_ESCORT_VIEW, onOpenEscortView)
|
|
|
|
local function scene_change_func()
|
|
self:ChangeScene()
|
|
end
|
|
GlobalEventSystem:Bind(EventName.SCENE_LOAD_VIEW_COMPLETE, scene_change_func)
|
|
local function on_activity_change( ... )
|
|
-- local rob_id = RoleManager.Instance:GetMainRoleVo():GetFlagsByKey(RoleVo.Act_Flag.CONVOY_ROB)
|
|
-- local scene_mgr = SceneManager:getInstance()
|
|
-- if rob_id > 0 and scene_mgr:IsEscortScene() then--打劫id大于0 且在护送2阶段场景 才显示
|
|
-- if self.EscortSceneView == nil then
|
|
-- self.EscortSceneView = EscortSceneView.New()
|
|
-- end
|
|
-- if not self.EscortSceneView:HasOpen() then
|
|
-- self.EscortSceneView:Open()
|
|
-- end
|
|
-- self:SetMainUIVisible(false)
|
|
-- end
|
|
end
|
|
RoleManager:getInstance():GetMainRoleVo():BindOne("activity_flags", on_activity_change)
|
|
|
|
local function on_open_escort_result_view(show, data)
|
|
if show then
|
|
if self.EscortResultView == nil then
|
|
self.EscortResultView = EscortResultView.New()
|
|
end
|
|
self.EscortResultView:Open(data)
|
|
else
|
|
if self.EscortResultView and self.EscortResultView:HasOpen() then
|
|
self.EscortResultView:Close()
|
|
end
|
|
end
|
|
end
|
|
self.model:Bind(EscortConst.OPEN_ESCORT_RESULT_VIEW, on_open_escort_result_view)
|
|
|
|
local function on_open_stage_result_view( show )
|
|
if show then
|
|
if self.EscortStageResultView == nil then
|
|
self.EscortStageResultView = EscortStageResultView.New()
|
|
end
|
|
self.EscortStageResultView:Open()
|
|
else
|
|
if self.EscortStageResultView and self.EscortStageResultView:HasOpen() then
|
|
self.EscortStageResultView:Close()
|
|
end
|
|
end
|
|
end
|
|
self.model:Bind(EscortConst.OPEN_STAGE_ESCORT_RESULT_VIEW, on_open_stage_result_view)
|
|
local function on_fly_to_npc( )
|
|
self.model:FlyToNpc()
|
|
end
|
|
self.model:Bind(EscortConst.FLY_TO_NPC, on_fly_to_npc)
|
|
|
|
local function on_change_scene()
|
|
self:ChangeScene()
|
|
end
|
|
self.model:Bind(EscortConst.CHANGE_SCENE, on_change_scene)
|
|
end
|
|
|
|
function EscortController:TipsCall( )
|
|
local main_vo = RoleManager.Instance.mainRoleInfo
|
|
local temp_head_name = main_vo.name
|
|
local head_type = "100"..main_vo.career
|
|
local str = string.format("后面的路程会有一点危险,请集中注意力!")
|
|
local data = {
|
|
head_type = head_type,
|
|
desc = str,
|
|
head_name = temp_head_name or "",
|
|
hide_time = 5,
|
|
dalay_time = 1,
|
|
is_task_type = true,
|
|
}
|
|
self.model:SetEscortSceneLeftHideState(true)
|
|
GlobalEventSystem:Fire(EventName.SHOW_COM_DIALOGUE_SHOW_VIEW,data)
|
|
end
|
|
|
|
function EscortController:ChangeScene()
|
|
local scene_mgr = SceneManager.Instance
|
|
if self.model:IsEscortState() and scene_mgr:IsEscortAllScene() then
|
|
if self.EscortSceneView == nil then
|
|
self.EscortSceneView = EscortSceneView.New()
|
|
end
|
|
if not self.EscortSceneView:HasOpen() then
|
|
self.EscortSceneView:Open()
|
|
end
|
|
self:SetMainUIVisible(false)
|
|
elseif scene_mgr:IsEscortAllScene(scene_mgr:GetLastSceneId()) then -- 上一个场景是护送
|
|
if self.EscortSceneView then
|
|
self.EscortSceneView:Close()
|
|
end
|
|
self:SetMainUIVisible(true)
|
|
else
|
|
if self.EscortSceneView then
|
|
self.EscortSceneView:Close()
|
|
end
|
|
-- 非自己场景由其他模块负责判断主界面ui可见性
|
|
-- self:SetMainUIVisible(true)
|
|
end
|
|
if scene_mgr:IsEscortScene() and self.model:IsEscortState() then
|
|
-- self:TipsCall()
|
|
Scene:getInstance():CleanEscortInfo()--切了场景 需要清空一下跟车状态
|
|
self.model.not_pause = false--暂停一下
|
|
local function delay_method( )
|
|
self.model.not_pause = true
|
|
end
|
|
setTimeout(delay_method, 2)
|
|
local function delay_method( )
|
|
self.model:GoEscortNpc()
|
|
end
|
|
setTimeout(delay_method, 1)
|
|
end
|
|
if self.model.need_find_npc then
|
|
self.model.need_find_npc = false
|
|
local function delay_method( )
|
|
self.model:GoEscortNpc(0, true)
|
|
end
|
|
setTimeout(delay_method, 1)
|
|
end
|
|
end
|
|
|
|
function EscortController:SetMainUIVisible(value)
|
|
self:Fire(EventName.HIDE_TASK_TEAM_VIEW, not value)--任务栏
|
|
GlobalEventSystem:Fire(EventName.CHANGE_RIGHT_TIP_ICON, not value, MainUIModel.OTHER_MODE) --菜单伸展
|
|
end
|
|
|
|
function EscortController:RegisterAllProtocals( )
|
|
self:RegisterProtocal(50000, "Handle50000")--打开护送信息
|
|
self:RegisterProtocal(50001, "Handle50001")--刷新护送品质
|
|
self:RegisterProtocal(50002, "Handle50002")--开始护送
|
|
self:RegisterProtocal(50003, "Handle50003")--完成阶段护送
|
|
self:RegisterProtocal(50004, "Handle50004")--结算
|
|
self:RegisterProtocal(50008, "Handle50008")--取消护送
|
|
self:RegisterProtocal(50009, "Handle50009")--切换到任务NPC
|
|
self:RegisterProtocal(50010, "Handle50010")--通知场景的人玩家开始护送
|
|
end
|
|
|
|
-- ########### 打开护送信息 ##########
|
|
-- protocol=50000
|
|
-- {
|
|
-- c2s{
|
|
-- }
|
|
-- s2c{
|
|
-- object_id:int32 // 对象ID
|
|
-- convoy_counts:int8 // 今天护送次数
|
|
-- is_convoy:int8 // 是否护送状态
|
|
-- }
|
|
-- }
|
|
|
|
function EscortController:Handle50000( )
|
|
local scmd = SCMD50000.New(true)
|
|
print("HWR:EscortController [start:207] scmd:", scmd)
|
|
PrintTable(scmd)
|
|
print("HWR:EscortController [end]")
|
|
|
|
self.model:SetEscortBaseInfo(scmd)
|
|
self.model:Fire(EscortConst.ANS_BASIC_INFO)
|
|
self:ChangeScene()
|
|
end
|
|
|
|
-- ########### 刷新护送品质 ##########
|
|
-- protocol=50001
|
|
-- {
|
|
-- c2s{
|
|
-- auto_buy:int8 // 是否自动购买
|
|
-- }
|
|
-- s2c{
|
|
-- code:int32 // 错误码
|
|
-- object_id:int32 // 新的对象id
|
|
-- pray_val:int16 // 祝福值
|
|
-- reward_list:arr_object_list // 消耗列表
|
|
-- }
|
|
-- }
|
|
|
|
function EscortController:Handle50001( )
|
|
local scmd = SCMD50001.New(true)
|
|
print("HWR:EscortController [start:225] scmd:", scmd)
|
|
PrintTable(scmd)
|
|
print("HWR:EscortController [end]")
|
|
local base_info = self.model:GetEscortBaseInfo()
|
|
local cur_pray_val = base_info.pray_val or 0
|
|
local up_pray_val = scmd.pray_val - cur_pray_val
|
|
if scmd.object_id ~= 0 then
|
|
self.model:SetEscortObjectId(scmd.object_id, scmd.pray_val)
|
|
end
|
|
local str = "消耗%s刷新"
|
|
local len = #scmd.reward_list
|
|
if len > 0 then
|
|
local use_goods = false
|
|
local use_money = 0
|
|
if len > 0 then
|
|
for i,v in ipairs(scmd.reward_list) do
|
|
if v.style == 2 or v.style == 1 then
|
|
use_money = use_money + 1
|
|
elseif v.style == 0 then
|
|
use_goods = true
|
|
end
|
|
end
|
|
end
|
|
--如果花钱了 就优先提示花钱多少
|
|
--没花钱就提示消耗道具
|
|
local count = 0
|
|
for i,v in ipairs(scmd.reward_list) do
|
|
if use_money > 0 then--如果是花了钱的就不提示物品了
|
|
if v.style ~= 0 then
|
|
count = count + 1
|
|
local typeId, lock = GoodsModel:getInstance():GetMappingTypeId(v.style, v.typeId)
|
|
local goods_name,colorStr = GoodsModel:getInstance():getGoodsName(typeId, true)
|
|
if count < use_money then--到最后一个元素了没
|
|
str = string.format(str, goods_name..HtmlColorTxt("x"..v.count, colorStr).."、%s")
|
|
else
|
|
str = string.format(str, goods_name..HtmlColorTxt("x"..v.count, colorStr))
|
|
end
|
|
end
|
|
else
|
|
local typeId, lock = GoodsModel:getInstance():GetMappingTypeId(v.style, v.typeId)
|
|
local goods_name,colorStr = GoodsModel:getInstance():getGoodsName(typeId, true)
|
|
str = string.format(str, goods_name..HtmlColorTxt("x"..v.count, colorStr))
|
|
end
|
|
end
|
|
end
|
|
if scmd.code == 1 and len > 0 then
|
|
if scmd.pray_val == 0 then
|
|
self.model:Fire(EscortConst.UPGRADE_SUCCESS, scmd.object_id)
|
|
Message.show("提升品质成功")
|
|
else
|
|
local text = string.format("提升失败,获得%s点祝福值", up_pray_val)
|
|
Message.show(text)
|
|
end
|
|
Message.show(str,"success")
|
|
elseif len > 0 then
|
|
Message.show(str)
|
|
ErrorCodeShow(scmd.code)
|
|
else
|
|
ErrorCodeShow(scmd.code)
|
|
end
|
|
end
|
|
|
|
-- ########### 开始护送 ##########
|
|
-- protocol=50002
|
|
-- {
|
|
-- c2s{
|
|
-- is_double:int8 // 是否双倍 0否|1是
|
|
-- }
|
|
-- s2c{
|
|
-- code:int32 // 错误码
|
|
-- convoy_id:int32 // 护送id
|
|
-- is_double:int8 // 是否双倍 0否|1是
|
|
-- }
|
|
-- }
|
|
|
|
function EscortController:Handle50002( )
|
|
local scmd = SCMD50002.New(true)
|
|
self.model.is_go_on = true
|
|
if scmd.code == 1 then
|
|
GlobalEventSystem:Fire(EventName.HIDE_HORSE)
|
|
GlobalEventSystem:Fire(EscortConst.OPEN_ESCORT_VIEW, false)
|
|
local str = "护送开始"
|
|
Message.show(str,"success")
|
|
self:ChangeScene()
|
|
self.model:GoEscortNpc(1)
|
|
self.model:SetEscortCarFollow(true)
|
|
|
|
local main_vo = RoleManager.Instance.mainRoleInfo
|
|
local cfg = Config.Convoyobject[scmd.convoy_id]
|
|
local name = ""
|
|
if cfg then
|
|
name = Trim(cfg.name)
|
|
end
|
|
local temp_head_name = main_vo.name
|
|
local head_type = "100"..main_vo.career
|
|
local str = string.format("运气不错!接取了%s护送 任务!让我们开始护送吧!", name)
|
|
local data = {
|
|
head_type = head_type,
|
|
desc = str,
|
|
head_name = temp_head_name or "",
|
|
hide_time = 5,
|
|
dalay_time = 1,
|
|
is_task_type = true,
|
|
}
|
|
GlobalEventSystem:Fire(EventName.SHOW_COM_DIALOGUE_SHOW_VIEW,data)
|
|
self.model:SetEscortSceneLeftHideState(true)
|
|
TaskModel:getInstance():SetNeedTaskFlag(false)
|
|
self.model.not_show_go_ask_indeed = self.model.not_show_go_ask
|
|
self.model:SetIsLastDouble(scmd.is_double, true)
|
|
else
|
|
ErrorCodeShow(scmd.code)
|
|
end
|
|
end
|
|
|
|
-- ########### 完成阶段护送 ##########
|
|
-- protocol=50003
|
|
-- {
|
|
-- c2s{
|
|
-- type:int8 // 1阶段一|2阶段二
|
|
-- }
|
|
-- s2c{
|
|
-- result:int32 // 返回码
|
|
-- type:int8 // 1阶段一|2阶段二
|
|
-- }
|
|
-- }
|
|
function EscortController:Handle50003( )
|
|
local scmd = SCMD50003.New(true)
|
|
print("HWR:EscortController [start:337] scmd:", scmd)
|
|
PrintTable(scmd)
|
|
print("HWR:EscortController [end]")
|
|
if scmd.result == 1 and scmd.type == 2 then
|
|
Message.show("运送完成")
|
|
elseif scmd.result ~= 1 then
|
|
ErrorCodeShow(scmd.result)
|
|
end
|
|
end
|
|
|
|
-- ########### 结算 ##########
|
|
-- protocol=50004
|
|
-- {
|
|
-- s2c{
|
|
-- result:int8 // 1完美|2损坏|3超时|4主动取消护送
|
|
-- stage:int8 // 1第一阶段 2第二阶段
|
|
-- object_id:int32 // 对象ID
|
|
-- convoy_counts:int8 // 今天护送次数
|
|
-- }
|
|
-- }
|
|
|
|
function EscortController:Handle50004( )
|
|
local scmd = SCMD50004.New(true)
|
|
if scmd.result ~= 3 then
|
|
self.model:Fire(EscortConst.OPEN_ESCORT_RESULT_VIEW, true, scmd)
|
|
-- self:ChangeScene()
|
|
-- self:SetMainUIVisible(true)
|
|
self.model:SetEscortBaseInfo({})
|
|
else
|
|
self:SetMainUIVisible(true)
|
|
self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50000)
|
|
self.model:SetEscortBaseInfo({})
|
|
end
|
|
if scmd.stage == 1 then
|
|
elseif scmd.stage == 2 then
|
|
self:SetMainUIVisible(true)
|
|
end
|
|
end
|
|
|
|
function EscortController:Handle50008( )
|
|
-- self.model:SetEscortStageInfo({})
|
|
self.model:SetEscortBaseInfo({})
|
|
self:ChangeScene()
|
|
OperateManager.Instance:StopMove()
|
|
end
|
|
|
|
-- ########### 切换到任务NPC##########
|
|
function EscortController:Handle50009( )
|
|
local scmd = SCMD50009.New(true)
|
|
if scmd.code ~= 1 then
|
|
ErrorCodeShow(scmd.code)
|
|
end
|
|
end
|
|
|
|
-- ########### 通知场景的人玩家开始护送 ##########
|
|
function EscortController:Handle50010( )
|
|
local scmd = SCMD50010.New(true)
|
|
local scene_mgr = SceneManager:getInstance()
|
|
local roleVo = scene_mgr:GetRoleVo(scmd.role_id)
|
|
if roleVo ~= nil then
|
|
roleVo:ChangeVar("escort_state", scmd.angel_id, nil, true)
|
|
else
|
|
end
|
|
end
|