Upgraded resources to have spawn and drop chance.

This commit is contained in:
JoshuaNavarro 2019-08-14 14:32:22 -07:00
parent 5cf0211339
commit 47c50b6c18
4 changed files with 146 additions and 23 deletions

View File

@ -12,7 +12,9 @@ namespace Revitalize.Framework.Objects.InformationFiles
{
/// <summary>
/// The floors of the mine that this resource should spawn in.
/// </summary>
public List<IntRange> floorsToSpawnOn;
/// <summary>
/// The list of floors to exclude spawning on in the mine.
@ -20,21 +22,32 @@ namespace Revitalize.Framework.Objects.InformationFiles
public List<IntRange> floorsToExclude;
/// <summary>
///
/// Should this resource spawn in the mine in the mountains?
/// </summary>
public List<string> minesToSpawnIn;
public bool spawnInRegularMine;
/// <summary>
/// Should this resource spawn in Skull Cavern?
/// </summary>
public bool spawnInSkullCavern;
/// <summary>
/// Should this resource spawn on farms. Notably the hiltop farm?
/// </summary>
public bool spawnsOnFarm;
/// <summary>
/// Should this resource spawn in the quarry?
/// </summary>
public bool spawnsInQuarry;
/// <summary>
/// Empty Constructor.
/// </summary>
public OreResourceInformation() : base()
{
}
public OreResourceInformation(Item I, int MinDropAmount, int MaxDropAmount, int MinNumberOfNodes, int MaxNumberOfNodes,bool SpawnsOnFarm, bool SpawnsInQuarry,List<IntRange> FloorsToSpawnOn, List<IntRange> FloorsToExclude,bool SpawnInRegularMine,bool SpawnInSkullCave,float SpawnLuckFactor=0f,float DropLuckFactor=0f) : base(I, MinDropAmount, MaxDropAmount, MinNumberOfNodes, MaxNumberOfNodes,SpawnLuckFactor,DropLuckFactor)
public OreResourceInformation(Item I,bool SpawnsOnFarm, bool SpawnsInQuarry, bool SpawnInRegularMine, bool SpawnInSkullCave,List<IntRange> FloorsToSpawnOn,List<IntRange>FloorsToExclude ,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 = SpawnsOnFarm;
this.spawnsInQuarry = SpawnsInQuarry;
@ -44,16 +57,30 @@ namespace Revitalize.Framework.Objects.InformationFiles
this.spawnInSkullCavern = SpawnInSkullCave;
}
/// <summary>
/// Gets the number of drops that should spawn for this ore.
/// </summary>
/// <param name="limitToMax"></param>
/// <returns></returns>
public override int getNumberOfDropsToSpawn(bool limitToMax = true)
{
return base.getNumberOfDropsToSpawn(limitToMax);
}
/// <summary>
/// Gets the number of nodes that should spawn for this ore.
/// </summary>
/// <param name="limitToMax"></param>
/// <returns></returns>
public override int getNumberOfNodesToSpawn(bool limitToMax = true)
{
return base.getNumberOfNodesToSpawn(limitToMax);
}
/// <summary>
/// Can this ore spawn at the given location?
/// </summary>
/// <returns></returns>
public override bool canSpawnAtLocation()
{
if (this.spawnsOnFarm && Game1.player.currentLocation is StardewValley.Farm)

View File

@ -17,12 +17,45 @@ namespace Revitalize.Framework.Objects.InformationFiles
/// </summary>
public Item droppedItem;
/// <summary>
/// The min amount of resources to drop given the getNumberOfDrops function.
/// </summary>
public int minResourcePerDrop;
/// <summary>
/// The max amount of resources to drop given the getNumberOfDrops function.
/// </summary>
public int maxResourcePerDrop;
/// <summary>
/// The min amount of nodes that would be spawned given the getNumberOfNodesToSpawn function.
/// </summary>
public int minNumberOfNodesSpawned;
/// <summary>
/// The max amount of nodes that would be spawned given the getNumberOfNodesToSpawn function.
/// </summary>
public int maxNumberOfNodesSpawned;
public float spawnLuckFactor;
public float dropLuckFactor;
/// <summary>
/// The influence multiplier that luck has on how many nodes of this resource spawn.
/// </summary>
public double spawnAmountLuckFactor;
/// <summary>
/// The influence multiplier that luck has on ensuring the resource spawns.
/// </summary>
public double spawnChanceLuckFactor;
public double dropAmountLuckFactor;
/// <summary>
/// The influence multiplier that luck has on ensuring the resource drops.
/// </summary>
public double dropChanceLuckFactor;
/// <summary>
/// The chance for the resource to spawn from 0.0 ~ 1.0
/// </summary>
public double chanceToSpawn;
/// <summary>
/// The chance for the resource to drop from 0.0 ~ 1.0
/// </summary>
public double chanceToDrop;
/// <summary>
/// Empty constructor.
@ -35,18 +68,30 @@ namespace Revitalize.Framework.Objects.InformationFiles
/// <summary>
/// Constructor.
/// </summary>
/// <param name="I">The item to drop.</param>
/// <param name="MinDropAmount">The min amount to drop.</param>
/// <param name="MaxDropAmount">The max amount to drop.</param>
public ResourceInformaton(Item I, int MinDropAmount, int MaxDropAmount, int MinNumberOfNodes, int MaxNumberOfNodes, float SpawnLuckFactor = 0f, float DropLuckFactor=0f)
/// <param name="I"></param>
/// <param name="MinDropAmount"></param>
/// <param name="MaxDropAmount"></param>
/// <param name="MinNumberOfNodes"></param>
/// <param name="MaxNumberOfNodes"></param>
/// <param name="ChanceToSpawn"></param>
/// <param name="ChanceToDrop"></param>
/// <param name="SpawnChanceLuckFactor"></param>
/// <param name="SpawnAmountLuckFactor"></param>
/// <param name="DropChanceLuckFactor"></param>
/// <param name="DropAmountLuckFactor"></param>
public ResourceInformaton(Item I, 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)
{
this.droppedItem = I;
this.minResourcePerDrop = MinDropAmount;
this.maxResourcePerDrop = MaxDropAmount;
this.minNumberOfNodesSpawned = MinNumberOfNodes;
this.maxNumberOfNodesSpawned = MaxNumberOfNodes;
this.spawnLuckFactor = SpawnLuckFactor;
this.dropLuckFactor = DropLuckFactor;
this.spawnAmountLuckFactor = SpawnAmountLuckFactor;
this.dropAmountLuckFactor = DropAmountLuckFactor;
this.chanceToSpawn = ChanceToSpawn;
this.chanceToDrop = ChanceToDrop;
this.spawnChanceLuckFactor = SpawnChanceLuckFactor;
this.dropChanceLuckFactor = DropChanceLuckFactor;
}
@ -60,11 +105,11 @@ namespace Revitalize.Framework.Objects.InformationFiles
if (limitToMax)
{
amount = (int)Math.Min(amount + (this.dropLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)), this.maxResourcePerDrop);
amount = (int)Math.Min(amount + (this.dropAmountLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)), this.maxResourcePerDrop);
}
else
{
amount = (int)(amount + (this.dropLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)));
amount = (int)(amount + (this.dropAmountLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)));
}
return amount;
}
@ -78,22 +123,56 @@ namespace Revitalize.Framework.Objects.InformationFiles
int amount = Game1.random.Next(this.minNumberOfNodesSpawned, this.maxNumberOfNodesSpawned + 1);
if (limitToMax)
{
amount = (int)Math.Min(amount + (this.spawnLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)), this.maxNumberOfNodesSpawned);
amount = (int)Math.Min(amount + (this.spawnAmountLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)), this.maxNumberOfNodesSpawned);
}
else
{
amount = (int)(amount + (this.spawnLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)));
amount = (int)(amount + (this.spawnAmountLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)));
}
return amount;
}
/// <summary>
/// Checks to see if the resource can spawn at the player's location.
/// </summary>
/// <returns></returns>
public virtual bool canSpawnAtLocation()
{
return true;
}
/// <summary>
/// Checks to see if the resource can spawn at the given location.
/// </summary>
/// <param name="location"></param>
/// <returns></returns>
public virtual bool canSpawnAtLocation(GameLocation location)
{
return true;
}
/// <summary>
/// Checks to see if this resource's spawn chance is greater than the spawn chance it is checked against.
/// </summary>
/// <returns></returns>
public virtual bool shouldSpawn()
{
double chance = Game1.random.NextDouble();
chance = (chance - (this.spawnChanceLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)));
if (this.chanceToSpawn >= chance) return true;
else return false;
}
/// <summary>
/// Checks to see if this resource's drop chance is greater than the spawn chance it is checked against.
/// </summary>
/// <returns></returns>
public virtual bool shouldDropResource()
{
double chance = Game1.random.NextDouble();
chance= (chance - (this.dropChanceLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)));
if (this.chanceToDrop >= chance) return true;
else return false;
}
}
}

