public override void PreUpdate() { var mymod = ResetModeMod.Instance; ResetModeSessionData sessData = mymod.Session?.Data; if (sessData == null) { LogHelpers.WarnOnce("No session data."); } if (sessData.IsRunning) { if (!sessData.AwaitingNextWorld) { string worldId = WorldHelpers.GetUniqueIdForCurrentWorld(true); if (sessData.CurrentSessionedWorldId == "") { LogHelpers.WarnOnce("Invalid world session state - No world id (world id: " + worldId + ")\n" + mymod.Session.DataOnLoad.ToString()); } else if (sessData.CurrentSessionedWorldId != worldId) { LogHelpers.WarnOnce("Invalid world session state - Mismatched world id " + "(" + sessData.CurrentSessionedWorldId + " vs " + worldId + ")\n" + mymod.Session.DataOnLoad.ToString()); } } } }
//////////////// private void PrepareDataForPlayer(Player player) { var mymod = ResetModeMod.Instance; string uid = null; try { uid = PlayerIdentityHelpers.GetUniqueId(player); this.NewData = mymod.Session.Data.Clone(); this.NewData.PlayersValidated.Clear(); this.NewData.PlayerPPSpendings.Clear(); } catch (Exception e) { LogHelpers.Warn("Error 1: " + e.ToString()); } try { if (mymod.Session.Data.PlayersValidated.Contains(uid)) { this.NewData.PlayersValidated.Add(uid); } } catch (Exception e) { LogHelpers.Warn("Error 2: " + e.ToString()); } try { float sessVal; if (mymod.Session.Data.TryGetPlayerPPSpendingSync(uid, out sessVal)) { this.NewData.SetPlayerPPSpendingSync(uid, sessVal); } } catch (Exception e) { LogHelpers.Warn("Error 3a: " + e.ToString()); } }
//////////////// public void Load() { var mymod = ResetModeMod.Instance; if (Main.netMode == 1) { LogHelpers.Warn("Clients cannot load config from file"); return; } var data = ModCustomDataFileHelpers.LoadJson <ResetModeSessionData>(mymod, SessionLogic.DataFileNameOnly); if (data != null) { // Very specific failsafe: if (data.IsRunning && !data.AwaitingNextWorld && data.CurrentSessionedWorldId == "" && data.AllPlayedWorlds.Count == 0) { data.IsRunning = false; } this.DataOnLoad = data.Clone(); this.Data = data; } if (mymod.Config.DebugModeInfo) { LogHelpers.Alert("Success? " + (data != null) + ": " + this.Data.ToString()); } }
//////////////// internal SessionLogic() { this.Data = new ResetModeSessionData(); this.OnTickGet = Timers.MainOnTickGet(); Main.OnTick += SessionLogic._Update; }
//////////////// internal void SetData(ResetModeSessionData data) { this.Data = data; }