diff --git a/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs b/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs index 9bc0c2d2..9fef3029 100644 --- a/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs +++ b/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs @@ -46,10 +46,10 @@ namespace Revitalize.Framework.Objects OreVeinObj testOre = new OreVeinObj(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Resources.Ore.Test", TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Test"), typeof(OreVeinTile), Color.White), new BasicItemInformation("Test Ore Vein", "Omegasis.Revitalize.Resources.Ore.Test", "A ore vein that is used for testing purposes.", "Revitalize.Ore", Color.Black, -300, 0, false, 350, Vector2.Zero, true, true, TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Test"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Resources.Ore", "Test"), new Animation(0, 0, 16, 16)), Color.White, false, null, null)); - testOre.addComponent(new Vector2(0, 0), new OreVeinTile(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Resources.Ore.Test", TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Test"), typeof(OreVeinTile), Color.White), new BasicItemInformation("Test Ore Vein", "Omegasis.Revitalize.Resources.Ore.Test", "A ore vein that is used for testing purposes.", "Revitalize.Ore", Color.Black, -300, 0, false, 350, Vector2.Zero, true, true, TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Test"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Resources.Ore", "Test"), new Animation(0, 0, 16, 16)), Color.White, false, null, null), new InformationFiles.OreResourceInformation(new StardewValley.Object(211, 1),false,false,true,false,new List() + testOre.addComponent(new Vector2(0, 0), new OreVeinTile(PyTKHelper.CreateOBJData("Omegasis.Revitalize.Resources.Ore.Test", TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Test"), typeof(OreVeinTile), Color.White), new BasicItemInformation("Test Ore Vein", "Omegasis.Revitalize.Resources.Ore.Test", "A ore vein that is used for testing purposes.", "Revitalize.Ore", Color.Black, -300, 0, false, 350, Vector2.Zero, true, true, TextureManager.GetTexture(ModCore.Manifest, "Resources.Ore", "Test"), new AnimationManager(TextureManager.GetExtendedTexture(ModCore.Manifest, "Resources.Ore", "Test"), new Animation(0, 0, 16, 16)), Color.White, false, null, null), new InformationFiles.OreResourceInformation(new StardewValley.Object(211, 1), false, true, true, false, new List() { new IntRange(1,9) - },new List(),1,5,1,10,1d,1d,0,0,0,0),new List())); + }, new List(), 1, 5, 1, 10, 1d, 1d, 0, 0, 0, 0), new List())); this.ores.Add("Omegasis.Revitalize.Resources.Ore.Test", testOre); } @@ -57,7 +57,7 @@ namespace Revitalize.Framework.Objects /// Spawns an ore vein at the given location if possible. /// /// - public bool spawnOreVein(string name,GameLocation Location, Vector2 TilePosition) + public bool spawnOreVein(string name, GameLocation Location, Vector2 TilePosition) { if (this.ores.ContainsKey(name)) { @@ -70,7 +70,7 @@ namespace Revitalize.Framework.Objects if (spawnable) { //ModCore.log("Location is: " + Location.Name); - spawn.placementAction(Location, (int)TilePosition.X*Game1.tileSize, (int)TilePosition.Y*Game1.tileSize,Game1.player); + spawn.placementAction(Location, (int)TilePosition.X * Game1.tileSize, (int)TilePosition.Y * Game1.tileSize, Game1.player); } else { @@ -104,7 +104,7 @@ namespace Revitalize.Framework.Objects /// /// /// - public bool canResourceBeSpawnedHere(MultiTiledObject OBJ,GameLocation Location, Vector2 TilePosition) + public bool canResourceBeSpawnedHere(MultiTiledObject OBJ, GameLocation Location, Vector2 TilePosition) { return OBJ.canBePlacedHere(Location, TilePosition) && Location.isTileLocationTotallyClearAndPlaceable(TilePosition); } @@ -129,7 +129,7 @@ namespace Revitalize.Framework.Objects } List spawnableOreVeins = new List(); //Get a list of all of the ores that can spawn on this mine level. - foreach(KeyValuePair pair in this.ores) + foreach (KeyValuePair pair in this.ores) { if (pair.Value.resourceInfo.canSpawnAtLocation() && (pair.Value.resourceInfo as OreResourceInformation).canSpawnOnCurrentMineLevel()) { @@ -137,7 +137,7 @@ namespace Revitalize.Framework.Objects } } - foreach(OreVeinObj ore in spawnableOreVeins) + foreach (OreVeinObj ore in spawnableOreVeins) { if (ore.resourceInfo.shouldSpawn()) { @@ -151,6 +151,7 @@ namespace Revitalize.Framework.Objects if (didSpawn == false) { i--; //If the tile didn't spawn due to some odd reason ensure that the amount is spawned. + openTiles.Remove(openTiles[position]); } else { @@ -177,20 +178,117 @@ namespace Revitalize.Framework.Objects return this.visitedFloors.Contains(Floor); } + /// + /// Source: SDV. + /// + /// + /// + /// + private bool isTileOpenForQuarryStone(int tileX, int tileY) + { + GameLocation loc = Game1.getLocationFromName("Mountain"); + if (loc.doesTileHaveProperty(tileX, tileY, "Diggable", "Back") != null) + return loc.isTileLocationTotallyClearAndPlaceable(new Vector2((float)tileX, (float)tileY)); + return false; + } + + /// + /// Update the quarry every day with new ores to spawn. + /// + private void quarryDayUpdate() + { + List spawnableOreVeins = new List(); + //Get a list of all of the ores that can spawn on this mine level. + foreach (KeyValuePair pair in this.ores) + { + if ((pair.Value.resourceInfo as OreResourceInformation).spawnsInQuarry) + { + spawnableOreVeins.Add(pair.Value); + //ModCore.log("Found an ore that spawns in the quarry"); + } + } + foreach (OreVeinObj ore in spawnableOreVeins) + { + if (ore.resourceInfo.shouldSpawn()) + { + int amount = ore.resourceInfo.getNumberOfNodesToSpawn(); + List openTiles = this.getOpenQuarryTiles(ore); + //ModCore.log("Number of open tiles is: " + openTiles.Count); + amount = Math.Min(amount, openTiles.Count); //Only spawn for as many open tiles or the amount of nodes to spawn. + for (int i = 0; i < amount; i++) + { + int position = Game1.random.Next(openTiles.Count); + bool didSpawn = this.spawnOreVein(ore.info.id,Game1.getLocationFromName("Mountain"),openTiles[position]); + if (didSpawn == false) + { + i--; //If the tile didn't spawn due to some odd reason ensure that the amount is spawned. + openTiles.Remove(openTiles[position]); + //amount = Math.Min(amount, openTiles.Count); //Only spawn for as many open tiles or the amount of nodes to spawn. + } + else + { + //ModCore.log("Spawned ore in the quarry!"); + openTiles.Remove(openTiles[position]); //Remove that tile from the list of open tiles. + } + } + } + else + { + //Ore doesn't meet spawn chance. + } + //ModCore.log("Spawned :" + amount + " pancake test ores!"); + } + + } + + /// + /// Gets a list of all of the open quarry tiles. + /// + /// + private List getOpenQuarryTiles(MultiTiledObject obj) + { + List tiles = new List(); + Microsoft.Xna.Framework.Rectangle r = new Microsoft.Xna.Framework.Rectangle(106, 13, 21, 21); + for(int i = r.X; i <= r.X + r.Width; i++) + { + for(int j=r.Y;j<= r.Y + r.Height; j++) + { + if (this.isTileOpenForQuarryStone(i, j) && this.canResourceBeSpawnedHere(obj,Game1.getLocationFromName("Mountain"),new Vector2(i,j))) + { + tiles.Add(new Vector2(i, j)); + } + } + } + if (tiles.Count == 0) + { + //ModCore.log("Quarry is full! Can't spawn more resources!"); + } + return tiles; + } + + #endregion + + + /// /// What happens when the player warps maps. /// /// /// - public void OnPlayerLocationChanged(object o,EventArgs playerWarped) + public void OnPlayerLocationChanged(object o, EventArgs playerWarped) { this.spawnOreInMine(); - if(LocationUtilities.IsPlayerInMine()==false && LocationUtilities.IsPlayerInSkullCave() == false && LocationUtilities.IsPlayerInMineEnterance()==false) + if (LocationUtilities.IsPlayerInMine() == false && LocationUtilities.IsPlayerInSkullCave() == false && LocationUtilities.IsPlayerInMineEnterance() == false) { this.visitedFloors.Clear(); } } - #endregion + public void DailyResourceSpawn(object o, EventArgs NewDay) + { + this.quarryDayUpdate(); + } + + } } diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index de492af2..c4d79961 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -231,6 +231,7 @@ namespace Revitalize ModHelper.Events.GameLoop.ReturnedToTitle += this.GameLoop_ReturnedToTitle; ModHelper.Events.Input.ButtonPressed += this.Input_ButtonPressed; ModHelper.Events.Player.Warped += ObjectManager.resources.OnPlayerLocationChanged; + ModHelper.Events.GameLoop.DayStarted += ObjectManager.resources.DailyResourceSpawn; } private void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e)