예제 #1
0
        public override void process(Client client)
        {
            Log.debug("Got farmer data for other players.");

            foreach (SFarmer farmer in client.others.Values)
            {
                if (farmer.currentLocation != null)
                {
                    farmer.currentLocation.farmers.Remove(farmer);
                }
            }
            client.others.Clear();

            foreach (KeyValuePair <byte, string> other in others)
            {
                SFarmer farmer = (SFarmer)SaveGame.farmerSerializer.Deserialize(Util.stringStream(other.Value));
                farmer.uniqueMultiplayerID += 1 + client.id; // For IsMainPlayer

                //SFarmer oldPlayer = Game1.player;
                NewSaveGame.loadDataToFarmer(farmer);
                //Game1.player = oldPlayer; // Seriously, why does this get reassigned in there?

                client.others.Add(other.Key, farmer);

                if (other.Key == 0)
                {
                    foreach (string mail in Multiplayer.checkMail)
                    {
                        if (farmer.mailReceived.Contains(mail) && !SaveGame.loaded.player.mailReceived.Contains(mail))
                        {
                            SaveGame.loaded.player.mailReceived.Add(mail);
                        }
                        if (farmer.mailForTomorrow.Contains(mail) && !SaveGame.loaded.player.mailForTomorrow.Contains(mail))
                        {
                            SaveGame.loaded.player.mailForTomorrow.Add(mail);
                        }
                        if (farmer.mailReceived.Contains(mail + "%&NL&%") && !SaveGame.loaded.player.mailReceived.Contains(mail + "%&NL&%"))
                        {
                            SaveGame.loaded.player.mailReceived.Add(mail + "%&NL&%");
                        }
                        if (farmer.mailForTomorrow.Contains(mail + "%&NL&%") && !SaveGame.loaded.player.mailForTomorrow.Contains(mail + "%&NL&%"))
                        {
                            SaveGame.loaded.player.mailForTomorrow.Add(mail + "%&NL&%");
                        }
                    }
                    // Maybe more
                }
            }
        }
예제 #2
0
 public override void update(GameTime time)
 {
     if (!didModeSelect)
     {
         return;
     }
     if (readyToLoad)
     {
         Multiplayer.lobby = false;
         NewSaveGame.Load(path);
         Game1.exitActiveMenu();
     }
     else if (Multiplayer.mode == Mode.Client && modeInit != null && modeInit.ThreadState != ThreadState.Running)
     {
         readyToLoad = true;
     }
 }
