Got ores spawning on the farm, finished resource manager statistics, and made ore use proper health values.

This commit is contained in:
JoshuaNavarro 2019-08-16 12:26:50 -07:00
parent 01cc1d29ec
commit 16d35e2d42
6 changed files with 249 additions and 47 deletions

View File

@ -275,17 +275,43 @@ namespace Revitalize.Framework.Objects.InformationFiles
return amount;
}
/*
/// <summary>
/// Checks to see if this resource can spawn in the quarry based off of RNG.
/// </summary>
/// <returns></returns>
public virtual bool shouldSpawnInQuarry()
{
double chance = Game1.random.NextDouble();
chance = (chance - (this.spawnChanceLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)));
if (this.quarrySpawnChance >= chance) return true;
else return false;
}
public virtual bool shouldSpawnInFarm()
/// <summary>
/// Checks to see if this resource should spawn on the farm based of of rng.
/// </summary>
/// <returns></returns>
public virtual bool shouldSpawnOnFarm()
{
double chance = Game1.random.NextDouble();
chance = (chance - (this.spawnChanceLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)));
if (this.farmSpawnChance >= chance) return true;
else return false;
}
*/
/// <summary>
/// Checks to see if this resource should spawn in the skull cavern based of of rng.
/// </summary>
/// <returns></returns>
public virtual bool shouldSpawnInSkullCave()
{
double chance = Game1.random.NextDouble();
chance = (chance - (this.spawnChanceLuckFactor * (Game1.player.LuckLevel + Game1.player.addedLuckLevel.Value)));
if (this.skullCaveSpawnChance >= chance) return true;
else return false;
}
/// <summary>
/// Can this ore spawn at the given location?

View File

@ -211,6 +211,15 @@ namespace Revitalize.Framework.Objects
if (ObjectPools == null) ObjectPools = new Dictionary<string, ObjectManager>();
ObjectPools.Add(Manifest.UniqueID, new ObjectManager(Manifest));
}
/// <summary>
/// Cleans up all stored information.
/// </summary>
public void returnToTitleCleanUp()
{
}
}

View File

