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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
"use strict";
cc._RF.push(module, 'f17504ZKR9EfYNuXooysn4U', 'voyage_dispatch_window');
// Scripts/mod/voyage/view/voyage_dispatch_window.js
 
"use strict";
 
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//     远航派遣界面
// <br/>Create: 2019-03-07 20:23:27
// --------------------------------------------------------------------
var PathTool = require("pathtool");
 
var HeroConst = require("hero_const");
 
var HeroController = require("hero_controller");
 
var RoleController = require("role_controller");
 
var CommonScrollView = require("common_scrollview");
 
var TimeTool = require("timetool");
 
var VoyageConst = require("voyage_const");
 
var VoyageEvent = require("voyage_event");
 
var VoyageController = require("voyage_controller");
 
var GuideEvent = require("guide_event");
 
var Voyage_dispatchWindow = cc.Class({
  "extends": BaseView,
  ctor: function ctor() {
    this.prefabPath = PathTool.getPrefabPath("voyage", "voyage_order_info");
    this.viewTag = SCENE_TAG.dialogue; //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意
 
    this.win_type = WinType.Big; //是否是全屏窗体  WinType.Full, WinType.Big, WinType.Mini, WinType.Tips
  },
  // 初始化一些配置数据,可以用于声明一些变量之类的
  initConfig: function initConfig() {
    this.role_vo = RoleController.getInstance().getRoleVo();
    this.ctrl = VoyageController.getInstance();
    this.model = this.ctrl.getModel();
    this.camp_btns = {};
    this.cur_camp = HeroConst.CampType.eNone;
    this.need_hero_num = 0; // 可选英雄最大数
 
    this.chose_heros = []; // 选中的英雄列表
 
    this.hero_boxs = {}; // 英雄头像框(最大英雄数量)
 
    this.hero_icons = []; // 选中的英雄头像
 
    this.camp_icons = []; // 阵营条件图标
 
    this.conditions = []; // 条件
 
    this.con_status = false; // 条件满足状态
 
    this.con_tips = Utils.TI18N("不满足派遣条件"); // 派遣提示
 
    this.node_list = [];
  },
  // 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
  openCallBack: function openCallBack() {
    this.background = this.seekChild("background");
    this.background.scale = FIT_SCALE;
    this.main_container = this.seekChild("main_container");
    var camp_nd = this.seekChild(this.main_container, "camp_node");
    this.img_select_nd = this.seekChild(camp_nd, "img_select");
 
    for (var i = 0; i <= 5; i++) {
      var camp_btn = camp_nd.getChildByName("camp_btn" + i);
      this.camp_btns[i] = camp_btn;
 
      if (i == 0) {
        var pos = camp_btn.getPosition();
        this.img_select_nd.setPosition(pos);
      }
    }
 
    this.no_hero_image_nd = this.seekChild(this.main_container, "no_hero_image");
    this.quick_btn_nd = this.seekChild(this.main_container, "quick_btn");
    this.dispatch_btn_nd = this.seekChild(this.main_container, "dispatch_btn");
    var num_bg_1 = this.seekChild(this.main_container, "num_bg_1");
    this.item_num_lb = this.seekChild(num_bg_1, "item_num_label", cc.Label);
    var num_bg_2 = this.seekChild(this.main_container, "num_bg_2");
    this.time_lb = this.seekChild(num_bg_2, "time_label", cc.Label);
    var num_image_sp = this.seekChild(num_bg_1, "image_res", cc.Sprite);
    this.loadRes(PathTool.getItemRes(7), function (sf_obj) {
      num_image_sp.spriteFrame = sf_obj;
    }.bind(this));
    this.status_label_nd = this.seekChild(this.main_container, "status_label");
    this.move_item_nd = this.seekChild(this.main_container, "move_item");
    this.move_item = ItemsPool.getInstance().getItem("hero_exhibition_item");
    ;
    this.move_item.setParent(this.move_item_nd);
    this.move_item.setData(null);
    this.move_item.show();
    this.move_item_nd.active = false; //条件满足图标
 
    this.condition_layout = this.seekChild(this.main_container, "condition_layout"); //选择的英雄
 
    this.hero_layout = this.seekChild(this.main_container, "hero_layout");
    var lay_scrollview = this.seekChild(this.main_container, "lay_scrollview");
    var bgSize = lay_scrollview.getContentSize();
    var tab_size = cc.size(bgSize.width, bgSize.height);
    var setting = {
      item_class: "hero_exhibition_item",
      // 单元类
      start_x: 10,
      // 第一个单元的X起点
      space_x: 20,
      // x方向的间隔
      start_y: 0,
      // 第一个单元的Y起点
      space_y: 0,
      // y方向的间隔
      item_width: 120 * 0.9,
      // 单元的尺寸width
      item_height: 120 * 0.9,
      // 单元的尺寸height
      row: 0,
      // 行数,作用于水平滚动类型
      col: 5,
      // 列数,作用于垂直滚动类型
      scale: 0.9
    };
    this.hero_scrollview = new CommonScrollView();
    this.hero_scrollview.createScroll(lay_scrollview, cc.v2(0, 0), ScrollViewDir.vertical, ScrollViewStartPos.top, tab_size, setting, cc.v2(0.5, 0.5));
  },
  // 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
  registerEvent: function registerEvent() {
    Utils.onTouchEnd(this.background, function () {
      this._onClickCloseBtn();
    }.bind(this), 1);
    Utils.onTouchEnd(this.quick_btn_nd, function () {
      this._onClickQuickChoseBtn();
    }.bind(this), 1);
    Utils.onTouchEnd(this.dispatch_btn_nd, function () {
      this._onClickDispatchBtn();
    }.bind(this), 1);
 
    var func = function (index, btn) {
      Utils.onTouchEnd(btn, function () {
        this._onClickCampBtn(index, btn);
      }.bind(this), 1);
    }.bind(this);
 
    for (var i = 0; i <= 5; i++) {
      func(i, this.camp_btns[i]);
    } //情报值更新
 
 
    if (this.role_assets_event == null) {
      if (this.role_vo == null) {
        this.role_vo = RoleController.getInstance().getRoleVo();
      }
 
      this.role_assets_event = this.role_vo.bind(EventId.UPDATE_ROLE_ATTRIBUTE, function (key, value) {
        if (key == "energy") {
          this.refreshItemNum();
        }
      }, this);
    } //消耗情报值变化(活动期间)
 
 
    this.addGlobalEvent(VoyageEvent.UpdateActivityStatusEvent, function () {
      this.refreshItemNum();
    }, this);
  },
  // 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
  openRootWnd: function openRootWnd(data) {
    this.refreshCampHeroList();
    this.showBaseInfo(data);
  },
  //刷新英雄列表
  refreshCampHeroList: function refreshCampHeroList() {
    var hero_array = [];
    var all_hero_arry = HeroController.getInstance().getModel().getAllHeroArray();
 
    for (var i = 0; i < all_hero_arry.length; i++) {
      var hero_vo = all_hero_arry[i];
 
      if (this.cur_camp == HeroConst.CampType.eNone || this.cur_camp == hero_vo.camp_type) {
        //避免每次切换阵营都走这个循环判断是否在任务中
        if (hero_vo.in_task == null) {
          hero_vo.in_task = this.model.checkHeroIsInTaskById(hero_vo.partner_id);
        }
 
        hero_array.push(hero_vo);
      }
    }
 
    var hero_num = hero_array.length;
 
    if (hero_num <= 0) {
      this.no_hero_image_nd.active = true;
 
      if (this.no_hero_image_sp == null) {
        this.no_hero_image_sp = this.no_hero_image_nd.getComponent(cc.Sprite);
        this.loadRes(PathTool.getBigBg("bigbg_3"), function (sp) {
          this.no_hero_image_sp.spriteFrame = sp;
        }.bind(this));
      }
 
      this.hero_scrollview.setData([]);
      return;
    } else {
      this.no_hero_image_nd.active = false;
    }
 
    var hero_list = hero_array;
 
    var sortFunc = function sortFunc(objA, objB) {
      if (objA.in_task && !objB.in_task) {
        return false;
      } else if (!objA.in_task && objB.in_task) {
        return true;
      } else {
        if (objA.camp_type != objB.camp_type) {
          return objA.camp_type < objB.camp_type;
        } else {
          if (objA.star != objB.star) {
            return objA.star > objB.star;
          } else {
            return objA.lev > objB.lev;
          }
        }
      }
    };
 
    hero_list.sort(sortFunc);
    var extendData = {
      scale: 0.9,
      can_click: true,
      click_delay: 0.5,
      from_type: HeroConst.ExhibitionItemType.eVoyage
    };
    this.hero_scrollview.setData(hero_list, function (item, hero_vo) {
      this._onClickHero(item, hero_vo);
    }.bind(this), extendData);
  },
  //刷新情报值
  refreshItemNum: function refreshItemNum() {
    if (this.role_vo && this.config) {
      var cur_energy = this.role_vo.energy;
      var need_energy = 0;
 
      if (this.config.expend[0]) {
        need_energy = this.config.expend[0][1] || 0;
 
        if (this.model.getActivityStatus() == 1) {
          var discount_cfg = Config.shipping_data.data_const["discount"];
 
          if (discount_cfg) {
            need_energy = need_energy * discount_cfg.val / 1000;
          }
        }
      }
 
      this.item_num_lb.string = cur_energy + "/" + need_energy;
    }
  },
  //基础信息显示
  showBaseInfo: function showBaseInfo(data) {
    this.data = data || {};
    var config = this.data.config || {};
    this.config = config; //情报值
 
    this.refreshItemNum(); //时间
 
    this.time_lb.string = TimeTool.getTimeFormat(config.need_time); //需要英雄数量的头像框
 
    for (var k in this.hero_boxs) {
      this.hero_boxs[k].node.active = false;
    }
 
    var limit_num = config.limit_num;
    this.need_hero_num = limit_num;
    var box_pos = VoyageConst.Chose_Hero_PosX[limit_num];
 
    var func = function (i) {
      var hero_box = this.hero_boxs[i];
 
      if (hero_box == null) {
        hero_box = Utils.createImage(this.hero_layout, null, 0, 0, cc.v2(0.5, 0.5), true);
        this.loadRes(PathTool.getCommonIcomPath("common_1005"), function (sf_obj) {
          hero_box.spriteFrame = sf_obj;
        }.bind(this));
        this.hero_boxs[i] = hero_box;
      }
 
      hero_box.node.active = true;
      var pos_x = box_pos[i - 1];
 
      if (pos_x) {
        hero_box.node.setPosition(cc.v2(pos_x - 319, 0));
      }
    }.bind(this);
 
    for (var i = 1; i <= limit_num; i++) {
      func(i);
    } //条件图标
 
 
    this.initConditionData();
    var temp_icons = [];
    var need_star = 0;
    var star_num = 1;
    var need_camps = [];
 
    for (var k in this.conditions) {
      var v = this.conditions[k];
 
      if (v.star_num) {
        need_star = v.need_num;
        star_num = v.star_num;
      } else if (v.camp_type) {
        need_camps.push(v.camp_type);
      }
    }
 
    if (need_star > 0) {
      this.star_icon = Utils.createImage(this.condition_layout, null, 0, 0, cc.v2(0.5, 0.5), true);
      this.loadRes(PathTool.getUIIconPath("voyage", "voyage_1009"), function (sf_obj) {
        this.star_icon.spriteFrame = sf_obj;
      }.bind(this));
      this.star_icon.setState(cc.Sprite.State.GRAY);
      var star_text = Utils.createLabel(22, 1, new cc.Color(0x84, 0x10, 0, 0xff), 0, 0, star_num, this.star_icon.node, null, cc.v2(0.5, 0.5));
      this.star_icon.node.on(cc.Node.EventType.TOUCH_END, function () {
        message(cc.js.formatStr(Utils.TI18N("需要一个%d星英雄"), star_num));
      }, this);
      temp_icons.push(this.star_icon);
    }
 
    for (var k in this.camp_icons) {
      this.camp_icons[k].node.active = false;
    }
 
    var func = function (camp_icon, i) {
      if (camp_icon == null) {
        camp_icon = Utils.createImage(this.condition_layout, null, 0, 0, cc.v2(0.5, 0.5), true);
        var res = PathTool.getHeroCampRes(camp_type);
        this.loadRes(PathTool.getCommonIcomPath(res), function (sf_obj) {
          camp_icon.spriteFrame = sf_obj;
        }.bind(this));
        camp_icon.node.scale = 0.8;
        camp_icon.node.on(cc.Node.EventType.TOUCH_END, function (camp_type) {
          message(cc.js.formatStr(Utils.TI18N("需要一个%s英雄"), HeroConst.CampAttrName[camp_type]));
        }.bind(this, camp_type), this);
        camp_icon.setState(cc.Sprite.State.GRAY);
        this.camp_icons.push(camp_icon);
      }
 
      camp_icon.camp_type = camp_type;
      camp_icon.node.active = true;
      temp_icons.push(camp_icon);
    }.bind(this);
 
    for (var i in need_camps) {
      var camp_type = need_camps[i];
      var camp_icon = this.camp_icons[i];
      func(camp_icon, i);
    }
 
    var icon_pos = VoyageConst.Condition_Icon_PosX[temp_icons.length];
 
    for (var i in temp_icons) {
      var pos_x = icon_pos[i];
 
      if (pos_x != null) {
        // temp_icons[i].node.setPosition(cc.v2(pos_x, 0));
        temp_icons[i].node.x = pos_x;
      }
    }
  },
  //根据阵营类型获取阵营图标
  getCampIconByCampType: function getCampIconByCampType(camp_type) {
    for (var k in this.camp_icons) {
      var camp_icon = this.camp_icons[k];
 
      if (camp_icon.camp_type == camp_type) {
        return camp_icon;
      }
    }
  },
  //初始化派遣条件
  initConditionData: function initConditionData() {
    this.conditions = [];
 
    if (this.config) {
      var conditions = this.config.condition || {};
 
      for (var k in conditions) {
        var con_id = conditions[k];
        var con_config = Config.shipping_data.data_condition[con_id] || {};
        var condition = con_config.conition || {};
 
        if (condition[0]) {
          var con_data = {};
 
          if (condition[0][0] == "partner_star") {
            con_data.star_num = condition[0][1]; //星数要求
 
            con_data.need_num = condition[0][2];
          } else if (condition[0][0] == "partner_camp_type") {
            con_data.camp_type = condition[0][1]; //阵营要求
 
            con_data.need_num = condition[0][2];
          }
 
          if (Utils.next(con_data) != null) {
            this.conditions.push(con_data);
          }
        }
      }
    }
  },
  //刷新条件满足状态
  refreshConditionStatus: function refreshConditionStatus() {
    this.con_status = true;
 
    for (var k in this.conditions) {
      var is_meet = false;
      var v = this.conditions[k];
 
      if (v.star_num) {
        is_meet = this.checkIsMeetCondition(1, v.star_num, v.need_num);
        this.star_icon.setState(is_meet ? cc.Sprite.State.NORMAL : cc.Sprite.State.GRAY);
      } else if (v.camp_type) {
        is_meet = this.checkIsMeetCondition(2, v.camp_type, v.need_num);
        var camp_icon = this.getCampIconByCampType(v.camp_type);
        camp_icon.setState(is_meet ? cc.Sprite.State.NORMAL : cc.Sprite.State.GRAY);
      }
 
      if (is_meet == false && this.con_status) {
        if (v.star_num) {
          this.con_tips = cc.js.formatStr(Utils.TI18N("需要一个%s星英雄"), v.star_num);
        } else if (v.camp_type) {
          this.con_tips = cc.js.formatStr(Utils.TI18N("需要一个%s系英雄"), HeroConst.CampName[v.camp_type]);
        }
 
        this.con_status = false;
      }
    }
 
    if (this.con_status) {
      this.status_label_nd.color = new cc.Color(36, 144, 3, 255);
    } else {
      this.status_label_nd.color = new cc.Color(201, 38, 6, 255);
    }
  },
  //判断所选英雄是否满足该条件 ttype:1星级 2阵营
  checkIsMeetCondition: function checkIsMeetCondition(ttype, value, num) {
    var have_num = 0;
 
    for (var k in this.chose_heros) {
      var hero_vo = this.chose_heros[k];
 
      if (ttype == 1 && hero_vo.star >= value) {
        have_num = have_num + 1;
      } else if (ttype == 2 && hero_vo.camp_type == value) {
        have_num = have_num + 1;
      }
    }
 
    return have_num >= num;
  },
  //判断当前所选的英雄是否满足所有条件
  checkIsMeetAllCondition: function checkIsMeetAllCondition() {
    var con_status = true;
 
    for (var k in this.conditions) {
      var v = this.conditions[k];
      var is_meet = false;
 
      if (v.star_num) {
        is_meet = this.checkIsMeetCondition(1, v.star_num, v.need_num);
      } else if (v.camp_type) {
        is_meet = this.checkIsMeetCondition(2, v.star_num, v.need_num);
      }
 
      if (is_meet == false) {
        con_status = false;
        break;
      }
    }
 
    return con_status;
  },
  _onClickHero: function _onClickHero(item, hero_vo) {
    hero_vo = item.data;
    if (hero_vo.in_task) return;
 
    if (hero_vo.is_ui_select) {
      for (var k in this.hero_icons) {
        var hero_icon = this.hero_icons[k];
        var data = hero_icon.getData();
 
        if (data.partner_id == hero_vo.partner_id) {
          var hero_box = hero_icon.parent;
          var pos = hero_box.convertToWorldSpaceAR(cc.v2(0, 0));
          var start_pos = this.main_container.convertToNodeSpaceAR(pos);
          var end_pos = this.main_container.convertToNodeSpaceAR(item.getWorldPos());
          this.move_item_nd.setPosition(start_pos);
          this.move_item_nd.active = true;
          var move_act = cc.moveTo(0.07, end_pos);
 
          var callback = function () {
            hero_icon.deleteMe();
            hero_icon = null;
            hero_box.box_index = null;
            this.hero_icons.splice(k, 1);
            this.move_item_nd.active = false;
          }.bind(this);
 
          this.move_item_nd.runAction(cc.sequence(move_act, cc.callFunc(callback)));
          break;
        }
      }
 
      hero_vo.is_ui_select = false;
      item.setSelected(false);
      this.updateChoseHeroList(hero_vo, 2);
    } else {
      //判断当前是否还有空位
      if (this.need_hero_num <= this.chose_heros.length) {
        message(Utils.TI18N("已达英雄数量上限"));
        return;
      }
 
      this.createChoseHeroIcon(hero_vo, item);
      hero_vo.is_ui_select = true;
      item.setSelected(true);
      this.updateChoseHeroList(hero_vo, 1);
    }
 
    this.refreshConditionStatus();
  },
  //创建一个选中的英雄图标
  createChoseHeroIcon: function createChoseHeroIcon(hero_vo, item) {
    this.checkDeleteSameHeroIcon(hero_vo.partner_id);
    var hero_icon = ItemsPool.getInstance().getItem("hero_exhibition_item");
    hero_icon.show();
    hero_icon.setData(hero_vo);
    hero_icon.setVisible(false);
    this.move_item.setData(hero_vo);
    hero_icon.addCallBack(function () {
      var vo = hero_icon.getData();
      var list = this.hero_scrollview.getItemList();
      var item_node = null; //当英雄列表滑动了,对应的英雄item可能已经不存在
 
      for (var k in list) {
        var h_vo = list[k].getData();
 
        if (h_vo.partner_id == vo.partner_id) {
          item_node = list[k];
        }
      }
 
      if (item_node) {
        this._onClickHero(item_node, item_node.getData());
      } else {
        for (var k in this.hero_icons) {
          var icon = this.hero_icons[k];
          var data = icon.getData();
 
          if (data.partner_id == vo.partner_id) {
            icon.deleteMe(); // icon.stopAllActions();
 
            this.hero_icons.splice(k, 1);
            break;
          }
        }
 
        vo.is_ui_select = false;
        this.updateChoseHeroList(vo, 2);
        this.refreshConditionStatus();
      }
    }.bind(this));
    var hero_box = this.getMastLeftEmptyBox();
 
    if (hero_box) {
      // hero_icon.name = "hero_exhibition_item";
      hero_icon.setParent(hero_box.node);
      this.hero_icons.push(hero_icon);
 
      if (item) {
        var start_pos = this.main_container.convertToNodeSpaceAR(item.getWorldPos());
        var pos = hero_box.node.convertToWorldSpaceAR(cc.v2(0, 0));
        var end_pos = this.main_container.convertToNodeSpaceAR(pos);
        this.move_item_nd.setPosition(start_pos);
        this.move_item_nd.active = false;
        this.move_item_nd.runAction(cc.moveTo(0.07, end_pos), cc.callFunc(function () {
          this.move_item_nd.active = false;
          hero_icon.setVisible(true);
        }.bind(this)));
      } else {
        hero_icon.setVisible(true);
      }
    }
  },
  //删除已经创建的一致的头像(点太快可能会出现)
  checkDeleteSameHeroIcon: function checkDeleteSameHeroIcon(id) {
    for (var k in this.hero_icons) {
      var hero_icon = this.hero_icons[k];
      var data = hero_icon.getData();
 
      if (data.partner_id == id) {
        // hero_icon.stopAllActions();
        hero_icon.deleteMe();
        this.hero_icons.splice(k, 1);
        break;
      }
    }
  },
  //获取最靠前的一个空的头像box
  getMastLeftEmptyBox: function getMastLeftEmptyBox() {
    var hero_box;
 
    for (var i in this.hero_boxs) {
      var box = this.hero_boxs[i];
 
      if (!box.node.getChildByName("hero_exhibition_item") && box.node.box_index == null) {
        hero_box = box;
        box.node.box_index = i;
        break;
      }
    }
 
    return hero_box;
  },
  //更新选中的英雄列表 ttype:1为增 2为减
  updateChoseHeroList: function updateChoseHeroList(hero_vo, ttype) {
    if (ttype == 1) {
      this.chose_heros.push(hero_vo);
    } else if (ttype == 2) {
      for (var k in this.chose_heros) {
        var v = this.chose_heros[k];
 
        if (v.partner_id == hero_vo.partner_id) {
          this.chose_heros.splice(k, 1);
          break;
        }
      }
    }
  },
  _onClickCampBtn: function _onClickCampBtn(index, sender) {
    if (this.cur_camp == index) return;
    this.cur_camp = index;
    var pos_x = sender.x;
    var pos_y = sender.y;
    this.img_select_nd.setPosition(cc.v2(pos_x, pos_y));
    this.refreshCampHeroList();
  },
  //一键出战
  _onClickQuickChoseBtn: function _onClickQuickChoseBtn() {
    //先清掉所有选择的数据
    for (var k in this.hero_icons) {
      if (this.hero_icons[k]) {
        // this.hero_icons[k].stopAllActions();
        this.hero_icons[k].deleteMe();
        this.hero_icons[k] = null;
      }
    }
 
    for (var k in this.hero_boxs) {
      if (this.hero_boxs[k]) {
        this.hero_boxs[k].node.box_index = null;
      }
    }
 
    if (window.TASK_TIPS) gcore.GlobalEvent.fire(GuideEvent.TaskNextStep, "quick_btn"); //任务引导用到
 
    gcore.Timer.set(function () {
      this.oneCallBack();
    }.bind(this), 100, 1);
  },
  oneCallBack: function oneCallBack() {
    this.hero_icons = [];
 
    for (var k in this.chose_heros) {
      this.chose_heros[k].is_ui_select = false;
    }
 
    this.chose_heros = [];
    var item_list = this.hero_scrollview.getItemList();
 
    for (var k in item_list) {
      item_list[k].setSelected(false);
    }
 
    var all_hero = HeroController.getInstance().getModel().getHeroList();
    var star_num = 0;
    var star_need = 0;
    var need_camps = {};
 
    for (var k in this.conditions) {
      var con_data = this.conditions[k];
 
      if (con_data.star_num) {
        star_num = con_data.star_num;
        star_need = con_data.need_num;
      } else if (con_data.camp_type) {
        need_camps[con_data.camp_type] = con_data.need_num;
      }
    }
 
    var star_hero = []; //满足星级条件的英雄
 
    var all_camp_hero = {}; //满足阵营条件的英雄
 
    var both_hero = []; //同时满足星级和阵营的英雄
 
    for (var k in all_hero) {
      var hero_vo = all_hero[k];
      var star_is_meet = false;
 
      if (hero_vo.star >= star_num && !this.model.checkHeroIsInTaskById(hero_vo.partner_id)) {
        star_is_meet = true;
        star_hero.push(hero_vo);
      }
 
      for (var i in this.conditions) {
        var con_data = this.conditions[i];
 
        if (con_data.camp_type && con_data.camp_type == hero_vo.camp_type && !this.model.checkHeroIsInTaskById(hero_vo.partner_id)) {
          if (!all_camp_hero[con_data.camp_type]) {
            all_camp_hero[con_data.camp_type] = [];
          }
 
          all_camp_hero[con_data.camp_type].push(hero_vo);
 
          if (star_is_meet) {
            both_hero.push(hero_vo);
          }
        }
      }
    }
 
    var sortFunc = Utils.tableLowerSorter(["star", "lev", "camp_type"]); //按星级、等级、阵营从低到高排列
 
    star_hero.sort(sortFunc);
    both_hero.sort(sortFunc);
 
    for (var k in all_camp_hero) {
      all_camp_hero[k].sort(sortFunc);
    }
 
    for (var i in both_hero) {
      var hero_vo = both_hero[i];
 
      if (this.chose_heros.length < star_need) {
        this.chose_heros.push(hero_vo);
      } else if (this.checkIsMeetAllCondition()) {
        for (var camp in need_camps) {
          var need_num = need_camps[camp];
 
          if (hero_vo.camp_type == camp && this.checkChoseHeroNumByCamp(camp) < need_num) {
            this.chose_heros.push(hero_vo);
          }
        }
      } else {
        break;
      }
    }
 
    if (this.checkIsMeetAllCondition()) {
      this.afterQuickChoseHero();
      return;
    }
 
    var star_dif_num = star_need - this.chose_heros.length; //满足星级条件的英雄,还差的个数
 
    if (star_dif_num > 0) {
      var temp_num = 0;
 
      for (var i in star_hero) {
        var vo = star_hero[i];
 
        if (!this.checkIsChoseHeroById(vo.partner_id)) {
          this.chose_heros.push(vo);
          temp_num = temp_num + 1;
        }
 
        if (temp_num >= star_dif_num) {
          break;
        }
      }
    } //满足条件或者星级条件都无法满足,则无需选择其他英雄
 
 
    if (this.checkIsMeetAllCondition()) {
      this.afterQuickChoseHero();
      return;
    }
 
    for (var camp_type in all_camp_hero) {
      var hero_list = all_camp_hero[camp_type];
      var need_num = need_camps[camp_type];
      var cur_num = this.checkChoseHeroNumByCamp(camp_type);
      var diff_num = need_num - cur_num;
 
      if (diff_num > 0) {
        var temp_num = 0;
 
        for (var i in hero_list) {
          var vo = hero_list[i];
 
          if (!this.checkIsChoseHeroById(vo.partner_id)) {
            this.chose_heros.push(vo);
            temp_num = temp_num + 1;
          }
 
          if (temp_num >= diff_num) {
            break;
          }
        }
      }
    }
 
    this.afterQuickChoseHero();
  },
  checkIsChoseHeroById: function checkIsChoseHeroById(id) {
    var is_have = false;
 
    for (var k in this.chose_heros) {
      if (this.chose_heros[k].partner_id == id) {
        is_have = true;
        break;
      }
    }
 
    return is_have;
  },
  checkChoseHeroNumByCamp: function checkChoseHeroNumByCamp(camp_type) {
    var have_num = 0;
 
    for (var k in this.chose_heros) {
      if (this.chose_heros[k].camp_type == camp_type) {
        have_num = have_num + 1;
      }
    }
 
    return have_num;
  },
  //一键出战选择合适英雄之后界面刷新
  afterQuickChoseHero: function afterQuickChoseHero() {
    for (var i in this.chose_heros) {
      var hero_vo = this.chose_heros[i];
      hero_vo.is_ui_select = true;
      var item_list = this.hero_scrollview.getItemList();
 
      for (var k in item_list) {
        var item = item_list[k];
        var item_data = item.getData();
 
        if (item_data.partner_id == hero_vo.partner_id) {
          item.setSelected(true);
        }
      }
 
      this.createChoseHeroIcon(hero_vo);
    }
 
    this.refreshConditionStatus();
  },
  //派遣
  _onClickDispatchBtn: function _onClickDispatchBtn() {
    if (this.con_status == true) {
      var assign_ids = [];
 
      for (var k in this.chose_heros) {
        var v = this.chose_heros[k];
        var assign = {};
        assign.partner_id = v.partner_id;
        assign_ids.push(assign);
      }
 
      if (this.data) {
        this.ctrl.requestReceiveOrder(this.data.order_id, assign_ids);
      }
 
      if (window.TASK_TIPS) gcore.GlobalEvent.fire(GuideEvent.TaskNextStep, "dispatch_btn"); //任务引导用到
    } else {
      this.con_tips = this.con_tips || Utils.TI18N("不满足派遣条件");
      message(this.con_tips);
    }
  },
  _onClickCloseBtn: function _onClickCloseBtn() {
    this.ctrl.openVoyageDispatchWindow(false);
  },
  // 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
  closeCallBack: function closeCallBack() {
    if (this.hero_scrollview) {
      this.hero_scrollview.deleteMe();
      this.hero_scrollview = null;
    } //清空选中状态
 
 
    var hero_list = HeroController.getInstance().getModel().getHeroList();
 
    for (var k in hero_list) {
      hero_list[k].is_ui_select = false;
      hero_list[k].in_task = null;
    }
 
    if (this.role_assets_event) {
      if (this.role_vo) {
        this.role_vo.unbind(this.role_assets_event);
      }
 
      this.role_assets_event = null;
      this.role_vo = null;
    }
 
    for (var k in this.hero_icons) {
      if (this.hero_icons[k]) {
        // this.hero_icons[k].stopAllActions();
        this.hero_icons[k].deleteMe();
        this.hero_icons[k] = null;
      }
    }
 
    if (this.move_item) {
      this.move_item.deleteMe();
      this.move_item = null;
    }
 
    if (this.camp_icons) {
      for (var k in this.camp_icons) {
        var v = this.camp_icons[k];
 
        if (v) {
          v.node.destroy();
          v = null;
        }
      }
 
      this.camp_icons = null;
    }
 
    gcore.GlobalEvent.fire(GuideEvent.CloseTaskEffect);
    this.ctrl.openVoyageDispatchWindow(false);
  }
});
 
cc._RF.pop();