예제 #3
0
        public override void update(GameTime time)
        {
            if (pendingClient != null)
            {
                pendingClient.update();
                if (pendingClient.id != 255)
                {
                    readyToLoad = true;
                }
                else
                {
                    return;
                }
            }

            if (!didModeSelect || Multiplayer.problemStarting)
            {
                return;
            }
            if (readyToLoad)
            {
                if (pendingClient != null)
                {
                    Multiplayer.client = pendingClient;
                }
                Multiplayer.lobby = false;
                NewSaveGame.Load(path);
                Game1.exitActiveMenu();
            }
            else if (Multiplayer.mode == Mode.Client && modeInit != null && modeInit.ThreadState != ThreadState.Running)
            {
                readyToLoad = true;
            }
            else if (modeInit == null && Multiplayer.mode == Mode.Client)
            {
                if (showingFriends && friends != null)
                {
                    friends.update(time);
                }
                else if (showingLan)
                {
                    lan.update(time);
                }
            }
        }
        public override void process(Server server, Server.Client client)
        {
            Log.debug("Got farmer data for client " + client.id);

            //SFarmer old = client.farmer;
            SaveGame theirs = (SaveGame)SaveGame.serializer.Deserialize(Util.stringStream(xml));

            if (client.farmer == null)
            {
                ChatMenu.chat.Add(new ChatEntry(null, theirs.player.name + " has connected."));
                server.broadcast(new ChatPacket(255, theirs.player.name + " has connected."), client.id);

                String str = "Currently playing: ";
                str += NewLoadMenu.pendingSelected.name;
                foreach (Server.Client other in server.clients)
                {
                    if (other == client || other.farmer == null)
                    {
                        continue;
                    }
                    str += ", " + other.farmer.name;
                }
                client.send(new ChatPacket(255, str));
            }

            client.farmerXml = Util.serialize <SFarmer>(theirs.player);
            client.farmer    = theirs.player;
            client.farmer.uniqueMultiplayerID += 1 + client.id;

            NewSaveGame.loadDataToFarmer(client.farmer);
            client.farmer.FarmerSprite.setOwner(client.farmer);
            Game1.player.FarmerSprite.setOwner(Game1.player);

            //if(!server.playing)
            //if (server.playing) client.farmer = old;

            // About second-day-sleeping crashes:
            // So just adding the location directly puts the raw deserialized one into the game.
            // The raw deserialized one doesn't have the tiles and stuff loaded. Just the game data.
            // I think this is why vanilla copies data over in loadDataToLocations instead of using
            // the loaded objects directly. Why not just postpone loading until later, I don't know.
            //
            // So, when the second day begins, otherFarmer.currentLocation was still set to the
            // previous day's farm house[*]. On day two, the 'good' one[**] was removed, so when they go
            // back in, the bad one is used. Basically, I need to make them all the 'good' one.
            // For now, I'm just going to reload the needed data for this client's farmhouse.
            // I'll figure out how to do it 'properly' later. Maybe. (My mind is muddled today.)
            //
            // [*] Looking at addFixedLocationToOurWorld now you'll see that this isn't the case.
            // I added the part about fixing SFarmer.currentLocation as I was going through this
            // thought process. So things will break more obviously if something like this happens
            // again.
            //
            // [**] The first day's farmhouse is okay because in loadDataToLocations, (called in
            // NewSaveGame.getLoadEnumerator), the map is reloaded from FarmHouse_setMapForUpgradeLevel.
            // If CO-OP weren't on, worse things would happen, because things besides the farm house
            // would need loading (see Multiplayer.isPlayerUnique). The client doesn't have this
            // issue because they do the whole loading process each day anyways.
            //
            // Of course, the whole second-day-crash doesn't happen when I test it on localhost. Hence
            // why this was so annoying. And probably why I documented all this.
            foreach (GameLocation theirLoc in theirs.locations)
            {
                if (theirLoc.name == "FarmHouse")
                {
                    NewSaveGame.FarmHouse_setMapForUpgradeLevel(theirLoc as FarmHouse);
                }
            }

            fixPetDuplicates(theirs);

            Multiplayer.fixLocations(theirs.locations, client.farmer, addFixedLocationToOurWorld, client);

            foreach (string mail in Multiplayer.checkMail)
            {
                if (client.farmer.mailForTomorrow.Contains(mail))
                {
                    if (!SaveGame.loaded.player.mailForTomorrow.Contains(mail))
                    {
                        SaveGame.loaded.player.mailForTomorrow.Add(mail);
                    }
                    if (Game1.player != null && !Game1.player.mailForTomorrow.Contains(mail))
                    {
                        Game1.player.mailForTomorrow.Add(mail);
                    }
                }
                if (client.farmer.mailForTomorrow.Contains(mail + "%&NL&%"))
                {
                    if (!SaveGame.loaded.player.mailForTomorrow.Contains(mail + "%&NL&%"))
                    {
                        SaveGame.loaded.player.mailForTomorrow.Add(mail + "%&NL&%");
                    }
                    if (Game1.player != null && !Game1.player.mailForTomorrow.Contains(mail + "%&NL&%"))
                    {
                        Game1.player.mailForTomorrow.Add(mail + "%&NL&%");
                    }
                }
            }

            client.stage = Server.Client.NetStage.WaitingForStart;
        }
