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()); } } } }
public bool EndSession() { var mymod = ResetModeMod.Instance; if (Main.netMode == 1) { throw new Exception("Clients cannot call this."); } // Already ended? if (!this.Data.IsRunning) { LogHelpers.Alert("Already stopped."); return(false); } if (mymod.Config.DebugModeInfo) { string worldId = WorldHelpers.GetUniqueIdForCurrentWorld(true); LogHelpers.Alert("Sets ALL session data to defaults, stops all TimeLimit \"reset\" commands (world id: " + worldId + ")"); } this.IsExiting = false; this.Data.ResetAll(); this.Save(); if (Main.netMode == 2) { SessionProtocol.SyncToClients(); } this.ResetCurrentWorldForSession(); return(true); }
internal void Begin() { if (!this.HasEnteredWorld) { throw new ModHelpersException("Cannot begin game if player hasn't joined game."); } this.BegunWorldIds.Add(WorldHelpers.GetUniqueIdForCurrentWorld(true)); }
//////////////// internal bool HasBegunCurrentWorld() { if (!this.HasEnteredWorld) { throw new ModHelpersException("Cannot check if game is running for player if player hasn't joined game."); } return(this.BegunWorldIds.Contains(WorldHelpers.GetUniqueIdForCurrentWorld(true))); }
public void LoadKillData() { var mymod = RewardsMod.Instance; bool success = this.WorldData.Load(this.GetDataFileBaseName()); if (mymod.SettingsConfig.DebugModeInfo || mymod.SettingsConfig.DebugModeKillInfo) { LogHelpers.Alert("World id: " + WorldHelpers.GetUniqueIdForCurrentWorld(true) + ", success: " + success + ", " + this.WorldData.ToString()); } }
//////////////// public string GetDataFileBaseName() { if (RewardsMod.Instance.SettingsConfig.UseUpdatedWorldFileNameConvention) { return(WorldHelpers.GetUniqueIdForCurrentWorld(true)); } else { return("World_" + FileHelpers.SanitizePath(Main.worldName) + "_" + Main.worldID); } }
//////////////// private void UpdateGame() { var mymod = ResetModeMod.Instance; string worldId = WorldHelpers.GetUniqueIdForCurrentWorld(true); if (this.IsSessionNeedingWorld()) { if (mymod.Config.DebugModeInfo) { LogHelpers.Alert("Session needs a world (current world id: " + worldId + ")"); } if (this.HasWorldEverBeenPlayed(worldId)) { //if( Main.netMode != 2 ) { // Servers should just indefinitely boot people until closed; stopgap measure this.GoodExit(); } else { this.BeginResetTimer(); this.AddWorldToSession(); // Changes world status } } else if (this.IsSessionedWorldNotOurs()) { if (mymod.Config.DebugModeInfo) { LogHelpers.Alert("World has expired (current world id: " + worldId + "). Session data: " + this.Data.ToString()); } if (mymod.Config.WrongWorldForcesHardReset) { if (mymod.Config.DebugModeInfo) { LogHelpers.Alert("WrongWorldForcesHardReset == true. Sets AwaitingNextWorld=true, CurrentSessionedWorldId=\"\""); } this.Data.AwaitingNextWorld = true; this.Data.CurrentSessionedWorldId = ""; this.Save(); } if (this.HasWorldEverBeenPlayed(worldId)) { this.GoodExit(); } else { this.BadExit(); } } }
private void LoadDataSources() { DataDumper.SetDumpSource("WorldUidWithSeed", () => { return(" " + WorldHelpers.GetUniqueIdForCurrentWorld(true) + " (net mode: " + Main.netMode + ")"); }); DataDumper.SetDumpSource("PlayerUid", () => { if (Main.myPlayer < 0 || Main.myPlayer >= (Main.player.Length - 1)) { return(" Unobtainable"); } return(" " + PlayerIdentityHelpers.GetUniqueId()); }); }
//// public static void Eject(Player player) { var mymod = ResetModeMod.Instance; if (mymod.Session.HasWorldEverBeenPlayed(WorldHelpers.GetUniqueIdForCurrentWorld(true))) { LogHelpers.Log("Ejecting player " + Main.LocalPlayer.name + " via good exit..."); mymod.Session.GoodExit(); } else { LogHelpers.Log("Ejecting player " + Main.LocalPlayer.name + " via bad exit..."); mymod.Session.BadExit(); } }
//////////////// public override void Initialize() { var mymod = (ModHelpersMod)this.mod; this.ObsoleteId = Guid.NewGuid().ToString("D"); this.ObsoleteId2 = WorldHelpers.GetUniqueIdForCurrentWorld(false); this.HasObsoleteId = false; // 'Load()' decides if no pre-existing one is found this.WorldLogic = new WorldLogic(); if (String.IsNullOrEmpty(this.ObsoleteId2)) { throw new ModHelpersException("UID not defined."); } }
public void AddWorldToSession() { var mymod = ResetModeMod.Instance; string worldId = WorldHelpers.GetUniqueIdForCurrentWorld(true); if (mymod.Config.DebugModeInfo) { LogHelpers.Alert("Sets AllPlayedWorlds.Add(<world id>), CurrentSessionedWorldId=<world id>, AwaitingNextWorld=false (worldId: " + worldId + ")"); } this.Data.AllPlayedWorlds.Add(worldId); this.Data.CurrentSessionedWorldId = worldId; this.Data.AwaitingNextWorld = false; if (Main.netMode != 1) { this.Save(); } this.RunModCalls(); }
internal void Update() { var mymod = ResetModeMod.Instance; if (mymod.Config.DebugModeRealTimeInfo) { string worldId = WorldHelpers.GetUniqueIdForCurrentWorld(true); var myplayer = (ResetModePlayer)TmlHelpers.SafelyGetModPlayer(Main.LocalPlayer, mymod, "ResetModePlayer"); DebugHelpers.Print("ResetModeSession", "Is running? " + this.Data.IsRunning + ", Exiting? " + this.IsExiting + ", Needs world? " + this.IsSessionNeedingWorld() + ", World id: " + worldId + ", Been played? " + this.HasWorldEverBeenPlayed(worldId), 20); DebugHelpers.Print("ResetModePlayer", "IsPromptingForResetOnLocal? " + myplayer.Logic.IsPromptingForResetOnLocal + ", IsSynced? " + myplayer.IsSynced + ", HasModSettings? " + myplayer.HasModSettings + ", HasSessionData? " + myplayer.HasSessionData, 20); } if (this.Data.IsRunning && !this.IsExiting) { if (Main.netMode == 0) { this.UpdateSingle(); } else if (Main.netMode == 1) { this.UpdateClient(); } else { this.UpdateServer(); } } }
public void SaveEveryonesKillData() { var mymod = RewardsMod.Instance; if (mymod.SettingsConfig.DebugModeInfo || mymod.SettingsConfig.DebugModeKillInfo) { LogHelpers.Alert("World id: " + WorldHelpers.GetUniqueIdForCurrentWorld(true) + ", " + this.WorldData.ToString()); } for (int i = 0; i < Main.player.Length; i++) { Player player = Main.player[i]; if (player == null || !player.active) { continue; } var myplayer = (RewardsPlayer)TmlHelpers.SafelyGetModPlayer(player, mymod, "RewardsPlayer"); myplayer.SaveKillData(); } this.WorldData.Save(this.GetDataFileBaseName()); }
//////////////// private Item AccountForPurchase(Player player, long spent, Item lastBuyItem) { NPC talkNpc = Main.npc[player.talkNPC]; if (talkNpc == null || !talkNpc.active) { LogHelpers.Log("AccountForPurchase - No shop npc."); return(null); } var mymod = CapitalismMod.Instance; ISet <int> possiblePurchases = ItemFinderHelpers.FindPossiblePurchaseTypes(player.inventory, spent); Item item = null; int stack = 1; if (possiblePurchases.Count > 0) { var changesAt = PlayerItemFinderHelpers.FindInventoryChanges(player, this.PrevMouseInfo, this.PrevInventoryInfos); changesAt = ItemFinderHelpers.FilterByTypes(changesAt, possiblePurchases); if (changesAt.Count == 1) { foreach (var entry in changesAt) { if (entry.Key == -1) { item = Main.mouseItem; } else { item = player.inventory[entry.Key]; } if (item != null) { // Must be a false positive? if (lastBuyItem != null && lastBuyItem.type != item.type) { item = null; } else { //stack = entry.Value.Value; break; } } } } } if (item == null) { if (lastBuyItem != null) { var vendor = this.GetOrCreateVendor(WorldHelpers.GetUniqueIdForCurrentWorld(true), talkNpc.type); int value = (int)vendor.GetPriceOf(lastBuyItem.type); if ((spent % value) == 0) { item = lastBuyItem; stack = (int)(spent / value); } } } if (item != null) { this.BoughtFrom(player, talkNpc, item, stack); } return(item); }
public bool IsSessionedWorldNotOurs() { return(this.Data.CurrentSessionedWorldId != WorldHelpers.GetUniqueIdForCurrentWorld(true)); }