hch
2025-12-10 8704250d9701db5ddb475d19b39100d6d24650aa
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;
 
 
public partial class AchievementManager : GameSystemManager<AchievementManager>
{
    //成就类型:条件(可以是空):进度
    Dictionary<int, Dictionary<string, int>> achivementDict = new Dictionary<int, Dictionary<string, int>>();
    public event Action<int> OnAchievementUpdateEvent;
    //key:第几个记录值 每个key存31个succid   0-30为0, 31-61为1..; value: 根据成就ID位判断是否已领取
    Dictionary<int, int> achivementAwardDict = new Dictionary<int, int>();
    public override void Init()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
        FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
    }
 
    public override void Release()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
        FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
    }
 
    void OnBeforePlayerDataInitialize()
    {
        achivementDict.Clear();
    }
 
    void OnFuncStateChangeEvent(int funcID)
    {
        if (funcID == (int)FuncOpenEnum.DayMission)
        {
            UpdateRedpoint(new List<int>() { 1 });
        }
    }
 
    public void UpdateAchievement(HA340_tagSCSuccessInfoList netPack)
    {
        List<int> types = new List<int>();
        for (int i = 0; i < netPack.Count; i++)
        {
            var info = netPack.SuccessInfoList[i];
            if (!achivementDict.ContainsKey(info.SuccType))
            {
                achivementDict[info.SuccType] = new Dictionary<string, int>();
            }
 
            string key = info.CLen > 0 ? string.Join("|", info.Conds) : "";
            achivementDict[info.SuccType][key] = (int)info.CurValue;
 
            OnAchievementUpdateEvent?.Invoke(info.SuccType);
            if (!types.Contains(info.SuccType))
            {
                types.Add(info.SuccType);
            }
        }
        UpdateRedpoint(types);
    }
 
    public int GetAchievementProgress(int type, string condKey = "")
    {
        if (achivementDict.ContainsKey(type))
        {
            if (string.IsNullOrEmpty(condKey))
            {
                condKey = SuccessConfig.GetConditionString(type);
            }
            if (achivementDict[type].ContainsKey(condKey))
            {
                return achivementDict[type][condKey];
            }
        }
        return 0;
 
    }
 
    public void UpdateAchievementAward(HA342_tagSCSuccessAwardRecordList netPack)
    {
        List<int> types = new List<int>();
        for (int i = 0; i < netPack.RecordCnt; i++)
        {
            var record = netPack.RecordList[i];
            achivementAwardDict[record.RecordIndex] = (int)record.Record;
            var startID = record.RecordIndex * 31;
            var endID = startID + 30;
            for (int j = startID; j <= endID; j++)
            {
                if (SuccessConfig.HasKey(j))
                {
                    var type = SuccessConfig.Get(j).Type;
                    if (!types.Contains(type))
                    {
                        types.Add(type);
                    }
                }
            }
        }
        OnAchievementUpdateEvent?.Invoke(-1);
        UpdateRedpoint(types);
    }
 
    //成就是否已领取 
    //每个key存31个succid   0-30为0, 31-61为1..; 根据成就ID位判断是否已领取
    public bool IsAchievementAwarded(int id)
    {
        var index = id / 31;
        var bit = id % 31;
        if (achivementAwardDict.ContainsKey(index))
        {
            return (achivementAwardDict[index] & (1 << bit)) != 0;
        }
        return false;
    }
 
    //获取成就状态  0: 未领取 1: 未达成 2: 已领取
    public int GetAchievementState(int id, string condKey = "")
    {
        var config = SuccessConfig.Get(id);
        var process = GetAchievementProgress(config.Type, condKey);
        if (process < config.NeedCnt)
        {
            return 1;
        }
        if (IsAchievementAwarded(id))
        {
            return 2;
        }
        return 0;
    }
 
 
    //主线章节
    Redpoint mainLevelRedpoint = new Redpoint(MainRedDot.RedPoint_DailyKey, MainRedDot.RedPoint_MainMissionKey);
    //庆典成就
    const int osGalaRepointSuccessID = MainRedDot.RedPoint_OSGala * 10 + 1;
    Redpoint osGalaRedpoint = new Redpoint(MainRedDot.RedPoint_OSGala, osGalaRepointSuccessID);
 
    //类型:红点id
    Dictionary<int, int> redpointDict = new Dictionary<int, int>()
    {
        {1, MainRedDot.RedPoint_MainMissionKey},
        {2, osGalaRepointSuccessID},
        {3, osGalaRepointSuccessID},
        {4, osGalaRepointSuccessID},
        {5, osGalaRepointSuccessID},
        {6, osGalaRepointSuccessID},
        {7, osGalaRepointSuccessID},
        {8, osGalaRepointSuccessID},
        {9, osGalaRepointSuccessID},
        {10, osGalaRepointSuccessID},
        {11, osGalaRepointSuccessID},
        {12, osGalaRepointSuccessID},
        {13, osGalaRepointSuccessID},
        {14, osGalaRepointSuccessID},
        {15, osGalaRepointSuccessID},
        {16, osGalaRepointSuccessID},
        {17, osGalaRepointSuccessID},
        {18, osGalaRepointSuccessID},
        {19, osGalaRepointSuccessID},
 
    };
 
    void UpdateRedpoint(List<int> _types)
    {
        if (_types.IsNullOrEmpty())
        {
            _types = redpointDict.Keys.ToList();
        }
 
        bool isGalaRed = false;
 
        foreach (var type in _types)
        {
            if (!redpointDict.ContainsKey(type))
            {
                continue;
            }
            if (isGalaRed && type >= 2 && type <= 19)
            {
                continue;
            }
            var redpoint = RedpointCenter.Instance.GetRedpoint(redpointDict[type]);
            redpoint.state = RedPointState.None;
            if (!isOpened(type))
            {
                continue;
            }
            //根据ID判断是否有可领取的
            var allAchivement = SuccessConfig.GetTypeToIDDict(type);
            var process = GetAchievementProgress(type);
            foreach (var id in allAchivement)
            {
                var config = SuccessConfig.Get(id);
                if (type == 6)
                {
                    process = GetAchievementProgress(type, config.Condition[0].ToString());
                }
                if (config.NeedCnt <= process)
                {
                    if (!IsAchievementAwarded(id))
                    {
                        redpoint.state = RedPointState.Simple;
                        if (type >= 2 && type <= 19)
                        {
                            isGalaRed = true;
                        }
                        break;
                    }
                }
            }
 
        }
    }
 
 
    bool isOpened(int type)
    {
        if (type == 1)
        {
            if (FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.DayMission))
            {
                return true;
            }
        }
        else if (type >= 2 && type <= 19)
        {
            return OSActivityManager.Instance.IsOpenedOSGala();
        }
        return false;
    }
 
    //根据类型获取所有成就ID, 且是排序后的 未领取>未达成>已领取
    public List<int> GetAchievementIDs(int type)
    {
        var ids = SuccessConfig.GetTypeToIDDict(type);
        ids.Sort(CmpIds);
        return ids;
    }
 
    int CmpIds(int a, int b)
    {
        var configA = SuccessConfig.Get(a);
        var configB = SuccessConfig.Get(b);
 
        var condA = configA.Condition.IsNullOrEmpty() ? "" : configA.Condition[0].ToString();
        var condB = configB.Condition.IsNullOrEmpty() ? "" : configB.Condition[0].ToString();
 
        var stateA = GetAchievementState(a, condA);
        var stateB = GetAchievementState(b, condB);
 
        if (stateA != stateB)
        {
            return stateA - stateB;
        }
 
        return a - b;
    }
 
    public List<int> GetAchievementIDsByTypes(int[] types)
    {
        List<int> allIds = new List<int>();
        foreach (var type in types)
        {
            var ids = SuccessConfig.GetTypeToIDDict(type);
            if (!ids.IsNullOrEmpty())
            {
                //合并
                allIds.AddRange(SuccessConfig.GetTypeToIDDict(type));
            }
            // else
            // {
            //     Debug.LogError($"{type}");
            // }
        }
        allIds.Sort(CmpIds);
        return allIds;
    }
 
 
    public void SendGetAward(int id)
    {
        var config = SuccessConfig.Get(id);
        //简单判断背包
        if (PackManager.Instance.GetEmptyGridCount(PackType.Item) < config.AwardItemList.Length)
        {
            SysNotifyMgr.Instance.ShowTip("GeRen_lhs_202580");
            return;
        }
        
        var pack = new CA504_tagCMPlayerGetReward();
        pack.RewardType = 59;
        pack.DataEx = (uint)id;
        GameNetSystem.Instance.SendInfo(pack);
    }
}