예제 #5
0
        public override void process(Client client)
        {
            Log.Async("Got world data");
            //Log.Async(xml);

            SaveGame mine = SaveGame.loaded;

            /*if ( mine.player.spouse != null && mine.player.spouse.EndsWith( "engaged" ) &&
             *   mine.countdownToWedding == 0 && !mine.weddingToday )
             * {
             *  // Not (entirely) sure why this is happening in the first place, but this should fix it.
             *  mine.player.spouse = mine.player.spouse.Replace("engaged", "");
             *  mine.weddingToday = true;
             * }*/

            SaveGame world = ( SaveGame )SaveGame.serializer.Deserialize(Util.stringStream(xml));

            if (Multiplayer.COOP)
            {
                mine.player.farmName         = world.player.farmName;
                mine.player.money            = world.player.money;
                mine.player.clubCoins        = world.player.clubCoins;
                mine.player.totalMoneyEarned = world.player.totalMoneyEarned;
                mine.player.hasRustyKey      = world.player.hasRustyKey;
                mine.player.hasSkullKey      = world.player.hasSkullKey;
                mine.player.hasClubCard      = world.player.hasClubCard;
                // Should I sync dark talisman / magic ink?
                mine.player.dateStringForSaveGame = world.player.dateStringForSaveGame;
            }
            world.player = mine.player;

            foreach (string mail in Multiplayer.checkMail)
            {
                if (world.mailbox.Contains(mail) && !mine.mailbox.Contains(mail))
                {
                    mine.mailbox.Add(mail);
                }
                if (world.player.mailForTomorrow.Contains(mail) && !mine.player.mailForTomorrow.Contains(mail))
                {
                    mine.player.mailForTomorrow.Add(mail);
                }
                if (world.player.mailReceived.Contains(mail) && !mine.player.mailReceived.Contains(mail))
                {
                    mine.player.mailReceived.Add(mail);
                }
                if (world.mailbox.Contains(mail + "%&NL&%") && !mine.mailbox.Contains(mail + "%&NL&%"))
                {
                    mine.mailbox.Add(mail + "%&NL&%");
                }
                if (world.player.mailForTomorrow.Contains(mail + "%&NL&%") && !mine.player.mailForTomorrow.Contains(mail + "%&NL&%"))
                {
                    mine.player.mailForTomorrow.Add(mail + "%&NL&%");
                }
                if (world.player.mailReceived.Contains(mail + "%&NL&%") && !mine.player.mailReceived.Contains(mail + "%&NL&%"))
                {
                    mine.player.mailReceived.Add(mail + "%&NL&%");
                }
            }

            world.mailbox         = mine.mailbox;
            world.samBandName     = mine.samBandName;
            world.elliottBookName = mine.elliottBookName;
            // wallpaper/flooring doesn't look needed?
            world.countdownToWedding = mine.countdownToWedding;
            world.weddingToday       = mine.weddingToday;
            world.musicVolume        = mine.musicVolume;
            world.soundVolume        = mine.soundVolume;
            world.options            = mine.options;
            world.minecartHighScore  = mine.minecartHighScore;
            if (!Multiplayer.COOP)
            {
                world.stats               = mine.stats;
                world.incubatingEgg       = mine.incubatingEgg;
                world.dailyLuck           = mine.dailyLuck;
                world.whichFarm           = mine.whichFarm;
                world.shouldSpawnMonsters = mine.shouldSpawnMonsters;
            }
            world.mine_mineLevel            = mine.mine_mineLevel;
            world.mine_nextLevel            = mine.mine_nextLevel;
            world.mine_lowestLevelReached   = mine.mine_lowestLevelReached;
            world.mine_resourceClumps       = mine.mine_resourceClumps;
            world.mine_permanentMineChanges = mine.mine_permanentMineChanges;
            //}

            fixPetMultiplication(mine, world);
            fixRelationships(mine, world);

            Multiplayer.fixLocations(world.locations, null, debugStuff);
            Woods        woods    = null;
            GameLocation toRemove = null;

            foreach (GameLocation loc in world.locations)
            {
                if (loc.name == "FarmHouse")
                {
                    toRemove = loc;
                }
                else if (loc.name == "Woods")
                {
                    woods = (Woods)loc;
                }
            }
            if (toRemove != null)
            {
                world.locations.Remove(toRemove);
            }
            foreach (GameLocation loc in mine.locations)
            {
                if (loc.name == "FarmHouse")
                {
                    world.locations.Add(loc);
                }
                else if (loc.name == "Woods" && woods != null)
                {
                    Woods myWoods = ( Woods )loc;
                    woods.hasUnlockedStatue = myWoods.hasUnlockedStatue;
                    woods.hasFoundStardrop  = myWoods.hasFoundStardrop;
                }
            }

            // See the giant block of comments in ClientFarmerDataPacket
            foreach (GameLocation theirLoc in world.locations)
            {
                if (theirLoc is FarmHouse)
                {
                    Log.Async("FarmHouse: " + theirLoc.name);
                    NewSaveGame.FarmHouse_setMapForUpgradeLevel(theirLoc as FarmHouse);
                }
            }

            /*
             * findReplaceLocation("FarmHouse", world.locations, mine.locations);
             * if ( !Multiplayer.COOP )
             * {
             *  findReplaceLocation("Farm", world.locations, mine.locations);
             *  findReplaceLocation("FarmCave", world.locations, mine.locations);
             *  findReplaceLocation("Greenhouse", world.locations, mine.locations);
             *  findReplaceLocation("ArchaeologyHouse", world.locations, mine.locations);
             *  findReplaceLocation("CommunityCenter", world.locations, mine.locations);
             *  // ^ How should I do rewards? The ones that affect town permanently
             *  // Mines?
             * }*/

            SaveGame.loaded = world;
            client.stage    = Client.NetStage.Waiting;
            //client.tempStopUpdating = true;
        }
