| | |
| | | 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;
|
| | |
| | | {
|
| | | operation.inTimeNotify = true;
|
| | | operation.stepTimeNotify = false;
|
| | | operation.inAdvanceNotify = false;
|
| | | DesignDebug.LogFormat("{0} 活动时间开始", (Operation)i);
|
| | | if (operationStartEvent != null)
|
| | | {
|
| | |
| | | if (operationEndEvent != null)
|
| | | {
|
| | | operationEndEvent((Operation)i, 0);
|
| | | }
|
| | | }
|
| | |
|
| | | if (!operation.inAdvanceNotify && operation.InAdvanceTime(TimeUtility.ServerNow))
|
| | | {
|
| | | operation.inAdvanceNotify = true;
|
| | | if (operationAdvanceEvent != null)
|
| | | {
|
| | | operationAdvanceEvent((Operation)i);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | 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;
|
| | |
| | | {
|
| | | 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;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | public OperationDate startDate;
|
| | | public OperationDate endDate;
|
| | | public List<OperationTime> times = new List<OperationTime>();
|
| | | public OperationDateEnumerator dateEnumerator;
|
| | |
|
| | | public bool allDay = false;
|
| | |
|
| | |
| | |
|
| | | public bool inTimeNotify = false;
|
| | | public bool inDateNotify = false;
|
| | |
|
| | | public bool inAdvanceNotify = false;
|
| | |
|
| | | public int inAdvanceSeconds = 0;
|
| | |
|
| | | public int limitLv;
|
| | |
|
| | |
| | | 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;
|
| | |
| | | stepDateNotify = false;
|
| | | inTimeNotify = false;
|
| | | inDateNotify = false;
|
| | | inAdvanceNotify = false;
|
| | | allDay = false;
|
| | | inAdvanceSeconds = 0;
|
| | | limitLv = 0;
|
| | | times.Clear();
|
| | | }
|
| | |
| | | {
|
| | | 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"));
|