Lizzaran / PoGoBot

Pokemon Go Bot
GNU General Public License v3.0
0 stars 1 forks source link

Walking #1

Open drakbar opened 8 years ago

drakbar commented 8 years ago

Here is my walking function the input is a struct with an interface but you can feed it however you like, if it has a lat and long then you can move towards it. The speed is set to just barely under(max incubation speed) 20Km/h.

static void WalkTowards<T>(T input) where T : PointInfo {
  var lat_speed = 0.0000490; var long_speed = 0.0000490;   //update speed approximately 20Km/h 
  var sLat = input.Latitude; var sLon = input.Longitude;   //destination Geos
  var pLat = Program.session.Player.Latitude;
  var pLon = Program.session.Player.Longitude;

  var deltaX = pLat - sLat;                //is my destination north or south?
  var deltaY = pLon - sLon;                //is my destination east or west?

  // this works if you are in the north-west hemisphere 
  if (deltaX > 0) pLat -= lat_speed;  else pLat += lat_speed;  // head south else head north
  if (deltaY > 0) pLon -= long_speed; else pLon += long_speed; // head west else head east

  Program.session.Player.SetCoordinates(pLat, pLon);   //our new point about 5-6m away
}

This is the loop that calls the walk function once per second.

var oldTime    = TimeUtil.GetCurrentTimestampInMilliseconds(); //get the time now
var mDeltaTime = 0.0;  //the amount of time since the last frame
do                     //loop this until we are at the destination
{
   //update how far from the destination we are
   playerDistance = Program.session.Player.DistanceTo(shop.Latitude, shop.Longitude);

   //get the time now
   var newtime = TimeUtil.GetCurrentTimestampInMilliseconds();

   //find out how long its been since the last frame and add it to accumulator 
   mDeltaTime += newtime - oldTime;

   //if it has been one second since we last updated the position update again and reset deltatime
   if (mDeltaTime > 1000) {  WalkTowards(shop);  mDeltaTime = 0;  LegTime++;  }

   //the is gives a reference point for the new delta calculation 
   oldTime = newtime;
} 
while (playerDistance > 15);                // I like to get up nice and close
drakbar commented 8 years ago

Lol whats with...

"Ignores": [
          {
            "PokemonId": "Mewtwo"
          }
        ]

:grinning:

Lizzaran commented 8 years ago

@Eliminster0 just as an example, as far as I know Mewtwo isn't even in the game yet :smile: Thanks for the function, the only "problem" which I'm facing is with the caching of the TSP walking. I plan to add 3 modes:

  1. Simple/Greedy: Walk to the nearest Pokestop
  2. GPX support
  3. TSP (Traveling Salesman Problem) to generate the "best" route possible. As this is expensive and takes some time to compute, it is necessary to cache previous calculations. For a single instance this is no problem but gets complex if there are multiple instances running. Probably will need to look into inter-process communication or create a separate program which creates this files.