Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Storm.ExternalEvent;
- using Storm.StardewValley;
- using Storm.StardewValley.Event;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Storm.StardewValley.Wrapper;
- using Storm.StardewValley.Proxy;
- using System.Collections;
- using Storm.StardewValley.Accessor;
- namespace FarmingBotMod
- {
- [Mod]
- public class FarmingBotMod : DiskResource
- {
- // bots crafting ingrediants 1 iridium ingot, 50 coal, 1 battery, 1 refined crystal
- // bot starts with 50 coal
- // setting bot down
- // allow interaction of the bot
- // configuration of the bot 3x3 and 5x5
- // bot needs coal to run
- // bot uses coal every 7.5 seconds
- [Subscribe]
- public void PreObjectDayUpdateCallback(PreObjectDayUpdateEvent @event)// using as a place holder
- {
- //get location
- Storm.StardewValley.Wrapper.ObjectItem obj = @event.This;
- GameLocation location = @event.ArgLocation;
- int savedCounter = 0;
- //Dictionary<int, Vector2> savedLocationHarvestableCrops = new Dictionary<int, Vector2>(); // using dictionary as a list
- var savedLocationHarvestableCrops = new List<Vector2>(); // create list to store tileLocations that are plants that have product.
- // bot senses when crops are done
- if (obj.Name == "Hardwood Fence")
- {
- //debugging
- Console.WriteLine();
- Console.WriteLine("----------New day Start---------");
- // find location of the bot and save the default location
- Microsoft.Xna.Framework.Vector2 tileLocation = obj.TileLocation;
- Microsoft.Xna.Framework.Vector2 defLocation = tileLocation;
- // tileLocation is where the search for crops start
- // because we want to cover a 5*5 spread includ ing the first x value. x will start at -= 4 and end at += 4, y will start at -= 1 and end at -= 5
- // an increase in y is lower on the screen. ex plots start top left at 0,0 to bottom right at 9999,9999
- tileLocation.X -= 4;
- tileLocation.Y += 1;
- //debugging
- //Console.WriteLine("First Tile Location for x = " + tileLocation.X + " Tile Location for y = " + tileLocation.Y);
- //Console.WriteLine("default Location for x = " + defLocation.X + " default Location for y = " + defLocation.Y);
- int counter = 0;
- int actuallyHarvestableCropsCounter = 0;
- //counts the crops to out put for debugging
- int cropCounter = 0;
- //count the crops
- //debugging
- //Console.WriteLine("before running the while statement.");
- while (counter < 5)
- {
- //debugging
- Console.WriteLine("Starting Tile Location for x = " + tileLocation.X + " Tile Location for y = " + tileLocation.Y);
- //debugging
- /*Console.WriteLine("before running the if statement.");
- Console.WriteLine(location.TerrainFeatures.ContainsKey(tileLocation));
- try
- {
- //Console.WriteLine(location.TerrainFeatures[tileLocation].IsHoeDirt()); //old
- Console.WriteLine(location.TerrainFeatures[tileLocation].Is<HoeDirtAccessor>());
- }
- catch
- {
- Console.WriteLine("Not hoedirt");
- }*/
- //HoeDirt[] hoeDirts = location.TerrainFeatures.Where(x => x.Value.Expose() is HoeDirtAccessor).ToArray<HoeDirt>();
- //Console.WriteLine(hoeDirts[0].ToString());
- Console.WriteLine("Before verifiying if tileLocation is hoeDirt.");
- //if (location.TerrainFeatures.ContainsKey(tileLocation) && location.TerrainFeatures[tileLocation].IsHoeDirt()) // old
- if (location.TerrainFeatures.ContainsKey(tileLocation) && location.TerrainFeatures[tileLocation].Is<HoeDirtAccessor>())
- {
- Console.WriteLine("Succesfully verified hoeDirt");
- HoeDirt crop = location.TerrainFeatures[tileLocation].As<HoeDirt,HoeDirtAccessor>();
- //degbuging
- //Console.WriteLine("Before checking crops is true or not.");
- //check if crops are fully grown
- try
- {
- // check if fully grown
- if (crop.Crop.IsFullyGrown == true)
- {
- Console.WriteLine("Found fully grown crop.");
- ++cropCounter;
- // if fully grown check if harvestable
- if(crop.Crop.CurrentPhase >= crop.Crop.PhaseDays.Count - 1 && (!crop.Crop.IsFullyGrown || crop.Crop.DayOfCurrentPhase <= 0))
- {
- Console.WriteLine("Found a crop that can be harvested located at " + tileLocation.X + " and " + tileLocation.Y);
- ++actuallyHarvestableCropsCounter;
- // save location
- savedLocationHarvestableCrops.Add(tileLocation);
- ++savedCounter;
- }
- }
- } catch (Exception e) //(System.NullReferenceException) this crashes the game when ran in concecutive days
- {
- Console.WriteLine("--------------------------");
- Console.WriteLine(e);
- Console.WriteLine("hoedirt but no crop");
- Console.WriteLine("--------------------------");
- }
- //debuging
- //Console.WriteLine("After checking if crops are true or not.");
- }
- //debugging
- //Console.WriteLine("before check 1");
- // check if tileLocation is equal to default location, x will go to default x, y will go to default y + 5
- // may not be needed
- if (tileLocation.X == defLocation.X && tileLocation.Y == defLocation.Y + 5)
- {
- //debugging
- //Console.WriteLine("Finished checking tiles");
- ++counter;
- }
- //check if tilelocation.x is the default location
- else if (tileLocation.X == defLocation.X)
- {
- tileLocation.X -= 4;
- tileLocation.Y += 1;
- counter = 0;
- //debugging
- //Console.WriteLine("reseting pos to 1 down 4 to the left");
- }
- // if nether previous are true continue counting.
- else
- {
- //debugging
- //Console.WriteLine("inside check 3");
- tileLocation.X += 1;
- ++counter;
- }
- //debugging
- //Console.WriteLine("after check 3");
- //debugging
- //Console.WriteLine("Ending Tile Location for x = " + tileLocation.X + " Tile Location for y = " + tileLocation.Y);
- }
- Console.WriteLine(cropCounter + " total fully grown crops and " + actuallyHarvestableCropsCounter + " total crops ready to be harvested.");
- //harvest find chest
- @event.ReturnEarly = true;
- }
- //debugging
- if (savedCounter != 0)
- {
- int test = 0;
- Console.WriteLine();
- Console.WriteLine(savedCounter + " saved locations");
- while (test < savedCounter)
- {
- Console.WriteLine("{0}, {1}", savedLocationHarvestableCrops[test].X, savedLocationHarvestableCrops[test].Y);
- ++test;
- }
- }//end debugging
- }
- // bot finds a path to crops (going around sprinklers and scarecrows)
- // bot farms the crops and contains them in a chest.
- // bot return to the spot it was placed.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement