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
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//      星命塔
// <br/>Create: 2019-02-27 11:03:16
// --------------------------------------------------------------------
var StartowerEvent = require("startower_event");
 
var StartowerModel = cc.Class({
    extends: BaseClass,
    ctor: function () {
        this.ctrl = require("startower_controller").getInstance();
        this.initConfig();
    },
 
    properties: {
    },
 
    initConfig: function () {
        // 已通关的最大层数
        this.max_tower = 0;
        //剩余挑战次数
        this.less_count = 0;
        //已购买次数
        this.buy_count = 0;
        this.reward_list = [];  //通关奖励状态
 
    },
 
    setStarTowerData:function(data){
        var tempsort = {
            0: 2,  // 0 未领取放中间
            1: 1,  // 1 可领取放前面
            2: 3,  // 2 已领取放最后
        }
        this.max_tower = data.max_tower || 0;
        this.less_count = data.count || 0;
        this.buy_count = data.buy_count || 0; 
        if(Utils.next(data.award_list)!=null){
            for(var i in data.award_list){
                var tab = {};
                tab.id = data.award_list[i].id;
                tab.status = data.award_list[i].status;
                tab.sort = tempsort[tab.status];
                this.reward_list[data.award_list[i].id-1] = tab;
                
            }
        }
        
        this.reward_list.sort(Utils.tableLowerSorter(["sort","id"]))
        this.updateRedPoint();
        gcore.GlobalEvent.fire(StartowerEvent.Update_All_Data);
    },
 
    setRewardData:function(data){
        if(!this.reward_list || !data[0])return;
        var tempsort = {
            0: 2,  // 0 未领取放中间
            1: 1,  // 1 可领取放前面
            2: 3,  // 2 已领取放最后
        }
        for(var i in this.reward_list){
            if(this.reward_list[i].id == data[0].id){
                this.reward_list[i].status = data[0].status;
                this.reward_list[i].sort = tempsort[data[0].status];
                break;
            }
        }
        
        this.reward_list.sort(Utils.tableLowerSorter(["sort","id"]))
    },
 
    sortFunc:function(data){
        data.sort(function(objA, objB){
            if(objA.sort != objB.sort){
                if(objA.sort && objB.sort){
                    return objA.sort - objB.sort;
                }else{
                    return false;
                }
            }else{
                return objA.id - objB.id;
            }
        })
 
        return data
    },
    
    getRewardData:function(id){
        if(!this.reward_list)return;
        if(id == null){
            return this.reward_list || {};
        }else{
            return this.reward_list[id] || {};
        }
    },
 
    updateRedPoint: function() {
        RedMgr.getInstance().addCalHandler(this.checkRedPoint.bind(this), RedIds.StarTower);
    },
 
    checkRedPoint:function(){
        var is_open = this.ctrl.checkIsOpen();
        if(!is_open)return;
        var status = false;
        for(var i in this.reward_list){
            if(this.reward_list[i].status == 1){
                status = true;
                break;
            }
        }
        status = status || (this.less_count > 0);
        var SceneConst = require("scene_const");
        var MainSceneController = require("mainscene_controller");
        MainSceneController.getInstance().setBuildRedStatus(SceneConst.CenterSceneBuild.startower, {bid: 1, status: status}) 
    },
 
    updateMaxTower:function(data){
        if(data && data.max_tower && this.max_tower < data.max_tower){
            this.max_tower = data.max_tower;
        }
        gcore.GlobalEvent.fire(StartowerEvent.Fight_Success_Event)
    },
 
    updateLessCount:function(data){
        if(data.count != null){
            this.less_count = data.count || 0;
            this.updateRedPoint();
        }
        if(data.buy_count != null){
            this.buy_count = data.buy_count;
        }
        gcore.GlobalEvent.fire(StartowerEvent.Count_Change_Event);
    },
 
    getNowTowerId:function(){
        return this.max_tower || 0;
    },
 
    getTowerLessCount:function(){
        return this.less_count;
    },
 
    getBuyCount:function(){
        return this.buy_count;
    }
});