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
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
//      这里填写详细说明,主要填写该模块的功能简要
// <br/>Create: 2019-02-13 11:19:47
// --------------------------------------------------------------------
var RedbagEvent = require("redbag_event");
var GuildController = require("guild_controller");
var MainuiConst = require("mainui_const");
var MainuiController = require("mainui_controller");
var BackpackController = require("backpack_controller");
var GuildConst = require("guild_const");
var GuildEvent = require("guild_event");
 
var RedbagModel = cc.Class({
    extends: BaseClass,
    ctor: function () {
        this.ctrl = require("redbag_controller").getInstance();
    },
 
    properties: {
    },
 
    initConfig: function () {
        this.redbag_list = {};
        this.redbag_num = 0;
        this.redbag_send_num = 0;
        this.redbag_rec_num = 0;
        this.is_get_redbag = 0;
        this.red_bag_item_num = [];
        this.all_red_show = false;
    },
 
    resetData: function () {
        this.initConfig();
    },
 
    updateData: function (data) {
        if (!data)
            return
        if (data.type && data.type == 0) {
            this.redbag_list = {};
        }
        var list = data.list || {};
        for (var i in list) {
            var v = list[i];
            v.order = 0 - v.time;
            if (v.flag == 0 && v.num < v.max_num && v.time - gcore.SmartSocket.getTime() >= 0) {
                v.order = gcore.SmartSocket.getTime() - v.time;
            }
            this.redbag_list[v.id] = v;
        }
        gcore.GlobalEvent.fire(RedbagEvent.Get_Data_Event, data);
 
        if (this.is_get_redbag != 0) {
            this.checkRedBagRedPoint();
        } else {
            GuildController.getInstance().SendProtocal(13523, {});
        }
        this.is_get_redbag = 0;
    },
 
    updateRedBagNum: function (send_num, rec_num) {
        this.redbag_send_num = send_num || 0;
        this.redbag_rec_num = rec_num || 0;
        this.is_get_redbag = 1;
        var max_rec_num = gdata("guild_data", "data_const", "red_packet_get").val;
        if (this.redbag_rec_num >= max_rec_num) {
            this.is_get_redbag = 2;
        }
        this.checkRedBagRedPoint();
    },
 
    checkRedBagRedPoint: function () {
        //判断有没有没领取的红包,有就抛事件推送
        var vo;
        this.is_have_red = false;
        this.all_red_show = false;
        this.redbag_num = 0;
        for (var i in this.redbag_list) {
            this.redbag_num = this.redbag_num + 1;
            var v = this.redbag_list[i];
            //没过期也没被领完的
            if (v.num < v.max_num) {
                if (v.time - gcore.SmartSocket.getTime() >= 0) {
                    if (v.flag == 0) {
                        vo = v;
                        this.is_have_red = true;
                        this.all_red_show = true;
                        break
                    }
                }
            }
        }
        if (this.is_get_redbag == 2) {
            vo = null;
            this.is_have_red = false;
            this.all_red_show = false;
        }
 
        this.checkItemNumRedPoint();
        if (this.red_bag_item_num && Utils.next(this.red_bag_item_num || {}) != null) {
            for (var i in this.red_bag_item_num) {
                var v = this.red_bag_item_num[i];
                if (v.status == true) {
                    this.all_red_show = true;
                    break
                }
            }
        }
 
        //抛去主界面播特效
        gcore.GlobalEvent.fire(RedbagEvent.Can_Get_Red_Bag, vo);
        //抛去公会界面红点
        gcore.GlobalEvent.fire(GuildEvent.UpdateGuildRedStatus, GuildConst.red_index.red_bag, this.all_red_show);
        //更新场景红点
        var base_data = Config.function_data.data_base;
        var bool = MainuiController.getInstance().checkIsOpenByActivate(base_data[6].activate);
        if (bool == true)
            MainuiController.getInstance().setBtnRedPoint(MainuiConst.btn_index.guild, { bid: GuildConst.red_index.red_bag, status: this.all_red_show });
    },
 
    //主要红包道具的数量判断
    checkItemNumRedPoint: function () {
        if (Config.guild_data.data_guild_red_bag) {
            this.red_bag_item_num = [];
            for (var i in Config.guild_data.data_guild_red_bag) {
                var v = gdata("guild_data", "data_guild_red_bag", [i]);
                if (v && v.loss_item && v.loss_item[0]) {
                    var has_num = BackpackController.getInstance().getModel().getBackPackItemNumByBid(v.loss_item[0][0])
                    var status = false;
                    if (has_num >= v.loss_item[0][1]) {
                        status = true;
                    }
                    this.red_bag_item_num.push({ id: v.id, status: status, bid: v.loss_item[0][0] })
                }
            }
        }
    },
 
    getRedBagNum: function () {
        return this.redbag_num || 0;
    },
 
    getIsHaveRedBag: function () {
        return this.is_have_red || false;
    },
 
    getAllRedBagStatus: function () {
        return this.all_red_show || false;
    },
 
    //每次打开获取拥有红包道具的的最少来ID来默认打开那个界面
    getHaveItemID: function () {
        if (this.red_bag_item_num && Utils.next(this.red_bag_item_num || {} != null)) {
            var temp_id = 99;
            for (var i in this.red_bag_item_num) {
                var v = this.red_bag_item_num[i];
                if (v.status == true && v.id <= temp_id) {
                    temp_id = v.id;
                }
            }
            return temp_id
        }
    },
 
    getSendRedBagStatue: function (id) {
        var status = false;
        if (this.red_bag_item_num && Utils.next(this.red_bag_item_num || {}) != null) {
            for (var i in this.red_bag_item_num) {
                var v = this.red_bag_item_num[i];
                if (id) {
                    if (v.id != id) {
                        if (v.status == true) {
                            status = true;
                            break
                        }
                    }
                } else {
                    if (v.status == true) {
                        status = true;
                        break
                    }
                }
            }
        }
        return status
    },
 
    getRebBagItemNumList: function () {
        if (this.red_bag_item_num && Utils.next(this.red_bag_item_num || {}) != null) {
            return this.red_bag_item_num;
        }
    },
 
    getRedBagList: function () {
        var redbag_list = [];
        for (var k in this.redbag_list) {
            var v = this.redbag_list[k];
            redbag_list.push(v);
        }
        return redbag_list;
    },
 
    getRedBagListById: function (id) {
        return this.redbag_list[id];
    }
});