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
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//      这里填写详细说明,主要填写该模块的功能简要
// <br/>Create: 2019-03-06 20:33:19
// --------------------------------------------------------------------
var RoleController = require("role_controller");
var VoyageEvent = require("voyage_event");
 
var VoyageController = cc.Class({
    extends: BaseController,
    ctor: function () {
    },
 
    // 初始化配置数据
    initConfig: function () {
        var VoyageModel = require("voyage_model");
 
        this.model = new VoyageModel();
        this.model.initConfig();
    },
 
    // 返回当前的model
    getModel: function () {
        return this.model;
    },
 
    // 注册监听事件
    registerEvents: function () {
        if (this.init_role_event == null) {
            this.init_role_event = gcore.GlobalEvent.bind(EventId.EVT_ROLE_CREATE_SUCCESS, function () {
                gcore.GlobalEvent.unbind(this.init_role_event);
                this.init_role_event = null;
            }, this)
        }
 
        //断线重连的时候
        if (this.re_link_game_event == null) {
            this.re_link_game_event = gcore.GlobalEvent.bind(EventId.EVT_RE_LINK_GAME, function () {
            }, this)
        }
    },
 
    //请求远航数据
    requestVoyageInfo: function () {
        this.SendProtocal(23800, {});
    },
 
    //请求接取订单
    requestReceiveOrder: function (order_id, assign_ids) {
        var protocal = {};
        protocal.order_id = order_id;
        protocal.assign_ids = assign_ids;
        this.SendProtocal(23802, protocal);
    },
 
    //请求完成订单
    requestFinishOrder: function (order_id, type) {
        var protocal = {};
        protocal.order_id = order_id;
        protocal.type = type;
        this.SendProtocal(23803, protocal);
    },
 
    //请求刷新
    requestRefreshOrder: function () {
        this.SendProtocal(23804, {})
    },
 
    //请求远航活动状态
    requestActivityStatus: function () {
        var protocal = {};
        this.SendProtocal(23805, protocal);
    },
 
    // 注册协议接受事件
    registerProtocals: function () {
        this.RegisterProtocal(23800, this.handle23800)     // 远航数据(订单、刷新次数等)
        this.RegisterProtocal(23801, this.handle23801)     // 远航订单数据
        this.RegisterProtocal(23802, this.handle23802)     // 远航接取订单
        this.RegisterProtocal(23803, this.handle23803)     // 远航完成订单
        this.RegisterProtocal(23804, this.handle23804)     // 远航刷新订单
        this.RegisterProtocal(23805, this.handle23805)     // 远航活动状态
        this.RegisterProtocal(23820, this.handle23820)     // 远航记录返回
        this.RegisterProtocal(23821, this.handle23821)     // 第一次弹出特权提示
    },
 
    //远航数据(订单、刷新次数等)
    handle23800: function (data) {
        if (data.order_list) {
            this.model.setOrderList(data.order_list);
        }
        if (data.free_times) {
            this.model.setFreeTimes(data.free_times);
        }
        if (data.coin_times) {
            this.model.setCoinTimes(data.coin_times);
        }
        gcore.GlobalEvent.fire(VoyageEvent.UpdateVoyageDataEvent)
        gcore.GlobalEvent.fire(VoyageEvent.UpdateVoyageRedEvent)
    },
 
    //远航订单数据更新
    handle23801: function (data) {
        if (data) {
            this.model.updateOneOrderData(data);
            gcore.GlobalEvent.fire(VoyageEvent.UpdateVoyageRedEvent)
        }
    },
 
    //接取订单返回
    handle23802: function (data) {
        message(data.msg)
        if (data.flag == 1) {
            this.openVoyageDispatchWindow(false);
        }
    },
 
    //完成订单返回
    handle23803: function (data) {
        message(data.msg);
        if (data.flag == 1 && data.order_id) {
            this.model.deleteOneOrderData(data.order_id);
            gcore.GlobalEvent.fire(VoyageEvent.DeleteOrderDataEvent)
            gcore.GlobalEvent.fire(VoyageEvent.UpdateVoyageRedEvent)
        }
    },
 
    //刷新订单返回
    handle23804: function (data) {
        message(data.msg);
    },
 
    //远航活动状态
    handle23805: function (data) {
        if (data.flag) {
            this.model.setActivityStatus(data.flag);
            gcore.GlobalEvent.fire(VoyageEvent.UpdateActivityStatusEvent)
        }
    },
 
    //远航第一次点击特权记录
    send23820: function () {
        this.SendProtocal(23820,{})
    },
 
    handle23820: function (data) {
    },
 
    //请求特权记录情况
    send23821: function () {
        this.SendProtocal(23821,{})
    },
 
    handle23821: function (data) {
        this.model.setFirstFresh(data.flag != 1);
    },
 
    //--------------------------@ 界面相关
    openVoyageMainWindow: function (status, not_tips) {
        if (status == true) {
            if (!this.checkVoyageIsOpen(not_tips)) {
                return
            }
            if (!this.voyage_main_window) {
                this.voyage_main_window = Utils.createClass("voyage_main_window");
                this.voyage_main_window.open();
            }
        } else {
            if (this.voyage_main_window) {
                this.voyage_main_window.close();
                this.voyage_main_window = null;
            }
        }
    },
 
    //引导需要
    getVoyageMainRoot: function () {
        if (this.voyage_main_window) {
            return this.voyage_main_window.root_wnd
        }
    },
 
    //打开远航派遣界面
    openVoyageDispatchWindow: function (status, data) {
        if (status == true) {
            if (!this.voyage_dispatch_window) {
                this.voyage_dispatch_window = Utils.createClass("voyage_dispatch_window");
                this.voyage_dispatch_window.open(data);
            }
        } else {
            if (this.voyage_dispatch_window) {
                this.voyage_dispatch_window.close();
                this.voyage_dispatch_window = null;
            }
        }
    },
 
    //远航是否开启
    checkVoyageIsOpen: function (no_tips) {
        var is_open = false;
        var lev_config = Config.shipping_data.data_const["guild_lev"];
        var role_vo = RoleController.getInstance().getRoleVo();
        if (lev_config && lev_config.val <= role_vo.lev) {
            is_open = true;
        } else if (!no_tips) {
            message(lev_config.desc)
        }
        return is_open;
    },
 
    getVoyageMainRoot: function () {
        if (this.voyage_main_window)
            return this.voyage_main_window.root_wnd;
    },
 
    getVoyageDispatchRoot: function () {
        if (this.voyage_dispatch_window)
            return this.voyage_dispatch_window.root_wnd;
    },
});
 
module.exports = VoyageController;