private void CreatePanningSpot(GameLocation location, MapOreConfig mapConfig) { Random random = new Random(Game1.timeOfDay + (int)Game1.uniqueIDForThisGame / 2 + (int)Game1.stats.DaysPlayed); if (mapConfig.OreSpots.Count != 0 && Game1.timeOfDay >= mapConfig.StartTime && Game1.timeOfDay <= mapConfig.EndTime) { for (int i = 0; i < 4; i++) // should only ever need to try once, but just in case... { int indx = random.Next(0, mapConfig.OreSpots.Count); Point newOrePoint = mapConfig.OreSpots[indx]; // Double check to make sure it's a valid point/tile if (location.isWaterTile(newOrePoint.X, newOrePoint.Y) && FishingRod.distanceToLand(newOrePoint.X, newOrePoint.Y, location) <= 0) { if (Game1.player.currentLocation.Equals(location) && config.enableSplashSounds) { location.playSound("slosh"); } location.orePanPoint.Value = newOrePoint; hasPanningSpot = true; playerPannedSpot = false; modCreatedPanningSpot[location] = true; if (i > 0) { this.Monitor.Log($"Had to loop... check data file {location}.json"); } break; } } } }
private void UpdatePossibleTiles(GameLocation currentLocation) { if (!openWaterTiles.ContainsKey(currentLocation.Name)) { string file = Path.Combine("DataFiles", $"{currentLocation.Name}.json"); if (currentLocation.Name == "Farm") // Special Case { file = Path.Combine("DataFiles", farmFile); } //List<Point> possibleTiles = this.Helper.Data.ReadJsonFile<List<Point>>(file); var mapOreConfig = this.Helper.Data.ReadJsonFile <MapOreConfig>(file); if (mapOreConfig == null) //No file was found... { mapOreConfig = new MapOreConfig() { AreaName = currentLocation.Name, numberOfOreSpotsPerDay = config.maxNumberOfOrePointsGathered }; var possibleTiles = new List <Point>(); int maxWidth = currentLocation.Map.GetLayer("Back").LayerWidth; int maxHeight = currentLocation.Map.GetLayer("Back").LayerHeight; for (int width = 0; width < maxWidth; width++) { for (int height = 0; height < maxHeight; height++) { Point possibleOrePoint = new Point(width, height); if (currentLocation.isOpenWater(width, height) && FishingRod.distanceToLand(width, height, currentLocation) <= 0) { possibleTiles.Add(possibleOrePoint); } } } mapOreConfig.OreSpots = possibleTiles; if (!currentLocation.Name.Contains("UndergroundMine")) { this.Helper.Data.WriteJsonFile(file, mapOreConfig); // Write out new file since we had to try and find spawn points. } else if (currentLocation.Name == "UndergroundMine20" || currentLocation.Name == "UndergroundMine60" || currentLocation.Name == "UndergroundMine100") { this.Helper.Data.WriteJsonFile(file, mapOreConfig); // The only mine levels with water } } openWaterTiles.Add(currentLocation.Name, mapOreConfig); } }
private void UpdatePossibleTiles(GameLocation currentLocation) { if (!openWaterTiles.ContainsKey(currentLocation.Name)) { string file = Path.Combine("DataFiles", $"{currentLocation.Name}.json"); if (currentLocation.Name == "Farm") // Special Case { file = Path.Combine("DataFiles", farmFile); } MapOreConfig mapOreConfig = null; try { mapOreConfig = this.Helper.Data.ReadJsonFile <MapOreConfig>(file); } catch { } if (mapOreConfig == null) //No file was found or old file... { List <Point> possibleTiles = null; try // Trying to see if there is an old file... { possibleTiles = this.Helper.Data.ReadJsonFile <List <Point> >(file); } catch { } mapOreConfig = new MapOreConfig() { FileVersion = 1, AreaName = currentLocation.Name, NumberOfOreSpotsPerDay = config.maxNumberOfOrePointsGathered, StartTime = 0600, EndTime = 2600, CustomTreasure = false }; if (possibleTiles == null) { possibleTiles = new List <Point>(); int maxWidth = currentLocation.Map.GetLayer("Back").LayerWidth; int maxHeight = currentLocation.Map.GetLayer("Back").LayerHeight; for (int width = 0; width < maxWidth; width++) { for (int height = 0; height < maxHeight; height++) { Point possibleOrePoint = new Point(width, height); if (currentLocation.isWaterTile(width, height) && FishingRod.distanceToLand(width, height, currentLocation) <= 0) { possibleTiles.Add(possibleOrePoint); } } } } mapOreConfig.OreSpots = possibleTiles; if (!currentLocation.Name.Contains("UndergroundMine")) { this.Helper.Data.WriteJsonFile(file, mapOreConfig); // Write out new file since we had to try and find spawn points. } else if (currentLocation.Name == "UndergroundMine20" || currentLocation.Name == "UndergroundMine60" || currentLocation.Name == "UndergroundMine100") { this.Helper.Data.WriteJsonFile(file, mapOreConfig); // The only mine levels with water } } if (mapOreConfig.FileVersion == 0) { mapOreConfig.FileVersion = 1; mapOreConfig.AreaName = currentLocation.Name; mapOreConfig.StartTime = 600; mapOreConfig.EndTime = 2600; mapOreConfig.CustomTreasure = false; this.Helper.Data.WriteJsonFile(file, mapOreConfig); } if (mapOreConfig.CustomTreasure) { string treasureFile = Path.Combine("DataFiles", $"{currentLocation.Name}_Treasure.json"); var tresureGroups = this.Helper.Data.ReadJsonFile <Dictionary <TREASURE_GROUP, TreasureGroup> >(treasureFile) ?? TreasureGroupDefaultConfig.CreateTreasureGroup(treasureFile); areaTreasureGroups.Add(currentLocation.Name, tresureGroups); } openWaterTiles.Add(currentLocation.Name, mapOreConfig); } }