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.
/// </summary>
public Dictionary<string, OreVeinObj> ores;
public List<int> visitedFloors;
/// <summary>
/// Constructor.
@ -32,6 +33,7 @@ namespace Revitalize.Framework.Objects
{
self = this;
this.ores = new Dictionary<string, OreVeinObj>();
this.visitedFloors = new List<int>();
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<OreVeinObj> spawnableOreVeins = new List<OreVeinObj>();
//Get a list of all of the ores that can spawn on this mine level.
foreach(KeyValuePair<string,OreVeinObj> pair in this.ores)
@ -128,36 +138,57 @@ namespace Revitalize.Framework.Objects
}
foreach(OreVeinObj ore in spawnableOreVeins)
{
if (ore.resourceInfo.shouldSpawn())
{
int amount = ore.resourceInfo.getNumberOfNodesToSpawn();
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);
this.spawnOreVein(ore.info.id, openTiles[position]);
}
ModCore.log("Spawned :" + amount + " pancake test ores!");
}
/*
if(floorLevel>=1 && floorLevel <= 9)
bool didSpawn = this.spawnOreVein(ore.info.id, openTiles[position]);
if (didSpawn == false)
{
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++)
i--; //If the tile didn't spawn due to some odd reason ensure that the amount is spawned.
}
else
{
int position = Game1.random.Next(openTiles.Count);
this.spawnOreVein("Omegasis.Revitalize.Resources.Ore.Test", openTiles[position]);
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!");
}
}
*/
/// <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)
{
this.spawnOreInMine();
if(LocationUtilities.IsPlayerInMine()==false && LocationUtilities.IsPlayerInSkullCave() == false && LocationUtilities.IsPlayerInMineEnterance()==false)
{
this.visitedFloors.Clear();
}
}
#endregion

View File

@ -140,6 +140,8 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
if (this.extraDrops != null)
{
foreach (ResourceInformaton extra in this.extraDrops)
{
if (extra.shouldDropResource())
{
Item extraItem = extra.droppedItem.getOne();
int extraAmount = extra.getNumberOfDropsToSpawn();
@ -148,6 +150,11 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
Game1.createItemDebris(extraItem.getOne(), this.TileLocation * Game1.tileSize, Game1.random.Next(0, 3), this.location);
}
}
else
{
//Resource did not meet spawn chance.
}
}
}
if (this.location != null)

View File

@ -23,6 +23,19 @@ namespace Revitalize.Framework.Utilities
}
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>
/// Checks to see if the player is in skull cave.
/// </summary>