@ -24,6 +24,9 @@ namespace Revitalize.Framework.Objects
/// A list of all of the ores held by the resource manager.
/// </summary>
public Dictionary<string, OreVeinObj> ores;
/// <summary>
/// A list of all visited floors on the current visit to the mines.
/// </summary>
public List<int> visitedFloors;
/// <summary>
@ -46,15 +49,43 @@ 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<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), true, true, true, false, new List<IntRange>()
{
new IntRange(1,9)
}, new List<IntRange>(), 1, 5, 1, 10, 1d, 1d, 0, 0, 0, 0), new List<ResourceInformaton>()));
}, new List<IntRange>(), (i => i == 1), (i => i % 10 == 0), 1, 5, 1, 10, new IntRange(1, 3), new IntRange(1, 3), new IntRange(0, 0), new List<IntRange>()
{
new IntRange(0,0)
}, new List<IntRange>()
{
new IntRange(0,9999)
}, (i => i == -1), (i => i == -1), 1d, 1.0d, 0.10d, 1d, 1d, 0, 0, 0, 0), new List<ResourceInformaton>(),4));
this.ores.Add("Omegasis.Revitalize.Resources.Ore.Test", testOre);
*/
}
/// <summary>
/// Checks to see if a resource can be spawned here.
/// </summary>
/// <param name="OBJ"></param>
/// <param name="Location"></param>
/// <param name="TilePosition"></param>
/// <returns></returns>
public bool canResourceBeSpawnedHere(MultiTiledObject OBJ, GameLocation Location, Vector2 TilePosition)
{
return OBJ.canBePlacedHere(Location, TilePosition) && Location.isTileLocationTotallyClearAndPlaceable(TilePosition);
}
//~~~~~~~~~~~~~~~~~~~~~~~//
// World Ore Spawn Code //
//~~~~~~~~~~~~~~~~~~~~~~~//
#region
/// <summary>
/// Spawns an ore vein at the given location if possible.
/// </summary>
@ -100,23 +131,8 @@ namespace Revitalize.Framework.Objects
}
/// <summary>
/// Checks to see if a resource can be spawned here.
/// Spawns ore in the mine depending on a lot of given variables such as floor level and spawn chance.
/// </summary>
/// <param name="OBJ"></param>
/// <param name="Location"></param>
/// <param name="TilePosition"></param>
/// <returns></returns>
public bool canResourceBeSpawnedHere(MultiTiledObject OBJ, GameLocation Location, Vector2 TilePosition)
{
return OBJ.canBePlacedHere(Location, TilePosition) && Location.isTileLocationTotallyClearAndPlaceable(TilePosition);
}
//~~~~~~~~~~~~~~~~~~~~~~~//
// Mine ore spawn code //
//~~~~~~~~~~~~~~~~~~~~~~~//
#region
public void spawnOreInMine()
{
int floorLevel = LocationUtilities.CurrentMineLevel();
@ -211,16 +227,15 @@ namespace Revitalize.Framework.Objects
}
foreach (OreVeinObj ore in spawnableOreVeins)
{
if (ore.resourceInfo.shouldSpawn())
if ((ore.resourceInfo as OreResourceInformation).shouldSpawnInQuarry())
{
int amount = ore.resourceInfo.getNumberOfNodesToSpawn();
int amount = (ore.resourceInfo as OreResourceInformation).getNumberOfNodesToSpawnQuarry();
List<Vector2> openTiles = this.getOpenQuarryTiles(ore);
//ModCore.log("Number of open tiles is: " + openTiles.Count);
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,Game1.getLocationFromName("Mountain"),openTiles[position]);
bool didSpawn = this.spawnOreVein(ore.info.id, Game1.getLocationFromName("Mountain"), openTiles[position]);
if (didSpawn == false)
{
i--; //If the tile didn't spawn due to some odd reason ensure that the amount is spawned.
@ -238,7 +253,65 @@ namespace Revitalize.Framework.Objects
{
//Ore doesn't meet spawn chance.
}
//ModCore.log("Spawned :" + amount + " pancake test ores!");
}
}
/// <summary>
/// Spawns ore in the mountain farm every day.
/// </summary>
public void mountainFarmDayUpdate()
{
if (LocationUtilities.Farm_IsFarmHiltopFarm() == false)
{
ModCore.log("Farm is not hiltop farm!");
return;
}
GameLocation farm = Game1.getFarm();
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)
{
if ((pair.Value.resourceInfo as OreResourceInformation).spawnsOnFarm)
{
spawnableOreVeins.Add(pair.Value);
ModCore.log("Found an ore that spawns on the farm!");
}
}
foreach (OreVeinObj ore in spawnableOreVeins)
{
if ((ore.resourceInfo as OreResourceInformation).shouldSpawnOnFarm())
{
int amount = (ore.resourceInfo as OreResourceInformation).getNumberOfNodesToSpawnFarm();
List<Vector2> openTiles = this.getFarmQuarryOpenTiles(ore);
if (openTiles.Count == 0)
{
ModCore.log("No open farm tiles!");
}
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, farm, openTiles[position]);
if (didSpawn == false)
{
i--; //If the tile didn't spawn due to some odd reason ensure that the amount is spawned.
openTiles.Remove(openTiles[position]);
//amount = Math.Min(amount, openTiles.Count); //Only spawn for as many open tiles or the amount of nodes to spawn.
ModCore.log("Did not spawn ore in the farm quarry!");
}
else
{
ModCore.log("Spawned ore in the farm quarry!");
openTiles.Remove(openTiles[position]); //Remove that tile from the list of open tiles.
}
}
}
else
{
//Ore doesn't meet spawn chance.
}
}
}
@ -251,11 +324,11 @@ namespace Revitalize.Framework.Objects
{
List<Vector2> tiles = new List<Vector2>();
Microsoft.Xna.Framework.Rectangle r = new Microsoft.Xna.Framework.Rectangle(106, 13, 21, 21);
for(int i = r.X; i <= r.X + r.Width; i++)
for (int i = r.X; i <= r.X + r.Width; i++)
{
for(int j=r.Y;j<= r.Y + r.Height; j++)
for (int j = r.Y; j <= r.Y + r.Height; j++)
{
if (this.isTileOpenForQuarryStone(i, j) && this.canResourceBeSpawnedHere(obj,Game1.getLocationFromName("Mountain"),new Vector2(i,j)))
if (this.isTileOpenForQuarryStone(i, j) && this.canResourceBeSpawnedHere(obj, Game1.getLocationFromName("Mountain"), new Vector2(i, j)))
{
tiles.Add(new Vector2(i, j));
}
@ -268,10 +341,42 @@ namespace Revitalize.Framework.Objects
return tiles;
}
/// <summary>
/// Gets all of the open tiles in the farm quarry.
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
private List<Vector2> getFarmQuarryOpenTiles(MultiTiledObject obj)
{
List<Vector2> tiles = new List<Vector2>();
Microsoft.Xna.Framework.Rectangle r = new Microsoft.Xna.Framework.Rectangle(5, 37, 22, 8);
GameLocation farm = Game1.getFarm();
for (int i = r.X; i <= r.X + r.Width; i++)
{
for (int j = r.Y; j <= r.Y + r.Height; j++)
{
Vector2 pos = new Vector2(i, j);
if (farm.doesTileHavePropertyNoNull((int)pos.X, (int)pos.Y, "Type", "Back").Equals("Dirt") && this.canResourceBeSpawnedHere(obj, farm, new Vector2(i, j)))
{
tiles.Add(pos);
}
}
}
if (tiles.Count == 0)
{
//ModCore.log("Quarry is full! Can't spawn more resources!");
}
return tiles;
}
#endregion
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// SMAPI Events //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
#region
/// <summary>
/// What happens when the player warps maps.
/// </summary>
@ -286,11 +391,17 @@ namespace Revitalize.Framework.Objects
}
}
/// <summary>
/// Triggers at the start of every new day to populate the world full of ores.
/// </summary>
/// <param name="o"></param>
/// <param name="NewDay"></param>
public void DailyResourceSpawn(object o, EventArgs NewDay)
{
this.mountainFarmDayUpdate();
this.quarryDayUpdate();
}
#endregion
}
}

