//读取数据 private IEnumerator ReadDb(Coroutine coroutine, LodeManager _this, int serverId) { var tasks = TeamServer.Instance.DB.Get <DBLodeManager>(coroutine, DataCategory.TeamLode, GetDbName(serverId)); yield return(tasks); _this.ServerId = serverId; if (tasks.Data == null) { _this.InitByBase(); yield break; } //Debug.Assert(false); foreach (var lodedata in tasks.Data.SceneLodeList) { var tbFlag = Table.GetWarFlag(lodedata.Value.FlagId); if (tbFlag == null) { continue; } var tmp = new DBSceneLode(); foreach (var l in lodedata.Value.LodeList) { var lode = l.Value; var tb = Table.GetLode(lode.Id); if (tb == null) { continue; } tmp.LodeList.Add(l.Key, l.Value); } tmp.SceneId = lodedata.Value.SceneId; tmp.TeamId = lodedata.Value.TeamId; tmp.TeamName = lodedata.Value.TeamName; DateTime rstTime = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(lodedata.Value.ResetTime); if (rstTime < DateTime.Now) { tmp.TeamId = 0; tmp.TeamName = ""; } rstTime = DateTime.Now.Date.AddHours((int)(tbFlag.BelongToTime[0] / 100)).AddMinutes(tbFlag.BelongToTime[0] % 100); if (rstTime < DateTime.Now) { rstTime.AddDays(1); } tmp.ResetTime = (int)(rstTime - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; tmp.FlagId = lodedata.Value.FlagId; _this.mDbData.SceneLodeList.Add(lodedata.Value.SceneId, tmp); } _this.mDbData.ActivityInfo = tasks.Data.ActivityInfo; _this.InitByBase(); }
public void InitByBase(LodeManager _this) { Table.ForeachWarFlag(tb => { if (_this.mDbData.SceneLodeList.ContainsKey(tb.FlagInMap) == true) { return(true); } var tmp = new DBSceneLode(); tmp.SceneId = tb.FlagInMap; tmp.FlagId = tb.Id; DateTime t = DateTime.Now.Date.AddHours((int)(tb.BelongToTime[0] / 100)).AddMinutes(tb.BelongToTime[0] % 100); if (t < DateTime.Now) { t.AddDays(1); } tmp.ResetTime = (int)(t - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; _this.mDbData.SceneLodeList.Add(tb.FlagInMap, tmp); return(true); }); Table.ForeachLode(record => { var sceneId = record.LodeInMap; if (_this.mDbData.SceneLodeList.ContainsKey(sceneId) == false) { return(true); } var l = _this.mDbData.SceneLodeList[sceneId]; if (l.LodeList.ContainsKey(record.Id) == false) { var lode = new DBLode(); lode.Id = record.Id; lode.Times = record.CanCollectNum; l.LodeList.Add(record.Id, lode); } return(true); }); {//重点活动相关 if (_this.mDbData.ActivityInfo == null) { _this.mDbData.ActivityInfo = new DBActiveTask(); } //一上来先调用一次 OnDayTimer(_this); var t = DateTime.Now.Date.AddDays(1).AddSeconds(5); TeamServerControl.tm.CreateTrigger(t, () => { OnDayTimer(_this); }, 60 * 60 * 24 * 1000); } }
public int ApplyHoldLode(LodeManager _this, int sceneId, ref MsgSceneLode msg) { DBSceneLode sl = null; if (false == _this.mDbData.SceneLodeList.TryGetValue(sceneId, out sl)) { return((int)ErrorCodes.Unknow); } System.DateTime startTime = DataTimeExtension.EpochStart; // 当地时区 DateTime rstTime = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(sl.ResetTime); if (rstTime < DateTime.Now) { sl.ResetTime += 60 * 60 * 24; sl.TeamId = 0; sl.TeamName = ""; } foreach (var v in sl.LodeList) { msgLode l = new msgLode(); l.Id = v.Value.Id; if (null == v.Value) { DateTime dt = startTime.AddSeconds(v.Value.UpdateTime); if (dt < DateTime.Now && v.Value.Times <= 0) { var tb = Table.GetLode(l.Id); if (tb != null) { v.Value.Times = tb.CanCollectNum; } } } l.Times = v.Value.Times; l.UpdateTime = v.Value.UpdateTime; msg.LodeList.Add(v.Key, l); } msg.TeamId = sl.TeamId; msg.TeamName = sl.TeamName; msg.FlagId = sl.FlagId; msg.ResetTime = sl.ResetTime; return((int)ErrorCodes.OK); }