Got the code working for ores to properly spawn in the mine!

This commit is contained in:
JoshuaNavarro 2019-08-13 20:13:27 -07:00
parent 9b8c469eb6
commit 768e09cf43
5 changed files with 129 additions and 7 deletions

View File

@ -104,5 +104,34 @@ namespace Revitalize.Framework.Objects
return OBJ.canBePlacedHere(Location, TilePosition);
}
//~~~~~~~~~~~~~~~~~~~~~~~//
// Mine ore spawn code //
//~~~~~~~~~~~~~~~~~~~~~~~//
#region
public void spawnOreInMine()
{
int floorLevel = LocationUtilities.CurrentMineLevel();
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["Test"].getOne());
for(int i = 0; i <= amount; i++)
{
int position = Game1.random.Next(openTiles.Count);
this.spawnOreVein("Test", openTiles[position]);
}
ModCore.log("Spawned :" + amount + " pancake test ores!");
}
}
public void OnPlayerLocationChanged(object o,EventArgs playerWarped)
{
this.spawnOreInMine();
}
#endregion
}
}

View File

@ -131,7 +131,7 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
Item newItem = this.resourceInfo.droppedItem.getOne();
for(int i = 0; i < amount; i++)
{
Game1.createItemDebris(newItem, this.TileLocation*Game1.tileSize, Game1.random.Next(0, 3), this.location);
Game1.createItemDebris(newItem.getOne(), this.TileLocation*Game1.tileSize, Game1.random.Next(0, 3), this.location);
}
if (this.location != null)
{

View File

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Revitalize.Framework.Objects;
using StardewValley;
namespace Revitalize.Framework.Utilities
{
public class LocationUtilities
{
/// <summary>
/// Checks to see if the player is in the regular mine.
/// </summary>
/// <returns></returns>
public static bool IsPlayerInMine()
{
if (Game1.player.currentLocation.Name.StartsWith("UndergroundMine"))
{
return true;
}
return false;
}
/// <summary>
/// Checks to see if the player is in skull cave.
/// </summary>
/// <returns></returns>
public static bool IsPlayerInSkullCave()
{
if (Game1.player.currentLocation.Name == "SkullCave" || Game1.player.currentLocation.Name.StartsWith("SkullCave"))
{
return true;
}
return false;
}
/// <summary>
/// Gets the current mine level for the player. If the player is not in the mine this is -1.
/// </summary>
/// <returns></returns>
public static int CurrentMineLevel()
{
if (IsPlayerInMine())
{
return (Game1.player.currentLocation as StardewValley.Locations.MineShaft).mineLevel;
}
else
{
return -1;
}
}
/// <summary>
/// Gets the tile width and height for the map.
/// </summary>
/// <param name="location"></param>
/// <returns></returns>
public static Vector2 GetLocationTileDimensions(GameLocation location)
{
Vector2 dimensions = new Vector2(location.Map.GetLayer("Back").LayerWidth, location.Map.GetLayer("Back").LayerHeight);
ModCore.log("Dimensions of map is: " + dimensions);
return dimensions;
}
/// <summary>
/// Gets all open positions for this location for this object.
/// </summary>
/// <param name="Location"></param>
/// <param name="TestObject"></param>
/// <returns></returns>
public static List<Vector2> GetOpenObjectTiles(GameLocation Location,MultiTiledObject TestObject)
{
Vector2 dimensions = GetLocationTileDimensions(Location);
List<Vector2> openTiles = new List<Vector2>();
for(int i = 0; i < dimensions.X; i++)
{
for(int j = 0; j < dimensions.Y; j++)
{
Vector2 tile = new Vector2(i, j);
if (TestObject.canBePlacedHere(Location, tile))
{
openTiles.Add(tile);
}
}
}
return openTiles;
}
}
}

View File

@ -198,11 +198,7 @@ namespace Revitalize
this.createDirectories();
this.initailizeComponents();
ModHelper.Events.GameLoop.SaveLoaded += this.GameLoop_SaveLoaded;
ModHelper.Events.GameLoop.TimeChanged += this.GameLoop_TimeChanged;
ModHelper.Events.GameLoop.UpdateTicked += this.GameLoop_UpdateTicked;
ModHelper.Events.GameLoop.ReturnedToTitle += this.GameLoop_ReturnedToTitle;
ModHelper.Events.Input.ButtonPressed += this.Input_ButtonPressed;
playerInfo = new PlayerInfo();
TextureManager.AddTextureManager(Manifest, "Furniture");
@ -229,7 +225,12 @@ namespace Revitalize
Serializer = new Serializer();
ObjectsToDraw = new Dictionary<GameLocation, MultiTiledObject>();
ModHelper.Events.GameLoop.SaveLoaded += this.GameLoop_SaveLoaded;
ModHelper.Events.GameLoop.TimeChanged += this.GameLoop_TimeChanged;
ModHelper.Events.GameLoop.UpdateTicked += this.GameLoop_UpdateTicked;
ModHelper.Events.GameLoop.ReturnedToTitle += this.GameLoop_ReturnedToTitle;
ModHelper.Events.Input.ButtonPressed += this.Input_ButtonPressed;
ModHelper.Events.Player.Warped += ObjectManager.resources.OnPlayerLocationChanged;
}
private void Input_ButtonPressed(object sender, StardewModdingAPI.Events.ButtonPressedEventArgs e)

View File

@ -136,6 +136,7 @@
<Compile Include="Framework\Player\PlayerInfo.cs" />
<Compile Include="Framework\Utilities\BoundingBoxInfo.cs" />
<Compile Include="Framework\Utilities\InventoryManager.cs" />
<Compile Include="Framework\Utilities\LocationUtilities.cs" />
<Compile Include="Framework\Utilities\PyTKHelper.cs" />
<Compile Include="Framework\Utilities\RotationUtilities.cs" />
<Compile Include="Framework\Utilities\Serialization\ContractResolvers\NetFieldContract.cs" />