少年修仙传客户端代码仓库
client_Zxw
2018-09-19 92948f5aa10abc4edf464d00a16f59dbb8ca7198
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, September 12, 2018
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using TableConfig;
using System.Collections.Generic;
using System;
using Snxxz.UI;
 
//功能预告红点
public class FeatureNoticeModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
{
    public List<FunctionForecastConfig> FunctionList = new List<FunctionForecastConfig>();
    private const int Redpoint_key1 = 38;
    public Redpoint redPointStre1 = new Redpoint(Redpoint_key1);
    private int OpenFuncId = 0;
    private bool RedPointChange = false;
    private bool IsRedPoint = false;
    public int FunctionForecastIndex = 0;
    public override void Init()
    {
        AddList();
    }
 
    public void OnBeforePlayerDataInitialize()
    {
        PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= OnPlayersUpLV;
        FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
        treasureModel.treasureStateChangeEvent -= treasureStateChangeEvent;
        treasureModel.treasureStageUpEvent -= treasureStageUpEvent;
    }
 
    public void OnPlayerLoginOk()
    {                    
        FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
        PlayerDatas.Instance.PlayerDataRefreshInfoEvent += OnPlayersUpLV;
        treasureModel.treasureStateChangeEvent += treasureStateChangeEvent;
        treasureModel.treasureStageUpEvent += treasureStageUpEvent;
        StageManager.Instance.onStageLoadFinish -= OnStageLoadFinish;
        StageManager.Instance.onStageLoadFinish += OnStageLoadFinish;
        RedDotStatus();
    }
 
   
 
    public override void UnInit()
    {
 
    }
    private void OnStageLoadFinish()
    {
        if (!(StageManager.Instance.CurrentStage is DungeonStage))
        {
            OpenFuncId = 0;
            RedPointChange = false;
            IsRedPoint = false;
        }
    }     
    private void treasureStageUpEvent(int obj)
    {
        RedDotStatus();
    }
 
    private void treasureStateChangeEvent(int obj)
    {
        RedDotStatus();
    }
 
    private void OnFuncStateChangeEvent(int obj)
    {
        RedDotStatus();
    }
 
    private void OnPlayersUpLV(PlayerDataRefresh obj)
    {
        if (obj == PlayerDataRefresh.LV)
        {
            RedDotStatus();
        }
    }
    private void AddList()//添加列表信息
    {
        if (FunctionList.Count <= 0)
        {
            var configs = Config.Instance.GetAllKeys<FunctionForecastConfig>();
            foreach (var key in configs)
            {
                var functionForecastConfig = Config.Instance.Get<FunctionForecastConfig>(key);
                if (functionForecastConfig != null && functionForecastConfig.Display == 1)
                {
                    FunctionList.Add(functionForecastConfig);
                }
            }
        }
    }
 
    private void RedDotStatus()
    {
        for (int i = 0; i < FunctionList.Count; i++)
        {
            if (!FuncOpen.Instance.IsFuncOpen(FunctionList[i].FuncId))
            {
                redPointStre1.state = RedPointState.None;
                if (OpenFuncId != FunctionList[i].FuncId)
                {
                    RedPointChange = false;
                }
                if (OpenFuncId != FunctionList[i].FuncId || !RedPointChange)
                {
                    OpenFuncId = FunctionList[i].FuncId;
                    IsRedPoint = false;
                    TrailerClassification(FunctionList[i].FuncId);
                }
                return;
            }
        }
    }
 
