| | |
| | | public class FairyLeagueModel : Model, IAfterPlayerDataInitialize, IBeforePlayerDataInitialize, IPlayerLoginOk
|
| | | {
|
| | | public event Action OnRefreshFairyLeagueEvent;
|
| | | private FairyLeagueStage m_FairyLeagueStage = FairyLeagueStage.Prepare;
|
| | |
|
| | | public FairyLeagueWeekTime currentWeekTime
|
| | | {
|
| | | get { return fairyLeagueWeekTime; }
|
| | | }
|
| | |
|
| | | public FairyLeagueWeekTime nextWeekTime
|
| | | {
|
| | | get { return fairyLeagueWeekTime; }
|
| | | }
|
| | |
|
| | | FairyLeagueStage cacheLeagueStage = FairyLeagueStage.Prepare;
|
| | |
|
| | | public FairyLeagueStage fairyLeagueStage
|
| | | {
|
| | | get
|
| | | {
|
| | | if (StepRing())
|
| | | return currentWeekTime.fairyLeagueStage;
|
| | | }
|
| | | }
|
| | |
|
| | | public int fairyLeagueSession
|
| | | {
|
| | | return FairyLeagueStage.Over;
|
| | | }
|
| | | return m_FairyLeagueStage;
|
| | | get
|
| | | {
|
| | | return currentWeekTime.currentSession;
|
| | | }
|
| | | }
|
| | |
|
| | | public int fairyLeagueRing
|
| | | {
|
| | | get
|
| | | {
|
| | | if (IsNextWeek)
|
| | | {
|
| | | return 0;
|
| | | }
|
| | | var _dayOfWeek = TimeUtility.ServerNow.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)TimeUtility.ServerNow.DayOfWeek;
|
| | | if (_dayOfWeek < groupTimes[1].dayOfWeek || _dayOfWeek > resultTimes[1].dayOfWeek)
|
| | | {
|
| | | return 0;
|
| | | }
|
| | | else if (_dayOfWeek == groupTimes[1].dayOfWeek)
|
| | | {
|
| | | if (TimeUtility.ServerNow.Hour < groupTimes[1].startHour)
|
| | | {
|
| | | return 0;
|
| | | }
|
| | | else if (TimeUtility.ServerNow.Hour == groupTimes[1].startHour &&
|
| | | TimeUtility.ServerNow.Minute < groupTimes[1].startMinute)
|
| | | {
|
| | | return 0;
|
| | | return currentWeekTime.currentRing;
|
| | | }
|
| | | }
|
| | | return 1;
|
| | | }
|
| | | }
|
| | |
|
| | | public int OpenServerWeek
|
| | | {
|
| | | get;
|
| | | private set;
|
| | | }
|
| | | public int ringCnt
|
| | | {
|
| | | get;
|
| | | private set;
|
| | | }
|
| | |
|
| | | public bool IsNextWeek
|
| | | {
|
| | | get
|
| | | {
|
| | | if (TimeUtility.OpenWeekCnt >= OpenServerWeek)
|
| | | {
|
| | | var _dayOfWeek = TimeUtility.ServerNow.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)TimeUtility.ServerNow.DayOfWeek;
|
| | | if (_dayOfWeek > resultTimes[1].dayOfWeek && _dayOfWeek <= 7)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | | else
|
| | | {
|
| | | return true;
|
| | | return currentWeekTime.IsNextWeek;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | bool serverInited = false;
|
| | |
|
| | | FairyModel fairyModel { get { return ModelCenter.Instance.GetModel<FairyModel>(); } }
|
| | |
|
| | |
| | | {
|
| | | ParseConfig();
|
| | | m_JoinFairyLeagueRedpoint = new Redpoint(10704, 1070401);
|
| | | dataRequestDict.Add(FairyLeagueStage.Grouping, false);
|
| | | dataRequestDict.Add(FairyLeagueStage.Fight, false);
|
| | | dataRequestDict.Add(FairyLeagueStage.Over, false);
|
| | | TimeUtility.OnServerOpenDayRefresh += OnServerOpenDayRefresh;
|
| | | DTCA003_tagUniversalGameRecInfo.onGetUniversalGameInfo += OnGetUniversalGameInfo;
|
| | | PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent;
|
| | | StageManager.Instance.onStageLoadFinish += OnStageLoadFinish;
|
| | | TimeMgr.Instance.OnMinuteEvent += MinuteEvent;
|
| | | TimeMgr.Instance.OnDayEvent += DayEvent;
|
| | | fairyLeagueHelp = new FairyLeagueHelp();
|
| | | }
|
| | |
|
| | | public override void UnInit()
|
| | | {
|
| | | DTCA003_tagUniversalGameRecInfo.onGetUniversalGameInfo -= OnGetUniversalGameInfo;
|
| | | TimeMgr.Instance.OnMinuteEvent -= MinuteEvent;
|
| | | TimeMgr.Instance.OnDayEvent -= DayEvent;
|
| | | }
|
| | |
|
| | | public void OnBeforePlayerDataInitialize()
|
| | | {
|
| | | ClearFairyWarHelp();
|
| | | frontFairyList.Clear();
|
| | | fairyLeagueFairyId = 0;
|
| | | fairyLeagueFairyName = string.Empty;
|
| | | serverInited = false;
|
| | | }
|
| | |
|
| | | public void OnAfterPlayerDataInitialize()
|
| | | {
|
| | | for (int i = 0; i < fairyStages.Length; i++)
|
| | | {
|
| | | dataRequestDict[fairyStages[i]] = false;
|
| | | }
|
| | | TimeMgr.Instance.OnSyntonyEvent -= OnSyntonyEvent;
|
| | | TimeMgr.Instance.OnSyntonyEvent += OnSyntonyEvent;
|
| | | }
|
| | |
|
| | | public void OnPlayerLoginOk()
|
| | | {
|
| | | CheckFairyLeagueStage();
|
| | | ResetFairyLeagueTime();
|
| | | cacheLeagueStage = fairyLeagueStage;
|
| | | CheckFairyLeagueData();
|
| | | UpdateRedpoint();
|
| | | serverInited = true;
|
| | | }
|
| | |
|
| | | private void OnServerOpenDayRefresh()
|
| | | {
|
| | | CheckFairyLeagueStage();
|
| | | ResetFairyLeagueTime();
|
| | | }
|
| | |
|
| | | private void DayEvent()
|
| | | {
|
| | | ResetFairyLeagueTime();
|
| | | }
|
| | |
|
| | | private void MinuteEvent()
|
| | | {
|
| | | if (!(StageManager.Instance.CurrentStage is DungeonStage) || !serverInited)
|
| | | {
|
| | | return;
|
| | | }
|
| | | if (cacheLeagueStage != fairyLeagueStage)
|
| | | {
|
| | | cacheLeagueStage = fairyLeagueStage;
|
| | | if (cacheLeagueStage != FairyLeagueStage.Prepare)
|
| | | {
|
| | | CheckFairyLeagueData();
|
| | | }
|
| | | if (OnRefreshFairyLeagueEvent != null)
|
| | | {
|
| | | OnRefreshFairyLeagueEvent();
|
| | | }
|
| | | DebugEx.LogFormat("进入{0}阶段", fairyLeagueStage);
|
| | | }
|
| | | }
|
| | |
|
| | | void ResetFairyLeagueTime()
|
| | | {
|
| | | if (OnRefreshFairyLeagueEvent != null)
|
| | | {
|
| | | OnRefreshFairyLeagueEvent();
|
| | | }
|
| | | }
|
| | |
|
| | | private void PlayerDataRefreshInfoEvent(PlayerDataRefresh _type)
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | private void OnSyntonyEvent(TimeMgr.SyntonyType type)
|
| | | {
|
| | | if (type == TimeMgr.SyntonyType.FairyLeaugeStage)
|
| | | {
|
| | | CheckFairyLeagueStage();
|
| | | CheckFairyLeagueData();
|
| | | if (OnRefreshFairyLeagueEvent != null)
|
| | | {
|
| | | OnRefreshFairyLeagueEvent();
|
| | | }
|
| | | UpdateRedpoint();
|
| | | }
|
| | | }
|
| | | #region 配置
|
| | | public const int FAIRY_LEAGUE_DUNGEON = 31220;
|
| | | public const int FAIRY_LEAGUE_BATTLE = 68;
|
| | | public readonly int[] groupRingStates = new int[] { 11, 21 };
|
| | | public readonly int[] fightRingStates = new int[] { 12, 22 };
|
| | | public readonly int overRingStates = 99;
|
| | | public WeekTime[] groupTimes { get; private set; }
|
| | | public WeekTime[] fightTimes { get; private set; }
|
| | | public WeekTime[] resultTimes { get; private set; }
|
| | | public WeekTime overTime { get; private set; }
|
| | | public readonly WeekTime skipWeekTime = new WeekTime(1, 0, 0, 0, 0);
|
| | | public List<WeekTime> fairyLeagueWeekTimes = new List<WeekTime>();
|
| | | private string[] guideImgKeys;
|
| | | public string[] GuideImgKeys
|
| | | {
|
| | |
| | | return guideImgKeys;
|
| | | }
|
| | | }
|
| | | private readonly FairyLeagueStage[] fairyStages = new FairyLeagueStage[]
|
| | | {
|
| | | FairyLeagueStage.Grouping,
|
| | | FairyLeagueStage.Fight, FairyLeagueStage.Over
|
| | | };
|
| | |
|
| | | public int fairyWarResUpperLimit
|
| | | {
|
| | | get;
|
| | |
| | | public Dictionary<int, List<AwardItem>> finalWarAwardDict = new Dictionary<int, List<AwardItem>>();
|
| | | public Dictionary<int, List<AwardItem>> finalWarChampionAwardDict = new Dictionary<int, List<AwardItem>>();
|
| | | private Dictionary<int, float> crystalRateDict = new Dictionary<int, float>();
|
| | | readonly List<int> fairyLeagueStateValues = new List<int>() { 11, 12, 13, 21, 22, 23 };
|
| | | FairyLeagueWeekTime fairyLeagueWeekTime = new FairyLeagueWeekTime();
|
| | | private void ParseConfig()
|
| | | {
|
| | | FuncConfigConfig cfg = Config.Instance.Get<FuncConfigConfig>("FamilyMatchGuide");
|
| | |
| | | {
|
| | | guideImgKeys = ConfigParse.GetMultipleStr(cfg.Numerical1);
|
| | | }
|
| | | ringCnt = groupRingStates.Length;
|
| | | groupTimes = new WeekTime[groupRingStates.Length];
|
| | | DungeonStateTimeConfig stateCfg = null;
|
| | | for (int i = 0; i < groupRingStates.Length; i++)
|
| | | var configs = Config.Instance.GetAllValues<DungeonStateTimeConfig>();
|
| | | for (int i = 0; i < configs.Count; i++)
|
| | | {
|
| | | stateCfg = DungeonStateTimeConfig.DungeonStateTime(FAIRY_LEAGUE_DUNGEON, groupRingStates[i]);
|
| | | if (stateCfg != null)
|
| | | if (fairyLeagueStateValues.Contains(configs[i].StateValue))
|
| | | {
|
| | | OpenServerWeek = stateCfg.OpenServerWeek;
|
| | | groupTimes[i] = new WeekTime(stateCfg.StartWeekday, stateCfg.StartHour,
|
| | | stateCfg.StartMinute, stateCfg.EndHour, stateCfg.EndMinute);
|
| | | fairyLeagueWeekTimes.Add(groupTimes[i]);
|
| | | fairyLeagueWeekTime.AddStage(configs[i]);
|
| | | }
|
| | | }
|
| | | fightTimes = new WeekTime[fightRingStates.Length];
|
| | | resultTimes = new WeekTime[fightRingStates.Length];
|
| | | for (int i = 0; i < fightRingStates.Length; i++)
|
| | | {
|
| | | stateCfg = DungeonStateTimeConfig.DungeonStateTime(FAIRY_LEAGUE_DUNGEON, fightRingStates[i]);
|
| | | if (stateCfg != null)
|
| | | {
|
| | | fightTimes[i] = new WeekTime(stateCfg.StartWeekday, stateCfg.StartHour,
|
| | | stateCfg.StartMinute, stateCfg.EndHour, stateCfg.EndMinute);
|
| | | fairyLeagueWeekTimes.Add(fightTimes[i]);
|
| | | resultTimes[i] = new WeekTime(stateCfg.StartWeekday, stateCfg.EndHour, stateCfg.EndMinute, 0, 0);
|
| | | fairyLeagueWeekTimes.Add(resultTimes[i]);
|
| | | }
|
| | | }
|
| | | stateCfg = DungeonStateTimeConfig.DungeonStateTime(FAIRY_LEAGUE_DUNGEON, overRingStates);
|
| | | overTime = new WeekTime(stateCfg.StartWeekday, stateCfg.StartHour,
|
| | | stateCfg.StartMinute, stateCfg.EndHour, stateCfg.EndMinute);
|
| | | fairyLeagueWeekTimes.Add(overTime);
|
| | | fairyLeagueWeekTimes.Sort(CompareTime);
|
| | |
|
| | | cfg = Config.Instance.Get<FuncConfigConfig>("FamilyMatchResourcePoint");
|
| | | if (cfg != null)
|
| | | {
|
| | |
| | | return crystalRateDict.TryGetValue(_npcId, out _rate);
|
| | | }
|
| | | #endregion
|
| | | public void CheckFairyLeagueStage()
|
| | | {
|
| | | var _dayOfWeek = TimeUtility.ServerNow.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)TimeUtility.ServerNow.DayOfWeek;
|
| | | if (IsNextWeek)
|
| | | {
|
| | | m_FairyLeagueStage = FairyLeagueStage.Prepare;
|
| | | return;
|
| | | }
|
| | | for (int i = 0; i < fairyLeagueWeekTimes.Count; i++)
|
| | | {
|
| | | var _weekTime = fairyLeagueWeekTimes[i];
|
| | | if (_dayOfWeek < _weekTime.dayOfWeek)
|
| | | {
|
| | | m_FairyLeagueStage = GetFairyLeagueStage(i);
|
| | | return;
|
| | | }
|
| | | if (_dayOfWeek == _weekTime.dayOfWeek)
|
| | | {
|
| | | if (TimeUtility.Hour < _weekTime.startHour)
|
| | | {
|
| | | m_FairyLeagueStage = GetFairyLeagueStage(i);
|
| | | return;
|
| | | }
|
| | | if (TimeUtility.Hour == _weekTime.startHour &&
|
| | | TimeUtility.Minute < _weekTime.startMinute)
|
| | | {
|
| | | m_FairyLeagueStage = GetFairyLeagueStage(i);
|
| | | return;
|
| | | }
|
| | | }
|
| | | }
|
| | | var _nowTime = new WeekTime(_dayOfWeek, TimeUtility.Hour, TimeUtility.Minute, 0, 0, TimeUtility.Second);
|
| | | TimeMgr.Instance.Register(TimeMgr.SyntonyType.FairyLeaugeStage,
|
| | | (float)(skipWeekTime - _nowTime).TotalSeconds);
|
| | | m_FairyLeagueStage = FairyLeagueStage.Prepare;
|
| | | }
|
| | | private FairyLeagueStage GetFairyLeagueStage(int _index)
|
| | | {
|
| | | var _dayOfWeek = TimeUtility.ServerNow.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)TimeUtility.ServerNow.DayOfWeek;
|
| | | var _nowTime = new WeekTime(_dayOfWeek, TimeUtility.Hour, TimeUtility.Minute, 0, 0, TimeUtility.Second);
|
| | | TimeMgr.Instance.Register(TimeMgr.SyntonyType.FairyLeaugeStage,
|
| | | (float)(fairyLeagueWeekTimes[_index] - _nowTime).TotalSeconds);
|
| | | switch (_index)
|
| | | {
|
| | | case 0:
|
| | | return FairyLeagueStage.Prepare;
|
| | | case 1:
|
| | | case 4:
|
| | | return FairyLeagueStage.Grouping;
|
| | | case 2:
|
| | | case 5:
|
| | | return FairyLeagueStage.Fight;
|
| | | case 3:
|
| | | case 6:
|
| | | return FairyLeagueStage.Over;
|
| | | }
|
| | | return FairyLeagueStage.Prepare;
|
| | | }
|
| | | private int CompareTime(WeekTime x, WeekTime y)
|
| | | {
|
| | | if (x.dayOfWeek.CompareTo(y.dayOfWeek) != 0)
|
| | | {
|
| | | return x.dayOfWeek.CompareTo(y.dayOfWeek);
|
| | | }
|
| | | if (x.startHour.CompareTo(y.startHour) != 0)
|
| | | {
|
| | | return x.startHour.CompareTo(y.startHour);
|
| | | }
|
| | | return x.startMinute.CompareTo(y.startMinute);
|
| | | }
|
| | |
|
| | | #region 仙盟联赛副本
|
| | | public int[] fairyLeagueCrystals
|
| | | {
|
| | |
| | |
|
| | | public bool BattleChampion()
|
| | | {
|
| | | var _ring = fairyLeagueRing;
|
| | | if (_ring == 0 &&
|
| | | fairyLeagueBattleDict.ContainsKey(_ring)
|
| | | && fairyLeagueBattleDict[_ring].ContainsKey(5))
|
| | | var _session = fairyLeagueSession;
|
| | | if (_session == 0 &&
|
| | | fairyLeagueBattleDict.ContainsKey(_session)
|
| | | && fairyLeagueBattleDict[_session].ContainsKey(5))
|
| | | {
|
| | | var _list = fairyLeagueBattleDict[_ring][5];
|
| | | var _list = fairyLeagueBattleDict[_session][5];
|
| | | return _list.Count == 1;
|
| | | }
|
| | | return false;
|
| | |
| | | onFairyLeagueBattleEvent();
|
| | | }
|
| | | UpdateRedpoint();
|
| | | for (int i = 0; i < fairyStages.Length; i++)
|
| | | {
|
| | | dataRequestDict[fairyStages[i]] = fairyStages[i] == fairyLeagueStage ? true : false;
|
| | | }
|
| | | }
|
| | | }
|
| | | public bool SelfFairyInBattle(out int _error)
|
| | | {
|
| | | _error = 3;
|
| | | var _ring = fairyLeagueRing;
|
| | | var _session = fairyLeagueSession;
|
| | | var _fairyId = PlayerDatas.Instance.fairyData.fairy.FamilyID;
|
| | | if (!fairyLeagueBattleDict.ContainsKey(_ring))
|
| | | if (!fairyLeagueBattleDict.ContainsKey(_session))
|
| | | {
|
| | | return false;
|
| | | }
|
| | | var _dict = fairyLeagueBattleDict[_ring];
|
| | | var _dict = fairyLeagueBattleDict[_session];
|
| | | foreach (var _grade in _dict.Keys)
|
| | | {
|
| | | if (_dict[_grade] == null)
|
| | |
| | | SysNotifyMgr.Instance.ShowTip("LeagueCannotGo4");
|
| | | break;
|
| | | case 5:
|
| | | var _ring = fairyLeagueRing;
|
| | | _ring = fairyLeagueStage == FairyLeagueStage.Fight || fairyLeagueStage == FairyLeagueStage.Over ? 1 - _ring : _ring;
|
| | | if (_ring == 1)
|
| | | var _session = fairyLeagueSession;
|
| | | var isNextWeek = IsNextWeek;
|
| | | FairyLeagueWeekTime.Session session;
|
| | | var weekTime = isNextWeek ? nextWeekTime : currentWeekTime;
|
| | | weekTime.TryGetSession(fairyLeagueRing, 1 - _session, out session);
|
| | | var fightStage = session.stages.Find((x) =>
|
| | | {
|
| | | var _param = StringUtility.Contact(Language.Get(StringUtility.Contact("Weekday", groupTimes[_ring].dayOfWeek)),
|
| | | fightTimes[1].startHour.ToString("D2"), ":", fightTimes[1].startMinute.ToString("D2"));
|
| | | return x.stage == FairyLeagueStage.Fight;
|
| | | });
|
| | | if (_session == 0)
|
| | | {
|
| | | var _param = StringUtility.Contact(Language.Get(StringUtility.Contact("Weekday", weekTime.GetDayOfWeek(fairyLeagueRing))),
|
| | | fightStage.startHour.ToString("D2"), ":", fightStage.startMinute.ToString("D2"));
|
| | | SysNotifyMgr.Instance.ShowTip("LeagueCannotGo1", _param);
|
| | | }
|
| | | else
|
| | | {
|
| | | var _param = StringUtility.Contact(Language.Get("Next"), Language.Get(StringUtility.Contact("Weekday", groupTimes[_ring].dayOfWeek)),
|
| | | fightTimes[0].startHour.ToString("D2"), ":", fightTimes[0].startMinute.ToString("D2"));
|
| | | var _param = StringUtility.Contact(isNextWeek ? Language.Get("Next") : Language.Get("ThisTime"),
|
| | | Language.Get(StringUtility.Contact("Weekday", weekTime.GetDayOfWeek(fairyLeagueRing))),
|
| | | fightStage.startHour.ToString("D2"), ":", fightStage.startMinute.ToString("D2"));
|
| | | SysNotifyMgr.Instance.ShowTip("LeagueCannotGo2", _param);
|
| | | }
|
| | | break;
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | private Dictionary<FairyLeagueStage, bool> dataRequestDict = new Dictionary<FairyLeagueStage, bool>();
|
| | | public void CheckFairyLeagueData()
|
| | | {
|
| | | //if (dataRequestDict.ContainsKey(fairyLeagueStage) && !dataRequestDict[fairyLeagueStage])
|
| | | //{
|
| | | CA001_tagViewUniversalGameRec _pak = new CA001_tagViewUniversalGameRec();
|
| | | _pak.ViewType = (byte)FAIRY_LEAGUE_BATTLE;
|
| | | GameNetSystem.Instance.SendInfo(_pak);
|
| | | //}
|
| | | }
|
| | |
|
| | | public List<FairyLeagueBattleData> GetFairyLeague(int _ring, int _grade)
|
| | | {
|
| | | Dictionary<int, List<FairyLeagueBattleData>> dic = null;
|
| | |
| | |
|
| | | public FairyLeagueBattleData GetSelfBattleInfo()
|
| | | {
|
| | | var _ring = fairyLeagueRing;
|
| | | var _session = fairyLeagueSession;
|
| | | var _fairyId = PlayerDatas.Instance.fairyData.fairy.FamilyID;
|
| | | if (!fairyLeagueBattleDict.ContainsKey(_ring))
|
| | | if (!fairyLeagueBattleDict.ContainsKey(_session))
|
| | | {
|
| | | return null;
|
| | | }
|
| | | var _dict = fairyLeagueBattleDict[_ring];
|
| | | var _dict = fairyLeagueBattleDict[_session];
|
| | | foreach (var _grade in _dict.Keys)
|
| | | {
|
| | | if (_dict[_grade] == null)
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | public bool StepRing(int _grade = 5)
|
| | | public bool StepSession(int _grade = 5)
|
| | | {
|
| | | if (fairyLeagueRing == 1)
|
| | | if (fairyLeagueSession == 1)
|
| | | {
|
| | | if (!fairyLeagueBattleDict.ContainsKey(1))
|
| | | {
|
| | |
| | | }
|
| | | #endregion
|
| | | }
|
| | | public struct WeekTime
|
| | | {
|
| | | public int dayOfWeek { get; private set; }
|
| | | public int startHour { get; private set; }
|
| | | public int startMinute { get; private set; }
|
| | | public int startSeconds { get; private set; }
|
| | | public int endHour { get; private set; }
|
| | | public int endMinute { get; private set; }
|
| | |
|
| | | public WeekTime(int _weekDay, int _startHour, int _startMinute, int _endHour, int _endMinute, int _startSeconds = 0)
|
| | | public class FairyLeagueWeekTime
|
| | | {
|
| | | dayOfWeek = _weekDay;
|
| | | startHour = _startHour;
|
| | | startMinute = _startMinute;
|
| | | startSeconds = _startSeconds;
|
| | | endHour = _endHour;
|
| | | endMinute = _endMinute;
|
| | | }
|
| | | public static TimeSpan operator -(WeekTime y, WeekTime x)
|
| | | {
|
| | | var _totalSeconds = 0;
|
| | | int i = x.dayOfWeek;
|
| | | for (i = x.dayOfWeek; i != y.dayOfWeek; i = i == 7 ? 1 : i + 1)
|
| | | {
|
| | | if (i == x.dayOfWeek)
|
| | | {
|
| | | _totalSeconds += (23 - x.startHour) * 3600 + (59 - x.startMinute) * 60 + 60 - x.startSeconds;
|
| | | }
|
| | | else
|
| | | {
|
| | | _totalSeconds += 24 * 3600;
|
| | | }
|
| | | }
|
| | | if (i == y.dayOfWeek)
|
| | | {
|
| | | if (x.dayOfWeek == i)
|
| | | {
|
| | | var _timeSpany = new TimeSpan(y.startHour, y.startMinute, y.startSeconds);
|
| | | var _timeSpanx = new TimeSpan(x.startHour, x.startMinute, x.startSeconds);
|
| | | _totalSeconds += (int)(_timeSpany.TotalSeconds - _timeSpanx.TotalSeconds);
|
| | | }
|
| | | else
|
| | | {
|
| | | _totalSeconds += y.startHour * 3600;
|
| | | }
|
| | | }
|
| | | return new TimeSpan(_totalSeconds * TimeSpan.TicksPerSecond);
|
| | | }
|
| | | public List<Ring> rings = new List<Ring>();
|
| | |
|
| | | private static WeekTime s_Now = new WeekTime();
|
| | | public static WeekTime Now
|
| | | public bool IsNextWeek
|
| | | {
|
| | | get
|
| | | {
|
| | | var _dayOfWeek = TimeUtility.ServerNow.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)TimeUtility.ServerNow.DayOfWeek;
|
| | | s_Now.dayOfWeek = _dayOfWeek;
|
| | | s_Now.startHour = TimeUtility.Hour;
|
| | | s_Now.startMinute = TimeUtility.Minute;
|
| | | s_Now.startSeconds = TimeUtility.Second;
|
| | | return s_Now;
|
| | | return rings.Count == 0 || rings[rings.Count - 1].IsOver(TimeUtility.ServerNow);
|
| | | }
|
| | | }
|
| | |
|
| | | public FairyLeagueStage fairyLeagueStage
|
| | | {
|
| | | get
|
| | | {
|
| | | if (IsNextWeek)
|
| | | {
|
| | | return FairyLeagueStage.Prepare;
|
| | | }
|
| | | Ring ring;
|
| | | if (TryGetCurrentRing(out ring))
|
| | | {
|
| | | Session session;
|
| | | if (ring.TryGetSession(TimeUtility.ServerNow, out session))
|
| | | {
|
| | | Stage stage;
|
| | | if (session.TryGetStage(TimeUtility.ServerNow, out stage))
|
| | | {
|
| | | return stage.stage;
|
| | | }
|
| | | }
|
| | | }
|
| | | return FairyLeagueStage.Prepare;
|
| | | }
|
| | | }
|
| | |
|
| | | public int currentRing
|
| | | {
|
| | | get
|
| | | {
|
| | | var ring = 0;
|
| | | for (int i = 0; i < rings.Count; i++)
|
| | | {
|
| | | if (rings[i].InRing(TimeUtility.ServerNow))
|
| | | {
|
| | | return i;
|
| | | }
|
| | | if (rings[i].IsOver(TimeUtility.ServerNow))
|
| | | {
|
| | | ring++;
|
| | | }
|
| | | }
|
| | | return Mathf.Min(ring, rings.Count - 1);
|
| | | }
|
| | | }
|
| | |
|
| | | public int GetDayOfWeek(int _index)
|
| | | {
|
| | | if (_index >= 0 && _index < rings.Count)
|
| | | {
|
| | | return rings[_index].dayOfWeek;
|
| | | }
|
| | | return 0;
|
| | | }
|
| | |
|
| | | public int currentSession
|
| | | {
|
| | | get
|
| | | {
|
| | | Ring ring;
|
| | | if (TryGetCurrentRing(out ring))
|
| | | {
|
| | | return ring.currentSession;
|
| | | }
|
| | | return 0;
|
| | | }
|
| | | }
|
| | |
|
| | | public void AddStage(DungeonStateTimeConfig config)
|
| | | {
|
| | | var ring = rings.Find((x) =>
|
| | | {
|
| | | return x.dayOfWeek == config.StartWeekday;
|
| | | });
|
| | | if (ring == null)
|
| | | {
|
| | | ring = new Ring();
|
| | | rings.Add(ring);
|
| | | ring.dayOfWeek = config.StartWeekday;
|
| | | }
|
| | | ring.ParseConfig(config);
|
| | | }
|
| | |
|
| | | public void Sort()
|
| | | {
|
| | | rings.Sort((Ring x, Ring y) =>
|
| | | {
|
| | | return x.dayOfWeek.CompareTo(y.dayOfWeek);
|
| | | });
|
| | | for (int i = 0; i < rings.Count; i++)
|
| | | {
|
| | | rings[i].Sort();
|
| | | }
|
| | | }
|
| | |
|
| | | public bool TryGetCurrentRing(out Ring ring)
|
| | | {
|
| | | ring = null;
|
| | | for (int i = 0; i < rings.Count; i++)
|
| | | {
|
| | | if (rings[i].InRing(TimeUtility.ServerNow))
|
| | | {
|
| | | ring = rings[i];
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | public bool TryGetSession(int _ring, int _session, out Session session)
|
| | | {
|
| | | session = null;
|
| | | if (_ring >= 0 && _ring < rings.Count)
|
| | | {
|
| | | if (_session >= 0 && _session < rings[_ring].sessions.Count)
|
| | | {
|
| | | session = rings[_ring].sessions[_session];
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | public class Ring
|
| | | {
|
| | | public List<Session> sessions = new List<Session>();
|
| | |
|
| | | public int currentSession
|
| | | {
|
| | | get
|
| | | {
|
| | | for (int i = 0; i < sessions.Count; i++)
|
| | | {
|
| | | if (sessions[i].InSession(TimeUtility.ServerNow))
|
| | | {
|
| | | return i;
|
| | | }
|
| | | }
|
| | | return 0;
|
| | | }
|
| | | }
|
| | |
|
| | | public int dayOfWeek { get; set; }
|
| | |
|
| | | public void Sort()
|
| | | {
|
| | | sessions.Sort((Session x, Session y) =>
|
| | | {
|
| | | return x.session.CompareTo(y.session);
|
| | | });
|
| | | for (int i = 0; i < sessions.Count; i++)
|
| | | {
|
| | | sessions[i].Sort();
|
| | | }
|
| | | }
|
| | |
|
| | | public void ParseConfig(DungeonStateTimeConfig config)
|
| | | {
|
| | | var session = sessions.Find((x) =>
|
| | | {
|
| | | return x.session == (config.StateValue < 20 ? 0 : 1);
|
| | | });
|
| | | if (session == null)
|
| | | {
|
| | | session = new Session();
|
| | | session.session = config.StateValue < 20 ? 0 : 1;
|
| | | sessions.Add(session);
|
| | | }
|
| | | session.ParseConfig(config);
|
| | | }
|
| | |
|
| | | public bool InRing(DateTime time)
|
| | | {
|
| | | for (int i = 0; i < sessions.Count; i++)
|
| | | {
|
| | | if (sessions[i].InSession(time))
|
| | | {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | public bool TryGetSession(DateTime time, out Session session)
|
| | | {
|
| | | session = null;
|
| | | for (int i = 0; i < sessions.Count; i++)
|
| | | {
|
| | | if (sessions[i].InSession(time))
|
| | | {
|
| | | session = sessions[i];
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | | public bool IsOver(DateTime time)
|
| | | {
|
| | | bool allOver = true;
|
| | | for (int i = 0; i < sessions.Count; i++)
|
| | | {
|
| | | if (!sessions[i].IsOver(time))
|
| | | {
|
| | | allOver = false;
|
| | | break;
|
| | | }
|
| | | }
|
| | | return allOver;
|
| | | }
|
| | | }
|
| | |
|
| | | public class Session
|
| | | {
|
| | | public List<Stage> stages = new List<Stage>();
|
| | |
|
| | | public int session { get; set; }
|
| | |
|
| | | public void Sort()
|
| | | {
|
| | | stages.Sort(Compare);
|
| | | }
|
| | |
|
| | | public void ParseConfig(DungeonStateTimeConfig config)
|
| | | {
|
| | | var state = config.StateValue % 10;
|
| | | var stage = new Stage()
|
| | | {
|
| | | stage = state == 1 ? FairyLeagueStage.Grouping : (state == 2 ? FairyLeagueStage.Fight : FairyLeagueStage.Over),
|
| | | dayOfWeek = config.StartWeekday,
|
| | | startHour = config.StartHour,
|
| | | endHour = config.EndHour,
|
| | | startMinute = config.StartMinute,
|
| | | endMinute = config.EndMinute
|
| | | };
|
| | | stages.Add(stage);
|
| | | }
|
| | |
|
| | | public bool InSession(DateTime time)
|
| | | {
|
| | | var groupStage = stages.Find((x) =>
|
| | | {
|
| | | return x.stage == FairyLeagueStage.Grouping;
|
| | | });
|
| | | var overStage = stages.Find((x) =>
|
| | | {
|
| | | return x.stage == FairyLeagueStage.Over;
|
| | | });
|
| | | var _dayOfWeek = time.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)time.DayOfWeek;
|
| | | if (_dayOfWeek != groupStage.dayOfWeek)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | if (time.Hour < groupStage.startHour || time.Hour > overStage.endHour)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | if (time.Hour == groupStage.startHour && time.Minute < groupStage.startMinute)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | if (time.Hour == overStage.endHour && time.Minute > overStage.endMinute)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | public bool TryGetStage(DateTime time, out Stage stage)
|
| | | {
|
| | | stage = default(Stage);
|
| | | for (int i = 0; i < stages.Count; i++)
|
| | | {
|
| | | if (stages[i].InStage(time))
|
| | | {
|
| | | stage = stages[i];
|
| | | return true;
|
| | | }
|
| | | if (stages[i].IsOver(time))
|
| | | {
|
| | | stage = stages[i];
|
| | | }
|
| | | }
|
| | | return !stage.Equals(default(Stage));
|
| | | }
|
| | |
|
| | | public bool IsOver(DateTime time)
|
| | | {
|
| | | var stage = stages.Find((x) =>
|
| | | {
|
| | | return x.stage == FairyLeagueStage.Over;
|
| | | });
|
| | | return stage.IsOver(time);
|
| | | }
|
| | |
|
| | | int Compare(Stage x, Stage y)
|
| | | {
|
| | | return x.stage.CompareTo(y.stage);
|
| | | }
|
| | | }
|
| | |
|
| | | public struct Stage
|
| | | {
|
| | | public FairyLeagueStage stage;
|
| | | public int dayOfWeek;
|
| | | public int startHour;
|
| | | public int endHour;
|
| | | public int startMinute;
|
| | | public int endMinute;
|
| | |
|
| | | public bool InStage(DateTime time)
|
| | | {
|
| | | var _dayOfWeek = time.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)time.DayOfWeek;
|
| | | if (dayOfWeek != _dayOfWeek)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | if (time.Hour < startHour || time.Hour > endHour)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | if (time.Hour == startHour && time.Minute < startMinute)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | if (time.Hour == endHour && time.Minute > endMinute)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | public bool IsOver(DateTime time)
|
| | | {
|
| | | var _dayOfWeek = time.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)time.DayOfWeek;
|
| | | if (_dayOfWeek > dayOfWeek)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | if (dayOfWeek == _dayOfWeek)
|
| | | {
|
| | | if (time.Hour > endHour)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | if (time.Hour == endHour && time.Minute > endMinute)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public enum FairyLeagueStage
|
| | | {
|
| | | Prepare,
|