public static void DoLoad() { if (!Game1.IsMasterGame) { return; } ModEntry.Log("DeepWoodsSettings.DoLoad()", StardewModdingAPI.LogLevel.Trace); // load data DeepWoodsState = ModEntry.GetHelper().Data.ReadSaveData <DeepWoodsStateData>("data"); if (DeepWoodsState == null) { // legacy file FileInfo legacyFile = new FileInfo($"{Constants.CurrentSavePath}/{SAVE_FILE_NAME}.json"); if (legacyFile.Exists) { DeepWoodsState = JsonConvert.DeserializeObject <DeepWoodsStateData>(File.ReadAllText(legacyFile.FullName)); } } if (DeepWoodsState == null) { DeepWoodsState = new DeepWoodsStateData(); } // init settings Settings = ModEntry.GetHelper().ReadConfig <DeepWoodsSettings>() ?? new DeepWoodsSettings(); }
public override bool performUseAction(Vector2 tileLocation, GameLocation location) { if (this.wasPickedUp.Value) { return(false); } if (Game1.player.addItemToInventoryBool(new EasterEggItem(), false)) { this.wasPickedUp.Value = true; try { Game1.player.currentLocation.playSound("coin"); if (!(Game1.player.FarmerSprite is DeepWoodsMod.FarmerSprite)) { Game1.player.FarmerSprite = new DeepWoodsMod.FarmerSprite(Game1.player.FarmerSprite); } Game1.player.animateOnce(StardewValley.FarmerSprite.harvestItemUp + Game1.player.FacingDirection); Game1.player.canMove = false; } catch (Exception e) { ModEntry.Log("Failed to play pickup animation: " + e, StardewModdingAPI.LogLevel.Warn); } return(true); } else { Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Crop.cs.588")); return(false); } }
private void SaveEvents_BeforeSave(object sender, EventArgs args) { ModEntry.Log("SaveEvents_BeforeSave", StardewModdingAPI.LogLevel.Trace); isBeforeSaveCount++; if (isBeforeSaveCount > 1) { ModEntry.Log("BeforeSave event was called twice in a row. Ignoring second call.", StardewModdingAPI.LogLevel.Warn); return; } DeepWoodsManager.Remove(); EasterEggFunctions.RemoveAllEasterEggsFromGame(); WoodsObelisk.RemoveAllFromGame(); DeepWoodsSettings.DoSave(); foreach (var who in Game1.getAllFarmers()) { if (who.currentLocation is DeepWoods) { who.currentLocation = Game1.getLocationFromName("Woods"); who.Position = new Vector2(WOODS_WARP_LOCATION.X * 64, WOODS_WARP_LOCATION.Y * 64); } } }
private void SaveEvents_AfterReturnToTitle(object sender, EventArgs args) { ModEntry.Log("GameEvents_AfterReturnToTitle", StardewModdingAPI.LogLevel.Trace); isDeepWoodsGameRunning = false; hasRequestedInitMessageFromServer = false; }
private void InitGameIfNecessary() { ModEntry.Log("InitGameIfNecessary(" + isDeepWoodsGameRunning + ")", StardewModdingAPI.LogLevel.Trace); // Make sure our interceptor is set. // E.g. MTN overrides Game1.multiplayer instead of wrapping. Game1MultiplayerAccessProvider.InterceptMultiplayerIfNecessary(); if (isDeepWoodsGameRunning) { return; } if (Game1.IsMasterGame) { DeepWoodsSettings.DoLoad(); DeepWoodsManager.Add(); EasterEggFunctions.RestoreAllEasterEggsInGame(); WoodsObelisk.RestoreAllInGame(); isDeepWoodsGameRunning = true; } else { DeepWoodsManager.Remove(); hasRequestedInitMessageFromServer = true; Game1.MasterPlayer.queueMessage(Settings.Network.DeepWoodsMessageId, Game1.player, new object[] { NETWORK_MESSAGE_DEEPWOODS_INIT }); } }
private static bool IsInterceptedMultiplayer(Multiplayer multiplayer) { if (multiplayer == null) { ModEntry.Log("IsInterceptedMultiplayer: null", StardewModdingAPI.LogLevel.Trace); return(false); } ModEntry.Log("IsInterceptedMultiplayer called on: " + multiplayer.GetType().Name, StardewModdingAPI.LogLevel.Trace); if (multiplayer is InterceptingMultiplayer) { ModEntry.Log("IsInterceptedMultiplayer: true", StardewModdingAPI.LogLevel.Trace); return(true); } // Since other mods can also write a multiplayer wrapper, // we recursively check fields for an instance of our class. // (Otherwise we might create an infinite loop.) foreach (var field in multiplayer.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)) { if (IsMultiplayerType(field.GetType())) { ModEntry.Log("IsInterceptedMultiplayer, nested field: " + field.Name, StardewModdingAPI.LogLevel.Trace); if (IsInterceptedMultiplayer(field.GetValue(multiplayer) as Multiplayer)) { return(true); } } } ModEntry.Log("IsInterceptedMultiplayer: false", StardewModdingAPI.LogLevel.Trace); return(false); }
private static bool IsMultiplayerType(Type t) { bool result = t.IsSubclassOf(typeof(Multiplayer)) || t == typeof(Multiplayer); ModEntry.Log("IsMultiplayerType: " + t.Name + " (" + result + ")", StardewModdingAPI.LogLevel.Trace); return(result); }
private void InitAfterLoad() { ModEntry.Log("SaveEvents_AfterLoad", StardewModdingAPI.LogLevel.Trace); isDeepWoodsGameRunning = false; InitGameIfNecessary(); }
public static void InterceptMultiplayerIfNecessary() { ModEntry.Log("InterceptMultiplayerIfNecessary", StardewModdingAPI.LogLevel.Trace); if (!IsInterceptedMultiplayer(Game1.multiplayer)) { InterceptMultiplayer(); } }
private void SaveEvents_AfterLoad(object sender, EventArgs args) { ModEntry.Log("SaveEvents_AfterLoad", StardewModdingAPI.LogLevel.Trace); isDeepWoodsGameRunning = false; hasRequestedInitMessageFromServer = false; InitGameIfNecessary(); }
public DeepWoods(DeepWoods parent, int level, EnterDirection enterDir) : this() { base.isOutdoors.Value = true; base.ignoreDebrisWeather.Value = true; base.ignoreOutdoorLighting.Value = true; this.hasReceivedNetworkData.Value = true; this.uniqueMultiplayerID.Value = Game1.MasterPlayer.UniqueMultiplayerID; this.seed = DeepWoodsRandom.CalculateSeed(level, enterDir, parent?.Seed); if (level == 1) { base.name.Value = "DeepWoods"; } else { base.name.Value = "DeepWoods_" + this.seed; } this.parentName.Value = parent?.Name; this.ParentExitLocation = parent?.GetExit(EnterDirToExitDir(enterDir))?.Location ?? new Location(); this.level.Value = level; DeepWoodsState.LowestLevelReached = Math.Max(DeepWoodsState.LowestLevelReached, this.level.Value - 1); this.EnterDir = enterDir; this.spawnTime.Value = Game1.timeOfDay; this.spawnedFromObelisk.Value = parent?.spawnedFromObelisk?.Value ?? false; ModEntry.GetAPI().CallOnCreate(this); CreateSpace(); DetermineExits(); updateMap(); ModEntry.GetAPI().CallBeforeFill(this); if ((this.isLichtung.Value && this.lichtungHasLake.Value) || !ModEntry.GetAPI().CallOverrideFill(this)) { DeepWoodsStuffCreator.AddStuff(this, new DeepWoodsRandom(this, this.seed ^ Game1.currentGameTime.TotalGameTime.Milliseconds ^ Game1.random.Next())); } ModEntry.GetAPI().CallAfterFill(this); ModEntry.GetAPI().CallBeforeMonsterGeneration(this); if (!ModEntry.GetAPI().CallOverrideMonsterGeneration(this)) { DeepWoodsMonsters.AddMonsters(this, new DeepWoodsRandom(this, this.seed ^ Game1.currentGameTime.TotalGameTime.Milliseconds ^ Game1.random.Next())); } ModEntry.GetAPI().CallAfterMonsterGeneration(this); if (parent == null && level > 1 && !this.HasExit(CastEnterDirToExitDir(this.EnterDir))) { this.exits.Add(new DeepWoodsExit(this, CastEnterDirToExitDir(this.EnterDir), this.EnterLocation)); } if (parent != null) { ModEntry.Log($"Child spawned, time: {Game1.timeOfDay}, name: {this.Name}, level: {this.level}, parent: {this.parentName}, enterDir: {this.EnterDir}, enterLocation: {this.EnterLocation.X}, {this.EnterLocation.Y}", LogLevel.Trace); } }
// 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); } }
public void FixPlayerPosAfterWarp(Farmer who) { // Only fix position for local player if (who != Game1.player) { return; } // Check if level is properly initialized if (this.map == null || this.map.Id != this.Name || this.Seed == 0 || !this.HasReceivedNetworkData || mapWidth.Value == 0 || mapHeight.Value == 0) { return; } ModEntry.Log($"FixPlayerPosAfterWarp: {this.Name}, mapWidth: {mapWidth}", LogLevel.Trace); // First check for current warp request (stored globally for local player): if (DeepWoodsManager.currentWarpRequestName == this.Name && DeepWoodsManager.currentWarpRequestLocation.HasValue) { who.Position = DeepWoodsManager.currentWarpRequestLocation.Value; DeepWoodsManager.currentWarpRequestName = null; DeepWoodsManager.currentWarpRequestLocation = null; } else { // If no current warp request is known, we will heuristically determine the nearest valid location: Vector2 nearestEnterLocation = new Vector2(EnterLocation.X * 64, EnterLocation.Y * 64); float nearestEnterLocationDistance = (nearestEnterLocation - who.Position).Length(); int faceDirection = EnterDirToFacingDirection(this.EnterDir); foreach (var exit in this.exits) { Vector2 exitLocation = new Vector2(exit.Location.X * 64, exit.Location.Y * 64); float exitDistance = (exitLocation - who.Position).Length(); if (exitDistance < nearestEnterLocationDistance) { nearestEnterLocation = exitLocation; nearestEnterLocationDistance = exitDistance; faceDirection = EnterDirToFacingDirection(CastExitDirToEnterDir(exit.ExitDir)); } } who.Position = nearestEnterLocation; // who.faceDirection(faceDirection); // Keep original face direction } // Finally fix any errors on the border (this still happens according to some bug reports) who.Position = new Vector2( Math.Max(0, Math.Min((mapWidth - 1) * 64, who.Position.X)), Math.Max(0, Math.Min((mapHeight - 1) * 64, who.Position.Y)) ); }
private void OpenPassageInSecretWoods(Woods woods) { // TODO: Configurable (and moddable!) locations to modify Woods // Game isn't running if (!isDeepWoodsGameRunning) { ModEntry.Log("OpenPassageInSecretWoods: Cancelled, mod not initialized.", LogLevel.Trace); return; } Layer buildingsLayer = woods.map.GetLayer("Buildings"); // Just to be sure if (buildingsLayer == null) { ModEntry.Log("OpenPassageInSecretWoods: Cancelled, invalid map (buildingsLayer is null).", LogLevel.Trace); return; } // Already patched if (buildingsLayer.Tiles[29, 25] == null) { ModEntry.Log("OpenPassageInSecretWoods: Cancelled, map incompatible or already patched.", LogLevel.Trace); return; } ModEntry.Log("OpenPassageInSecretWoods", LogLevel.Trace); TileSheet borderTileSheet = buildingsLayer.Tiles[29, 25].TileSheet; int borderTileIndex = buildingsLayer.Tiles[29, 25].TileIndex; buildingsLayer.Tiles[29, 25] = null; buildingsLayer.Tiles[29, 26] = null; for (int x = 24; x < 29; x++) { buildingsLayer.Tiles[x, 24] = new StaticTile(buildingsLayer, borderTileSheet, BlendMode.Alpha, borderTileIndex); woods.warps.Add(new Warp(x, 32, "DeepWoods", Settings.Map.RootLevelEnterLocation.X, Settings.Map.RootLevelEnterLocation.Y + 1, false)); } /* * foreach (var location in DeleteBuildingTiles) * { * } * * foreach (var location in AddBuildingTiles) * { * } * * foreach (var location in WarpLocations) * { * } */ }
public static void Add() { if (!Game1.IsMasterGame) { return; } ModEntry.Log("DeepWoodsManager.Add()", StardewModdingAPI.LogLevel.Trace); CheckValid(); }
public static void DoLoad() { if (!Game1.IsMasterGame) { return; } ModEntry.Log("DeepWoodsSettings.DoLoad()", StardewModdingAPI.LogLevel.Trace); // load data DeepWoodsState = ModEntry.GetHelper().Data.ReadSaveData <DeepWoodsStateData>("data"); if (DeepWoodsState == null) { // legacy file FileInfo legacyFile = new FileInfo($"{Constants.CurrentSavePath}/{SAVE_FILE_NAME}.json"); ModEntry.Log("DeepWoodsSettings.DoLoad: Couldn't find savedata, trying legacy save: " + legacyFile.FullName, StardewModdingAPI.LogLevel.Trace); if (legacyFile.Exists) { ModEntry.Log("DeepWoodsSettings.DoLoad: Loading legacy save.", StardewModdingAPI.LogLevel.Trace); DeepWoodsState = JsonConvert.DeserializeObject <DeepWoodsStateData>(File.ReadAllText(legacyFile.FullName)); } } if (DeepWoodsState == null) { ModEntry.Log("DeepWoodsSettings.DoLoad: No savedata, falling back to default.", StardewModdingAPI.LogLevel.Trace); DeepWoodsState = new DeepWoodsStateData(); } // init settings ModEntry.Log("DeepWoodsSettings.DoLoad: Loading settings.", StardewModdingAPI.LogLevel.Trace); DeepWoodsSettings settings = ModEntry.GetHelper().ReadConfig <DeepWoodsSettings>(); if (settings == null) { ModEntry.Log("Settings are null, using defaults.", StardewModdingAPI.LogLevel.Trace); Settings = new DeepWoodsSettings(); } else { ModEntry.Log("Settings loaded successfully.", StardewModdingAPI.LogLevel.Trace); Settings = settings; if (Settings.WoodsPassage.AddBuildingTiles.Length == 0 && Settings.WoodsPassage.DeleteBuildingTiles.Length == 0 && Settings.WoodsPassage.WarpLocations.Length == 0) { Settings.WoodsPassage = new WoodsPassageSettings(); } } ModEntry.Log("DeepWoodsSettings.DoLoad: Done.", StardewModdingAPI.LogLevel.Trace); }
private static void InterceptMultiplayer() { if (Game1.multiplayer == null) { ModEntry.Log("InterceptMultiplayer: null", StardewModdingAPI.LogLevel.Debug); } else { ModEntry.Log("InterceptMultiplayer: " + Game1.multiplayer.GetType().Name, StardewModdingAPI.LogLevel.Debug); } Game1.multiplayer = new InterceptingMultiplayer(Game1.multiplayer); }
private static void ProcessLocation(GameLocation location, ProcessMethod method) { if (location == null) { return; } ModEntry.Log("EasterEggFunctions.ProcessLocation(" + location.Name + ", " + method + ")", StardewModdingAPI.LogLevel.Trace); if (processedLocations.Contains(location)) { ModEntry.Log("EasterEggFunctions.ProcessLocation(" + location.Name + ", " + method + "): Already processed this location (infinite recursion?), aborting!", StardewModdingAPI.LogLevel.Warn); return; } processedLocations.Add(location); if (location is BuildableGameLocation buildableGameLocation) { foreach (Building building in buildableGameLocation.buildings) { ProcessLocation(building.indoors.Value, method); if (building is Mill mill) { ProcessItemList(mill.output.Value.items, method); } else if (building is JunimoHut hut) { ProcessItemList(hut.output.Value.items, method); } } } if (location is DecoratableLocation decoratableLocation) { foreach (Furniture furniture in decoratableLocation.furniture) { furniture.heldObject.Value = (StardewValley.Object)ProcessSingleItem(furniture.heldObject.Value, method); } } if (location is FarmHouse farmHouse) { ProcessItemList(farmHouse.fridge.Value.items, method); } foreach (var key in new List <Vector2>(location.objects.Keys)) { location.objects[key] = (StardewValley.Object)ProcessSingleItem(location.objects[key], method); } }
private void TimeEvents_AfterDayStarted(object sender, EventArgs args) { ModEntry.Log("TimeEvents_AfterDayStarted", StardewModdingAPI.LogLevel.Trace); InitGameIfNecessary(); if (!isDeepWoodsGameRunning) { return; } DeepWoodsManager.LocalDayUpdate(Game1.dayOfMonth); EasterEggFunctions.InterceptIncubatorEggs(); }
public static void DeepWoodsInitServerAnswerReceived(List <string> deepWoodsLevelNames) { if (Game1.IsMasterGame) { return; } ModEntry.Log("DeepWoodsInitServerAnswerReceived", StardewModdingAPI.LogLevel.Debug); DeepWoodsManager.AddAll(deepWoodsLevelNames); EasterEggFunctions.RestoreAllEasterEggsInGame(); // WoodsObelisk.RestoreAllInGame(); <- Not needed, server already sends correct building mod.isDeepWoodsGameRunning = true; }
public override bool performUseAction(Vector2 tileLocation, GameLocation location) { if (this.swordPulledOut.Value) { return(true); } if (Game1.player.DailyLuck >= 0.25 && Game1.player.LuckLevel >= DeepWoodsGlobals.MAXIMUM_POSSIBLE_LUCKLEVEL && Game1.player.MiningLevel >= 10 && Game1.player.ForagingLevel >= 10 && Game1.player.FishingLevel >= 10 && Game1.player.FarmingLevel >= 10 && Game1.player.CombatLevel >= 10 && (Game1.player.timesReachedMineBottom >= 1 || Game1.MasterPlayer.timesReachedMineBottom >= 1) && Game1.getFarm().grandpaScore.Value >= 4 && (!Game1.player.mailReceived.Contains("JojaMember") && !Game1.MasterPlayer.mailReceived.Contains("JojaMember")) && (Game1.player.hasCompletedCommunityCenter() || Game1.MasterPlayer.hasCompletedCommunityCenter())) { location.playSoundAt(Sounds.YOBA, this.tilePosition.Value); Game1.player.addItemByMenuIfNecessaryElseHoldUp(Excalibur.GetOne()); this.swordPulledOut.Value = true; } else { location.playSoundAt(Sounds.THUD_STEP, this.tilePosition.Value); Game1.showRedMessage("It won't budge."); ModEntry.Log($"Excalibur doesn't budge. " + $" DailyLuck is {Game1.player.DailyLuck}, must be >= 0.25. " + $" LuckLevel is {Game1.player.LuckLevel}, must be >= {DeepWoodsGlobals.MAXIMUM_POSSIBLE_LUCKLEVEL}. " + $" MiningLevel is {Game1.player.MiningLevel}, must be >= 10. " + $" ForagingLevel is {Game1.player.ForagingLevel}, must be >= 10. " + $" FishingLevel is {Game1.player.FishingLevel}, must be >= 10. " + $" FarmingLevel is {Game1.player.FarmingLevel}, must be >= 10. " + $" CombatLevel is {Game1.player.CombatLevel}, must be >= 10. " + $" timesReachedMineBottom is {Math.Max(Game1.player.timesReachedMineBottom, Game1.MasterPlayer.timesReachedMineBottom)}, must be >= 1. " + $" grandpaScore is {Game1.getFarm().grandpaScore.Value}, must be >= 4. " + $" JojaMember is {Game1.player.mailReceived.Contains("JojaMember") || Game1.MasterPlayer.mailReceived.Contains("JojaMember")}, must be false. " + $" hasCompletedCommunityCenter is {(Game1.player.hasCompletedCommunityCenter() || Game1.MasterPlayer.hasCompletedCommunityCenter())}, must be true." + $"", StardewModdingAPI.LogLevel.Info); } return(true); }
public static void RestoreAllInGame() { if (!Game1.IsMasterGame) { return; } ModEntry.Log("WoodsObelisk.RestoreAllInGame()", StardewModdingAPI.LogLevel.Trace); processedLocations.Clear(); foreach (GameLocation location in Game1.locations) { ProcessAllInLocation(location, ProcessMethod.Restore); } processedLocations.Clear(); }
private static Item ProcessSingleItem(Item item, ProcessMethod method) { if (item == null) { return(item); } if (processedItems.Contains(item)) { ModEntry.Log("EasterEggFunctions.ProcessSingleItem(" + item.Name + ", " + method + "): Already processed this item (infinite recursion?), aborting!", StardewModdingAPI.LogLevel.Warn); return(item); } processedItems.Add(item); if (item is Chest chest) { ProcessItemList(chest.items, method); } else if (item is StardewValley.Object @object && @object.heldObject.Value is Chest chest2) { ProcessItemList(chest2.items, method); } if (method == ProcessMethod.Remove && item is EasterEggItem easterEggItem) { return(new StardewValley.Object(EASTER_EGG_REPLACEMENT_ITEM, easterEggItem.Stack) { name = UNIQUE_NAME_FOR_EASTER_EGG_ITEMS }); } else if (method == ProcessMethod.Restore && item is StardewValley.Object @object && @object.ParentSheetIndex == EASTER_EGG_REPLACEMENT_ITEM && @object.name == UNIQUE_NAME_FOR_EASTER_EGG_ITEMS) { return(new EasterEggItem() { Stack = @object.Stack }); } return(item); }
public void RemovePlayer(Farmer who) { ModEntry.Log("RemovePlayer(" + who.UniqueMultiplayerID + "): " + this.Name, LogLevel.Debug); if (who == Game1.player) { if (DeepWoodsManager.currentDeepWoods == this) { DeepWoodsManager.currentDeepWoods = null; } } if (!Game1.IsMasterGame) { return; } this.playerCount.Value = this.playerCount.Value - 1; }
public void RemovePlayer(Farmer who) { ModEntry.Log($"RemovePlayer({who.UniqueMultiplayerID}): {this.Name}", LogLevel.Trace); if (who == Game1.player) { if (DeepWoodsManager.currentDeepWoods == this) { DeepWoodsManager.currentDeepWoods = null; } } if (!Game1.IsMasterGame) { return; } this.playerCount.Value = this.playerCount.Value - 1; }
public void AddPlayer(Farmer who) { ModEntry.Log($"AddPlayer({who.UniqueMultiplayerID}): {this.Name}", LogLevel.Trace); if (who == Game1.player) { // Fix enter position (some bug I haven't figured out yet spawns network clients outside the map delimiter...) FixPlayerPosAfterWarp(who); DeepWoodsManager.currentDeepWoods = this; } if (!Game1.IsMasterGame) { return; } this.hasEverBeenVisited.Value = true; this.playerCount.Value = this.playerCount.Value + 1; ValidateAndIfNecessaryCreateExitChildren(); }
public static void RestoreAllEasterEggsInGame() { ModEntry.Log("EasterEggFunctions.RestoreAllEasterEggsInGame()", StardewModdingAPI.LogLevel.Trace); processedLocations.Clear(); processedItems.Clear(); foreach (GameLocation location in Game1.locations) { ProcessLocation(location, ProcessMethod.Restore); } foreach (Farmer farmer in Game1.getOnlineFarmers()) { ProcessItemList(farmer.items, ProcessMethod.Restore); } processedLocations.Clear(); processedItems.Clear(); }
private static void ProcessAllInLocation(GameLocation location, ProcessMethod method) { if (location == null) { return; } ModEntry.Log("WoodsObelisk.ProcessAllInLocation(" + location.Name + ", " + method + ")", StardewModdingAPI.LogLevel.Trace); if (processedLocations.Contains(location)) { ModEntry.Log("WoodsObelisk.ProcessAllInLocation(" + location.Name + ", " + method + "): Already processed this location (infinite recursion?), aborting!", StardewModdingAPI.LogLevel.Warn); return; } processedLocations.Add(location); if (location is BuildableGameLocation buildableGameLocation) { foreach (Building building in buildableGameLocation.buildings) { if (building != null) { ProcessAllInLocation(building.indoors.Value, method); if (method == ProcessMethod.Remove && building.buildingType.Value == WOODS_OBELISK_BUILDING_NAME) { building.buildingType.Value = EARTH_OBELISK_BUILDING_NAME; DeepWoodsState.WoodsObeliskLocations.Add(new XY(building.tileX.Value, building.tileY.Value)); } else if (method == ProcessMethod.Restore && building.buildingType.Value == EARTH_OBELISK_BUILDING_NAME) { if (DeepWoodsState.WoodsObeliskLocations.Contains(new XY(building.tileX.Value, building.tileY.Value))) { building.buildingType.Value = WOODS_OBELISK_BUILDING_NAME; building.resetTexture(); } } } } } }
private void SaveEvents_AfterSave(object sender, EventArgs args) { ModEntry.Log("SaveEvents_AfterSave", StardewModdingAPI.LogLevel.Trace); isBeforeSaveCount--; if (isBeforeSaveCount > 0) { ModEntry.Log("AfterSave event was called before save has finished. Ignoring.", StardewModdingAPI.LogLevel.Warn); return; } if (isBeforeSaveCount < 0) { ModEntry.Log("AfterSave event was called without previous BeforeSave call. Mod is now in unknown state, all hell might break lose.", StardewModdingAPI.LogLevel.Error); return; } DeepWoodsManager.Restore(); EasterEggFunctions.RestoreAllEasterEggsInGame(); WoodsObelisk.RestoreAllInGame(); }
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); } }