using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Text;
|
using UnityEngine;
|
|
public class OperationTimeHepler : Singleton<OperationTimeHepler>
|
{
|
public Dictionary<OperationType, OperationBase> operationDict = new Dictionary<OperationType, OperationBase>();
|
|
public static StringBuilder textBuilder = new StringBuilder();
|
|
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<OperationType> operationAdvanceEvent;//活动在提前开启的时间内
|
|
public OperationTimeHepler()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= BeforePlayerDataInitializeEvent;
|
GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
|
TimeMgr.Instance.OnHourEvent -= HourEvent;
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += BeforePlayerDataInitializeEvent;
|
GlobalTimeEvent.Instance.secondEvent += SecondEvent;
|
TimeMgr.Instance.OnHourEvent += HourEvent;
|
}
|
|
private void BeforePlayerDataInitializeEvent()
|
{
|
operationDict.Clear();
|
}
|
|
private void SecondEvent()
|
{
|
if (!ConfigManager.Instance.isLoadFinished)
|
return;
|
|
if (!DTC0403_tagPlayerLoginLoadOK.finishedLogin)
|
{
|
return;
|
}
|
for (int i = 0; i < (int)OperationType.max; i++)
|
{
|
if (operationDict.ContainsKey((OperationType)i))
|
{
|
var operation = operationDict[(OperationType)i];
|
if (!operation.inDateNotify && operation.SatisfyOpenCondition()
|
&& operation.InDay(TimeUtility.ServerNow))
|
{
|
operation.inDateNotify = true;
|
operation.stepDateNotify = false;
|
Debug.LogFormat("{0} 活动天开始", (OperationType)i);
|
if (operationStartEvent != null)
|
{
|
operationStartEvent((OperationType)i, 1);
|
}
|
}
|
else if (!operation.stepDateNotify && !operation.InDay(TimeUtility.ServerNow))
|
{
|
operation.inDateNotify = false;
|
operation.stepDateNotify = true;
|
Debug.LogFormat("{0} 活动天结束", (OperationType)i);
|
if (operationEndEvent != null)
|
{
|
operationEndEvent((OperationType)i, 1);
|
}
|
}
|
if (!operation.inTimeNotify && operation.SatisfyOpenCondition()
|
&& operation.InTime(TimeUtility.ServerNow))
|
{
|
operation.inTimeNotify = true;
|
operation.stepTimeNotify = false;
|
Debug.LogFormat("{0} 活动时间开始", (OperationType)i);
|
if (operationStartEvent != null)
|
{
|
operationStartEvent((OperationType)i, 0);
|
}
|
}
|
else if (!operation.stepTimeNotify && !operation.InTime(TimeUtility.ServerNow))
|
{
|
operation.inTimeNotify = false;
|
operation.stepTimeNotify = true;
|
operation.inAdvanceNotify = false;
|
Debug.LogFormat("{0} 活动时间结束", (OperationType)i);
|
if (operationEndEvent != null)
|
{
|
operationEndEvent((OperationType)i, 0);
|
}
|
}
|
|
if (!operation.inAdvanceNotify && operation.SatisfyOpenCondition()
|
&& operation.InAdvanceTime(TimeUtility.ServerNow))
|
{
|
operation.inAdvanceNotify = true;
|
Debug.LogFormat("{0} 活动提前开启", (OperationType)i);
|
if (operationAdvanceEvent != null)
|
{
|
operationAdvanceEvent((OperationType)i);
|
}
|
}
|
}
|
}
|
}
|
|
private void HourEvent()
|
{
|
if (!DTC0403_tagPlayerLoginLoadOK.finishedLogin)
|
{
|
return;
|
}
|
if (TimeUtility.Hour == 0 && dayResetEvent != null)
|
{
|
dayResetEvent(0);
|
}
|
if (TimeUtility.Hour == 5 && dayResetEvent != null)
|
{
|
dayResetEvent(1);
|
}
|
}
|
|
|
|
// /// <summary>
|
// /// 累计充值
|
// /// </summary>
|
// /// <param name="package"></param>
|
|
// public void UpdateAccumulateRecharge(HAA1D_tagMCActTotalRechargeInfo package)
|
// {
|
// OperationBase operationBase = null;
|
|
// Operation opreationType = Operation.AccumulateRecharge;
|
// if (package.ActNum == 10)
|
// {
|
// //精彩活动-单日累充
|
// opreationType = Operation.AccumulateRecharge;
|
// }
|
// else if (package.ActNum == 11)
|
// {
|
// //精彩活动-多日累充
|
// opreationType = Operation.DaysAccumulateRecharge;
|
// }
|
// else if (package.ActNum == 20)
|
// {
|
// //合服-福利(多日累充1档)
|
// opreationType = Operation.default8;
|
// }
|
// else if (package.ActNum == 30)
|
// {
|
// //节日-单日累充
|
// opreationType = Operation.HolidayAccumulateRecharge;
|
// }
|
// else if (package.ActNum == 31)
|
// {
|
// //节日-多日累充
|
// opreationType = Operation.HolidayMultiRecharge;
|
// }
|
// else if (package.ActNum == 34)
|
// {
|
// // 节日-指定1档充值
|
// opreationType = Operation.default20;
|
// }
|
// else if (package.ActNum == 35)
|
// {
|
// // 福缘- 长久累充(几个月或更长)
|
// opreationType = Operation.default32;
|
// }
|
|
// operationDict.TryGetValue(opreationType, out operationBase);
|
// if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
// {
|
// ForceStopOperation(opreationType);
|
// }
|
// else
|
// {
|
// if (operationBase == null)
|
// {
|
// operationBase = new OperationAccumulateRecharge();
|
// operationDict.Add(opreationType, operationBase);
|
// }
|
// OperationAccumulateRecharge operation = operationBase as OperationAccumulateRecharge;
|
// operation.Reset();
|
// operation.limitLv = package.LimitLV;
|
// operation.startDate = ParseOperationDate(package.StartDate);
|
// operation.endDate = ParseOperationDate(package.EndtDate);
|
// operation.dayReset = package.IsDayReset == 1;
|
// operation.ParseAccumulateRecharge(package);
|
// operation.ActNum = package.ActNum;
|
// if (operationTimeUpdateEvent != null)
|
// {
|
// operationTimeUpdateEvent(opreationType);
|
// }
|
// }
|
// }
|
|
|
|
// public void UpdateCollectWordsPackage(HAA40_tagMCActCollectWordsInfo package)
|
// {
|
// OperationBase operationBase = null;
|
|
// var opreationType = Operation.CollectWords;
|
|
// switch (package.ActNum)
|
// {
|
// case 10:
|
// opreationType = Operation.CollectWords;
|
// break;
|
// case 20:
|
// opreationType = Operation.default10;
|
// break;
|
// case 30:
|
// opreationType = Operation.HolidayCollectWords;
|
// break;
|
// }
|
|
// operationDict.TryGetValue(opreationType, out operationBase);
|
// if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
// {
|
// ForceStopOperation(opreationType);
|
// }
|
// else
|
// {
|
// if (operationBase == null)
|
// {
|
// operationBase = new OperationCollectWords();
|
// operationDict.Add(opreationType, operationBase);
|
// }
|
// OperationCollectWords operation = operationBase as OperationCollectWords;
|
// operation.Reset();
|
// operation.limitLv = package.LimitLV;
|
// operation.startDate = ParseOperationDate(package.StartDate);
|
// operation.endDate = ParseOperationDate(package.EndtDate);
|
// operation.ActNum = package.ActNum;
|
// operation.LastDayOnlyExchange = package.LastDayOnlyExchange;
|
// operation.ParseCollectWords(package);
|
// if (operationTimeUpdateEvent != null)
|
// {
|
// operationTimeUpdateEvent(opreationType);
|
// }
|
// }
|
// }
|
|
// public void UpdateSingleRechargeInfo(HAA50_tagMCActSingleRechargeInfo package)
|
// {
|
// OperationBase operationBase = null;
|
|
// var opreationType = Operation.default28;
|
|
// operationDict.TryGetValue(opreationType, out operationBase);
|
// if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
// {
|
// ForceStopOperation(opreationType);
|
// }
|
// else
|
// {
|
// if (operationBase == null)
|
// {
|
// operationBase = new OperationSingleRecharge();
|
// operationDict.Add(opreationType, operationBase);
|
// }
|
// OperationSingleRecharge operation = operationBase as OperationSingleRecharge;
|
// operation.Reset();
|
// operation.limitLv = package.LimitLV;
|
// operation.startDate = ParseOperationDate(package.StartDate);
|
// operation.endDate = ParseOperationDate(package.EndtDate);
|
// operation.ActNum = package.ActNum;
|
// operation.dayReset = package.IsDayReset == 1;
|
// operation.ParseSingleRecharge(package);
|
// if (operationTimeUpdateEvent != null)
|
// {
|
// operationTimeUpdateEvent(opreationType);
|
// }
|
// }
|
// }
|
|
// public void UpdateHolidayLogin(HAA42_tagMCFeastLoginInfo package)
|
// {
|
// OperationBase operationBase = null;
|
// operationDict.TryGetValue(Operation.HolidayLogin, out operationBase);
|
// if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
// {
|
// ForceStopOperation(Operation.HolidayLogin);
|
// }
|
// else
|
// {
|
// if (operationBase == null)
|
// {
|
// operationBase = new OperationHolidayLogin();
|
// operationDict.Add(Operation.HolidayLogin, operationBase);
|
// }
|
// var operation = operationBase as OperationHolidayLogin;
|
// operation.Reset();
|
// operation.startDate = ParseOperationDate(package.StartDate);
|
// operation.endDate = ParseOperationDate(package.EndtDate);
|
// operation.limitLv = package.LimitLV;
|
// operation.ParsePackage(package);
|
// if (operationTimeUpdateEvent != null)
|
// {
|
// operationTimeUpdateEvent(Operation.HolidayLogin);
|
// }
|
// }
|
// }
|
|
|
|
// public void UpdateMultiRechargePackage(HAA27_tagMCActRechargePrizeInfo package)
|
// {
|
// OperationBase operationBase = null;
|
// operationDict.TryGetValue(Operation.MultiRecharge, out operationBase);
|
// if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
// {
|
// ForceStopOperation(Operation.MultiRecharge);
|
// }
|
// else
|
// {
|
// if (operationBase == null)
|
// {
|
// operationBase = new OperationMultiRecharge();
|
// operationDict.Add(Operation.MultiRecharge, operationBase);
|
// }
|
// OperationMultiRecharge operation = operationBase as OperationMultiRecharge;
|
// operation.Reset();
|
// operation.limitLv = package.LimitLV;
|
// operation.startDate = ParseOperationDate(package.StartDate);
|
// operation.endDate = ParseOperationDate(package.EndtDate);
|
// operation.dayReset = package.IsDayReset == 1;
|
// operation.ParseMultiRecharge(package);
|
// if (operationTimeUpdateEvent != null)
|
// {
|
// operationTimeUpdateEvent(Operation.MultiRecharge);
|
// }
|
// }
|
// }
|
|
// /// <summary>
|
// /// 限时礼包
|
// /// </summary>
|
// /// <param name="package"></param>
|
|
// public void UpdateGiftPackage(HAA12_tagMCFlashGiftbagInfo package)
|
// {
|
// OperationBase operationBase = null;
|
// Operation operationType = Operation.GiftPackage;
|
|
// switch (package.ActNum)
|
// {
|
// case 10:
|
// operationType = Operation.GiftPackage;
|
// break;
|
// case 20:
|
// operationType = Operation.default13;
|
// break;
|
// case 30:
|
// operationType = Operation.HolidayGiftPackage;
|
// break;
|
// }
|
|
// operationDict.TryGetValue(operationType, out operationBase);
|
// if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
// {
|
// ForceStopOperation(operationType);
|
// }
|
// else
|
// {
|
// if (operationBase == null)
|
// {
|
// operationBase = new GiftPackageClass();
|
// operationDict.Add(operationType, operationBase);
|
// }
|
// GiftPackageClass operation = operationBase as GiftPackageClass;
|
// operation.Reset();
|
// operation.limitLv = package.LimitLV;
|
// operation.startDate = ParseOperationDate(package.StartDate);
|
// operation.endDate = ParseOperationDate(package.EndtDate);
|
// operation.dayReset = package.IsDayReset == 1;
|
// operation.inAdvanceMinute = package.AdvanceMinutes;
|
// operation.ActNum = package.ActNum;
|
// for (int i = 0; i < package.ActivityTimeCount; i++)
|
// {
|
// operation.times.Add(ParseOperationTime(package.ActivityTime[i].StartTime,
|
// package.ActivityTime[i].EndtTime));
|
// }
|
// operation.ParsePackage(package);
|
// if (operationTimeUpdateEvent != null)
|
// {
|
// operationTimeUpdateEvent(operationType);
|
// }
|
// }
|
// }
|
|
|
|
|
|
// public void UpdateCrossActLianQiInfo(HAA90_tagMCCrossActLianqiInfo package)
|
// {
|
// OperationBase operationBase = null;
|
// operationDict.TryGetValue(Operation.default51, out operationBase);
|
// if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
// {
|
// ForceStopOperation(Operation.default51);
|
// }
|
// else
|
// {
|
// if (operationBase == null)
|
// {
|
// operationBase = new OperationLianQiCross();
|
// operationDict.Add(Operation.default51, operationBase);
|
// }
|
// OperationLianQiCross operation = operationBase as OperationLianQiCross;
|
// operation.Reset();
|
// operation.m_ServerListStr = UIHelper.GetServers(package.ServerIDRangeInfo);
|
// operation.m_GroupValue1 = package.GroupValue1;
|
// operation.startDate = ParseOperationDate(package.StartDate);
|
// operation.endDate = ParseOperationDate(package.EndtDate);
|
// operation.dayReset = true;
|
// operation.limitLv = package.LimitLV;
|
// operation.ParseJoinTime(package.JoinStartTime, package.JoinEndTime);
|
// operation.ParseCrossActHorsePetTrainInfo(package);
|
// //for (int i = 0; i < package.ActivityTimeCount; i++)
|
// //{
|
// // operation.times.Add(ParseOperationTime(package.ActivityTime[i].StartTime,
|
// // package.ActivityTime[i].EndtTime));
|
// //}
|
// if (operationTimeUpdateEvent != null)
|
// {
|
// operationTimeUpdateEvent(Operation.default51);
|
// }
|
// }
|
// }
|
|
public void UpdateActLunhuidianInfo(HAA88_tagMCActLunhuidianInfo package)
|
{
|
OperationBase operationBase = null;
|
operationDict.TryGetValue(OperationType.TimeRush, out operationBase);
|
if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
{
|
ForceStopOperation(OperationType.TimeRush);
|
}
|
else
|
{
|
if (operationBase == null)
|
{
|
operationBase = new OperationCycleHall();
|
operationDict.Add(OperationType.TimeRush, operationBase);
|
}
|
OperationCycleHall operation = operationBase as OperationCycleHall;
|
operation.Reset();
|
operation.startDate = ParseOperationDate(package.StartDate);
|
operation.endDate = ParseOperationDate(package.EndtDate);
|
operation.resetType = package.ResetType;
|
operation.limitLv = package.LimitLV;
|
operation.ParseCycleHallInfo(package);
|
if (operationTimeUpdateEvent != null)
|
{
|
operationTimeUpdateEvent(OperationType.TimeRush);
|
}
|
}
|
}
|
|
// public void UpdateActYunShiInfo(HAA87_tagMCActYunshiInfo package)
|
// {
|
// Operation operationType = Operation.default48;
|
|
// switch (package.ActNum)
|
// {
|
// case 10:
|
// operationType = Operation.default48;
|
// break;
|
// }
|
// OperationBase operationBase = null;
|
// operationDict.TryGetValue(operationType, out operationBase);
|
// if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
// {
|
// ForceStopOperation(operationType);
|
// }
|
// else
|
// {
|
// if (operationBase == null)
|
// {
|
// operationBase = new OperationYunShi();
|
// operationDict.Add(operationType, operationBase);
|
// }
|
// OperationYunShi operation = operationBase as OperationYunShi;
|
// operation.Reset();
|
// operation.startDate = ParseOperationDate(package.StartDate);
|
// operation.endDate = ParseOperationDate(package.EndtDate);
|
// operation.resetType = package.ResetType;
|
// operation.limitLv = package.LimitLV;
|
// operation.treasureType = package.TreasureType;
|
// if (operationTimeUpdateEvent != null)
|
// {
|
// operationTimeUpdateEvent(operationType);
|
// }
|
// }
|
// }
|
|
|
// public void UpdateLoginAct(HAA69_tagMCActLoginNew package)
|
// {
|
// OperationBase operationBase = null;
|
// Operation operationType = Operation.default29;
|
|
// switch (package.ActNum)
|
// {
|
// case 11:
|
// operationType = Operation.default44;
|
// break;
|
// case 30:
|
// operationType = Operation.default29;
|
// break;
|
// }
|
|
// operationDict.TryGetValue(operationType, out operationBase);
|
// if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
// {
|
// ForceStopOperation(operationType);
|
// }
|
// else
|
// {
|
// if (operationBase == null)
|
// {
|
// operationBase = new OperationLoginAct();
|
// operationDict.Add(operationType, operationBase);
|
// }
|
// var operation = operationBase as OperationLoginAct;
|
// operation.Reset();
|
// operation.startDate = ParseOperationDate(package.StartDate);
|
// operation.endDate = ParseOperationDate(package.EndtDate);
|
// operation.limitLv = package.LimitLV;
|
// operation.ActNum = package.ActNum;
|
// operation.ParsePackage(package);
|
// if (operationTimeUpdateEvent != null)
|
// {
|
// operationTimeUpdateEvent(operationType);
|
// }
|
// }
|
// }
|
|
// public void UpdateMissionAct(HAA71_tagMCActTaskInfo package)
|
// {
|
// OperationBase operationBase = null;
|
|
// var opreationType = Operation.default30;
|
// switch (package.ActNum)
|
// {
|
// case 11:
|
// opreationType = Operation.default45;
|
// break;
|
// case 12:
|
// opreationType = Operation.default49;
|
// break;
|
// case 30:
|
// opreationType = Operation.default30;
|
// break;
|
// }
|
// operationDict.TryGetValue(opreationType, out operationBase);
|
|
// if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
// {
|
// ForceStopOperation(opreationType);
|
// }
|
// else
|
// {
|
// if (operationBase == null)
|
// {
|
// operationBase = new OperationMissionAct();
|
// operationDict.Add(opreationType, operationBase);
|
// }
|
// var operation = operationBase as OperationMissionAct;
|
// operation.Reset();
|
// operation.startDate = ParseOperationDate(package.StartDate);
|
// operation.endDate = ParseOperationDate(package.EndtDate);
|
// operation.limitLv = package.LimitLV;
|
// operation.dayReset = package.IsDayReset == 1;
|
// operation.resetType = package.ResetType;
|
// operation.ActNum = package.ActNum;
|
// operation.ParsePackage(package);
|
// if (operationTimeUpdateEvent != null)
|
// {
|
// operationTimeUpdateEvent(Operation.default30);
|
// }
|
// }
|
// }
|
|
// public void UpdateRechargeGiftAct(HAA74_tagMCActBuyCountGiftInfo package)
|
// {
|
// OperationBase operationBase = null;
|
|
// Operation operationType = Operation.default31;
|
|
// switch (package.ActNum)
|
// {
|
// case 30:
|
// operationType = Operation.default31;
|
// break;
|
// case 10:
|
// operationType = Operation.default35;
|
// break;
|
// case 31:
|
// operationType = Operation.default38;
|
// break;
|
// case 11:
|
// operationType = Operation.default46;
|
// break;
|
// case 12:
|
// operationType = Operation.default50;
|
// break;
|
// case 13:
|
// operationType = Operation.default52;
|
// break;
|
// default:
|
// return;
|
// }
|
// operationDict.TryGetValue(operationType, out operationBase);
|
// if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
// {
|
// ForceStopOperation(operationType);
|
// }
|
// else
|
// {
|
// if (operationBase == null)
|
// {
|
// operationBase = new OperationRechargeGiftAct();
|
// operationDict.Add(operationType, operationBase);
|
// }
|
// var operation = operationBase as OperationRechargeGiftAct;
|
// operation.Reset();
|
// operation.startDate = ParseOperationDate(package.StartDate);
|
// operation.endDate = ParseOperationDate(package.EndtDate);
|
// operation.limitLv = package.LimitLV;
|
// operation.dayReset = package.IsDayReset == 1;
|
// operation.resetType = package.ResetType;
|
// operation.ActNum = package.ActNum;
|
// operation.ParsePackage(package);
|
// if (operationTimeUpdateEvent != null)
|
// {
|
// operationTimeUpdateEvent(operationType);
|
// }
|
// }
|
// }
|
|
// public void UpdateActFamilyCTGAssistInfo(HAA77_tagMCActFamilyCTGAssistInfo package)
|
// {
|
// OperationBase operationBase = null;
|
|
// Operation operationType = Operation.default34;
|
|
// switch (package.ActNum)
|
// {
|
// case 30:
|
// operationType = Operation.default34;
|
// break;
|
// case 32:
|
// operationType = Operation.default54;
|
// break;
|
// default:
|
// return;
|
// }
|
// operationDict.TryGetValue(operationType, out operationBase);
|
// if (string.IsNullOrEmpty(package.StartDate) || string.IsNullOrEmpty(package.EndtDate))
|
// {
|
// ForceStopOperation(operationType);
|
// }
|
// else
|
// {
|
// if (operationBase == null)
|
// {
|
// operationBase = new OperationFamilyRechargeConn();
|
// operationDict.Add(operationType, operationBase);
|
// }
|
// var operation = operationBase as OperationFamilyRechargeConn;
|
// operation.Reset();
|
// operation.startDate = ParseOperationDate(package.StartDate);
|
// operation.endDate = ParseOperationDate(package.EndtDate);
|
// operation.limitLv = package.LimitLV;
|
// operation.dayReset = package.IsDayReset == 1;
|
// operation.ActNum = package.ActNum;
|
// operation.ParseActFamilyCTGAssistInfo(package);
|
// if (operationTimeUpdateEvent != null)
|
// {
|
// operationTimeUpdateEvent(operationType);
|
// }
|
// }
|
// }
|
|
public void ForceStopOperation(OperationType operationType)
|
{
|
if (operationDict.ContainsKey(operationType))
|
{
|
operationDict.Remove(operationType);
|
}
|
if (operationServerCloseEvent != null)
|
{
|
operationServerCloseEvent(operationType);
|
}
|
if (operationEndEvent != null)
|
{
|
operationEndEvent(operationType, 0);
|
operationEndEvent(operationType, 1);
|
}
|
}
|
|
public bool TryGetOperationTime(OperationType type, out OperationBase operation)
|
{
|
return operationDict.TryGetValue(type, out operation);
|
}
|
|
public bool TryGetOperation<T>(OperationType type, out T operation) where T : OperationBase
|
{
|
operation = null;
|
if (operationDict.ContainsKey(type))
|
{
|
operation = operationDict[type] as T;
|
return operation is T;
|
}
|
return false;
|
}
|
|
public bool InOperationTime(OperationType type)
|
{
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
return operation.InTime(TimeUtility.ServerNow);
|
}
|
return false;
|
}
|
|
public bool InOperationTime(OperationType type, DateTime time)
|
{
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
return operation.InTime(time);
|
}
|
return false;
|
}
|
|
public bool InOperationJoinTime(OperationType type, DateTime time)
|
{
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
return operation.InJoinTime(time);
|
}
|
return false;
|
}
|
|
public bool InOperationDay(OperationType type)
|
{
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
return operation.InDay(TimeUtility.ServerNow);
|
}
|
return false;
|
}
|
|
public int GetOperationSurplusTime(OperationType type)
|
{
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
return operation.GetSurplusTime(TimeUtility.ServerNow);
|
}
|
return 0;
|
}
|
|
public bool InOperationAdvance(OperationType type)
|
{
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
return operation.InAdvanceTime(TimeUtility.ServerNow);
|
}
|
return false;
|
}
|
|
public int GetOperationSecondsBeforeStart(OperationType type)
|
{
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
return operation.GetSecondsBeforeStart(TimeUtility.ServerNow);
|
}
|
return 0;
|
}
|
|
public bool SatisfyOpenCondition(OperationType type)
|
{
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
return operation.SatisfyOpenCondition() && InOperationTime(type);
|
}
|
return false;
|
}
|
|
public bool SatisfyOpenCondition(OperationType type, DateTime time)
|
{
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
return operation.SatisfyOpenCondition() && InOperationTime(type, time);
|
}
|
return false;
|
}
|
|
//活动开启中,有参与进行时间段
|
public bool SatisfyJoinCondition(OperationType type, DateTime time)
|
{
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
return InOperationJoinTime(type, time);
|
}
|
return false;
|
}
|
|
public bool IsPrepareTime(OperationType type, DateTime time)
|
{
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
return operation.IsPrepareTime(time);
|
}
|
return false;
|
}
|
|
public bool SatisfyAdvanceCondition(OperationType type)
|
{
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
return operation.SatisfyOpenCondition() && InOperationAdvance(type);
|
}
|
return false;
|
}
|
|
public void ProcessConditionError(OperationType type)
|
{
|
if (SatisfyOpenCondition(type))
|
{
|
return;
|
}
|
OperationBase operation;
|
if (TryGetOperationTime(type, out operation))
|
{
|
if (!InOperationTime(type))
|
{
|
SysNotifyMgr.Instance.ShowTip("InOperationTimeError");
|
}
|
else if (!operation.SatisfyOpenCondition())
|
{
|
SysNotifyMgr.Instance.ShowTip(StringUtility.Concat("OperationLevelLimit_", type.ToString()), operation.limitLv);
|
}
|
}
|
else
|
{
|
SysNotifyMgr.Instance.ShowTip("InOperationTimeError");
|
}
|
}
|
|
public OperationDate ParseOperationDate(string date)
|
{
|
string[] dateArray = date.Split('-');
|
if (dateArray != null && dateArray.Length == 3)
|
{
|
return new OperationDate()
|
{
|
year = int.Parse(dateArray[0].Trim()),
|
month = int.Parse(dateArray[1].Trim()),
|
day = int.Parse(dateArray[2].Trim())
|
};
|
}
|
//else if (dateArray != null && dateArray.Length == 1)
|
//{
|
// var time = TimeUtility.openServerTime;
|
// if (time.Equals(default(DateTime)))
|
// {
|
// Debug.Log("服务期开服时间下发顺序有问题");
|
// }
|
// var days = 0;
|
// int.TryParse(date, out days);
|
// days = Mathf.Max(1, days);
|
// time = time.AddDays(days - 1);
|
// return new OperationDate()
|
// {
|
// year = time.Year,
|
// month = time.Month,
|
// day = time.Day,
|
// };
|
//}
|
return default(OperationDate);
|
}
|
|
private OperationTime ParseOperationTime(string startTime, string endTime)
|
{
|
var startTimeArray = startTime.Split(':');
|
var endTimeArray = endTime.Split(':');
|
if (startTimeArray != null && startTimeArray.Length == 2
|
&& endTimeArray != null && endTimeArray.Length == 2)
|
{
|
return new OperationTime()
|
{
|
startHour = int.Parse(startTimeArray[0].Trim()),
|
startMinute = int.Parse(startTimeArray[1].Trim()),
|
endHour = int.Parse(endTimeArray[0].Trim()),
|
endMinute = int.Parse(endTimeArray[1].Trim()),
|
};
|
}
|
return default(OperationTime);
|
}
|
}
|
|
public struct OperationDate
|
{
|
public int year;
|
public int month;
|
public int day;
|
|
public static bool operator ==(OperationDate x, OperationDate y)
|
{
|
return x.year == y.year && x.month == y.month && x.day == y.day;
|
}
|
|
public static bool operator !=(OperationDate x, OperationDate y)
|
{
|
return !(x == y);
|
}
|
|
public static bool operator >(OperationDate x, OperationDate y)
|
{
|
if (x.year > y.year)
|
{
|
return true;
|
}
|
if (x.year == y.year)
|
{
|
if (x.month > y.month)
|
{
|
return true;
|
}
|
if (x.month == y.month)
|
{
|
return x.day > y.day;
|
}
|
}
|
return false;
|
}
|
|
public static bool operator <(OperationDate x, OperationDate y)
|
{
|
return !(x > y) && x != y;
|
}
|
|
public static bool operator >=(OperationDate x, OperationDate y)
|
{
|
return x > y || x == y;
|
}
|
|
public static bool operator <=(OperationDate x, OperationDate y)
|
{
|
return x < y || x == y;
|
}
|
|
public DateTime AddSeconds(int _seconds)
|
{
|
DateTime d = new DateTime(year, month, day);
|
return d.AddTicks(_seconds * TimeSpan.TicksPerSecond);
|
}
|
|
public OperationDate AddDays(int _days)
|
{
|
DateTime d = new DateTime(year, month, day);
|
d = d.AddTicks(_days * TimeSpan.TicksPerDay);
|
return new OperationDate()
|
{
|
year = d.Year,
|
month = d.Month,
|
day = d.Day,
|
};
|
}
|
|
public string ToDisplay(bool showYear = true)
|
{
|
if (showYear)
|
{
|
return $"{year}/{month}/{day}";
|
}
|
return $"{month}/{day}";
|
|
|
//var yearString = StringUtility.Concat(year, Language.Get("Year"));
|
//return StringUtility.Concat(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)(_x - _y).TotalDays;
|
}
|
}
|
|
public struct OperationTime
|
{
|
public int startHour;
|
public int startMinute;
|
|
public int endHour;
|
public int endMinute;
|
|
public bool InTime(DateTime time)
|
{
|
return CompareTime(time) == 0;
|
}
|
|
public int CompareTime(DateTime time)
|
{
|
if (time.Hour < startHour || (time.Hour == startHour && time.Minute < startMinute))
|
{
|
return -1;
|
}
|
if (time.Hour > endHour || (time.Hour == endHour && time.Minute >= endMinute))
|
{
|
return 1;
|
}
|
return 0;
|
}
|
|
public override string ToString()
|
{
|
return StringUtility.Concat(startHour.ToString("D2"), ":", startMinute.ToString("D2"),
|
"-", endHour.ToString("D2"), ":", endMinute.ToString("D2"));
|
}
|
|
public static int operator -(OperationTime x, DateTime y)
|
{
|
DateTime d = new DateTime(y.Year, y.Month, y.Day, x.endHour, x.endMinute, 0);
|
return Mathf.Max(0, (int)(d - y).TotalSeconds);
|
}
|
}
|
|
public enum OperationType
|
{
|
CustomizedGift, //自选礼包
|
TimeRush, //日期型活动 - 轮回殿
|
max,
|
}
|