Esempio n. 1
0
 public override bool checkAction(Farmer who, GameLocation l)
 {
     if (!isScared && !isPetted)
     {
         isPetted.Value           = true;
         this.farmerPassesThrough = true;
         who.health  = who.maxHealth;
         who.Stamina = who.MaxStamina;
         who.addedLuckLevel.Value = Math.Max(10, who.addedLuckLevel.Value);
         if (!DeepWoodsState.PlayersWhoGotStardropFromUnicorn.Contains(who.UniqueMultiplayerID))
         {
             who.addItemByMenuIfNecessaryElseHoldUp(new StardewValley.Object(434, 1), null);
             DeepWoodsState.PlayersWhoGotStardropFromUnicorn.Add(who.UniqueMultiplayerID);
             if (!Game1.IsMasterGame)
             {
                 ModEntry.SendMessage(MessageId.SetUnicornStardropReceived, Game1.MasterPlayer.UniqueMultiplayerID);
             }
         }
         else
         {
             l.playSoundAt(Sounds.STARDROP, this.getTileLocation());
         }
         l.playSoundAt(Sounds.ACHIEVEMENT, this.getTileLocation());
         l.playSoundAt(Sounds.HEAL_SOUND, this.getTileLocation());
         l.playSoundAt(Sounds.REWARD, this.getTileLocation());
         l.playSoundAt(Sounds.SECRET1, this.getTileLocation());
         l.playSoundAt(Sounds.SHINY4, this.getTileLocation());
         l.playSoundAt(Sounds.YOBA, this.getTileLocation());
         l.temporarySprites.Add(new TemporaryAnimatedSprite("TileSheets\\animations", new Rectangle(0, 320, 64, 64), 50f, 8, 0, this.Position, false, false));
     }
     return(true);
 }
        public static void RemoveDeepWoodsFromGameLocations(DeepWoods deepWoods)
        {
            // Player might be in this level, teleport them out
            if (Game1.player.currentLocation == deepWoods)
            {
                Game1.warpFarmer(Game1.getLocationRequest("Woods", false), WOODS_WARP_LOCATION.X, WOODS_WARP_LOCATION.Y, 0);
                // Take away all health and energy to avoid cheaters using Save Anywhere to escape getting lost
                if (deepWoods.level.Value > 1 && deepWoods.IsLost)
                {
                    Game1.player.health  = 1;
                    Game1.player.Stamina = 0;
                }
                Game1.player.currentLocation = Game1.getLocationFromName("Woods");
                Game1.player.Position        = new Vector2(WOODS_WARP_LOCATION.X * 64, WOODS_WARP_LOCATION.Y * 64);
            }

            Game1.locations.Remove(deepWoods);
            Game1.removeLocationFromLocationLookup(deepWoods);

            if (Game1.IsMasterGame)
            {
                foreach (Farmer who in Game1.otherFarmers.Values)
                {
                    if (who != Game1.player)
                    {
                        ModEntry.SendMessage(deepWoods.Name, MessageId.RemoveLocation, who.UniqueMultiplayerID);
                    }
                }
            }
        }
 public static void WarpFarmerIntoDeepWoods(int level)
 {
     // Warp into root level if appropriate.
     if (level <= 1)
     {
         Game1.warpFarmer("DeepWoods", Settings.Map.RootLevelEnterLocation.X, Settings.Map.RootLevelEnterLocation.Y, false);
     }
     else if (!Game1.IsMasterGame)
     {
         ModEntry.SendMessage(level, MessageId.RequestWarp, Game1.MasterPlayer.UniqueMultiplayerID);
     }
     else
     {
         WarpFarmerIntoDeepWoods(AddDeepWoodsFromObelisk(level));
     }
 }
        public static void AddDeepWoodsToGameLocations(DeepWoods deepWoods)
        {
            if (deepWoods == null)
            {
                return;
            }

            Game1.locations.Add(deepWoods);

            if (Game1.IsMasterGame)
            {
                foreach (Farmer who in Game1.otherFarmers.Values)
                {
                    if (who != Game1.player)
                    {
                        ModEntry.SendMessage(deepWoods.Name, MessageId.AddLocation, who.UniqueMultiplayerID);
                    }
                }
            }
        }
Esempio n. 5
0
        private void InitGameIfNecessary()
        {
            ModEntry.Log("InitGameIfNecessary(" + isDeepWoodsGameRunning + ")", StardewModdingAPI.LogLevel.Trace);

            if (isDeepWoodsGameRunning)
            {
                return;
            }

            if (Game1.IsMasterGame)
            {
                DeepWoodsSettings.DoLoad();
                DeepWoodsManager.Add();
                EasterEggFunctions.RestoreAllEasterEggsInGame();
                WoodsObelisk.RestoreAllInGame();
                isDeepWoodsGameRunning = true;
            }
            else
            {
                DeepWoodsManager.Remove();
                ModEntry.SendMessage(MessageId.RequestMetadata, Game1.MasterPlayer.UniqueMultiplayerID);
            }
        }
Esempio n. 6
0
 public static void SendMessage(string messageType, long playerID)
 {
     ModEntry.SendMessage(true, messageType, playerID);
 }
Esempio n. 7
0
        private void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e)
        {
            if (e.FromModID != this.ModManifest.UniqueID)
            {
                return;
            }

            ModEntry.Log($"[{(Context.IsMainPlayer ? "host" : "farmhand")}] Received {e.Type} from {e.FromPlayerID}.", LogLevel.Trace);

            switch (e.Type)
            {
            // farmhand requested metadata
            case MessageId.RequestMetadata:
                if (Context.IsMainPlayer)
                {
                    // client requests settings and state, send it:
                    InitResponseMessage response = new InitResponseMessage
                    {
                        Settings   = DeepWoodsSettings.Settings,
                        State      = DeepWoodsSettings.DeepWoodsState,
                        LevelNames = Game1.locations.OfType <DeepWoods>().Select(p => p.Name).ToArray()
                    };
                    ModEntry.SendMessage(response, MessageId.Metadata, e.FromPlayerID);
                }
                break;

            // host sent metadata
            case MessageId.Metadata:
                if (!Context.IsMainPlayer)
                {
                    InitResponseMessage response = e.ReadAs <InitResponseMessage>();
                    DeepWoodsSettings.Settings       = response.Settings;
                    DeepWoodsSettings.DeepWoodsState = response.State;
                    ModEntry.DeepWoodsInitServerAnswerReceived(response.LevelNames);
                }
                break;

            // farmhand requested that we load and activate a DeepWoods level
            case MessageId.RequestWarp:
                if (Context.IsMainPlayer)
                {
                    // load level
                    int       level     = e.ReadAs <int>();
                    DeepWoods deepWoods = DeepWoodsManager.AddDeepWoodsFromObelisk(level);

                    // send response
                    WarpMessage response = new WarpMessage
                    {
                        Level         = deepWoods.Level,
                        Name          = deepWoods.Name,
                        EnterLocation = new Vector2(deepWoods.enterLocation.Value.X, deepWoods.enterLocation.Value.Y)
                    };
                    ModEntry.SendMessage(response, MessageId.Warp, e.FromPlayerID);
                }
                break;

            // host loaded area for warp
            case MessageId.Warp:
                if (!Context.IsMainPlayer)
                {
                    WarpMessage data = e.ReadAs <WarpMessage>();

                    DeepWoodsManager.AddBlankDeepWoodsToGameLocations(data.Name);
                    DeepWoodsManager.WarpFarmerIntoDeepWoodsFromServerObelisk(data.Name, data.EnterLocation);
                }
                break;

            // host sent 'lowest level reached' update
            case MessageId.SetLowestLevelReached:
                if (!Context.IsMainPlayer)
                {
                    DeepWoodsState.LowestLevelReached = e.ReadAs <int>();
                }
                break;

            // host sent 'received stardrop from unicorn' update
            case MessageId.SetUnicornStardropReceived:
                if (Context.IsMainPlayer)
                {
                    DeepWoodsState.PlayersWhoGotStardropFromUnicorn.Add(e.FromPlayerID);
                }
                break;

            // host added/removed location
            case MessageId.AddLocation:
                if (!Context.IsMainPlayer)
                {
                    string name = e.ReadAs <string>();
                    DeepWoodsManager.AddBlankDeepWoodsToGameLocations(name);
                }
                break;

            case MessageId.RemoveLocation:
                if (!Context.IsMainPlayer)
                {
                    string name = e.ReadAs <string>();
                    DeepWoodsManager.RemoveDeepWoodsFromGameLocations(name);
                }
                break;

            default:
                ModEntry.Log("   ignored unknown type.", LogLevel.Trace);
                break;
            }
        }