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.)

This commit is contained in:
JoshuaNavarro 2019-08-14 20:21:44 -07:00
parent 47c50b6c18
commit 8f16593894
3 changed files with 76 additions and 25 deletions

View File

@ -24,6 +24,7 @@ namespace Revitalize.Framework.Objects
/// A list of all of the ores held by the resource manager. /// A list of all of the ores held by the resource manager.
/// </summary> /// </summary>
public Dictionary<string, OreVeinObj> ores; public Dictionary<string, OreVeinObj> ores;
public List<int> visitedFloors;
/// <summary> /// <summary>
/// Constructor. /// Constructor.
@ -32,6 +33,7 @@ namespace Revitalize.Framework.Objects
{ {
self = this; self = this;
this.ores = new Dictionary<string, OreVeinObj>(); this.ores = new Dictionary<string, OreVeinObj>();
this.visitedFloors = new List<int>();
this.loadOreVeins(); this.loadOreVeins();
} }
@ -116,7 +118,15 @@ namespace Revitalize.Framework.Objects
public void spawnOreInMine() public void spawnOreInMine()
{ {
int floorLevel = LocationUtilities.CurrentMineLevel(); int floorLevel = LocationUtilities.CurrentMineLevel();
if (this.hasVisitedFloor(floorLevel))
{
//Already has spawned ores for this visit.
return;
}
else
{
this.visitedFloors.Add(floorLevel);
}
List<OreVeinObj> spawnableOreVeins = new List<OreVeinObj>(); List<OreVeinObj> spawnableOreVeins = new List<OreVeinObj>();
//Get a list of all of the ores that can spawn on this mine level. //Get a list of all of the ores that can spawn on this mine level.
foreach(KeyValuePair<string,OreVeinObj> pair in this.ores) foreach(KeyValuePair<string,OreVeinObj> pair in this.ores)
@ -129,35 +139,56 @@ namespace Revitalize.Framework.Objects
foreach(OreVeinObj ore in spawnableOreVeins) foreach(OreVeinObj ore in spawnableOreVeins)
{ {
int amount = ore.resourceInfo.getNumberOfNodesToSpawn(); if (ore.resourceInfo.shouldSpawn())
List<Vector2> openTiles = LocationUtilities.GetOpenObjectTiles(Game1.player.currentLocation, (OreVeinObj)ore.getOne());
for (int i = 0; i < amount; i++)
{ {
int position = Game1.random.Next(openTiles.Count); int amount = ore.resourceInfo.getNumberOfNodesToSpawn();
this.spawnOreVein(ore.info.id, openTiles[position]); List<Vector2> 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<Vector2> 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]);
}
}
*/
} }
/// <summary>
/// Checks to see if the player has visited the given floor.
/// </summary>
/// <param name="Floor"></param>
/// <returns></returns>
public bool hasVisitedFloor(int Floor)
{
return this.visitedFloors.Contains(Floor);
}
/// <summary>
/// What happens when the player warps maps.
/// </summary>
/// <param name="o"></param>
/// <param name="playerWarped"></param>
public void OnPlayerLocationChanged(object o,EventArgs playerWarped) public void OnPlayerLocationChanged(object o,EventArgs playerWarped)
{ {
this.spawnOreInMine(); this.spawnOreInMine();
if(LocationUtilities.IsPlayerInMine()==false && LocationUtilities.IsPlayerInSkullCave() == false && LocationUtilities.IsPlayerInMineEnterance()==false)
{
this.visitedFloors.Clear();
}
} }
#endregion #endregion

View File

@ -141,11 +141,18 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
{ {
foreach (ResourceInformaton extra in this.extraDrops) foreach (ResourceInformaton extra in this.extraDrops)
{ {
Item extraItem = extra.droppedItem.getOne(); if (extra.shouldDropResource())
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); 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.
} }
} }
} }

View File

@ -23,6 +23,19 @@ namespace Revitalize.Framework.Utilities
} }
return false; return false;
} }
/// <summary>
/// Checks to see if the player is in the enterance to the mine.
/// </summary>
/// <returns></returns>
public static bool IsPlayerInMineEnterance()
{
if (Game1.player.currentLocation.Name.StartsWith("Mine") || Game1.player.currentLocation.Name=="Mine")
{
return true;
}
return false;
}
/// <summary> /// <summary>
/// Checks to see if the player is in skull cave. /// Checks to see if the player is in skull cave.
/// </summary> /// </summary>