少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using UnityEngine.UI;
using System.Linq;
using LitJson;
 
public class HolidayRefuseClassificationModel : ILModel<HolidayRefuseClassificationModel>
{
    public ILOpenServerActivityProxy activity;
 
    public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_JRZF;
    public const int activityID = 112;
    public const Operation operationType = Operation.default3; //垃圾分类
    //活动首次开启需要一次红点
    public const int redpointID = 28012;
    public Redpoint redpoint = new Redpoint(MainRedDot.RedPoint_HolidayWishes, redpointID);
    public Redpoint redpointCol = new Redpoint(redpointID, 280121);  //垃圾收集红点
    public event Action onSelectUpdate;
 
    //任务ID:x-当前总进度 y-完成次数  单次当前进度 = x-y*单次所需进度
    Dictionary<int, Int2> tasksInfo = new Dictionary<int, Int2>();
    public int hisEnvValueTotal = 0;
    public event Action<int, int, int> onDropResult;
    public event Action OnGarbageTaskPack;
 
    public SinglePack packModel;
    PackModel playerPack { get { return ModelCenter.Instance.GetModelEx<PackModel>(); } }
 
    int m_SelectIndex = 0; //选择物品索引
    public int selectIndex
    {
        get { return m_SelectIndex; }
        set
        {
            if (m_SelectIndex != value)
            {
                m_SelectIndex = value;
                if (onSelectUpdate != null)
                {
                    onSelectUpdate();
                }
            }
        }
    }
 
    protected override void Init()
    {
        GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
        ILOperationTimeHepler.Instance.operationTimeUpdateEvent += operationTimeUpdateEvent;
        playerPack.refreshItemCountEvent += refreshItemCountEvent;
        GameEvent.OnRefrechPackEvent += refrechPackEvent;
        GameEvent.playerLoginOkEvent += OnPlayerLoginOk;
        activity = new ILOpenServerActivityProxy(IsOpen, IsAdvance, priorityOpen);
        OpenServerActivityCenter.Instance.Register(activityID, activity, activityType);
    }
 
    protected override void UnInit()
    {
        GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
        ILOperationTimeHepler.Instance.operationTimeUpdateEvent -= operationTimeUpdateEvent;
        playerPack.refreshItemCountEvent -= refreshItemCountEvent;
        GameEvent.OnRefrechPackEvent -= refrechPackEvent;
        GameEvent.playerLoginOkEvent -= OnPlayerLoginOk;
    }
 
    public bool IsOpen()
    {
        return OperationTimeHepler.Instance.SatisfyOpenCondition(operationType);
    }
 
    public bool IsAdvance()
    {
        return false;
    }
 
    public bool priorityOpen()
    {
        //红点
        return redpoint.state == RedPointState.Simple;
    }
 
 
    public void OnBeforePlayerDataInitialize()
    {
        tasksInfo.Clear();
        packModel = null;
    }
 
    public void OnPlayerLoginOk()
    {
        if (packModel == null)
            packModel = playerPack.GetSinglePack(PackType.default1);
    }
 
    public void UpdateActGarbageTaskInfo(IL_HAA56_tagMCActGarbageTaskInfo package)
    {
 
        OperationBase operationBase;
        if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            return;
        }
        OperationRefuseClassification operation = operationBase as OperationRefuseClassification;
        if (operation.ActNum != package.ActNum)
        {
            return;
        }
        for (int i = 0; i < package.GarbageTaskList.Length; i++)
        {
            tasksInfo[package.GarbageTaskList[i].GarbageTaskID] = new Int2((int)package.GarbageTaskList[i].GarbageTaskValue, (int)package.GarbageTaskList[i].GarbageTaskFinishCount);
        }
        hisEnvValueTotal = (int)package.HisEnvValueTotal;
        OnGarbageTaskPack?.Invoke();
 
