I guess fixing pathfind and spritebatch errors.

This commit is contained in:
2017-11-24 13:12:36 -08:00
parent e51a8fbac5
commit 836d6861d8
11 changed files with 57 additions and 24 deletions

View File

@ -94,6 +94,7 @@ namespace StardustCore
lightColor = Color.Black;
thisType = this.GetType().ToString();
}
public CoreObject()

View File

@ -38,8 +38,12 @@ namespace StardustCore
IlluminateFramework.Colors.initializeColors();
}
private void SaveEvents_AfterLoad(object sender, EventArgs e)
{
SerializationManager.restoreAllModObjects(SerializationManager.trackedObjectList);

View File

@ -44,7 +44,6 @@
<ItemGroup>
<Compile Include="Animations\Animation.cs" />
<Compile Include="Animations\AnimationManager.cs" />
<Compile Include="DataNodes\PlacementNode.cs" />
<Compile Include="IlluminateFramework\Colors.cs" />
<Compile Include="ModCore.cs" />
<Compile Include="CoreObject.cs" />

View File

@ -8,7 +8,6 @@ using StardewValley.Objects;
using StardewValley.TerrainFeatures;
using StardewValley.Tools;
using StardustCore;
using StardustCore.DataNodes;
using System;
using System.Collections.Generic;
using System.Linq;
@ -23,6 +22,7 @@ namespace StardustCore
public class Utilities
{
public static List<CoreObject> masterRemovalList = new List<CoreObject>();
public static int sellToStorePrice(CoreObject c)
@ -31,6 +31,9 @@ namespace StardustCore
}
public static void createObjectDebris(Item I, int xTileOrigin, int yTileOrigin, int xTileTarget, int yTileTarget, int groundLevel = -1, int itemQuality = 0, float velocityMultiplyer = 1f, GameLocation location = null)
{
Debris debris = new Debris(I, new Vector2(xTileOrigin, yTileOrigin), new Vector2(xTileTarget, yTileTarget))

View File

@ -42,9 +42,10 @@ namespace StarAI
StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed;
StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad;
// StardewModdingAPI.Events.GraphicsEvents.OnPreRenderEvent += PathFindingCore.Utilities.addFromPlacementListBeforeDraw;
StardustCore.ModCore.SerializationManager.acceptedTypes.Add("StarAI.PathFindingCore.TileNode", new StardustCore.Serialization.SerializerDataNode(new StardustCore.Serialization.SerializerDataNode.SerializingFunction(TileNode.Serialize), new StardustCore.Serialization.SerializerDataNode.ParsingFunction(TileNode.ParseIntoInventory), new StardustCore.Serialization.SerializerDataNode.WorldParsingFunction(TileNode.SerializeFromWorld), new StardustCore.Serialization.SerializerDataNode.SerializingToContainerFunction(TileNode.Serialize)));
StardustCore.ModCore.SerializationManager.acceptedTypes.Add("StarAI.PathFindingCore.TileNode", new StardustCore.Serialization.SerializerDataNode(new StardustCore.Serialization.SerializerDataNode.SerializingFunction(StarAI.PathFindingCore.TileNode.Serialize), new StardustCore.Serialization.SerializerDataNode.ParsingFunction(StarAI.PathFindingCore.TileNode.ParseIntoInventory), new StardustCore.Serialization.SerializerDataNode.WorldParsingFunction(StarAI.PathFindingCore.TileNode.SerializeFromWorld), new StardustCore.Serialization.SerializerDataNode.SerializingToContainerFunction(StarAI.PathFindingCore.TileNode.Serialize)));
}
private void SaveEvents_AfterLoad(object sender, EventArgs e)
@ -83,7 +84,7 @@ namespace StarAI
{
CoreMonitor.Log("OK THE J KEY WAS PRESSED!");
List<Item> shoppingList = new List<Item>();
TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Aqua));
StarAI.PathFindingCore.TileNode t = new StarAI.PathFindingCore.TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Aqua));
if (t == null)
{
CoreMonitor.Log("WTF?????");
@ -110,7 +111,7 @@ namespace StarAI
{
CoreMonitor.Log("OK THE K KEY WAS PRESSED!");
TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.randomColor());
StarAI.PathFindingCore.TileNode t = new StarAI.PathFindingCore.TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.randomColor());
if (t == null)
{
CoreMonitor.Log("WTF?????");
@ -127,7 +128,7 @@ namespace StarAI
int yPos = (int)(Game1.player.getTileY()) * Game1.tileSize;
Rectangle r = new Rectangle(xPos, yPos, Game1.tileSize, Game1.tileSize);
Vector2 pos = new Vector2(r.X, r.Y);
bool ok = TileNode.checkIfICanPlaceHere(t, pos, Game1.player.currentLocation);
bool ok = StarAI.PathFindingCore.TileNode.checkIfICanPlaceHere(t, pos, Game1.player.currentLocation);
if (ok == false) return;
t.placementAction(Game1.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize);
//t.setAdjacentTiles(true);

View File

@ -29,7 +29,7 @@ namespace StarAI.PathFindingCore.CropLogic
{
//cropsToWater.Add(v.Key);
//If my dirt needs to be watered and the crop isn't fully grown.
if ((v.Value as StardewValley.TerrainFeatures.HoeDirt).state==0 && (v.Value as StardewValley.TerrainFeatures.HoeDirt).crop.fullyGrown == false)
if ((v.Value as StardewValley.TerrainFeatures.HoeDirt).state==0 && isCropFullGrown((v.Value as StardewValley.TerrainFeatures.HoeDirt).crop) == false)
{
TileNode t = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.LightSkyBlue));
t.placementAction(Game1.currentLocation, (int)v.Key.X * Game1.tileSize, (int)v.Key.Y * Game1.tileSize);
@ -114,7 +114,8 @@ namespace StarAI.PathFindingCore.CropLogic
tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX()*Game1.tileSize, Game1.player.getTileY()*Game1.tileSize);
//StaardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(tempSource, Game1.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize));
List<TileNode> path= PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource,nav,new List<TileNode>());
if (path != null)
if (path.Count!=0)
{
//ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn);
paths.Add(path);
@ -130,6 +131,7 @@ namespace StarAI.PathFindingCore.CropLogic
}
}
Console.WriteLine("GOALS COUNT:" + miniGoals.Count);
foreach(var q in removalList) {
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(q);
q.thisLocation.objects.Remove(q.tileLocation);
@ -141,6 +143,7 @@ namespace StarAI.PathFindingCore.CropLogic
{
if (potentialPath.Count < pathCost)
{
pathCost = potentialPath.Count;
correctPath = potentialPath;
}
@ -333,7 +336,7 @@ namespace StarAI.PathFindingCore.CropLogic
TileNode tempSource = new TileNode(1, Vector2.Zero, Path.Combine("Tiles", "GenericUncoloredTile.xnb"), Path.Combine("Tiles", "TileData.xnb"), StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.RosyBrown));
tempSource.placementAction(Game1.player.currentLocation, Game1.player.getTileX() * Game1.tileSize, Game1.player.getTileY() * Game1.tileSize);
List<TileNode> path = PathFindingCore.PathFindingLogic.pathFindToSingleGoalReturnPath(tempSource, nav, new List<TileNode>());
if (path != null)
if (path.Count!=0)
{
ModCore.CoreMonitor.Log("PATH WAS NOT NULL", LogLevel.Warn);
paths.Add(path);

View File

@ -114,7 +114,8 @@ namespace StarAI.PathFindingCore
if (x == -1 && y == 1) continue; //bottom left
if (x == 1 && y == -1) continue; //upper right
if (x == 1 && y == 1) continue; //bottom right
//TileNode t = new TileNode(1, Vector2.Zero, Souce.texturePath,source.dataPath, source.drawColor);
//TileNode t = new TileNode(1, Vector2.Zero, Souce.texturePath,source.dataPath, source.drawColor);
TileNode.setSingleTileAsChild(currentNode, (int)currentNode.tileLocation.X + x, (int)currentNode.tileLocation.Y + y);
Vector2 check = new Vector2((int)currentNode.tileLocation.X + x, (int)currentNode.tileLocation.Y + y);
if(check.X==Goal.tileLocation.X && check.Y == Goal.tileLocation.Y)
@ -261,7 +262,8 @@ namespace StarAI.PathFindingCore
}
calculateMovement(path);
// goals.Remove(Goal);
// goals.Remove(Goal);
//goals.Remove(Goal);
}
@ -301,7 +303,7 @@ namespace StarAI.PathFindingCore
bool goalFound = false;
while (currentNode.tileLocation != Goal.tileLocation && queue.Count != 0)
{
Console.WriteLine("OK WTF IS GOING ON????");
//Add children to current node
int xMin = -1;
int yMin = -1;
@ -321,7 +323,8 @@ namespace StarAI.PathFindingCore
if (x == 1 && y == -1) continue; //upper right
if (x == 1 && y == 1) continue; //bottom right
//TileNode t = new TileNode(1, Vector2.Zero, Souce.texturePath,source.dataPath, source.drawColor);
//ModCore.CoreMonitor.Log("HERE1", LogLevel.Error);
//ModCore.CoreMonitor.Log("HERE1", LogLevel.Error);
TileNode.setSingleTileAsChild(currentNode, (int)currentNode.tileLocation.X + x, (int)currentNode.tileLocation.Y + y);
//ModCore.CoreMonitor.Log("OR NO?", LogLevel.Error);
Vector2 check = new Vector2((int)currentNode.tileLocation.X + x, (int)currentNode.tileLocation.Y + y);
@ -399,7 +402,7 @@ namespace StarAI.PathFindingCore
if (currentNode.tileLocation != Goal.tileLocation)
{
ModCore.CoreMonitor.Log("NO PATH FOUND", LogLevel.Error);
return null;
return new List<TileNode>();
}
if (currentNode.tileLocation == Goal.tileLocation)
@ -487,6 +490,7 @@ namespace StarAI.PathFindingCore
bool xTargetReached = false;
bool yTargetReached = false;
List<TileNode> removalList = new List<TileNode>();
if (path.Count == 0) return;
while (path.Count > 0)
{
TileNode w = path[0];
@ -607,7 +611,7 @@ namespace StarAI.PathFindingCore
//StardustCore.Utilities.masterRemovalList.Add(v);
StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(v);
}
goals.Clear();
//goals.Clear();
}

