| | |
| | |
|
| | | public class OperationTimeHepler : Singleton<OperationTimeHepler>
|
| | | {
|
| | | public Dictionary<Operation, OperationBase> operationDict = new Dictionary<Operation, OperationBase>();
|
| | | public Dictionary<OperationType, OperationBase> operationDict = new Dictionary<OperationType, OperationBase>();
|
| | |
|
| | | public static StringBuilder textBuilder = new StringBuilder();
|
| | |
|
| | | public event Action<Operation> operationTimeUpdateEvent;
|
| | | public event Action<Operation> operationServerCloseEvent;//特殊情况下触发
|
| | | public event Action<Operation, int> operationEndEvent;//活动结束时间触发 第二个参数0--过活动时间触发 1--过活动天触发
|
| | | public event Action<Operation, int> operationStartEvent;//活动开始时间并且满足开启条件触发 第二个参数0--活动时间触发 1--活动天触发
|
| | | public event Action<OperationType> operationTimeUpdateEvent;
|
| | | public event Action<OperationType> operationServerCloseEvent;//特殊情况下触发
|
| | | public event Action<OperationType, int> operationEndEvent;//活动结束时间触发 第二个参数0--过活动时间触发 1--过活动天触发
|
| | | public event Action<OperationType, int> operationStartEvent;//活动开始时间并且满足开启条件触发 第二个参数0--活动时间触发 1--活动天触发
|
| | | public event Action<int> dayResetEvent;//活动重置事件0-0点 1-5点
|
| | | public event Action<Operation> operationAdvanceEvent;//活动在提前开启的时间内
|
| | | public event Action<OperationType> operationAdvanceEvent;//活动在提前开启的时间内
|
| | |
|
| | | public OperationTimeHepler()
|
| | | {
|
| | |
| | | {
|
| | | return;
|
| | | }
|
| | | for (int i = 0; i < (int)Operation.max; i++)
|
| | | for (int i = 0; i < (int)OperationType.max; i++)
|
| | | {
|
| | | if (operationDict.ContainsKey((Operation)i))
|
| | | if (operationDict.ContainsKey((OperationType)i))
|
| | | {
|
| | | var operation = operationDict[(Operation)i];
|
| | | var operation = operationDict[(OperationType)i];
|
| | | if (!operation.inDateNotify && operation.SatisfyOpenCondition()
|
| | | && operation.InDay(TimeUtility.ServerNow))
|
| | | {
|
| | | operation.inDateNotify = true;
|
| | | operation.stepDateNotify = false;
|
| | | Debug.LogFormat("{0} 活动天开始", (Operation)i);
|
| | | Debug.LogFormat("{0} 活动天开始", (OperationType)i);
|
| | | if (operationStartEvent != null)
|
| | | {
|
| | | operationStartEvent((Operation)i, 1);
|
| | | operationStartEvent((OperationType)i, 1);
|
| | | }
|
| | | }
|
| | | else if (!operation.stepDateNotify && !operation.InDay(TimeUtility.ServerNow))
|
| | | {
|
| | | operation.inDateNotify = false;
|
| | | operation.stepDateNotify = true;
|
| | | Debug.LogFormat("{0} 活动天结束", (Operation)i);
|
| | | Debug.LogFormat("{0} 活动天结束", (OperationType)i);
|
| | | if (operationEndEvent != null)
|
| | | {
|
| | | operationEndEvent((Operation)i, 1);
|
| | | operationEndEvent((OperationType)i, 1);
|
| | | }
|
| | | }
|
| | | if (!operation.inTimeNotify && operation.SatisfyOpenCondition()
|
| | |
| | | {
|
| | | operation.inTimeNotify = true;
|
| | | operation.stepTimeNotify = false;
|
| | | Debug.LogFormat("{0} 活动时间开始", (Operation)i);
|
| | | Debug.LogFormat("{0} 活动时间开始", (OperationType)i);
|
| | | if (operationStartEvent != null)
|
| | | {
|
| | | operationStartEvent((Operation)i, 0);
|
| | | operationStartEvent((OperationType)i, 0);
|
| | | }
|
| | | }
|
| | | else if (!operation.stepTimeNotify && !operation.InTime(TimeUtility.ServerNow))
|
| | |
| | | operation.inTimeNotify = false;
|
| | | operation.stepTimeNotify = true;
|
| | | operation.inAdvanceNotify = false;
|
| | | Debug.LogFormat("{0} 活动时间结束", (Operation)i);
|
| | | Debug.LogFormat("{0} 活动时间结束", (OperationType)i);
|
| | | if (operationEndEvent != null)
|
| | | {
|
| | | operationEndEvent((Operation)i, 0);
|
| | | operationEndEvent((OperationType)i, 0);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | && operation.InAdvanceTime(TimeUtility.ServerNow))
|
| | | {
|
| | | operation.inAdvanceNotify = true;
|
| | | Debug.LogFormat("{0} 活动提前开启", (Operation)i);
|
| | | Debug.LogFormat("{0} 活动提前开启", (OperationType)i);
|
| | | if (operationAdvanceEvent != null)
|
| | | {
|
| | | operationAdvanceEvent((Operation)i);
|
| | | operationAdvanceEvent((OperationType)i);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | // }
|
| | | // }
|
| | |
|
| | | public void ForceStopOperation(Operation operationType)
|
| | | public void ForceStopOperation(OperationType operationType)
|
| | | {
|
| | | if (operationDict.ContainsKey(operationType))
|
| | | {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public bool TryGetOperationTime(Operation type, out OperationBase operation)
|
| | | public bool TryGetOperationTime(OperationType type, out OperationBase operation)
|
| | | {
|
| | | return operationDict.TryGetValue(type, out operation);
|
| | | }
|
| | |
|
| | | public bool TryGetOperation<T>(Operation type, out T operation) where T : OperationBase
|
| | | public bool TryGetOperation<T>(OperationType type, out T operation) where T : OperationBase
|
| | | {
|
| | | operation = null;
|
| | | if (operationDict.ContainsKey(type))
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | public bool InOperationTime(Operation type)
|
| | | public bool InOperationTime(OperationType type)
|
| | | {
|
| | | OperationBase operation;
|
| | | if (TryGetOperationTime(type, out operation))
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | public bool InOperationTime(Operation type, DateTime time)
|
| | | public bool InOperationTime(OperationType type, DateTime time)
|
| | | {
|
| | | OperationBase operation;
|
| | | if (TryGetOperationTime(type, out operation))
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | public bool InOperationJoinTime(Operation type, DateTime time)
|
| | | public bool InOperationJoinTime(OperationType type, DateTime time)
|
| | | {
|
| | | OperationBase operation;
|
| | | if (TryGetOperationTime(type, out operation))
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | public bool InOperationDay(Operation type)
|
| | | public bool InOperationDay(OperationType type)
|
| | | {
|
| | | OperationBase operation;
|
| | | if (TryGetOperationTime(type, out operation))
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | public int GetOperationSurplusTime(Operation type)
|
| | | public int GetOperationSurplusTime(OperationType type)
|
| | | {
|
| | | OperationBase operation;
|
| | | if (TryGetOperationTime(type, out operation))
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | | public bool InOperationAdvance(Operation type)
|
| | | public bool InOperationAdvance(OperationType type)
|
| | | {
|
| | | OperationBase operation;
|
| | | if (TryGetOperationTime(type, out operation))
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | public int GetOperationSecondsBeforeStart(Operation type)
|
| | | public int GetOperationSecondsBeforeStart(OperationType type)
|
| | | {
|
| | | OperationBase operation;
|
| | | if (TryGetOperationTime(type, out operation))
|
| | |
| | | return 0;
|
| | | }
|
| | |
|
| | | public bool SatisfyOpenCondition(Operation type)
|
| | | public bool SatisfyOpenCondition(OperationType type)
|
| | | {
|
| | | OperationBase operation;
|
| | | if (TryGetOperationTime(type, out operation))
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | public bool SatisfyOpenCondition(Operation type, DateTime time)
|
| | | public bool SatisfyOpenCondition(OperationType type, DateTime time)
|
| | | {
|
| | | OperationBase operation;
|
| | | if (TryGetOperationTime(type, out operation))
|
| | |
| | | }
|
| | |
|
| | | //活动开启中,有参与进行时间段
|
| | | public bool SatisfyJoinCondition(Operation type, DateTime time)
|
| | | public bool SatisfyJoinCondition(OperationType type, DateTime time)
|
| | | {
|
| | | OperationBase operation;
|
| | | if (TryGetOperationTime(type, out operation))
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | public bool IsPrepareTime(Operation type, DateTime time)
|
| | | public bool IsPrepareTime(OperationType type, DateTime time)
|
| | | {
|
| | | OperationBase operation;
|
| | | if (TryGetOperationTime(type, out operation))
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | public bool SatisfyAdvanceCondition(Operation type)
|
| | | public bool SatisfyAdvanceCondition(OperationType type)
|
| | | {
|
| | | OperationBase operation;
|
| | | if (TryGetOperationTime(type, out operation))
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | public void ProcessConditionError(Operation type)
|
| | | public void ProcessConditionError(OperationType type)
|
| | | {
|
| | | if (SatisfyOpenCondition(type))
|
| | | {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public enum Operation
|
| | | public enum OperationType
|
| | | {
|
| | | MultipleExp,
|
| | | ConsumeRebate,
|