Exemple #1
0
        // Called whenever a player warps, both from and to may be null
        public static void PlayerWarped(Farmer who, GameLocation rawFrom, GameLocation rawTo)
        {
            DeepWoods from = rawFrom as DeepWoods;
            DeepWoods to   = rawTo as DeepWoods;

            if (from != null && to != null && from.Name == to.Name)
            {
                return;
            }

            ModEntry.Log("PlayerWarped from: " + rawFrom?.Name + ", to: " + rawTo?.Name, LogLevel.Trace);

            from?.RemovePlayer(who);
            to?.AddPlayer(who);

            if (from != null && to == null)
            {
                // We left the deepwoods, fix lighting
                DeepWoodsManager.FixLighting();

                // Stop music
                Game1.changeMusicTrack("none");
                Game1.updateMusic();

                // Workaround for bug where players are warped to [0,0] for some reason
                if (rawTo is Woods && who == Game1.player)
                {
                    who.Position = new Vector2(WOODS_WARP_LOCATION.X * 64, WOODS_WARP_LOCATION.Y * 64);
                }
            }

            if (who == Game1.player &&
                from != null &&
                to != null &&
                from.Parent == null &&
                to.Parent == from &&
                !lostMessageDisplayedToday &&
                !to.spawnedFromObelisk.Value &&
                ExitDirToEnterDir(CastEnterDirToExitDir(from.EnterDir)) == to.EnterDir)
            {
                Game1.addHUDMessage(new HUDMessage(I18N.LostMessage)
                {
                    noIcon = true
                });
                lostMessageDisplayedToday = true;
            }

            if (who == Game1.player &&
                to != null &&
                to.level.Value >= Settings.Level.MinLevelForWoodsObelisk &&
                !Game1.player.hasOrWillReceiveMail(WOODS_OBELISK_WIZARD_MAIL_ID) &&
                (Game1.player.mailReceived.Contains("hasPickedUpMagicInk") || Game1.player.hasMagicInk))
            {
                Game1.addMailForTomorrow(WOODS_OBELISK_WIZARD_MAIL_ID);
            }
        }