From 01cc1d29ec9bbe93b4f170d1698ff637f951d6fd Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Thu, 15 Aug 2019 20:32:12 -0700 Subject: [PATCH] Updated oreResourceInfo class to have more statistics for farm, quarry, skull cave, and mine as well as including functions for checking floors to spawn/exlucde on. --- .../OreResourceInformation.cs | 244 +++++++++++++++++- .../Framework/Objects/ResourceManager.cs | 2 + .../Framework/Utilities/IntRange.cs | 21 ++ 3 files changed, 260 insertions(+), 7 deletions(-) diff --git a/GeneralMods/Revitalize/Framework/Objects/InformationFiles/OreResourceInformation.cs b/GeneralMods/Revitalize/Framework/Objects/InformationFiles/OreResourceInformation.cs index 0c27a9d5..2f4f8211 100644 --- a/GeneralMods/Revitalize/Framework/Objects/InformationFiles/OreResourceInformation.cs +++ b/GeneralMods/Revitalize/Framework/Objects/InformationFiles/OreResourceInformation.cs @@ -13,14 +13,36 @@ namespace Revitalize.Framework.Objects.InformationFiles /// - /// The floors of the mine that this resource should spawn in. + /// The floors of the mine that this resource should spawn in in the regular mine. /// public List floorsToSpawnOn; + /// - /// The list of floors to exclude spawning on in the mine. + /// A function that compares whether or not the resource can be spawned on this floor. Used in conjecture with floorsToSpawnOn + /// + public Func canSpawnOnThisFloor; + public Func excludeSpawnOnThisFloor; + + /// + /// The list of floors to exclude spawning on in the regular mine. /// public List floorsToExclude; + /// + /// The floors this resource should spawn on in skull cave. + /// + public List floorsToSpawnOnSkullCave; + /// + /// The floors this resource should not spawn on in skull cave. + /// + public List floorsToExcludeSkullCave; + + /// + /// A function that compares whether or not the resource can be spawned on this floor in skull cave. Used in conjecture with floorsToSpawnOn + /// + public Func canSpawnOnThisFloorSkullCave; + public Func excludeSpawnOnThisFloorSkullCave; + /// /// Should this resource spawn in the mine in the mountains? /// @@ -38,6 +60,30 @@ namespace Revitalize.Framework.Objects.InformationFiles /// public bool spawnsInQuarry; + /// + /// The range of the number of nodes to spawn on the farm. + /// + public IntRange farmSpawnAmount; + /// + /// The range of the number of nodes to spawn in the quarry. + /// + public IntRange quarrySpawnAmount; + /// + /// The range of the number of nodes to spawn in skull cave. + /// + public IntRange skullCaveSpawnAmount; + /// + /// The chance that this resource spawns on the farm. + /// + public double farmSpawnChance; + /// + /// The chance that this resource spawns in the quarry. + /// + public double quarrySpawnChance; + /// + /// The chance that this resource spawns in skull cave. + /// + public double skullCaveSpawnChance; /// /// Empty Constructor. @@ -47,14 +93,108 @@ namespace Revitalize.Framework.Objects.InformationFiles } - public OreResourceInformation(Item I,bool SpawnsOnFarm, bool SpawnsInQuarry, bool SpawnInRegularMine, bool SpawnInSkullCave,List FloorsToSpawnOn,ListFloorsToExclude ,int MinDropAmount, int MaxDropAmount, int MinNumberOfNodes, int MaxNumberOfNodes, double ChanceToSpawn = 1f, double ChanceToDrop = 1f, double SpawnChanceLuckFactor = 0f, double SpawnAmountLuckFactor = 0f, double DropChanceLuckFactor = 0f, double DropAmountLuckFactor = 0f) : base(I, MinDropAmount, MaxDropAmount, MinNumberOfNodes, MaxNumberOfNodes,ChanceToSpawn,ChanceToDrop,SpawnChanceLuckFactor,SpawnAmountLuckFactor,DropChanceLuckFactor,DropAmountLuckFactor) + /// + /// Constructor for a resource that spawns only in the regular mine. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public OreResourceInformation(Item I, List FloorsToSpawnOn, List FloorsToExclude,Func CanSpawnOnGivenFloor,Func FloorsToExcludeFun,int MinDropAmount, int MaxDropAmount, int MinNumberOfNodes, int MaxNumberOfNodes, double ChanceToSpawn = 1f, double ChanceToDrop = 1f, double SpawnChanceLuckFactor = 0f, double SpawnAmountLuckFactor = 0f, double DropChanceLuckFactor = 0f, double DropAmountLuckFactor = 0f) : base(I, MinDropAmount, MaxDropAmount, MinNumberOfNodes, MaxNumberOfNodes, ChanceToSpawn, ChanceToDrop, SpawnChanceLuckFactor, SpawnAmountLuckFactor, DropChanceLuckFactor, DropAmountLuckFactor) { + this.spawnsOnFarm = false; + this.spawnsInQuarry = false; + this.floorsToSpawnOn = FloorsToSpawnOn; + this.floorsToExclude = FloorsToExclude != null ? FloorsToExclude : new List(); + this.spawnInRegularMine = true; + this.spawnInSkullCavern = false; + + this.farmSpawnAmount = new IntRange(); + this.quarrySpawnAmount = new IntRange(); + this.farmSpawnChance = 0f; + this.quarrySpawnChance = 0f; + + if (CanSpawnOnGivenFloor != null) + { + this.canSpawnOnThisFloor = CanSpawnOnGivenFloor; + } + else + { + this.canSpawnOnThisFloor = null; + } + + this.excludeSpawnOnThisFloor = FloorsToExcludeFun; + + this.canSpawnOnThisFloorSkullCave = null; + } + + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public OreResourceInformation(Item I,bool SpawnsOnFarm, bool SpawnsInQuarry, bool SpawnInRegularMine, bool SpawnInSkullCave,List FloorsToSpawnOn,ListFloorsToExclude,Func CanSpawnOnGivenFloor,Func FloorsToExludeFun,int MinDropAmount, int MaxDropAmount, int MinNumberOfNodes, int MaxNumberOfNodes, IntRange FarmSpawnAmount,IntRange QuarrySpawnAmount,IntRange SkullCaveSpawnAmount,List FloorsToSpawnOnSkullCave,ListFloorsToExludeSkullCave,Func CanSpawnOnGivenFloorSkullCave,FuncFloorsToExludeFunSkullCave,double ChanceToSpawn = 1f,double FarmSpawnChance=1f,double QuarrySpawnChance=1f,double SkullCaveSpawnChance=1f,double ChanceToDrop = 1f, double SpawnChanceLuckFactor = 0f, double SpawnAmountLuckFactor = 0f, double DropChanceLuckFactor = 0f, double DropAmountLuckFactor = 0f) : base(I, MinDropAmount, MaxDropAmount, MinNumberOfNodes, MaxNumberOfNodes,ChanceToSpawn,ChanceToDrop,SpawnChanceLuckFactor,SpawnAmountLuckFactor,DropChanceLuckFactor,DropAmountLuckFactor) + { + // Deals with setting where this ore can spawn. this.spawnsOnFarm = SpawnsOnFarm; this.spawnsInQuarry = SpawnsInQuarry; - this.floorsToSpawnOn = FloorsToSpawnOn; - this.floorsToExclude = FloorsToExclude!=null? FloorsToExclude: new List(); this.spawnInRegularMine = SpawnInRegularMine; this.spawnInSkullCavern = SpawnInSkullCave; + + //Deals with inclusion/Exclusion for floors in regular mine. + this.floorsToSpawnOn = this.spawnInRegularMine?FloorsToSpawnOn:new List(); + this.floorsToExclude = FloorsToExclude != null ? FloorsToExclude : new List(); + + ///Checks if a given resource shouds spawn and if not sets defaulted 0 values. + this.farmSpawnAmount = this.spawnsOnFarm? FarmSpawnAmount:new IntRange(0,0); + this.quarrySpawnAmount =this.spawnsInQuarry? QuarrySpawnAmount:new IntRange(0,0); + this.skullCaveSpawnAmount = this.spawnInSkullCavern ? SkullCaveSpawnAmount : new IntRange(0, 0); + this.farmSpawnChance = this.spawnsOnFarm?FarmSpawnChance:0f; + this.quarrySpawnChance = this.spawnsInQuarry?QuarrySpawnChance:0f; + this.skullCaveSpawnChance = this.spawnInSkullCavern ? SkullCaveSpawnChance : 0f; + + //Deals with inclusion/Exclusion for floors in skull cave. + this.floorsToExcludeSkullCave = FloorsToExludeSkullCave!=null? FloorsToExludeSkullCave: new List(); + this.floorsToSpawnOnSkullCave = FloorsToSpawnOnSkullCave!=null? FloorsToSpawnOnSkullCave: new List(); + + this.canSpawnOnThisFloorSkullCave = this.spawnInSkullCavern ? CanSpawnOnGivenFloorSkullCave : null; + this.excludeSpawnOnThisFloorSkullCave = FloorsToExludeFunSkullCave; + this.excludeSpawnOnThisFloor = FloorsToExludeFun; + + } /// @@ -77,6 +217,76 @@ namespace Revitalize.Framework.Objects.InformationFiles return base.getNumberOfNodesToSpawn(limitToMax); } + /// + /// Gets the number of nodes to spawn in the farm. + /// + /// + /// + public virtual int getNumberOfNodesToSpawnFarm(bool limitToMax = true) + { + if (this.spawnsOnFarm == false || this.farmSpawnAmount == null) return 0; + int amount = this.farmSpawnAmount.getRandomInclusive(); + if (limitToMax) + { + amount = (int)Math.Min(amount + (this.spawnAmountLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)), this.maxNumberOfNodesSpawned); + } + else + { + amount = (int)(amount + (this.spawnAmountLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value))); + } + return amount; + } + /// + /// Gets the number of nodes to spawn in the quarry. + /// + /// + /// + public virtual int getNumberOfNodesToSpawnQuarry(bool limitToMax = true) + { + if (this.spawnsInQuarry == false || this.quarrySpawnAmount == null) return 0; + int amount = this.quarrySpawnAmount.getRandomInclusive(); + if (limitToMax) + { + amount = (int)Math.Min(amount + (this.spawnAmountLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)), this.maxNumberOfNodesSpawned); + } + else + { + amount = (int)(amount + (this.spawnAmountLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value))); + } + return amount; + } + /// + /// Gets the number of nodes to spawn in skull cave. + /// + /// + /// + public virtual int getNumberOfNodesToSpawnSkullCavern(bool limitToMax = true) + { + if (this.spawnInSkullCavern == false || this.skullCaveSpawnAmount == null) return 0; + int amount = this.quarrySpawnAmount.getRandomInclusive(); + if (limitToMax) + { + amount = (int)Math.Min(amount + (this.spawnAmountLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)), this.maxNumberOfNodesSpawned); + } + else + { + amount = (int)(amount + (this.spawnAmountLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value))); + } + return amount; + } + + /* + public virtual bool shouldSpawnInQuarry() + { + + } + + public virtual bool shouldSpawnInFarm() + { + + } + */ + /// /// Can this ore spawn at the given location? /// @@ -137,11 +347,31 @@ namespace Revitalize.Framework.Objects.InformationFiles int level=LocationUtilities.CurrentMineLevel(); foreach(IntRange range in this.floorsToSpawnOn) { - if (range.ContainsInclusive(level)) + bool compareFun = false; + if (this.canSpawnOnThisFloor == null) + { + compareFun = false; + } + else + { + compareFun = this.canSpawnOnThisFloor(level); + } + + if (range.ContainsInclusive(level) || compareFun==true) { foreach(IntRange exclude in this.floorsToExclude) { - if (exclude.ContainsInclusive(level)) return false; + bool excludeFun = false; + if (this.excludeSpawnOnThisFloor == null) + { + excludeFun = false; + } + else + { + excludeFun = this.excludeSpawnOnThisFloor(level); + } + //Make this include exlude fun for regular mine. See above in this function. + if (exclude.ContainsInclusive(level) || excludeFun) return false; } return true; } diff --git a/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs b/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs index 9fef3029..1cce6743 100644 --- a/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs +++ b/GeneralMods/Revitalize/Framework/Objects/ResourceManager.cs @@ -46,11 +46,13 @@ 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, true, true, false, new List() { new IntRange(1,9) }, new List(), 1, 5, 1, 10, 1d, 1d, 0, 0, 0, 0), new List())); this.ores.Add("Omegasis.Revitalize.Resources.Ore.Test", testOre); + */ } /// diff --git a/GeneralMods/Revitalize/Framework/Utilities/IntRange.cs b/GeneralMods/Revitalize/Framework/Utilities/IntRange.cs index e425e2df..e15f3281 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/IntRange.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/IntRange.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using StardewValley; namespace Revitalize.Framework.Utilities { @@ -85,5 +86,25 @@ namespace Revitalize.Framework.Utilities if (value > this.min && value < this.max) return true; else return false; } + + /// + /// Returns an int value within the range of min and max inclusive. + /// + /// + public int getRandomInclusive() + { + int number = Game1.random.Next(this.min, this.max + 1); + return number; + } + + /// + /// Returns an int value within the range of min and max exclusive. + /// + /// + public int getRandomExclusive() + { + int number = Game1.random.Next(this.min, this.max); + return number; + } } }