Пример #1
0
 /// <summary>
 /// Handles broadcasting data from player to player.
 /// </summary>
 /// <param name="multiplayer">SMAPI's multiplayer helper.</param>
 /// <param name="playerIDs">Player IDs to send to. Leave null to mean everyone.</param>
 internal static void BroadcastData(IMultiplayerHelper multiplayer, long[]?playerIDs = null)
 {
     if (Context.IsMultiplayer)
     {
         multiplayer.SendMessage(data, RecieveDataValue, new[] { ModEntry.UNIQUEID }, playerIDs);
     }
 }
Пример #2
0
        /// <summary>
        /// The main player removes the warp at the portalPosition
        /// </summary>
        public static bool RemoveWarp(PortalPosition portalPosition, bool IsMainPlayer, PortalGunManager portalGuns, IMultiplayerHelper multiplayer, string uniqueModId)
        {
            // Warps are global, so only have host handle them to avoid duplicates and ghosts
            if (!IsMainPlayer)
            {
                multiplayer.SendMessage(portalPosition, "RemoveWarp", modIDs: new[] { uniqueModId });
                return(false);
            }
            string locationName = portalPosition.LocationName;

            if (locationName == "" || locationName == null)
            {
                return(false);
            }
            GameLocation location = Game1.getLocationFromName(portalPosition.LocationName);

            // remove the warp from the location
            Warp warp = portalGuns.GetWarp(portalPosition);

            if (warp != null)
            {
                location.warps.Remove(portalGuns.GetWarp(portalPosition));
            }

            return(true);
        }
 public static void SendMessageInMultiplayer <TMessage>(this IMultiplayerHelper self, Func <TMessage> message, string type, string[]?modIDs = null, long[]?playerIDs = null)
     where TMessage : notnull
 {
     if (GameExt.GetMultiplayerMode() != MultiplayerMode.SinglePlayer)
     {
         self.SendMessage(message(), type, modIDs, playerIDs);
     }
 }
Пример #4
0
        /// <summary>Send a message to all connected peers.</summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="message">Message to send. Can be plain text or even class objects.</param>
        /// <param name="type">Identifier for the message type.</param>
        public static void SendMessage <T>(T message, string type)
        {
            if (!Context.IsMultiplayer)
            {
                return;
            }

            Logger.Trace("Sending message to peers. Type = " + type);
            helper.SendMessage(message, type, new[] { ModId });
        }
Пример #5
0
        private void OnModMessageRecieved(object sender, ModMessageReceivedEventArgs e)
        {
            if (e.FromModID == "KoihimeNakamura.LunarDisturbances" && e.Type == "NewFarmHandJoin" && Context.IsMainPlayer && !HasGottenSync)
            {
                MoonMessage message = GenerateLunarSync();
                MPHandler.SendMessage <MoonMessage>(message, "MoonMessage", new[] { "KoihimeNakamura.LunarDisturbances" }, new[] { e.FromPlayerID });
                HasGottenSync = true;
            }

            if (e.FromModID == "KoihimeNakamura.LunarDisturbances" && e.Type == "MoonMessage")
            {
                MoonMessage message = e.ReadAs <MoonMessage>();
                if (ModConfig.Verbose)
                {
                    Monitor.Log($"Message contents at {Game1.timeOfDay} : Eclipse Setting: {message.isEclipse})");
                }
                SetLunarSync(message);
            }
        }
        private void OnModMessageRecieved(object sender, ModMessageReceivedEventArgs e)
        {
            if (e.FromModID == "KoihimeNakamura.ClimatesOfFerngill" && e.Type == "NewFarmHandJoin" && Context.IsMainPlayer && !HasGottenSync)
            {
                if (!Conditions.IsTodayTempSet)
                {
                    Conditions.SetTodayTemps(GameClimate.GetTemperatures(SDate.Now(), Dice));
                }

                WeatherSync message = Conditions.GenerateWeatherSyncMessage();
                MPHandler.SendMessage <WeatherSync>(message, "WeatherSync", new[] { "KoihimeNakamura.ClimatesOfFerngill" }, new[] { e.FromPlayerID });
                HasGottenSync = true;
            }

            if (e.FromModID == "KoihimeNakamura.ClimatesOfFerngill" && e.Type == "WeatherSync")
            {
                WeatherSync message = e.ReadAs <WeatherSync>();
                if (WeatherOpt.Verbose)
                {
                    Monitor.Log($"Message contents at {Game1.timeOfDay} : {GenSyncMessageString(message)}");
                }
                Conditions.SetSync(message);
            }
        }
Пример #7
0
        /// <summary>
        /// The main player adds the warp to the world
        /// </summary>
        public static bool AddWarp(PortalPosition portalPosition, bool IsMainPlayer, PortalGunManager portalGuns, IMultiplayerHelper multiplayer, string uniqueModId)
        {
            if (portalPosition.LocationName == "" || portalPosition.LocationName == null)
            {
                return(false);
            }
            // Warps are global, so only have host handle them to avoid duplicates and ghosts
            if (!IsMainPlayer)
            {
                multiplayer.SendMessage(portalPosition, "AddWarp", modIDs: new[] { uniqueModId });
                return(true);
            }
            // if a warp was created, add it
            Warp warp = portalGuns.GetWarp(portalPosition);

            if (warp == null)
            {
                return(false);
            }

            // add it to the game location
            Game1.getLocationFromName(portalPosition.LocationName).warps.Add(warp);
            return(true);
        }
 public static void SendMessage <TMessage>(this IMultiplayerHelper self, TMessage message, string[]?modIDs = null, long[]?playerIDs = null)
     where TMessage : notnull
 => self.SendMessage(message, typeof(TMessage).GetBestName(), modIDs, playerIDs);