少年修仙传客户端代码仓库
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
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
 
namespace vnxbqy.UI
{
    public class LoginActModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
    {
        public event Action<int> onStateUpdate;
        public const int redPointID = MainRedDot.NewDayActionRedPoint * 10;
        public Redpoint redPoint = new Redpoint(MainRedDot.RankActRepoint, redPointID); //可能挂多个父红点
 
        private uint LoginAwardState; //领取状态  可以补签
 
        public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_Activity2;
        public const int activityID = (int)NewDayActivityID.LoginAct;
        public static Operation operaType = Operation.default29;
 
        public int actNum = 10; //对应界面
        public event Action UpdateyLoginEvent; 
 
        public override void Init()
        {
            OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
            OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
            OperationTimeHepler.Instance.operationAdvanceEvent += OperationAdvanceEvent;
            OpenServerActivityCenter.Instance.Register(activityID, this, activityType);
        }
 
        public void OnBeforePlayerDataInitialize()
        {
        }
 
        public void OnPlayerLoginOk()
        {
        }
 
        public override void UnInit()
        {
 
        }
 
        public bool IsOpen {
            get {
                return OperationTimeHepler.Instance.SatisfyOpenCondition(operaType);
            }
        }
 
        public bool priorityOpen {
            get {
                return redPoint.state == RedPointState.Simple;
            }
        }
 
        public bool IsAdvance {
            get {
                return OperationTimeHepler.Instance.SatisfyAdvanceCondition(operaType);
            }
        }
 
        private void OperationEndEvent(Operation type, int state)
        {
            if (type == operaType && state == 0)
            {
                if (onStateUpdate != null)
                {
                    onStateUpdate(activityID);
                }
                UpdateRedpoint();
            }
        }
 
        private void OperationAdvanceEvent(Operation type)
        {
            if (type == operaType)
            {
                if (onStateUpdate != null)
                {
                    onStateUpdate(activityID);
                }
            }
        }
 
        private void OperationStartEvent(Operation type, int state)
        {
            if (type == operaType && state == 0)
            {
 
                if (onStateUpdate != null)
                {
                    onStateUpdate(activityID);
                }
            }
        }
 
        //0 不可领取(日期未到)  1 可领取  2 已领取 3补签(已过天)
        //day 从1开始
        public int GetLoginAwardState(int day)
        {
            //校验日期
            OperationLoginAct holiday;
            OperationTimeHepler.Instance.TryGetOperation(operaType, out holiday);
            if (holiday == null) return 0;
 
            int days = holiday.IndexOfDays(TimeUtility.ServerNow); //当前是第几天
            if (days == -1) return 0;
            if (day > days + 1) return 0;
 
            if (((int)Math.Pow(2, day) & LoginAwardState) == 0)
            {
                if (day != days + 1)
                    return 3;
                return 1;
            }
 
            return 2;
        }
 
        void UpdateRedpoint()
        {
            redPoint.state = RedPointState.None;
            if (!IsOpen) return;
            OperationLoginAct holiday;
            OperationTimeHepler.Instance.TryGetOperation(operaType, out holiday);
            if (holiday == null) return; //封包顺序如果有问题 此处为空
 
            for (int i = 0; i < holiday.loginAwards.Count; i++)
            {
                if (GetLoginAwardState(holiday.loginAwards[i].DayNum) == 1)
                {
                    redPoint.state = RedPointState.Simple;
                    return;
                }
            }
        }
 
        public void UpdateLoginInfo(HAA70_tagMCActLoginPlayerInfoNew netPack)
        {
            if (actNum != netPack.ActNum)
                return;
            LoginAwardState = netPack.LoginAward;
            UpdateyLoginEvent?.Invoke();
 
            UpdateRedpoint();
        }
 
        public void SendGetAward(int day)
        {
            CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
            getReward.RewardType = 70;
            getReward.DataEx = (uint)day;
            getReward.DataExStr = actNum.ToString();
            getReward.DataExStrLen = (byte)getReward.DataExStr.Length;
            GameNetSystem.Instance.SendInfo(getReward);
        }
 
    }
}