View File

@ -20,25 +20,29 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
/// </summary>
public ResourceInformaton resourceInfo;
public List<ResourceInformaton> extraDrops;
public int healthValue;
public OreVeinTile() : base()
{
}
public OreVeinTile(CustomObjectData PyTKData, BasicItemInformation Info,ResourceInformaton Resource,List<ResourceInformaton> ExtraDrops) : base(PyTKData, Info)
public OreVeinTile(CustomObjectData PyTKData, BasicItemInformation Info,ResourceInformaton Resource,List<ResourceInformaton> ExtraDrops,int Health) : base(PyTKData, Info)
{
this.health = 3;
this.healthValue = Health;
this.resourceInfo = Resource;
this.extraDrops = ExtraDrops != null ? ExtraDrops : new List<ResourceInformaton>();
this.setHealth(this.healthValue);
}
public OreVeinTile(CustomObjectData PyTKData, BasicItemInformation Info, Vector2 TileLocation,ResourceInformaton Resource, List<ResourceInformaton> ExtraDrops) : base(PyTKData, Info, TileLocation)
public OreVeinTile(CustomObjectData PyTKData, BasicItemInformation Info, Vector2 TileLocation,ResourceInformaton Resource, List<ResourceInformaton> ExtraDrops,int Health) : base(PyTKData, Info, TileLocation)
{
this.health = 3;
this.healthValue = Health;
this.resourceInfo = Resource;
this.extraDrops = ExtraDrops != null ? ExtraDrops : new List<ResourceInformaton>();
this.setHealth(this.healthValue);
}
@ -53,6 +57,24 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
return base.performDropDownAction(who);
}
public override void actionOnPlayerEntry()
{
base.actionOnPlayerEntry();
this.setHealth(this.healthValue);
}
public override void updateWhenCurrentLocation(GameTime time, GameLocation environment)
{
base.updateWhenCurrentLocation(time, environment);
this.setHealth(this.healthValue);
}
public override void DayUpdate(GameLocation location)
{
base.DayUpdate(location);
this.setHealth(this.healthValue);
}
//Checks for any sort of interaction IF and only IF there is a held object on this tile.
public override bool checkForAction(Farmer who, bool justCheckingForActivity = false)
{
@ -79,6 +101,12 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
//return false;
}
/// <summary>
/// What happens when the player hits this with a tool.
/// </summary>
/// <param name="t"></param>
/// <param name="location"></param>
/// <returns></returns>
public override bool performToolAction(Tool t, GameLocation location)
{
@ -89,7 +117,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
if (this.location != null)
{
this.location.playSound("hammer");
//ModCore.log("Ore has this much health left: "+this.health);
ModCore.log("Ore has this much health left: "+this.healthValue);
}
return false;
}
@ -101,6 +129,12 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
//return base.performToolAction(t, location);
}
/// <summary>
/// What happens when an explosion occurs for this object.
/// </summary>
/// <param name="who"></param>
/// <param name="location"></param>
/// <returns></returns>
public override bool onExplosion(Farmer who, GameLocation location)
{
this.destoryVein();
@ -117,8 +151,8 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
if (amount <= 0) return;
else
{
this.health -= amount;
if (this.health <= 0)
this.healthValue -= amount;
if (this.healthValue <= 0)
{
this.destoryVein();
}
@ -192,10 +226,9 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
return base.shiftRightClicked(who);
}
public override Item getOne()
{
OreVeinTile component = new OreVeinTile(this.data, this.info,this.resourceInfo,this.extraDrops);
OreVeinTile component = new OreVeinTile(this.data, this.info,this.resourceInfo,this.extraDrops,this.healthValue);
component.containerObject = this.containerObject;
component.offsetKey = this.offsetKey;
return component;
@ -204,9 +237,6 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
public override ICustomObject recreate(Dictionary<string, string> additionalSaveData, object replacement)
{
//instead of using this.offsetkey.x use get additional save data function and store offset key there
Vector2 offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"]));
OreVeinTile self = Revitalize.ModCore.Serializer.DeserializeGUID<OreVeinTile>(additionalSaveData["GUID"]);
if (self == null)

View File

@ -9,8 +9,24 @@ using StardewValley;
namespace Revitalize.Framework.Utilities
{
/// <summary>
/// Deals with helping with locational logic.
/// </summary>
public class LocationUtilities
{
/// <summary>
/// The int value used by SDV to determine if a farm is a hilltop farm.
/// </summary>
public static int Farm_HilltopFarmNumber
{
get
{
return 3;
}
}
/// <summary>
/// Checks to see if the player is in the regular mine.
/// </summary>
@ -100,5 +116,14 @@ namespace Revitalize.Framework.Utilities
}
return openTiles;
}
/// <summary>
/// Checks to see if the farm for the game is the hilltop farm.
/// </summary>
/// <returns></returns>
public static bool Farm_IsFarmHiltopFarm()
{
return Game1.whichFarm == Farm_HilltopFarmNumber;
}
}
}

View File

@ -220,7 +220,7 @@ namespace Revitalize
//customObjects = new Dictionary<string, CustomObject>();
ObjectGroups = new Dictionary<string, MultiTiledObject>();
ObjectManager = new ObjectManager();
ObjectManager = new ObjectManager(Manifest);
Serializer = new Serializer();
ObjectsToDraw = new Dictionary<GameLocation, MultiTiledObject>();
@ -257,6 +257,7 @@ namespace Revitalize
private void GameLoop_ReturnedToTitle(object sender, StardewModdingAPI.Events.ReturnedToTitleEventArgs e)
{
Serializer.returnToTitle();
ObjectManager = new ObjectManager(Manifest);
}
/// <summary>
/// Must be enabled for the tabled to be placed????