예제 #6
0
        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();
            }
        }
예제 #7
0
        ////////////////////////////////////////
        public override void update(GameTime time)
        {
            base.update(time);
            if (this.timerToLoad > 0)
            {
                this.timerToLoad -= time.ElapsedGameTime.Milliseconds;
                if (this.timerToLoad <= 0)
                {
                    ////////////////////////////////////////
                    this.timerToLoad = 1;

                    pendingSelected = saveGames[selected];
                    if (didModeSelect)
                    {
                        if (modeInit == null)
                        {
                            if (portBox == null)
                            {
                                if (Multiplayer.mode == Mode.Client)
                                {
                                    ipBox        = new TextBox(Game1.content.Load <Texture2D>("LooseSprites\\textBox"), null, Game1.smallFont, Game1.textColor);
                                    ipBox.Width *= 3;
                                    ipBox.X      = buttonX + buttonW / 2 - (SpriteText.getWidthOfString("IP Address:") + ipBox.Width + 20) / 2 + SpriteText.getWidthOfString("IP Address:") + 20;
                                    ipBox.Y      = buttonY1 + buttonH / 2 - ipBox.Height / 2;
                                    ipBox.Text   = Multiplayer.ipStr;
                                }

                                portBox        = new TextBox(Game1.content.Load <Texture2D>("LooseSprites\\textBox"), null, Game1.smallFont, Game1.textColor);
                                portBox.Width *= 3;
                                portBox.X      = buttonX + buttonW / 2 - (SpriteText.getWidthOfString("IP Address:") + portBox.Width + 20) / 2 + SpriteText.getWidthOfString("IP Address:") + 20;
                                portBox.Y      = buttonY2 + buttonH / 2 - portBox.Height / 2;
                                portBox.Text   = Multiplayer.portStr;
                            }
                        }
                        else
                        {
                            if (Multiplayer.mode == Mode.Client && Multiplayer.client != null)
                            {
                                readyToLoad = true;
                            }
                        }
                    }

                    if (Multiplayer.problemStarting)
                    {
                        /*didModeSelect = false;
                         * this.loading = false;
                         * this.timerToLoad = 0;
                         * this.selected = -1;
                         * Util.SetInstanceField(typeof(TitleMenu), Game1.activeClickableMenu, "subMenu", new NewLoadMenu());
                         */
                        return;
                    }

                    if (!readyToLoad)
                    {
                        return;
                    }

                    if (!NewSaveGame.Load(this.saveGames[this.selected].favoriteThing))
                    {
                        didModeSelect    = false;
                        this.loading     = false;
                        this.timerToLoad = 0;
                        this.selected    = -1;
                        Util.SetInstanceField(typeof(TitleMenu), Game1.activeClickableMenu, "subMenu", new NewLoadMenu());
                        return;
                    }
                    Multiplayer.lobby = false;
                    this.timerToLoad  = 0;

                    ////////////////////////////////////////

                    for (int i = 0; i < this.saveGames.Count; i++)
                    {
                        if (i != this.selected)
                        {
                            this.saveGames[i].unload();
                        }
                    }

                    //if (Multiplayer.mode == Mode.Singleplayer) ////////////////////////////////////////
                    Game1.exitActiveMenu();
                }
            }
        }
예제 #8
0
        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();
                }
            }
        }
