difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//      这里填写详细说明,主要填写该模块的功能简要
// <br/>Create: 2019-04-15 14:38:52
// --------------------------------------------------------------------
var StoryController = require("story_controller");
var GuideMainView   = require("guide_main_window");
var StoryEvent      = require("story_event");
var GuideEvent      = require("guide_event");
 
var GuideController = cc.Class({
    extends: BaseController,
    ctor: function () {
    },
 
    // 初始化配置数据
    initConfig: function () {
        var GuideModel = require("guide_model");
 
        this.model = new GuideModel();
        this.model.initConfig();
        this.is_guiding = false;
        this.guide_list = [];        // 缓存的引导id
    },
 
    // 返回当前的model
    getModel: function () {
        return this.model;
    },
 
    // 注册监听事件
    registerEvents: function () {
        // this.init_role_event = gcore.GlobalEvent.bind(EventId.EVT_ROLE_CREATE_SUCCESS, function() {
        //     var data = {};
        //     data.id = 10185;
        //     this.handle11120(data);
        // }.bind(this))
        this.init_role_event = gcore.GlobalEvent.bind(StoryEvent.STORY_OVER, function() {
            if (this.guide_list && this.guide_list.length > 0) {
                var cur_guide = this.guide_list.shift();
                this.checkGuideToPlay(cur_guide); 
            }
        }.bind(this))   
        this.can_play_drama_event = gcore.GlobalEvent.bind(StoryEvent.PREPARE_PLAY_PLOT, function(){
            if(this.guide_list != null && Utils.next(this.guide_list) != null){
                if(this.guide_list.length){
                    let config = this.guide_list.splice(0,1)//table.remove(self.guide_list, 1)
                    this.checkGuideToPlay(config)
                }
            }
        }.bind(this))     
    },
 
    // 注册协议接受事件
    registerProtocals: function () {
        this.RegisterProtocal(11120, this.handle11120.bind(this));   // 播放引导
        this.RegisterProtocal(11121, this.handle11121.bind(this));   // 引导心跳包
        this.RegisterProtocal(11123, this.handle11123.bind(this));   // 清除所有剧情和引导        
    },
 
    handle11120: function(data) {
        cc.log("收到服务端执行引导协议");
        cc.log(data);
        // return;
        if (!data || !data.id) return 
        if (this.cur_guide_config && this.cur_guide_config.id == data.id) return;
        // 如果没有引导数据,直接结束掉
        var config = Config.drama_data.data_guide[data.id];
        if (!config) {
            this.startPlayGuide(false, data.id);
            return
        } 
        
        // 储存服务器发送过来的该引导已经完成的步数
        this.startPlayGuide(true, data.id);
    },
 
    send11121: function(guide_id, step) {
        var protocal = {};
        protocal.id = guide_id;
        protocal.n = step;
        this.SendProtocal(11121, protocal);
    },
 
    handle11121: function(data) {
        if (this.guide_view) {
            cc.log("保存成功,服务器返回");
            this.guide_view.doNextGuideFromServer(data.id, data.n);
        }
    },
 
    handle11123: function() {
 
    },
 
    // ==============================--
    // desc:开始播放客户端引导
    // time:2017-07-24 08:06:26
    // @status:
    // @id:
    // @return  
    // ==============================--
    startPlayGuide: function(status, id, is_skip) {
        gcore.GlobalEvent.fire(GuideEvent.CloseButtonListPanelEffect)
        if (!status) {
            // 这个时候做一个处理吧
            this.delayTouchEnabled();
            if (this.guide_view) {
                this.guide_view.close();
                this.guide_view = null;
            }
            this.is_guiding = false;
            this.cur_guide_config = null
            this.send11122(id, is_skip);
 
            // 是否有下一个引导
            if (this.guide_list && this.guide_list.length > 0) {
                cc.log("执行缓存中的引导");
                var config = this.guide_list.shift();
                    this.checkGuideToPlay(config);
            } else {
                // 主ui的聊天气泡
                var MainuiController = require("mainui_controller")
                MainuiController.getInstance().setMainUIChatBubbleStatus(true)                
            }
        } else {
            cc.log("222");
            // 如果客户端缓存已经完成了该引导则不需要继续了
            // var guide_cache = RoleEnv:getInstance():get(RoleEnv.keys.guide_step_list, {})
            // if guide_cache[id] ~= nil then
            //     if guide_cache[id][RoleEnv.keys.guide_over_step] == true then
            //         this.startPlayGuide(false, id)
            //         return 
            //     end
            // end
 
            var config = Config.drama_data.data_guide[id];
 
            var RoleController = require("role_controller")
            var role_vo = RoleController.getInstance().getRoleVo();
 
            var guide_cache_data = cc.sys.localStorage.getItem("guide_data" + role_vo.srv_id + role_vo.rid);   
 
            if (guide_cache_data) {
                guide_cache_data = JSON.parse(guide_cache_data);
                if (guide_cache_data[id] && guide_cache_data[id][config.over_step]) {
                    this.startPlayGuide(false, id);
                    return;                    
                }
            }
 
            if (!config || !config.act || config.act.length == 0) {
                this.startPlayGuide(false, id);
                return;
            }
 
            cc.log("111");
 
            // 判断播放引导
            this.checkGuideToPlay(config);
        }
    },
 
    send11122: function(id, is_skip) {
        if (is_skip) {
            is_skip = true;
        } else {
            is_skip = false;
        }
 
        var protocal = {};
        protocal.id = id;
        protocal.is_skip = is_skip;
        this.SendProtocal(11122, protocal)        
    },
 
    checkGuideToPlay: function(config) {
        if (!config) return;
 
        // 正在播放当前引导,不需要储存了
        if (this.cur_guide_config && this.cur_guide_config.id == config.id) return;
 
        // 待播放引导列表里面存在,也不需要存了
        for (var guide_i in this.guide_list) {
            if (this.guide_list[guide_i].id == config.id)
                return;
        }
 
        // 剧情状态下.不播放引导
        var story_status = StoryController.getInstance().getModel().isStoryState() || false; 
        if (story_status) {
            this.guide_list.push(config);
            return
        }
 
        // 如果出升级提示
        // var is_inlevipgrade = LevupgradeController:getInstance():waitLevupgrade()
        // if is_inlevipgrade then
        //     table_insert( self.guide_list, 1, config )
        //     return
        // end
 
        // 如果在引导中的时候,不播,缓存这吧
        if (this.cur_guide_config) {
            this.guide_list.push(config);            
            return;
        }
 
        cc.log("3333");
 
        if (config.act.length > 0) {
            this.playGuide(config);
        } else {
            this.startPlayGuide(false, config.bid);
        }
    },
 
    playGuide: function(config) {
        if (this.is_guiding) return;
        this.cur_guide_config = config;
        this.is_guiding = true;
        
        if (config.is_close == 1) {
            Utils.closeAllWindow();
            // BaseView.closeAllView()
        }
        // BaseView.closeSomeWin()
 
        // 主ui的聊天气泡
        // var MainuiController = require("mainui_controller")
        // MainuiController.getInstance().setMainUIChatBubbleStatus(false)
 
        if (!this.guide_view) {
            this.guide_view = new GuideMainView(this);
        }
 
        this.guide_view.open();
        this.guide_view.addGuid(config);
    },
 
    delayTouchEnabled: function() {
 
    },
 
    isInGuide: function() {
        return this.is_guiding;
    },
 
 
 
    //打开任务引导
    openTaskGuideWindow:function(status,config){
        if(status){
            if(this.task_guide_window == null){
                this.task_guide_window = Utils.createClass("task_guide_window");
            }
            this.task_guide_window.open(config);
        }else{
            if(this.task_guide_window){
                this.task_guide_window.close();
            }
            this.task_guide_window = null;
        }
    },
 
    getTaskGuideWindow:function(){
        return this.task_guide_window
    },
 
    getTaskGuideEffectStatus:function(){
        if(this.task_guide_window){
            return this.task_guide_window.getEffectActive();
        }
        return false
    },
 
    setGuideMainRootWnd:function(status){
        if(this.guide_view){
            this.guide_view.root_wnd.active = status;
        }
    }
});
 
module.exports = GuideController;