少年修仙传客户端代码仓库
client_linchunjie
2018-08-13 ab379d599ab12da503fbc25246265deddf234bbd
2296【前端】提交活动提前开启代码
1个文件已修改
116 ■■■■■ 已修改文件
System/Welfare/OperationTimeHepler.cs 116 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/Welfare/OperationTimeHepler.cs
@@ -15,6 +15,7 @@
        public event Action<Operation> operationServerCloseEvent;//特殊情况下触发
        public event Action<Operation, int> operationEndEvent;//活动结束时间触发  第二个参数0--过活动时间触发  1--过活动天触发
        public event Action<Operation, int> operationStartEvent;//活动开始时间并且满足开启条件触发 第二个参数0--活动时间触发  1--活动天触发
        public event Action<Operation> operationAdvanceEvent;//活动提前开放事件
        public OperationTimeHepler()
        {
            DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += BeforePlayerDataInitializeEvent;
@@ -63,6 +64,7 @@
                    {
                        operation.inTimeNotify = true;
                        operation.stepTimeNotify = false;
                        operation.inAdvanceNotify = false;
                        DesignDebug.LogFormat("{0}  活动时间开始", (Operation)i);
                        if (operationStartEvent != null)
                        {
@@ -77,6 +79,15 @@
                        if (operationEndEvent != null)
                        {
                            operationEndEvent((Operation)i, 0);
                        }
                    }
                    if (!operation.inAdvanceNotify && operation.InAdvanceTime(TimeUtility.ServerNow))
                    {
                        operation.inAdvanceNotify = true;
                        if (operationAdvanceEvent != null)
                        {
                            operationAdvanceEvent((Operation)i);
                        }
                    }
                }
@@ -631,6 +642,40 @@
        }
    }
    public class OperationDateEnumerator : IEnumerable, IEnumerator
    {
        OperationDate start;
        OperationDate end;
        public int index = 0;
        public object Current
        {
            get
            {
                var date = start;
                date.day += index;
                return date;
            }
        }
        public IEnumerator GetEnumerator()
        {
            return (IEnumerator)this;
        }
        public bool MoveNext()
        {
            index++;
            return index <= (start - end);
        }
        public void Reset()
        {
            index = 0;
        }
    }
    public struct OperationDate
    {
        public int year;
@@ -657,6 +702,13 @@
        {
            var yearString = StringUtility.Contact(year, Language.Get("Year"));
            return StringUtility.Contact(showYear ? yearString : string.Empty, month, Language.Get("Month"), day, Language.Get("Day"));
        }
        public static int operator -(OperationDate x, OperationDate y)
        {
            DateTime _x = new DateTime(x.year, x.month, x.day);
            DateTime _y = new DateTime(y.year, y.month, y.day);
            return (int)(_y - _x).TotalDays;
        }
    }
@@ -712,6 +764,7 @@
        public OperationDate startDate;
        public OperationDate endDate;
        public List<OperationTime> times = new List<OperationTime>();
        public OperationDateEnumerator dateEnumerator;
        public bool allDay = false;
@@ -720,6 +773,10 @@
        public bool inTimeNotify = false;
        public bool inDateNotify = false;
        public bool inAdvanceNotify = false;
        public int inAdvanceSeconds = 0;
        public int limitLv;
@@ -837,6 +894,57 @@
            return -1;
        }
        public bool InAdvanceTime(DateTime time)
        {
            if (InTime(time) || inAdvanceSeconds <= 0)
            {
                return false;
            }
            var seconds = 0;
            if (TryGetInAdvanceSurplusSecond(time, out seconds))
            {
                return seconds < inAdvanceSeconds;
            }
            return false;
        }
        public bool TryGetInAdvanceSurplusSecond(DateTime time, out int seconds)
        {
            seconds = 0;
            if (InTime(time))
            {
                return false;
            }
            if (allDay)
            {
                var startTime = new DateTime(startDate.year, startDate.month, startDate.day);
                seconds = (int)(startTime - time).TotalSeconds;
            }
            else
            {
                if (dateEnumerator != null)
                {
                    foreach (OperationDate date in dateEnumerator)
                    {
                        for (int i = 0; i < times.Count; i++)
                        {
                            var startTime = new DateTime(date.year, date.month, date.day, times[i].startHour, times[i].startMinute, 0);
                            seconds = (int)(startTime - time).TotalSeconds;
                            if (seconds > 0)
                            {
                                break;
                            }
                        }
                        if (seconds > 0)
                        {
                            break;
                        }
                    }
                }
            }
            return seconds > 0;
        }
        public int GetSurplusTime(DateTime time)
        {
            var seconds = 0;
@@ -871,7 +979,9 @@
            stepDateNotify = false;
            inTimeNotify = false;
            inDateNotify = false;
            inAdvanceNotify = false;
            allDay = false;
            inAdvanceSeconds = 0;
            limitLv = 0;
            times.Clear();
        }
@@ -890,12 +1000,6 @@
        {
            var textBuilder = OperationTimeHepler.textBuilder;
            textBuilder.Length = 0;
            //textBuilder.Append(startDate.ToDisplay());
            //if (startDate != endDate)
            //{
            //    textBuilder.Append("—");
            //    textBuilder.Append(endDate.ToDisplay(startDate.year != endDate.year));
            //}
            if (allDay)
            {
                textBuilder.Append(Language.Get("OpenAllDay"));