View File

@ -44,10 +44,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), 1, 10,1,20,false,false,new List<IntRange>()
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<IntRange>()
{
new IntRange(1,9)
},null,true,true,0,0)));
},new List<IntRange>(),1,5,1,10,1d,1d,0,0,0,0),new List<ResourceInformaton>()));
this.ores.Add("Omegasis.Revitalize.Resources.Ore.Test", testOre);
}

View File

@ -19,23 +19,26 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
/// Deals with information tied to the resource itself.
/// </summary>
public ResourceInformaton resourceInfo;
public List<ResourceInformaton> extraDrops;
public OreVeinTile() : base()
{
}
public OreVeinTile(CustomObjectData PyTKData, BasicItemInformation Info,ResourceInformaton Resource) : base(PyTKData, Info)
public OreVeinTile(CustomObjectData PyTKData, BasicItemInformation Info,ResourceInformaton Resource,List<ResourceInformaton> ExtraDrops) : base(PyTKData, Info)
{
this.health = 3;
this.resourceInfo = Resource;
this.extraDrops = ExtraDrops != null ? ExtraDrops : new List<ResourceInformaton>();
}
public OreVeinTile(CustomObjectData PyTKData, BasicItemInformation Info, Vector2 TileLocation,ResourceInformaton Resource) : base(PyTKData, Info, TileLocation)
public OreVeinTile(CustomObjectData PyTKData, BasicItemInformation Info, Vector2 TileLocation,ResourceInformaton Resource, List<ResourceInformaton> ExtraDrops) : base(PyTKData, Info, TileLocation)
{
this.health = 3;
this.resourceInfo = Resource;
this.extraDrops = ExtraDrops != null ? ExtraDrops : new List<ResourceInformaton>();
}
@ -127,12 +130,26 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
/// </summary>
public void destoryVein()
{
int amount = Game1.random.Next(this.resourceInfo.minResourcePerDrop, this.resourceInfo.maxResourcePerDrop);
int amount = this.resourceInfo.getNumberOfDropsToSpawn();
Item newItem = this.resourceInfo.droppedItem.getOne();
for(int i = 0; i < amount; i++)
{
Game1.createItemDebris(newItem.getOne(), this.TileLocation*Game1.tileSize, Game1.random.Next(0, 3), this.location);
}
if (this.extraDrops != null)
{
foreach (ResourceInformaton extra in this.extraDrops)
{
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);
}
}
}
if (this.location != null)
{
this.location.playSound("stoneCrack");
@ -171,7 +188,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
public override Item getOne()
{
OreVeinTile component = new OreVeinTile(this.data, this.info,this.resourceInfo);
OreVeinTile component = new OreVeinTile(this.data, this.info,this.resourceInfo,this.extraDrops);
component.containerObject = this.containerObject;
component.offsetKey = this.offsetKey;
return component;