View File

@ -1,24 +1,27 @@
using StardewValley;
using StardustCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StardustCore.DataNodes
namespace StarAI.PathFindingCore
{
public class PlacementNode
{
public CoreObject cObj;
public TileNode cObj;
public GameLocation location;
public int x;
public int y;
public PlacementNode(CoreObject C, GameLocation Location, int X, int Y) {
public PlacementNode(TileNode C, GameLocation Location, int X, int Y)
{
cObj = C;
location = Location;
x = X;
y = Y;
ModCore.CoreMonitor.Log(location.name);
}
}

View File

@ -91,7 +91,14 @@ namespace StarAI.PathFindingCore
}
}
}
if (t == null)
{
Console.WriteLine("OK T IS NULL");
}
if (t.thisLocation == null)
{
Console.WriteLine("OK T LOCATION IS NULL");
}
if (t.thisLocation.isObjectAt((int)pos.X, (int)pos.Y))
{
//ModCore.CoreMonitor.Log("Object at this tile position!: " + t.thisLocation.name, LogLevel.Warn);
@ -129,18 +136,21 @@ namespace StarAI.PathFindingCore
public static void setSingleTileAsChild(TileNode t,int x, int y)
{
Vector2 pos = new Vector2(x * Game1.tileSize, y * Game1.tileSize);
bool f= checkIfICanPlaceHere(t, new Vector2(pos.X,pos.Y), null);
bool f= checkIfICanPlaceHere(t, new Vector2(pos.X,pos.Y));
if (f == false) return;
else
{
// ModCore.CoreMonitor.Log("Adding a child!");
System.Threading.Thread.Sleep(PathFindingCore.PathFindingLogic.delay);
TileNode child = new TileNode(1, Vector2.Zero, t.texturePath,t.dataPath,StardustCore.IlluminateFramework.Colors.invertColor(StardustCore.IlluminateFramework.ColorsList.Cyan));
child.seenState = (int)stateEnum.NotVisited;
child.parent = t;
child.placementAction(Game1.currentLocation, (int)pos.X, (int)pos.Y);
//StardustCore.Utilities.masterAdditionList.Add(new StardustCore.DataNodes.PlacementNode(child, Game1.currentLocation, (int)pos.X, (int)pos.Y));
//StarAI.PathFindingCore.Utilities.masterAdditionList.Add(new StarAI.PathFindingCore.PlacementNode(child, Game1.currentLocation, (int)pos.X, (int)pos.Y));
t.children.Add(child);
}
}

View File

@ -13,11 +13,15 @@ namespace StarAI.PathFindingCore
public class Utilities
{
public static List<TileExceptionMetaData> tileExceptionList = new List<TileExceptionMetaData>();
public static List<TileExceptionMetaData> tileExceptionList = new List<TileExceptionMetaData>();
public static List<TileExceptionNode> ignoreCheckTiles = new List<TileExceptionNode>();
public static string folderForExceptionTiles="ExceptionTilesData";
public static Vector2 parseCenterFromTile(int tileX, int tileY)
{
//int x = (tileX * Game1.tileSize) + Game1.tileSize / 2;

View File

@ -63,6 +63,7 @@
<Compile Include="ModCore.cs" />
<Compile Include="PathFindingCore\CropLogic\CropLogic.cs" />
<Compile Include="PathFindingCore\PathFindingLogic.cs" />
<Compile Include="PathFindingCore\PlacementNode.cs" />
<Compile Include="PathFindingCore\TileExceptionMetaData.cs" />
<Compile Include="PathFindingCore\TileExceptionNode.cs" />
<Compile Include="PathFindingCore\TileNodeObject.cs" />