From 8f16593894414eb4198214885cc326be4b6b88c1 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Wed, 14 Aug 2019 20:21:44 -0700 Subject: [PATCH] Updated resource info to have extra spawn items and made the mine spawn code only spawn ores per unvisited floor pe visit and gets cleared when leaving the mine. (I.E on a mine reset.) --- .../Framework/Objects/ResourceManager.cs | 73 +++++++++++++------ .../Objects/Resources/OreVeins/OreVeinTile.cs | 15 +++- .../Framework/Utilities/LocationUtilities.cs | 13 ++++ 3 files changed, 76 insertions(+), 25 deletions(-) diff --git a/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs b/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs index ef22a0fc..9bc0c2d2 100644 --- a/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs +++ b/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs @@ -24,6 +24,7 @@ namespace Revitalize.Framework.Objects /// A list of all of the ores held by the resource manager. /// public Dictionary ores; + public List visitedFloors; /// /// Constructor. @@ -32,6 +33,7 @@ namespace Revitalize.Framework.Objects { self = this; this.ores = new Dictionary(); + this.visitedFloors = new List(); this.loadOreVeins(); } @@ -116,7 +118,15 @@ namespace Revitalize.Framework.Objects public void spawnOreInMine() { int floorLevel = LocationUtilities.CurrentMineLevel(); - + if (this.hasVisitedFloor(floorLevel)) + { + //Already has spawned ores for this visit. + return; + } + else + { + this.visitedFloors.Add(floorLevel); + } 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) @@ -129,35 +139,56 @@ namespace Revitalize.Framework.Objects foreach(OreVeinObj ore in spawnableOreVeins) { - int amount = ore.resourceInfo.getNumberOfNodesToSpawn(); - List openTiles = LocationUtilities.GetOpenObjectTiles(Game1.player.currentLocation, (OreVeinObj)ore.getOne()); - for (int i = 0; i < amount; i++) + if (ore.resourceInfo.shouldSpawn()) { - int position = Game1.random.Next(openTiles.Count); - this.spawnOreVein(ore.info.id, openTiles[position]); + int amount = ore.resourceInfo.getNumberOfNodesToSpawn(); + List openTiles = LocationUtilities.GetOpenObjectTiles(Game1.player.currentLocation, (OreVeinObj)ore.getOne()); + 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, openTiles[position]); + if (didSpawn == false) + { + i--; //If the tile didn't spawn due to some odd reason ensure that the amount is spawned. + } + else + { + openTiles.Remove(openTiles[position]); //Remove that tile from the list of open tiles. + } + } } - ModCore.log("Spawned :" + amount + " pancake test ores!"); + else + { + //Ore doesn't meet spawn chance. + } + //ModCore.log("Spawned :" + amount + " pancake test ores!"); } - /* - if(floorLevel>=1 && floorLevel <= 9) - { - int amount = Game1.random.Next(1, 10); //Change this to be a frequency table or something. - List openTiles = LocationUtilities.GetOpenObjectTiles(Game1.player.currentLocation, (OreVeinObj)this.ores["Omegasis.Revitalize.Resources.Ore.Test"].getOne()); - - for(int i = 0; i <= amount; i++) - { - int position = Game1.random.Next(openTiles.Count); - this.spawnOreVein("Omegasis.Revitalize.Resources.Ore.Test", openTiles[position]); - } - - } - */ } + /// + /// Checks to see if the player has visited the given floor. + /// + /// + /// + public bool hasVisitedFloor(int Floor) + { + return this.visitedFloors.Contains(Floor); + } + + /// + /// What happens when the player warps maps. + /// + /// + /// public void OnPlayerLocationChanged(object o,EventArgs playerWarped) { this.spawnOreInMine(); + if(LocationUtilities.IsPlayerInMine()==false && LocationUtilities.IsPlayerInSkullCave() == false && LocationUtilities.IsPlayerInMineEnterance()==false) + { + this.visitedFloors.Clear(); + } } #endregion diff --git a/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinTile.cs b/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinTile.cs index 1b3374bc..f2302e73 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinTile.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinTile.cs @@ -141,11 +141,18 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins { foreach (ResourceInformaton extra in this.extraDrops) { - Item extraItem = extra.droppedItem.getOne(); - int extraAmount = extra.getNumberOfDropsToSpawn(); - for (int i = 0; i < amount; i++) + if (extra.shouldDropResource()) { - Game1.createItemDebris(extraItem.getOne(), this.TileLocation * Game1.tileSize, Game1.random.Next(0, 3), this.location); + Item extraItem = extra.droppedItem.getOne(); + int extraAmount = extra.getNumberOfDropsToSpawn(); + for (int i = 0; i < amount; i++) + { + Game1.createItemDebris(extraItem.getOne(), this.TileLocation * Game1.tileSize, Game1.random.Next(0, 3), this.location); + } + } + else + { + //Resource did not meet spawn chance. } } } diff --git a/GeneralMods/Revitalize/Framework/Utilities/LocationUtilities.cs b/GeneralMods/Revitalize/Framework/Utilities/LocationUtilities.cs index 12c1fc0b..35ca6ab5 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/LocationUtilities.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/LocationUtilities.cs @@ -23,6 +23,19 @@ namespace Revitalize.Framework.Utilities } return false; } + + /// + /// Checks to see if the player is in the enterance to the mine. + /// + /// + public static bool IsPlayerInMineEnterance() + { + if (Game1.player.currentLocation.Name.StartsWith("Mine") || Game1.player.currentLocation.Name=="Mine") + { + return true; + } + return false; + } /// /// Checks to see if the player is in skull cave. ///