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
"use strict";
cc._RF.push(module, 'dc0cbWrCZpHsKhtL0KmhaiN', 'guildwar_model');
// Scripts/mod/guildwar/guildwar_model.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//      这里填写详细说明,主要填写该模块的功能简要
// <br/>Create: 2019-05-06 17:56:47
// --------------------------------------------------------------------
var GuildConst = require("guild_const");
 
var GuildwarConst = require("guildwar_const");
 
var GuildWarPositionVo = require("guildwar_position_vo");
 
var GuildEvent = require("guild_event");
 
var GuildwarEvent = require("guildwar_event");
 
var GuildWarBoxVo = require("guildwar_box_vo");
 
var Guild_warModel = cc.Class({
  "extends": BaseClass,
  ctor: function ctor() {
    this.ctrl = arguments[0];
  },
  properties: {},
  initConfig: function initConfig() {
    this.challengeCount = 0; // 已挑战次数
 
    this.guildWarResult = GuildwarConst.result.fighting; // 战斗结果
 
    this.myGuildWarBaseInfo = {}; // 我方联盟战基础数据(星数、buff等)
 
    this.enemyGuildWarBaseInfo = {}; // 敌方联盟战基础数据(星数、名称)
 
    this.guildWarStatus = GuildwarConst.status.close; // 联盟战状态
 
    this.guildWarStartTime = 0; // 联盟战开始时间
 
    this.guildWarEndTime = 0; // 联盟战结束时间
 
    this.guildWarEnemyFlag = 0; // 是否匹配到对手
 
    this.guildWarTopThreeRank = {}; // 前三排名
 
    this.myGuildWarPositionList = {}; // 我方据点数据
 
    this.enemyGuildWarPositionList = {}; // 敌方据点数据
 
    this.award_box_data = []; // 奖励宝箱数据
 
    this.guildwar_red_list = {}; // 红点数据
  },
  //本地是否有联盟战敌方数据
  checkIsHaveEnemyCacheData: function checkIsHaveEnemyCacheData() {
    if (Utils.next(this.enemyGuildWarPositionList) == null) {
      return false;
    } else {
      return true;
    }
  },
  //设置已挑战次数
  setGuildWarChallengeCount: function setGuildWarChallengeCount(count) {
    this.challengeCount = count || 0;
    this.updateChallengeCountRedStatus(0);
  },
  getGuildWarChallengeCount: function getGuildWarChallengeCount() {
    return this.challengeCount;
  },
  //更新挑战次数红点
  updateChallengeCountRedStatus: function updateChallengeCountRedStatus() {
    if (this.guildWarEnemyFlag == 1 && this.guildWarStatus == GuildwarConst.status.processing && this.challengeCount < Config.guild_war_data.data_const.challange_time_limit.val) {
      this.updateGuildWarRedStatus(GuildConst.red_index.guildwar_count, true);
    } else {
      this.updateGuildWarRedStatus(GuildConst.red_index.guildwar_count, false);
    }
  },
  //设置联盟战结果
  setGuildWarResult: function setGuildWarResult(result) {
    this.guildWarResult = result;
  },
  getGuildWarResult: function getGuildWarResult() {
    return this.guildWarResult;
  },
  //设置我方联盟战基础数据(星数、buff等)
  setMyGuildWarBaseInfo: function setMyGuildWarBaseInfo(data) {
    this.myGuildWarBaseInfo = data || {};
  },
  getMyGuildWarBaseInfo: function getMyGuildWarBaseInfo() {
    return this.myGuildWarBaseInfo;
  },
  //更新我方联盟战基础数据
  updateMyGuildWarBaseInfo: function updateMyGuildWarBaseInfo(data) {
    for (var k in data) {
      this.myGuildWarBaseInfo[k] = data[k];
    }
  },
  //更新敌方联盟战基础数据(目前只是星数)
  updateEnemyGuildWarBaseInfo: function updateEnemyGuildWarBaseInfo(hp) {
    this.enemyGuildWarBaseInfo.hp = hp;
  },
  getEnemyGuildWarBaseInfo: function getEnemyGuildWarBaseInfo() {
    return this.enemyGuildWarBaseInfo;
  },
  //设置敌方联盟战数据
  setEnemyGuildWarData: function setEnemyGuildWarData(data) {
    //基础数据
    this.enemyGuildWarBaseInfo.gname = data.gname2 || "";
    this.enemyGuildWarBaseInfo.hp = data.hp2 || 0;
    this.enemyGuildWarBaseInfo.g_id = data.g_id || 0;
    this.enemyGuildWarBaseInfo.g_sid = data.g_sid || ""; //据点数据
 
    this.enemyGuildWarPositionList = {};
 
    for (var k in data.defense || {}) {
      var pdata = data.defense[k];
      var position_vo = new GuildWarPositionVo();
      position_vo.updateData(pdata);
      this.enemyGuildWarPositionList[pdata.pos] = position_vo;
    }
  },
  getEnemyGuildWarPositionList: function getEnemyGuildWarPositionList() {
    var list = [];
 
    for (var i in this.enemyGuildWarPositionList) {
      var vo = this.enemyGuildWarPositionList[i];
 
      if (vo) {
        list.push(vo);
      }
    }
 
    return list;
  },
  //获取敌方某一据点的当前血量
  getEnemyPositionHpByPos: function getEnemyPositionHpByPos(pos) {
    var position_vo = this.enemyGuildWarPositionList[pos];
 
    if (position_vo) {
      return position_vo.hp;
    }
 
    return 0;
  },
  //敌方是否还有存活的据点
  checkEnemyIsHaveLivePosition: function checkEnemyIsHaveLivePosition() {
    var is_have = false;
 
    for (var k in this.enemyGuildWarPositionList) {
      var vo = this.enemyGuildWarPositionList[k];
 
      if (vo.hp > 0) {
        is_have = true;
        break;
      }
    }
 
    return is_have;
  },
  //设置联盟战状态数据
  setGuildWarStatus: function setGuildWarStatus(data) {
    this.guildWarStatus = data.status || GuildwarConst.status.close;
    this.guildWarStartTime = data.start_time || 0;
    this.guildWarEndTime = data.end_time || 0;
    this.guildWarEnemyFlag = data.flag || 0; //当状态变为未开启时,清掉缓存数据
 
    if (this.guildWarStatus == GuildwarConst.status.close) {
      this.initConfig();
    }
 
    this.checkGuildWarStatusRed();
    this.updateChallengeCountRedStatus();
  },
  //更新联盟战状态的红点
  checkGuildWarStatusRed: function checkGuildWarStatusRed() {
    if (this.guildWarEnemyFlag == 1 && this.guildWarStatus == GuildwarConst.status.showing) {
      this.updateGuildWarRedStatus(GuildConst.red_index.guildwar_match, true);
    } else if (this.guildWarEnemyFlag == 1 && this.guildWarStatus == GuildwarConst.status.processing) {
      this.updateGuildWarRedStatus(GuildConst.red_index.guildwar_start, true);
      this.updateGuildWarRedStatus(GuildConst.red_index.guildwar_match, false);
    } else {
      this.updateGuildWarRedStatus(GuildConst.red_index.guildwar_match, false);
      this.updateGuildWarRedStatus(GuildConst.red_index.guildwar_start, false);
    }
  },
  getGuildWarStatus: function getGuildWarStatus() {
    return this.guildWarStatus;
  },
  getGuildWarSurplusTime: function getGuildWarSurplusTime() {
    return this.guildWarEndTime - gcore.SmartSocket.getTime();
  },
  getGuildWarEnemyFlag: function getGuildWarEnemyFlag() {
    return this.guildWarEnemyFlag;
  },
  //设置我方联盟战据点数据
  setMyGuildWarPositionData: function setMyGuildWarPositionData(dataList) {
    this.myGuildWarPositionList = {};
 
    for (var k in dataList) {
      var data = dataList[k];
      var position_vo = new GuildWarPositionVo();
      position_vo.updateData(data);
      this.myGuildWarPositionList[data.pos] = position_vo;
    }
  },
  getMyGuildWarPositionList: function getMyGuildWarPositionList() {
    return this.myGuildWarPositionList;
  },
  //更新我方据点数据(变量更)
  updateMyGuildWarPositionData: function updateMyGuildWarPositionData(dataList) {
    dataList = dataList || {};
 
    for (var k in dataList) {
      var data = dataList[k];
      var position_vo = this.myGuildWarPositionList[data.pos];
 
      if (position_vo) {
        position_vo.updateData(data);
      }
    }
  },
  //更新敌方据点数据(变量更)
  updateEnemyGuildWarPositionData: function updateEnemyGuildWarPositionData(dataList) {
    dataList = dataList || {};
 
    for (var k in dataList) {
      var data = dataList[k];
      var position_vo = this.enemyGuildWarPositionList[data.pos];
 
      if (position_vo) {
        position_vo.updateData(data);
      }
    }
  },
  //设置联盟战前三名数据
  setGuildWarTopThreeRank: function setGuildWarTopThreeRank(data) {
    this.guildWarTopThreeRank = data;
  },
  getGuildWarTopThreeRank: function getGuildWarTopThreeRank() {
    return this.guildWarTopThreeRank;
  },
  //更新联盟战红点
  updateGuildWarRedStatus: function updateGuildWarRedStatus(bid, status, is_just_guildwar) {
    if (this.guildwar_red_list == null) {
      this.guildwar_red_list = {};
    }
 
    var _status = this.guildwar_red_list[bid];
    if (_status == status) return;
    this.guildwar_red_list[bid] = status;
 
    if (!is_just_guildwar) {
      //更新场景红点状态
      var MainuiConst = require("mainui_const");
 
      require("mainui_controller").getInstance().setBtnRedPoint(MainuiConst.btn_index.guild, {
        bid: bid,
        status: status
      }); //更新公会主界面红点
 
 
      gcore.GlobalEvent.fire(GuildEvent.UpdateGuildRedStatus, bid, status);
    } //更新公会战主界面红点
 
 
    gcore.GlobalEvent.fire(GuildwarEvent.UpdateGuildWarRedStatusEvent, bid, status);
  },
  checkRedIsShowByRedType: function checkRedIsShowByRedType(redType) {
    return this.guildwar_red_list[redType] || false;
  },
  checkGuildGuildWarRedStatus: function checkGuildGuildWarRedStatus() {
    for (var k in this.guildwar_red_list) {
      //排除日志红点,日志无需在入口处显示红点
      var v = this.guildwar_red_list[k];
 
      if (v == true && k != GuildConst.red_index.guildwar_log) {
        return true;
      }
    }
 
    return false;
  },
  //设置奖励宝箱数据
  setGuildWarBoxData: function setGuildWarBoxData(data) {
    var dataList = data.guild_war_box;
    var result = data.result;
    var status = data.status;
    var end_time = data.end_time;
 
    if (dataList) {
      this.award_box_data = [];
 
      for (var k in dataList) {
        var data = dataList[k];
        data.status = result; // 在这里赋值宝箱类型(金和铜)
 
        var box_vo = new GuildWarBoxVo();
        box_vo.updateData(data);
        this.award_box_data.push(box_vo);
      }
    }
 
    var cur_time = gcore.SmartSocket.getTime(); //是否有权限领取宝箱、是否已到领取截止时间
 
    if (status && status == 1 && end_time && end_time > cur_time) {
      this.is_can_get_box = true;
    } else {
      this.is_can_get_box = false;
    }
 
    if (this.is_can_get_box && !this.checkIsGetBoxAward()) {
      this.updateGuildWarRedStatus(GuildConst.red_index.guildwar_box, true);
    } else {
      this.updateGuildWarRedStatus(GuildConst.red_index.guildwar_box, false);
    }
  },
  //更新宝箱数据
  updateGuildWarBoxData: function updateGuildWarBoxData(data) {
    if (data) {
      var box_vo = this.getGuildWarDataByOrder(data.order);
 
      if (box_vo) {
        box_vo.updateData(data);
      }
 
      if (this.is_can_get_box && !this.checkIsGetBoxAward()) {
        this.updateGuildWarRedStatus(GuildConst.red_index.guildwar_box, true);
      } else {
        this.updateGuildWarRedStatus(GuildConst.red_index.guildwar_box, false);
      }
    }
  },
  //根据序号获取宝箱数据
  getGuildWarDataByOrder: function getGuildWarDataByOrder(order) {
    for (var k in this.award_box_data) {
      var box_vo = this.award_box_data[k];
 
      if (box_vo.order == order) {
        return box_vo;
      }
    }
  },
  //获取全部宝箱数据
  getGuildWarBoxData: function getGuildWarBoxData() {
    return this.award_box_data;
  },
  //玩家是否领取了宝箱数据
  checkIsGetBoxAward: function checkIsGetBoxAward() {
    var is_get = false;
 
    var role_vo = require("role_controller").getInstance().getRoleVo();
 
    for (var k in this.award_box_data) {
      var box_vo = this.award_box_data[k];
 
      if (box_vo.rid == role_vo.rid && box_vo.sid == role_vo.srv_id) {
        is_get = true;
        break;
      }
    }
 
    return is_get;
  }
});
 
cc._RF.pop();