    private void TrailerClassification(int funcID)
    {
        FuncOpenLVConfig funcoPenConfig = Config.Instance.Get<FuncOpenLVConfig>(funcID);
        var functionForecastConfig = Config.Instance.Get<FunctionForecastConfig>(funcID);
        if (funcoPenConfig.LimitMagicWeapon != 0 || funcoPenConfig.LimitMissionID != 0)
        {
            if (funcoPenConfig.LimitMagicWeapon != 0)//法宝
            {
                int faBaoID = funcoPenConfig.LimitMagicWeapon / 100;
                MagicWeapon(faBaoID, funcID);
                return;
            }
            else if (funcoPenConfig.LimitMissionID != 0)//任务
            {
                if (functionForecastConfig.RedPointLV <= 0)
                {
                    return;
                }
                if (PlayerDatas.Instance.baseData.LV >= functionForecastConfig.RedPointLV)
                {
                    RedPointChange = true;
                    IsRedPoint = true;
                }
                if (IsRedPoint)
                {
                    redPointStre1.state = RedPointState.Simple;
                }
                else
                {
                    redPointStre1.state = RedPointState.None;
                }
                return;
            }
        }
        else//等级
        {
            if (functionForecastConfig.RedPointLV <= 0)
            {
                return;
            }
            if (PlayerDatas.Instance.baseData.LV >= functionForecastConfig.RedPointLV)
            {
                RedPointChange = true;
                IsRedPoint = true;
            }
            if (IsRedPoint)
            {
                redPointStre1.state = RedPointState.Simple;
            }
            else
            {
                redPointStre1.state = RedPointState.None;
            }
            return;
        }
    }
    TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
    private void MagicWeapon(int fabaoID, int funcID)
    {
        var functionForecastConfig = Config.Instance.Get<FunctionForecastConfig>(funcID);
        if (functionForecastConfig.RedPointLV > 0)//根据填的等级来
        {
            if (PlayerDatas.Instance.baseData.LV >= functionForecastConfig.RedPointLV)
            {
                RedPointChange = true;
                IsRedPoint = true;
            }
            if (IsRedPoint)
            {
                redPointStre1.state = RedPointState.Simple;
            }
            else
            {
                redPointStre1.state = RedPointState.None;
            }
            return;
        }
        Treasure treasure;//根据解锁法宝的百分比
 
        if (treasureModel.TryGetTreasure(fabaoID, out treasure)
              && treasure.state == TreasureState.Collected)
        {
            var list = treasure.treasureStages;
            var funcStage = 0;
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].unlockType == TreasureStageUnlock.Func &&
                    list[i].func == funcID)
                {
                    funcStage = i;
                    break;
                }
            }
            if (treasure.stage == funcStage - 1 || funcStage == 0)
            {
                float exp = ((float)treasure.exp / treasure.treasureStages[funcStage].exp) * 100;
                if (functionForecastConfig.RedPointPercentage > -1)
                {
                    if (exp >= functionForecastConfig.RedPointPercentage)
                    {
                        RedPointChange = true;
                        IsRedPoint = true;
                    }
                    if (IsRedPoint)
                    {
                        redPointStre1.state = RedPointState.Simple;
                    }
                }
                else
                {
                    redPointStre1.state = RedPointState.None;
                }
            }
        }
    }
 
    public IEnumerator WhetherToPlayTheBox()
    {
        yield return new WaitForSeconds(0.7f);
        var inDungeon = IsDungeon();
        var IsOpenMaininterface = WindowCenter.Instance.CheckOpen<MainInterfaceWin>();
        var IsOpenOffLineOnHook = WindowCenter.Instance.CheckOpen<OffLineOnHookWin>();
        var treasureModel = ModelCenter.Instance.GetModel<TreasureModel>();
        if (NewBieCenter.Instance.inGuiding || treasureModel.newGotShowing || inDungeon || !IsOpenMaininterface
            || treasureModel.treasureStageUpShow || WindowCenter.Instance.ExitAnyFullScreenOrMaskWin() ||
            IsOpenOffLineOnHook)
        {
            yield break;
        }
        for (int i = 0; i < FunctionList.Count; i++)
        {
            if (!FuncOpen.Instance.IsFuncOpen(FunctionList[i].FuncId))
            {
                var functionForecastConfig = Config.Instance.Get<FunctionForecastConfig>(FunctionList[i].FuncId);
                if (functionForecastConfig.FrameLevel <= 0)
                {
                    yield break;
                }
                string strKey = "FeatureNotice" + functionForecastConfig.FrameLevel + PlayerDatas.Instance.baseData.PlayerID;
                int type = LocalSave.GetInt(strKey);
                bool IsOpenMain = WindowCenter.Instance.CheckOpen<MainInterfaceWin>();
                if (PlayerDatas.Instance.baseData.LV >= functionForecastConfig.FrameLevel && type == 0)
                {
                    LocalSave.SetInt(strKey, functionForecastConfig.FrameLevel);
                   var IsOpenFeatureNotice = WindowCenter.Instance.CheckOpen<FeatureNoticeWin>();
                    if (!IsOpenFeatureNotice)
                    {
                        WindowCenter.Instance.Close<MainInterfaceWin>();
                        WindowCenter.Instance.Open<FeatureNoticeWin>();
                    }              
                }
            }
        }
    }
    private bool IsDungeon()
    {
        var mapId = PlayerDatas.Instance.baseData.MapID;
        var mapConfig = Config.Instance.Get<MapConfig>(mapId);
        return mapConfig != null && mapConfig.MapFBType != 0;
    }
 
    public int GetOpenLv(int Inedx)
    {
        int lv = 0;
        var functionForecastValue = Config.Instance.GetAllValues<FunctionForecastConfig>();
        foreach (var value in functionForecastValue)
        {
            if (value.OpenNumber == Inedx)
            {
                lv = value.DisplayLevel;
                return lv;
            }
        }     
        return lv;
    }
   
}