// 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); } }
private void GameEvents_UpdateTick(object sender, EventArgs args) { if (!isDeepWoodsGameRunning) { return; } WorkErrorMessageQueue(); Dictionary <long, GameLocation> newPlayerLocations = new Dictionary <long, GameLocation>(); foreach (Farmer farmer in Game1.getOnlineFarmers()) { newPlayerLocations.Add(farmer.UniqueMultiplayerID, farmer.currentLocation); } // Detect any farmer who left, joined or changed location. foreach (var playerLocation in playerLocations) { if (!newPlayerLocations.ContainsKey(playerLocation.Key)) { // player left PlayerWarped(Game1.getFarmer(playerLocation.Key), playerLocation.Value, null); } else if (playerLocation.Value?.Name != newPlayerLocations[playerLocation.Key]?.Name) { // player warped PlayerWarped(Game1.getFarmer(playerLocation.Key), playerLocation.Value, newPlayerLocations[playerLocation.Key]); } } foreach (var newPlayerLocation in newPlayerLocations) { if (!playerLocations.ContainsKey(newPlayerLocation.Key)) { // player joined PlayerWarped(Game1.getFarmer(newPlayerLocation.Key), null, newPlayerLocation.Value); } } // Update cache playerLocations = newPlayerLocations; // DeepWoodsManager.LocalTick(); // Fix lighting in Woods and DeepWoods DeepWoodsManager.FixLighting(); // Add woods obelisk to wizard shop if possible and necessary, // intercept Building.obeliskWarpForReal() calls. WoodsObelisk.InjectWoodsObeliskIntoGame(); }
protected override void resetLocalState() { base.resetLocalState(); // TODO: Better critter spawning in forest this.tryToAddCritters(false); ModEntry.GetAPI().CallBeforeDebrisCreation(this); if (!ModEntry.GetAPI().CallOverrideDebrisCreation(this)) { DeepWoodsDebris.Initialize(this); } ModEntry.GetAPI().CallAfterDebrisCreation(this); foreach (Vector2 lightSource in this.lightSources) { Game1.currentLightSources.Add(new LightSource(LightSource.indoorWindowLight, lightSource * 64f, 1.0f)); } DeepWoodsManager.FixLighting(); }