public static void update() { if (Multiplayer.mode == Mode.Singleplayer) { return; } if (MultiplayerUtility.latestID > prevLatestId) { sendFunc(new LatestIdPacket()); } prevLatestId = MultiplayerUtility.latestID; //Log.Async("pos:" + Game1.player.position.X + " " + Game1.player.position.Y); // Clients sometimes get stuck in the top-right corner and can't move on second day+ if (Game1.player.currentLocation != null && Game1.player.currentLocation.name == "FarmHouse" && Game1.player.currentLocation == Game1.currentLocation && Game1.player.currentLocation != Game1.getLocationFromName(Game1.player.currentLocation.name)) { Game1.player.currentLocation = Game1.getLocationFromName(Game1.player.currentLocation.name); Game1.currentLocation = Game1.player.currentLocation; Game1.currentLocation.resetForPlayerEntry(); } // Really don't understand why it breaks without this // But as soon as you get to the second day, it does. Ugh. Game1.player.FarmerSprite.setOwner(Game1.player); if (Game1.newDay) { didNewDay = true; Game1.freezeControls = prevFreezeControls = true; Game1.player.CanMove = false; if (!sentNextDayPacket) { ChatMenu.chat.Add(new ChatEntry(null, Game1.player.name + " is in bed.")); if (mode == Mode.Host) { server.broadcast(new ChatPacket(255, Game1.player.name + " is in bed.")); } else if (mode == Mode.Client) { client.stage = Client.NetStage.Waiting; SaveGame oldLoaded = SaveGame.loaded; var it = NewSaveGame.Save(true); while (it.Current < 100) { it.MoveNext(); Thread.Sleep(5); } MemoryStream tmp = new MemoryStream(); SaveGame.serializer.Serialize(tmp, SaveGame.loaded); sendFunc(new NextDayPacket()); sendFunc(new ClientFarmerDataPacket(Encoding.UTF8.GetString(tmp.ToArray()))); //SaveGame.loaded = oldLoaded; } sentNextDayPacket = true; } if (waitingOnOthers() && Game1.fadeToBlackAlpha > 0.625f) { Game1.fadeToBlackAlpha = 0.625f; } } else { sentNextDayPacket = false; } // We want people to wait for everyone //Log.Async("menu:"+Game1.activeClickableMenu); if (Game1.activeClickableMenu is SaveGameMenu && Game1.activeClickableMenu.GetType() != typeof(NewSaveGameMenu)) { Game1.activeClickableMenu = new NewSaveGameMenu(); } else if (Game1.activeClickableMenu is ShippingMenu) { //Log.Async("Savegame:" + Util.GetInstanceField(typeof(ShippingMenu), Game1.activeClickableMenu, "saveGameMenu")); SaveGameMenu menu = ( SaveGameMenu )Util.GetInstanceField(typeof(ShippingMenu), Game1.activeClickableMenu, "saveGameMenu"); if (menu != null && menu.GetType() != typeof(NewSaveGameMenu)) { Util.SetInstanceField(typeof(ShippingMenu), Game1.activeClickableMenu, "saveGameMenu", new NewSaveGameMenu()); } } if (Game1.currentLocation != null && Game1.currentLocation.currentEvent != null) { Events.fix(); } else { Events.reset(); } // Causing issues after going a day? Maybe? // Plus it only fixes a few of the time pauses /*Game1.player.forceTimePass = true; * Game1.paused = false; * if ( prevFreezeControls != Game1.freezeControls ) * { * sendFunc( new PauseTimePacket() ); * } * prevFreezeControls = Game1.freezeControls;*/ if (Multiplayer.mode == Mode.Host && server != null) { server.update(); if (server == null) { return; } if (server.clients == null) { return; } foreach (Server.Client client_ in server.clients) { if (client_.stage != Server.Client.NetStage.Playing) { continue; } if (client_.farmer == null) { continue; } doUpdatePlayer(client_.farmer); } } else if (Multiplayer.mode == Mode.Client && client != null) { client.update(); if (client == null) { return; } if (client.others == null) { return; } foreach (KeyValuePair <byte, Farmer> other in client.others) { if (other.Value == null) { continue; } doUpdatePlayer(other.Value); } } if (Game1.gameMode == 6) { return; // Loading? } // ^ TODO: Check if != 3 works if (Multiplayer.mode == Mode.Host && server != null && server.playing || Multiplayer.mode == Mode.Client && client != null && client.stage == Client.NetStage.Playing) { if (Game1.newDay) { return; } NPCMonitor.startChecks(); foreach (GameLocation loc in Game1.locations) { if (!locations.ContainsKey(loc.name)) { locations.Add(loc.name, new LocationCache(loc)); } locations[loc.name].miniUpdate(); if (Game1.player.currentLocation == loc) { locations[loc.name].update(); } if (loc is Farm) { BuildableGameLocation farm = loc as BuildableGameLocation; foreach (Building building in farm.buildings) { if (building.indoors == null) { continue; } if (!locations.ContainsKey(building.nameOfIndoors)) { locations.Add(building.nameOfIndoors, new LocationCache(building.indoors)); } locations[loc.name].miniUpdate(); if (Game1.currentLocation != loc) { locations[building.nameOfIndoors].update(); } NPCMonitor.check(building.indoors); } } if (loc.name == "FarmHouse") { //Log.Async("Terrain features count for " + loc.name + " " + loc + ": " + loc.terrainFeatures.Count); //Log.Async("Object count for " + loc.name + " " + loc + ": " + loc.objects.Count); } } NPCMonitor.endChecks(); } }
public override void update(GameTime time) { if (this.quit) { if (Game1.currentLoader.Current < 100) { Game1.currentLoader.MoveNext(); } else { Game1.exitActiveMenu(); } return; } //////////////////////////////////////// if (Multiplayer.mode == Mode.Client) { Log.info("Reloading world for next day"); // Yes, it is necessary to do this again (previously done when the next day packet was sent before the fade) // This time newDayAfterFade has run, and so mail and stuff has changed var it = NewSaveGame.Save(true); while (it.Current < 100) { it.MoveNext(); Thread.Sleep(5); } Multiplayer.client.processDelayedPackets(); NewSaveGame.Load("MEOW", true); quit = true; return; } //////////////////////////////////////// if (!Game1.saveOnNewDay) { this.quit = true; if (Game1.activeClickableMenu.Equals(this)) { Game1.player.checkForLevelTenStatus(); Game1.exitActiveMenu(); } return; } if (this.loader != null) { this.loader.MoveNext(); if (this.loader.Current >= 100) { this.margin -= time.ElapsedGameTime.Milliseconds; if (this.margin <= 0) { Game1.playSound("money"); this.completePause = 1500; this.loader = null; Game1.game1.IsSaving = false; } } this._ellipsisDelay -= (float)time.ElapsedGameTime.TotalSeconds; if (this._ellipsisDelay <= 0f) { this._ellipsisDelay += 0.75f; this._ellipsisCount++; if (this._ellipsisCount > 3) { this._ellipsisCount = 1; } } } else if (this.hasDrawn && this.completePause == -1) { //////////////////////////////////////// if (Multiplayer.mode == Mode.Host) { foreach (Server.Client client in Multiplayer.server.clients) { // They should have sent their farmer data again. // We can update their stuff before the new day. client.processDelayedPackets(); } } //////////////////////////////////////// Game1.game1.IsSaving = true; this.loader = NewSaveGame.Save(); // SaveGame -> NewSaveGame } if (this.completePause >= 0) { this.completePause -= time.ElapsedGameTime.Milliseconds; this.saveText.update(time); if (this.completePause < 0) { this.quit = true; this.completePause = -9999; if (Game1.activeClickableMenu.Equals(this)) { Game1.player.checkForLevelTenStatus(); Game1.exitActiveMenu(); } Game1.currentLocation.resetForPlayerEntry(); } } }