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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
"use strict";
cc._RF.push(module, '0425f3UaltIrbxpcLSkBcOr', 'guildwar_controller');
// Scripts/mod/guildwar/guildwar_controller.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//      这里填写详细说明,主要填写该模块的功能简要
// <br/>Create: 2019-05-06 17:56:47
// --------------------------------------------------------------------
var RoleController = require("role_controller");
 
var GuildwarEvent = require("guildwar_event");
 
var GuildwarController = cc.Class({
  "extends": BaseController,
  ctor: function ctor() {},
  // 初始化配置数据
  initConfig: function initConfig() {
    var Guild_warModel = require("guildwar_model");
 
    this.model = new Guild_warModel(this);
    this.model.initConfig();
  },
  // 返回当前的model
  getModel: function getModel() {
    return this.model;
  },
  // 注册监听事件
  registerEvents: function registerEvents() {
    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.role_vo = RoleController.getInstance().getRoleVo();
 
        if (this.role_vo != null) {
          if (this.role_assets_event == null) {
            this.role_assets_event = this.role_vo.bind(EventId.UPDATE_ROLE_ATTRIBUTE, function (key, value) {
              if (key == "guild_lev") {
                if (value == 0) {
                  //退出联盟,清掉数据
                  this.model.initConfig();
                }
              }
            }, this);
          }
        }
      }, this);
    }
  },
  //登陆时、联盟等级变化时请求
  requestInitProtocal: function requestInitProtocal() {
    this.reqestGuildWarStatus();
    this.requestAwardBoxData(); //公会宝箱红点用到
  },
  //请求联盟战详细数据
  requestGuildWarData: function requestGuildWarData() {
    this.SendProtocal(24200, {});
  },
  //请求敌方单个据点数据
  requestEnemyPositionData: function requestEnemyPositionData(pos) {
    if (!pos) return;
    var protocal = {};
    protocal.pos = pos;
    this.SendProtocal(24201, protocal);
  },
  //发起战斗
  requestGuildWarFighting: function requestGuildWarFighting(pos, hp, flag) {
    if (!pos) return;
    var protocal = {};
    protocal.pos = pos;
    protocal.hp = hp;
    protocal.flag = flag;
    this.SendProtocal(24202, protocal);
  },
  //请求联盟战状态
  reqestGuildWarStatus: function reqestGuildWarStatus() {
    this.SendProtocal(24204, {});
  },
  //请求对战列表数据
  requestGuildWarBattleList: function requestGuildWarBattleList() {
    this.SendProtocal(24205, {});
  },
  //请求本方联盟战据点数据
  requestMyGuildPositionData: function requestMyGuildPositionData() {
    this.SendProtocal(24208, {});
  },
  //请求据点防守记录
  requestPositionDefendData: function requestPositionDefendData(g_id1, g_sid1, pos) {
    var protocal = {};
    protocal.pos = pos;
    protocal.g_id1 = g_id1;
    protocal.g_sid1 = g_sid1;
    this.SendProtocal(24209, protocal);
  },
  //请求战场日志
  requestBattleLogData: function requestBattleLogData() {
    this.SendProtocal(24212, {});
  },
  //请求联盟战详细排名数据
  requestGuildWarRankData: function requestGuildWarRankData() {
    this.SendProtocal(24213, {});
  },
  //请求宝箱数据
  requestAwardBoxData: function requestAwardBoxData() {
    this.SendProtocal(24220, {});
  },
  //请求领取宝箱数据
  requestGetBoxAward: function requestGetBoxAward(order) {
    var protocal = {};
    protocal.order = order;
    this.SendProtocal(24221, protocal);
  },
  // 注册协议接受事件
  registerProtocals: function registerProtocals() {
    this.RegisterProtocal(24200, this.handle24200); // 联盟战详细信息
 
    this.RegisterProtocal(24201, this.handle24201); // 敌方单个据点信息
 
    this.RegisterProtocal(24202, this.handle24202); // 发起战斗
 
    this.RegisterProtocal(24203, this.handle24203); // 战斗结果
 
    this.RegisterProtocal(24204, this.handle24204); // 联盟战的状态
 
    this.RegisterProtocal(24205, this.handle24205); // 对战列表
 
    this.RegisterProtocal(24206, this.handle24206); // 据点数据更新(只更新有变化的)
 
    this.RegisterProtocal(24207, this.handle24207); // 联盟战基础数据更新(星数、buff等)
 
    this.RegisterProtocal(24208, this.handle24208); // 本方联盟战据点数据
 
    this.RegisterProtocal(24209, this.handle24209); // 防守记录
 
    this.RegisterProtocal(24210, this.handle24210); // 有新的日志产生
 
    this.RegisterProtocal(24212, this.handle24212); // 战场日志
 
    this.RegisterProtocal(24213, this.handle24213); // 联盟战详细排名
 
    this.RegisterProtocal(24214, this.handle24214); // 联盟战结果
 
    this.RegisterProtocal(24220, this.handle24220); // 联盟战宝箱数据
 
    this.RegisterProtocal(24221, this.handle24221); // 领取联盟战宝箱
 
    this.RegisterProtocal(24223, this.handle24223); // 更新单个联盟战宝箱
  },
  //联盟战数据
  handle24200: function handle24200(data) {
    data = data || {};
 
    if (data.count) {
      //已挑战次数
      this.model.setGuildWarChallengeCount(data.count);
    }
 
    if (data.result) {
      this.model.setGuildWarResult(data.result);
    }
 
    if (data.ranks) {
      this.model.setGuildWarTopThreeRank(data.ranks);
    } //我方联盟基础信息
 
 
    var myBaseInfo = {};
    myBaseInfo.gname = data.gname1;
    myBaseInfo.hp = data.hp1;
    myBaseInfo.buff_lev = data.buff_lev1;
    this.model.setMyGuildWarBaseInfo(myBaseInfo); //敌方联盟数据
 
    this.model.setEnemyGuildWarData(data);
    gcore.GlobalEvent.fire(GuildwarEvent.GuildWarEnemyPositionDataInitEvent);
  },
  //敌方单个据点数据
  handle24201: function handle24201(data) {
    if (data && this.attk_position_window) {
      this.attk_position_window.setData(data);
    }
  },
  //发起战斗
  handle24202: function handle24202(data) {
    message(data.msg);
 
    if (data.code == 1) {
      this.model.setGuildWarChallengeCount(data.count);
      gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildwarChallengeCountEvent);
      this.openAttkPositionWindow(false);
      this.openAttkLookWindow(false);
    }
  },
  //挑战据点的战斗结果
  handle24203: function handle24203(data) {
    var BattleConst = require("battle_const");
 
    require("battle_controller").getInstance().openFinishView(true, BattleConst.Fight_Type.GuildWar, data);
  },
  //联盟战状态
  handle24204: function handle24204(data) {
    if (data) {
      this.model.setGuildWarStatus(data);
      gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarStatusEvent, data.status, data.flag);
    }
  },
  //联盟战对阵列表
  handle24205: function handle24205(data) {
    if (data && this.battle_list_window) {
      this.battle_list_window.setData(data);
    }
  },
  //据点数据更新(本方与对方都走这里,变量更)
  handle24206: function handle24206(data) {
    if (data) {
      if (data.flag && data.flag == 1) {
        this.model.updateMyGuildWarPositionData(data.defense);
      } else {
        this.model.updateEnemyGuildWarPositionData(data.defense);
      }
    }
  },
  //联盟战基础数据更新(星数、buff等)
  handle24207: function handle24207(data) {
    if (data) {
      if (data.result) {
        this.model.setGuildWarResult(data.result);
      }
 
      if (data.hp && data.buff_lev) {
        var myBaseInfo = {};
        myBaseInfo.hp = data.hp;
        myBaseInfo.buff_lev = data.buff_lev;
        this.model.updateMyGuildWarBaseInfo(myBaseInfo);
      }
 
      if (data.hp2) {
        this.model.updateEnemyGuildWarBaseInfo(data.hp2);
      }
 
      if (data.ranks) {
        this.model.setGuildWarTopThreeRank(data.ranks);
      }
 
      gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarBaseInfoEvent);
    }
  },
  //本方据点数据
  handle24208: function handle24208(data) {
    if (data) {
      this.model.setMyGuildWarPositionData(data.defense);
      gcore.GlobalEvent.fire(GuildwarEvent.GetGuildWarMyPositionDataEvent);
    }
  },
  //防守记录
  handle24209: function handle24209(data) {
    if (data && this.defend_look_window) {
      this.defend_look_window.setData(data);
    }
  },
  //有新的日志产生
  handle24210: function handle24210() {
    var GuildConst = require("guild_const");
 
    this.model.updateGuildWarRedStatus(GuildConst.red_index.guildwar_log, true, true);
  },
  //战场日志
  handle24212: function handle24212(data) {
    if (this.battle_log_window && data) {
      this.battle_log_window.setData(data.guild_war_log);
    }
  },
  //联盟战详细排名
  handle24213: function handle24213(data) {
    if (data) {
      gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarRankDataEvent, data.ranks);
    }
  },
  //联盟战结果
  handle24214: function handle24214(data) {
    if (data && data.result) {
      this.model.setGuildWarResult(data.result);
      gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarBaseInfoEvent);
    }
  },
  //联盟战宝箱数据
  handle24220: function handle24220(data) {
    if (data) {
      this.model.setGuildWarBoxData(data);
      gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarBoxDataEvent, data);
    }
  },
  //领取宝箱
  handle24221: function handle24221(data) {
    message(data.msg);
  },
  //更新单个宝箱数据
  handle24223: function handle24223(data) {
    if (data) {
      this.model.updateGuildWarBoxData(data); //判断一下是否为玩家自己领取了宝箱,更新界面领取状态
 
      if (this.role_vo && data.rid == this.role_vo.rid && data.sid == this.role_vo.srv_id) {
        gcore.GlobalEvent.fire(GuildwarEvent.UpdateMyAwardBoxEvent);
      }
    }
  },
  //-----------------------------------------------界面
  //打开联盟战主界面
  openMainWindow: function openMainWindow(status) {
    if (status == false) {
      if (this.main_window) {
        this.main_window.close();
        this.main_window = null;
      }
    } else {
      if (IS_SHOW_CHARGE == false) {
        message(Utils.TI18N("功能暂未开放,敬请期待"));
        return;
      }
 
      if (this.role_vo == null || this.role_vo.gid == 0) {
        message(Utils.TI18N("您当前未加入任何公会,加入公会后才能参与该玩法!"));
        return;
      }
 
      var config = Config.guild_war_data.data_const.limit_lev;
 
      if (config == null) {
        message(Utils.TI18N("公会战数据异常!"));
        return;
      }
 
      if (this.role_vo.guild_lev < config.val) {
        message(Utils.TI18N("您所在的公会未达参赛条件,不能参与哦,请努力提高公会等级!"));
        return;
      }
 
      if (this.main_window == null) {
        this.main_window = Utils.createClass("guildwar_main_window");
      }
 
      this.main_window.open();
    }
  },
  //打开进攻一览
  openAttkLookWindow: function openAttkLookWindow(status) {
    if (status == false) {
      if (this.attk_look_window) {
        this.attk_look_window.close();
        this.attk_look_window = null;
      }
    } else {
      if (this.attk_look_window == null) {
        this.attk_look_window = Utils.createClass("guildwar_attk_look_window");
      }
 
      this.attk_look_window.open();
    }
  },
  //打开防守记录
  openDefendLookWindow: function openDefendLookWindow(status, g_id, g_sid, pos) {
    if (status == false) {
      if (this.defend_look_window) {
        this.defend_look_window.close();
        this.defend_look_window = null;
      }
    } else {
      if (this.defend_look_window == null) {
        this.defend_look_window = Utils.createClass("guildwar_defend_look_window");
      }
 
      this.defend_look_window.open({
        g_id: g_id,
        g_sid: g_sid,
        pos: pos
      });
    }
  },
  //打开对阵列表
  openBattleListWindow: function openBattleListWindow(status) {
    if (status == false) {
      if (this.battle_list_window) {
        this.battle_list_window.close();
        this.battle_list_window = null;
      }
    } else {
      if (this.battle_list_window == null) {
        this.battle_list_window = Utils.createClass("guildwar_battle_list_window");
      }
 
      this.battle_list_window.open();
    }
  },
  //打开战场日志
  openBattleLogWindow: function openBattleLogWindow(status) {
    if (status == false) {
      if (this.battle_log_window) {
        this.battle_log_window.close();
        this.battle_log_window = null;
      }
    } else {
      if (this.battle_log_window == null) {
        this.battle_log_window = Utils.createClass("guildwar_battle_log_window");
      }
 
      this.battle_log_window.open();
    }
  },
  //打开战绩奖励
  openGuildWarAwardWindow: function openGuildWarAwardWindow(status) {
    if (status == false) {
      if (this.guildwar_award_window) {
        this.guildwar_award_window.close();
        this.guildwar_award_window = null;
      }
    } else {
      if (this.guildwar_award_window == null) {
        this.guildwar_award_window = Utils.createClass("guildwar_award_window");
      }
 
      this.guildwar_award_window.open();
    }
  },
  //打开挑战据点界面
  openAttkPositionWindow: function openAttkPositionWindow(status, pos) {
    if (status == false) {
      if (this.attk_position_window) {
        this.attk_position_window.close();
        this.attk_position_window = null;
      }
    } else {
      if (this.attk_position_window == null) {
        this.attk_position_window = Utils.createClass("guildwar_attk_position_window");
      }
 
      this.attk_position_window.open(pos);
    }
  },
  //打开战绩排行榜界面
  openGuildWarRankView: function openGuildWarRankView(status, pos) {
    if (status == false) {
      if (this.guildwar_rank_window) {
        this.guildwar_rank_window.close();
        this.guildwar_rank_window = null;
      }
    } else {
      if (this.guildwar_rank_window == null) {
        this.guildwar_rank_window = Utils.createClass("guildwar_rank_window");
      }
 
      this.guildwar_rank_window.open(pos);
    }
  },
  //判断是否开启联盟战
  checkIsCanOpenGuildWarWindow: function checkIsCanOpenGuildWarWindow(not_tips) {
    var isOpen = true;
    var limit_lev = Config.guild_war_data.data_const.limit_lev.val;
    var config_day = Config.guild_war_data.data_const.limit_open_time; //开服天数限制
 
    var role_vo = RoleController.getInstance().getRoleVo();
    var open_srv_day = RoleController.getInstance().getModel().getOpenSrvDay();
 
    if (!role_vo.isHasGuild()) {
      if (!not_tips) {
        message(Utils.TI18N("您当前未加入任何公会,加入公会后才能参与该玩法!"));
      }
 
      isOpen = false;
    } else if (role_vo.guild_lev < limit_lev) {
      if (!not_tips) {
        message(Utils.TI18N("您所在的公会未达参赛条件,不能参与哦,请努力提高公会等级!"));
      }
 
      isOpen = false;
    } else if (open_srv_day <= config_day.val) {
      if (!not_tips) {
        message(config_day.desc);
      }
 
      isOpen = false;
    }
 
    return isOpen, limit_lev;
  },
  //打开公会战宝箱奖励
  openAwardBoxWindow: function openAwardBoxWindow(status) {
    if (status == false) {
      if (this.award_box_window) {
        this.award_box_window.close();
        this.award_box_window = null;
      }
    } else {
      if (this.award_box_window == null) {
        this.award_box_window = Utils.createClass("guildwar_award_box_window");
      }
 
      this.award_box_window.open();
    }
  },
  //打开宝箱奖励预览
  openAwardBoxPreview: function openAwardBoxPreview(status) {
    if (status == false) {
      if (this.award_box_preview) {
        this.award_box_preview.close();
        this.award_box_preview = null;
      }
    } else {
      if (this.award_box_preview == null) {
        this.award_box_preview = Utils.createClass("guildwar_award_box_preview");
      }
 
      this.award_box_preview.open();
    }
  }
});
module.exports = GuildwarController;
 
cc._RF.pop();