コード例 #1
0
        private static void checkAnimal(FarmAnimal animal)
        {
            FarmAnimalState state = new FarmAnimalState(animal);

            if (!animals.ContainsKey(animal.myID))
            {
                animals.Add(animal.myID, state);
                if (!ignoreUpdates)
                {
                    Log.trace("Sending animal creation packet");
                    Multiplayer.sendFunc(new FarmAnimalPacket(animal));
                }
                return;
            }

            FarmAnimalState oldState = animals[animal.myID];

            if (state.isDifferentEnoughFromOldStateToSend(oldState))
            {
                animals[animal.myID] = state;
                if (!ignoreUpdates)
                {
                    Multiplayer.sendFunc(new FarmAnimalUpdatePacket(animal));
                }
            }
        }
コード例 #2
0
        private static void checkNPCs(GameLocation loc)
        {
            foreach (NPC npc in loc.characters)
            {
                if (npc.name == "Junimo" || npc.name == "Green Slime" || npc.name == "Frost Helly" || npc.IsMonster || npc is Child)
                {
                    continue;
                }
                if (npc.isMarried() && npc.name != Game1.player.spouse)
                {
                    continue;
                }

                NPCState state = new NPCState(npc);
                if (!npcs.ContainsKey(npc.name))
                {
                    npcs.Add(npc.name, state);
                    continue;
                }

                NPCState oldState = npcs[npc.name];
                if (state.isDifferentEnoughFromOldStateToSend(oldState))
                {
                    npcs[npc.name] = state;
                    if (!ignoreUpdates)
                    {
                        Multiplayer.sendFunc(new NPCUpdatePacket(npc));
                    }
                }
            }
        }
コード例 #3
0
        public static void endChecks()
        {
            foreach (long id in checkMissing)
            {
                if (!Multiplayer.COOP)
                {
                    Log.warn("NOT IMPLEMENTED:ANIMAL DELETION");
                    continue;
                }

                BuildableGameLocation farm = ( BuildableGameLocation )Game1.getLocationFromName("Farm");
                Building buildingAt        = null;
                foreach (Building building in farm.buildings)
                {
                    if (building.tileX == animals[id].homeLoc.X && building.tileY == animals[id].homeLoc.Y)
                    {
                        buildingAt = building;
                        break;
                    }
                }
                if (buildingAt != null)
                {
                    Log.trace("Sending animal deletion packet");
                    animals.Remove(id);
                    Multiplayer.sendFunc(new FarmAnimalPacket(buildingAt, id));
                }
            }
            checkMissing.Clear();
        }
コード例 #4
0
ファイル: Events.cs プロジェクト: phoenx34/StardewValleyMP
        private static void fixCommands(Event @event)
        {
            if (@event.isFestival && prevCommandCount != @event.eventCommands.Count() && prevCommandCount != -1)
            {
                // I'll worry about other festivals another time
                if (@event.FestivalName.Equals("Flower Dance"))
                {
                    Multiplayer.sendFunc(new ContinueEventPacket());
                }
            }
            prevCommandCount = @event.eventCommands.Count();

            if (prevCommand == @event.currentCommand)
            {
                return;
            }

            for (int i = prevCommand + 1; i <= @event.currentCommand; ++i)
            {
                string[] array = @event.eventCommands[Math.Min(@event.eventCommands.Count <string>() - 1, i)].Split(new char[]
                {
                    ' '
                });
                fixCommand(@event, array);
            }
            prevCommand = @event.currentCommand;
        }
コード例 #5
0
ファイル: ChatMenu.cs プロジェクト: blambin/StardewValleyMP
        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;
            }
        }
コード例 #6
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);
                    }
                }
            }
        }