        UpdateRedpoint();
    }
 
    public Dictionary<int, Int2> GetGarbageTasksInfo()
    {
        return tasksInfo;
    }
 
    public Int2 TryGetTaskInfo(int id)
    {
        if (tasksInfo.ContainsKey(id))
        {
            return tasksInfo[id];
        }
 
        return Int2.zero;
    }
 
    public void UpdateActGarbageSortingResult(IL_HAA57_tagMCActGarbageSortingResult package)
    {
 
        OperationBase operationBase;
        if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            return;
        }
        OperationRefuseClassification operation = operationBase as OperationRefuseClassification;
        if (operation.ActNum != package.ActNum)
        {
            return;
        }
        hisEnvValueTotal = (int)package.HisEnvValueTotal;
        onDropResult?.Invoke(package.GarbageSortingType, package.IsRight, (int)package.AddEnvValue);
    }
 
    private void operationTimeUpdateEvent(Operation type)
    {
        if (type == operationType)
        {
            OperationBase operationBase;
            if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
            {
                return;
            }
            OperationRefuseClassification operation = operationBase as OperationRefuseClassification;
 
            MarkNewActivity(operation.startDate.ToString());
 
            UpdateRedpoint();
        }
    }
 
    public void UpdateRedpoint()
    {
        redpoint.state = RedPointState.None;
        redpointCol.state = RedPointState.None;
        OperationBase operationBase;
        if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            return;
        }
        OperationRefuseClassification operation = operationBase as OperationRefuseClassification;
 
        if (GetGarbageCollectIndex() > -1)
        {
            redpointCol.state = RedPointState.Simple;
        }
        if (packModel == null)
            packModel = playerPack.GetSinglePack(PackType.default1);
        //新活动,垃圾未投放,可手动收集
        if (LocalSave.GetBool(StringUtility.Contact(PlayerDatas.Instance.PlayerId, "ActGarbageRedPoint")) || packModel.GetAllItems().Count > 0)
        {
            redpoint.state = RedPointState.Simple;
        }
    }
 
 
    public void SendGarbageSorting(int itemIndex, int garbageType)
    {
        OperationBase operationBase;
        if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            return;
        }
        OperationRefuseClassification operation = operationBase as OperationRefuseClassification;
 
        var pak = new IL_CAA14_tagCMActGarbageSorting();
        pak.ActNum = (byte)operation.ActNum;
        pak.GarbageSortingType = (byte)garbageType;
        pak.ItemIndexCount = 1;
        pak.ItemIndexList = new byte[] { (byte)itemIndex };
        GameNetSystem.Instance.SendInfo(pak);
    }
 
    public void SendActGarbageGetTaskAward(int ID)
    {
        OperationBase operationBase;
        if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
        {
            return;
        }
        OperationRefuseClassification operation = operationBase as OperationRefuseClassification;
 
        var pak = new IL_CAA15_tagCMActGarbageGetTaskAward();
        pak.ActNum = (byte)operation.ActNum;
        pak.GarbageTaskID = (byte)ID;
        GameNetSystem.Instance.SendInfo(pak);
    }
 
    //需要手动收集的位置
    public int GetGarbageCollectIndex()
    {
        var idList = tasksInfo.Keys.ToList();
        idList.Sort();
 
        for (int i = 0; i < idList.Count; i++)
        {
            var id = idList[i];
 
            //跳转到可手动收集行
            var config = ILActGarbageTaskConfig.Get(id);
            if (config != null)
            {
                if (config.AutoProduce == 1)
                {
                    continue;
                }
                var taskInfo = TryGetTaskInfo(id);
                if ((taskInfo.x - taskInfo.y * config.FinishNeedValue) >= config.FinishNeedValue)
                {
                    return i;
                }
            }
        }
        return -1;
    }
 
    public void MarkNewActivity(string newActMark)
    {
        if (LocalSave.GetString(StringUtility.Contact(PlayerDatas.Instance.PlayerId, "ActGarbage")) != newActMark)
        {
            LocalSave.SetString(StringUtility.Contact(PlayerDatas.Instance.PlayerId, "ActGarbage"), newActMark);
            LocalSave.SetBool(StringUtility.Contact(PlayerDatas.Instance.PlayerId, "ActGarbageRedPoint"), true);
        }
    }
 
    private void refreshItemCountEvent(PackType type, int index, int id)
    {
        if (type != PackType.default1)
            return;
        UpdateRedpoint();
    }
 
 
    private void refrechPackEvent(PackType type)
    {
        if (type != PackType.default1)
            return;
        UpdateRedpoint();
    }
}