예제 #9
0
        public NewLoadMenu() : base(Game1.viewport.Width / 2 - (1100 + IClickableMenu.borderWidth * 2) / 2, Game1.viewport.Height / 2 - (600 + IClickableMenu.borderWidth * 2) / 2, 1100 + IClickableMenu.borderWidth * 2, 600 + IClickableMenu.borderWidth * 2, false)
        {
            this.upArrow            = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + this.width + Game1.tileSize / 4, this.yPositionOnScreen + Game1.tileSize / 4, 11 * Game1.pixelZoom, 12 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(421, 459, 11, 12), (float)Game1.pixelZoom, false);
            this.downArrow          = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + this.width + Game1.tileSize / 4, this.yPositionOnScreen + this.height - Game1.tileSize, 11 * Game1.pixelZoom, 12 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(421, 472, 11, 12), (float)Game1.pixelZoom, false);
            this.scrollBar          = new ClickableTextureComponent(new Rectangle(this.upArrow.bounds.X + Game1.pixelZoom * 3, this.upArrow.bounds.Y + this.upArrow.bounds.Height + Game1.pixelZoom, 6 * Game1.pixelZoom, 10 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(435, 463, 6, 10), (float)Game1.pixelZoom, false);
            this.scrollBarRunner    = new Rectangle(this.scrollBar.bounds.X, this.upArrow.bounds.Y + this.upArrow.bounds.Height + Game1.pixelZoom, this.scrollBar.bounds.Width, this.height - Game1.tileSize - this.upArrow.bounds.Height - Game1.pixelZoom * 7);
            this.okDeleteButton     = new ClickableTextureComponent("OK", new Rectangle((int)Utility.getTopLeftPositionForCenteringOnScreen(Game1.tileSize, Game1.tileSize, 0, 0).X - Game1.tileSize, (int)Utility.getTopLeftPositionForCenteringOnScreen(Game1.tileSize, Game1.tileSize, 0, 0).Y + Game1.tileSize * 2, Game1.tileSize, Game1.tileSize), null, null, Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 46, -1, -1), 1f, false);
            this.cancelDeleteButton = new ClickableTextureComponent("Cancel", new Rectangle((int)Utility.getTopLeftPositionForCenteringOnScreen(Game1.tileSize, Game1.tileSize, 0, 0).X + Game1.tileSize, (int)Utility.getTopLeftPositionForCenteringOnScreen(Game1.tileSize, Game1.tileSize, 0, 0).Y + Game1.tileSize * 2, Game1.tileSize, Game1.tileSize), null, null, Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 47, -1, -1), 1f, false);
            for (int i = 0; i < 4; i++)
            {
                this.gamesToLoadButton.Add(new ClickableComponent(new Rectangle(this.xPositionOnScreen + Game1.tileSize / 4, this.yPositionOnScreen + Game1.tileSize / 4 + i * (this.height / 4), this.width - Game1.tileSize / 2, this.height / 4 + Game1.pixelZoom), string.Concat(i)));
                this.deleteButtons.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen + this.width - Game1.tileSize - Game1.pixelZoom, this.yPositionOnScreen + Game1.tileSize / 2 + Game1.pixelZoom + i * (this.height / 4), 12 * Game1.pixelZoom, 12 * Game1.pixelZoom), "", "Delete File", Game1.mouseCursors, new Rectangle(322, 498, 12, 12), (float)Game1.pixelZoom * 3f / 4f, false));
            }
            string text = Path.Combine(new string[]
            {
                Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley"), "Saves")
            });

            if (Directory.Exists(text))
            {
                string[] directories = Directory.GetDirectories(text);
                if (directories.Length != 0)
                {
                    string[] array = directories;
                    for (int j = 0; j < array.Length; j++)
                    {
                        string text2 = array[j];
                        try
                        {
                            Stream stream = null;
                            try
                            {
                                stream = File.Open(Path.Combine(text, text2, "SaveGameInfo"), FileMode.Open);
                            }
                            catch (IOException)
                            {
                                if (stream != null)
                                {
                                    stream.Close();
                                }
                            }
                            if (stream != null)
                            {
                                Farmer farmer = (Farmer)SaveGame.farmerSerializer.Deserialize(stream);
                                NewSaveGame.loadDataToFarmer(farmer, farmer);
                                farmer.favoriteThing = text2.Split(new char[]
                                {
                                    Path.DirectorySeparatorChar
                                }).Last <string>();
                                this.saveGames.Add(farmer);
                                stream.Close();
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            this.saveGames.Sort();
        }