示例#1
0
 private static Farmer getFarmerFromFarmerNumberString(string s)
 {
     if (s.Equals("farmer"))
     {
         return(Multiplayer.getFarmer(0));
     }
     return(Multiplayer.getFarmer((byte)(Convert.ToInt32(string.Concat(s[s.Count <char>() - 1])) - 1)));
 }
示例#2
0
        private void gotChar(object sender, CharacterEventArgs e)
        {
            if (Game1.activeClickableMenu != this)
            {
                return;
            }
            char c = e.Character;

            if (c == '\r' || c == '\n')
            {
                if (typing == "")
                {
                    exitThisMenu(true);
                    return;
                }

                chat.Add(new ChatEntry(Game1.player, typing));
                if (Multiplayer.mode != Mode.Singleplayer)
                {
                    Multiplayer.sendFunc(new ChatPacket(Multiplayer.getMyId(), typing));
                }

                if (MultiplayerMod.DEBUG)
                {
                    if (typing.StartsWith("/instance ") && typing.Length > 10)
                    {
                        string baseLoc = null;
                        if (Game1.player.currentLocation is StardewValley.Locations.FarmHouse)
                        {
                            baseLoc = "FarmHouse";
                        }
                        if (Game1.player.currentLocation is StardewValley.Locations.Cellar)
                        {
                            baseLoc = "Cellar";
                        }

                        if (baseLoc != null)
                        {
                            Log.debug("Looking for " + baseLoc + "_" + typing.Substring(10));
                            if (Game1.getLocationFromName(baseLoc + "_" + typing.Substring(10)) != null)
                            {
                                Game1.warpFarmer(baseLoc + "_" + typing.Substring(10), (int)Game1.player.position.X / Game1.tileSize, (int)Game1.player.position.Y / Game1.tileSize, false);
                            }
                        }
                    }
                }

                typing = "";
            }
            else if (c == '\b' && typing.Length > 0)
            {
                typing = typing.Substring(0, typing.Length - 1);
            }
            else if (!char.IsControl(c))
            {
                typing += c;
            }
        }
示例#3
0
        public void update()
        {
            for (int i = 0; !delayUpdates && i < clients.Count; ++i)
            {
                clients[i].update();
                if (!clients[i].connected())
                {
                    clients.Remove(clients[i]);
                    --i;
                    continue;
                }
            }

            if (Multiplayer.lobby)
            {
                return;
            }

            if (clients.Count == 0)
            {
                ChatMenu.chat.Add(new ChatEntry(null, "No more clients."));
                Multiplayer.mode   = Mode.Singleplayer;
                Multiplayer.server = null;
                return;
            }

            if (playing && Game1.player != null)
            {
                Multiplayer.doMyPlayerUpdates(0);

                if ((DateTime.Now - lastTimeSync).TotalMilliseconds >= 10000 /*&& Game1.timeOfDay % 100 == 0*/) // 10 seconds? Sure, why not
                {
                    broadcast(new TimeSyncPacket());
                    lastTimeSync = DateTime.Now;
                }
            }/*
              * else if ( !playing && Game1.player != null )
              * {
              * bool othersReady = true;
              * foreach ( Server.Client client in clients )
              * {
              *     othersReady = othersReady && ( client.stage == Client.NetStage.WaitingForStart );
              * }
              *
              * if ( othersReady )
              * {
              *     playing = true;
              * }
              * }*/
        }
示例#4
0
        public void update()
        {
            if (!conn.isConnected())
            {
                ChatMenu.chat.Add(new ChatEntry(null, "You lost connection to the server."));
                Multiplayer.mode   = Mode.Singleplayer;
                Multiplayer.client = null;
                return;
            }

            if (tempStopUpdating)
            {
                return;
            }
            if (stage != NetStage.Waiting)
            {
                processDelayedPackets();
            }

            if (stage == NetStage.Playing)
            {
                Multiplayer.doMyPlayerUpdates(id);
            }

            try
            {
                while (toReceive.Count > 0)
                {
                    Packet packet;
                    bool   success = toReceive.TryTake(out packet);
                    if (!success)
                    {
                        continue;
                    }

                    if (stage == NetStage.Waiting && packet.id != ID.NextDay && packet.id != ID.Chat /*&& packet.id != ID.WorldData*/)
                    {
                        packetDelay.Enqueue(packet);
                    }
                    else
                    {
                        packet.process(this);
                    }
                }
            }
            catch (Exception e)
            {
                Log.error("Exception receiving: " + e);
            }
        }
示例#5
0
        /// <summary>Raised after a player warps to a new location.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        public static void OnWarped(object sender, WarpedEventArgs e)
        {
            try
            {
                if (Multiplayer.mode == Mode.Singleplayer)
                {
                    return;
                }

                Multiplayer.locationChange(e.OldLocation, e.NewLocation);
            }
            catch (Exception ex)
            {
                Log.error("Exception during location change: " + ex);
            }
        }
