SomeoneEls
Sodbuster
And if this still technically isnt quite stardew valley it is still part of the game so...
This code. I hate it.
This code. I hate it.
C#:
private void randomWarpEvent(object obj)
{
while(Game1.player.IsBusyDoingSomething())
{
}
try
{
int loc = new Random().Next(0, 32);
//finds a valid location
while (loc == 15 || (loc >= 17 && loc <= 21) || (loc >= 25 && loc <= 30))
{
loc = new Random().Next(0, 32);
}
GameLocation locat = Game1.locations.ElementAt(loc);
Vector2 vect;
GameLocation playerLocat = Game1.player.currentLocation;
Vector2 playerVect = Game1.player.Tile;
try
{
//Looks at the diagonal left half of the map for an empty tile.
for (int y = 1; true; y++)
{
for (int x = 1; x<y; x++)
{
Vector2 buf = new Vector2(x, y);
if (!locat.IsTileBlockedBy(buf))
{
vect = buf;
int r = new Random().Next(0, 64);
if (r==3)
{
// I ****ing hate using goto here as goto sucks but its better than trying to create a complex break system that works with vector2 buf, as buf cannot be null.
goto randomWarpEvent_outOfLoop;
}
}
}
}
}
catch (Exception e)
{
//keep doing it until it works, since using goto causes issues. This is pretty cursed though. I'm sorry for my crimes.
if (GC.GetTotalMemory(false)> 1073741824)
{
//This doesnt really need to be here, but just in case you are SUPER unlucky and this loop goes on for far too long, no crash will happen.
// In reality, if this executes there is something very wrong. (ie, there is more than a GB of memory that is being used?!?!)
Console.WriteLine("Chaosaddon: Random warp failed due to lack of memory (OVER 1 GB OF MEMORY USED)");
return;
}
randomWarpEvent(obj);
return;
}
randomWarpEvent_outOfLoop:
Game1.warpFarmer(locat.Name, (int)vect.X, (int)vect.Y, false);
Thread.Sleep(15000);
//if the integer cast made the current tile blocked
if (playerLocat.IsTileBlockedBy(new Vector2((int)playerVect.X, (int)playerVect.Y)))
{
Game1.warpHome();
}
else
{
Game1.warpFarmer(playerLocat.Name, (int)playerVect.X, (int)playerVect.Y, false);
}
}
catch(Exception e)
{
}
}