示例#6
0
        public static void onCurrentLocationChange(object sender, EventArgs args)
        {
            try
            {
                if (Multiplayer.mode == Mode.Singleplayer)
                {
                    return;
                }

                Multiplayer.locationChange((args as EventArgsCurrentLocationChanged).PriorLocation, (args as EventArgsCurrentLocationChanged).NewLocation);
            }
            catch (Exception e)
            {
                Log.error("Exception during location change: " + e);
            }
        }
示例#7
0
        // loc oldName
        public static void fixLocations(List <GameLocation> locations, Farmer from, Action <GameLocation, string> onceFixed = null)
        {
            if (mode == Mode.Client)
            {
                from = client.others[0];
            }

            foreach (GameLocation loc in locations)
            {
                string oldName = loc.name;
                loc.name = Multiplayer.processLocationNameForPlayerUnique(from, loc.name);
                foreach (Warp warp in loc.warps)
                {
                    Util.SetInstanceField(typeof(Warp), warp, "targetName", Multiplayer.processLocationNameForPlayerUnique(from, warp.TargetName));
                }
                foreach (NPC npc in loc.characters)
                {
                    if (npc.defaultMap == null)
                    {
                        continue;
                    }
                    npc.defaultMap = Multiplayer.processLocationNameForPlayerUnique(from, npc.defaultMap);
                }
                if (loc is Farm)
                {
                    Farm farm = loc as Farm;
                    foreach (Building building in farm.buildings)
                    {
                        // TODO
                    }
                }

                if (isPlayerUnique(oldName) && onceFixed != null)
                {
                    onceFixed(loc, oldName);
                }
            }
        }
示例#8
0
        /// <summary>Raised after the game state is updated (≈60 times per second).</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        public static void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
        {
            if (DEBUG)
            {
                Game1.options.pauseWhenOutOfFocus = false;
            }
            try
            {
                IPlatform.instance.update();
                Multiplayer.update();

                // We need our load menu to be able to do things
                if (Game1.activeClickableMenu is TitleMenu)
                {
                    if (TitleMenu.subMenu is LoadGameMenu)
                    {
                        Log.debug("Found vanilla load game menu, replacing with ours.");

                        Multiplayer.lobby = true;

                        LoadGameMenu oldLoadMenu = ( LoadGameMenu )TitleMenu.subMenu;
                        NewLoadMenu  newLoadMenu = new NewLoadMenu();

                        IReflectedField <object> task = instance.Helper.Reflection.GetField <object>(oldLoadMenu, "_initTask");
                        newLoadMenu._initTask = (Task <List <SFarmer> >)task.GetValue();
                        Log.debug("Stole the save listing task, set it to: " + task);

                        TitleMenu.subMenu = newLoadMenu;
                    }
                }
                prevMenu = Game1.activeClickableMenu;
            }
            catch (Exception ex)
            {
                Log.error("Exception during update: " + ex);
            }
        }
示例#9
0
        public static void locationChange(GameLocation oldLoc, GameLocation newLoc)
        {
            string newLocName = getUniqueLocationName(newLoc);

            Log.Async("(Me) " + SaveGame.loaded.player.name + " moved to " + newLocName + " (" + newLoc + ")");
            LocationPacket    loc  = new LocationPacket(getMyId(), newLocName);
            MovingStatePacket move = new MovingStatePacket(getMyId(), Game1.player);

            if (!goingToFestival)
            {
                Multiplayer.sendFunc(loc);
            }
            Multiplayer.sendFunc(move);

            if (Multiplayer.mode == Mode.Host && server.playing)
            {
                // Move everyone to the festival
                if (newLocName == "Temp" && Game1.player.currentLocation.currentEvent != null)
                {
                    foreach (Server.Client other in server.clients)
                    {
                        if (other.farmer.currentLocation != null)
                        {
                            other.farmer.currentLocation.farmers.Remove(other.farmer);
                        }

                        other.farmer.currentLocation = Game1.player.currentLocation;
                        other.farmer.currentLocation.farmers.Add(other.farmer);
                    }
                    goingToFestival = false;
                }
                else if (oldLoc.Name == "Temp")
                {
                    foreach (Server.Client other in server.clients)
                    {
                        if (other.farmer.currentLocation != oldLoc)
                        {
                            continue;
                        }

                        other.farmer.currentLocation.farmers.Remove(other.farmer);

                        other.farmer.currentLocation = Game1.player.currentLocation;
                        other.farmer.currentLocation.farmers.Add(other.farmer);
                    }
                }
            }
            else if (Multiplayer.mode == Mode.Client && client.stage == Client.NetStage.Playing)
            {
                if (newLocName == "Temp" && Game1.player.currentLocation.currentEvent != null)
                {
                    foreach (KeyValuePair <byte, Farmer> other in client.others)
                    {
                        if (other.Value.currentLocation != null)
                        {
                            other.Value.currentLocation.farmers.Remove(other.Value);
                        }

                        other.Value.currentLocation = Game1.player.currentLocation;
                        other.Value.currentLocation.farmers.Add(other.Value);
                    }
                    goingToFestival = false;
                }
                else if (oldLoc.Name == "Temp")
                {
                    foreach (KeyValuePair <byte, Farmer> other in client.others)
                    {
                        if (other.Value.currentLocation != oldLoc)
                        {
                            continue;
                        }

                        other.Value.currentLocation.farmers.Remove(other.Value);

                        other.Value.currentLocation = Game1.player.currentLocation;
                        other.Value.currentLocation.farmers.Add(other.Value);
                    }
                }
            }
        }
示例#10
0
 /// <summary>Raised before the game begins writes data to the save file (except the initial save creation).</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event arguments.</param>
 public static void OnSaving(object sender, EventArgs e)
 {
     Multiplayer.onBeforeSave();
 }
示例#11
0
        private static void fixFlowerDance(Event dance, Dictionary <string, string> data)
        {
            if (dance.playerControlSequence || didFixDance)
            {
                return;
            }
            if (dance.eventCommands[0] != "pause 500")
            {
                return;
            }
            Log.Async("Flower dance beginning, fixing");
            didFixDance = true;

            // Copied from Event.setupFestivalMainEvent
            // All I did was make it use our players
            List <string> list  = new List <string>();
            List <string> list2 = new List <string>();
            List <string> list3 = new List <string>
            {
                "Abigail",
                "Penny",
                "Leah",
                "Maru",
                "Haley"
            };
            List <string> list4 = new List <string>
            {
                "Sebastian",
                "Sam",
                "Elliott",
                "Harvey",
                "Alex"
            };

            for (int i = 0; i < Multiplayer.getFarmerCount(); i++)
            {
                Farmer farmerFromFarmerNumber = Multiplayer.getFarmer(( byte )i);
                if (farmerFromFarmerNumber.dancePartner != null)
                {
                    if (farmerFromFarmerNumber.dancePartner.gender == 1)
                    {
                        list.Add(farmerFromFarmerNumber.dancePartner.name);
                        list3.Remove(farmerFromFarmerNumber.dancePartner.name);
                        list2.Add("farmer" + (i + 1));
                    }
                    else
                    {
                        list2.Add(farmerFromFarmerNumber.dancePartner.name);
                        list4.Remove(farmerFromFarmerNumber.dancePartner.name);
                        list.Add("farmer" + (i + 1));
                    }
                }
            }
            while (list.Count <string>() < 5)
            {
                string text = list3.Last <string>();
                if (list4.Contains(Utility.getLoveInterest(text)))
                {
                    list.Add(text);
                    list2.Add(Utility.getLoveInterest(text));
                }
                list3.Remove(text);
            }
            string text2 = data["mainEvent"];

            for (int j = 1; j <= 5; j++)
            {
                text2 = text2.Replace("Girl" + j, list[j - 1]);
                text2 = text2.Replace("Guy" + j, list2[j - 1]);
            }
            Regex regex  = new Regex("showFrame (?<farmerName>farmer\\d) 44");
            Regex regex2 = new Regex("showFrame (?<farmerName>farmer\\d) 40");
            Regex regex3 = new Regex("animate (?<farmerName>farmer\\d) false true 600 44 45");
            Regex regex4 = new Regex("animate (?<farmerName>farmer\\d) false true 600 43 41 43 42");
            Regex regex5 = new Regex("animate (?<farmerName>farmer\\d) false true 300 46 47");
            Regex regex6 = new Regex("animate (?<farmerName>farmer\\d) false true 600 46 47");

            text2 = regex.Replace(text2, "showFrame $1 12/faceDirection $1 0");
            text2 = regex2.Replace(text2, "showFrame $1 0/faceDirection $1 2");
            text2 = regex3.Replace(text2, "animate $1 false true 600 12 13 12 14");
            text2 = regex4.Replace(text2, "animate $1 false true 596 4 0");
            text2 = regex5.Replace(text2, "animate $1 false true 150 12 13 12 14");
            text2 = regex6.Replace(text2, "animate $1 false true 600 0 3");
            string[] array = text2.Split(new char[]
            {
                '/'
            });
            dance.eventCommands = array;
        }
示例#12
0
 public static void onBeforeSave(object sender, EventArgs args)
 {
     Multiplayer.onBeforeSave();
 }