New trainer icon & Grey looted pokestops

Brian [2016-08-16 16:23:42]
New trainer icon & Grey looted pokestops
Filename
PokemonGo.RocketBot.Logic/Event/LootPokestopEvent.cs
PokemonGo.RocketBot.Logic/PokemonGo.RocketBot.Logic.csproj
PokemonGo.RocketBot.Logic/Tasks/FarmPokestopsTask.cs
PokemonGo.RocketBot.Window/Forms/MainForm.cs
PokemonGo.RocketBot.Window/Images/Pokestop_Inrange.png
PokemonGo.RocketBot.Window/Images/Markers/Pokestop_looted.png
PokemonGo.RocketBot.Window/Images/Trainer.png
PokemonGo.RocketBot.Window/PokemonGo.RocketBot.Window.csproj
PokemonGo.RocketBot.Window/Properties/Resources.Designer.cs
PokemonGo.RocketBot.Window/Properties/Resources.resx
diff --git a/PokemonGo.RocketBot.Logic/Event/LootPokestopEvent.cs b/PokemonGo.RocketBot.Logic/Event/LootPokestopEvent.cs
new file mode 100644
index 0000000..05bf083
--- /dev/null
+++ b/PokemonGo.RocketBot.Logic/Event/LootPokestopEvent.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using POGOProtos.Map.Fort;
+
+namespace PokemonGo.RocketBot.Logic.Event
+{
+    public class LootPokestopEvent : IEvent
+    {
+        public FortData Pokestop;
+    }
+}
diff --git a/PokemonGo.RocketBot.Logic/PokemonGo.RocketBot.Logic.csproj b/PokemonGo.RocketBot.Logic/PokemonGo.RocketBot.Logic.csproj
index 50044b2..525714a 100644
--- a/PokemonGo.RocketBot.Logic/PokemonGo.RocketBot.Logic.csproj
+++ b/PokemonGo.RocketBot.Logic/PokemonGo.RocketBot.Logic.csproj
@@ -112,6 +112,7 @@
     <Compile Include="Event\FortUsedEvent.cs" />
     <Compile Include="Event\InventoryListEvent.cs" />
     <Compile Include="Event\ItemRecycledEvent.cs" />
+    <Compile Include="Event\LootPokestopEvent.cs" />
     <Compile Include="Event\NoPokeballEvent.cs" />
     <Compile Include="Event\OptimizeRouteEvent.cs" />
     <Compile Include="Event\SnipeEvent.cs" />
diff --git a/PokemonGo.RocketBot.Logic/Tasks/FarmPokestopsTask.cs b/PokemonGo.RocketBot.Logic/Tasks/FarmPokestopsTask.cs
index e5f191f..8f2d85c 100644
--- a/PokemonGo.RocketBot.Logic/Tasks/FarmPokestopsTask.cs
+++ b/PokemonGo.RocketBot.Logic/Tasks/FarmPokestopsTask.cs
@@ -22,7 +22,10 @@ namespace PokemonGo.RocketBot.Logic.Tasks
     public static class FarmPokestopsTask
     {
         public static int TimesZeroXPawarded;
-        private static int storeRI;
+        private static int _storeRi;
+
+        public delegate void LootPokestopDelegate(FortData pokestop);
+
         public static async Task Execute(ISession session, CancellationToken cancellationToken)
         {
             cancellationToken.ThrowIfCancellationRequested();
@@ -51,7 +54,7 @@ namespace PokemonGo.RocketBot.Logic.Tasks

             var stopsHit = 0;
             var rc = new Random(); //initialize pokestop random cleanup counter first time
-            storeRI = rc.Next(8, 15);
+            _storeRi = rc.Next(8, 15);
             var eggWalker = new EggWalker(1000, session);

             if (pokestopList.Count <= 0)
@@ -78,10 +81,10 @@ namespace PokemonGo.RocketBot.Logic.Tasks
                 session.LogicSettings.WalkingSpeedInKilometerPerHour,
                 async () =>
                 {
-                        // Catch normal map Pokemon
-                        await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
-                        //Catch Incense Pokemon
-                        await CatchIncensePokemonsTask.Execute(session, cancellationToken);
+                    // Catch normal map Pokemon
+                    await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
+                    //Catch Incense Pokemon
+                    await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                     return true;
                 }, cancellationToken, session.LogicSettings.DisableHumanWalking);

@@ -156,8 +159,9 @@ namespace PokemonGo.RocketBot.Logic.Tasks
                         });

                         if (fortSearch.Result == FortSearchResponse.Types.Result.InventoryFull)
-                            storeRI = 1;
+                            _storeRi = 1;

+                        OnLootPokestopEvent(pokeStop);
                         break; //Continue with program as loot was succesfull.
                     }
                 } while (fortTry < retryNumber - zeroCheck);
@@ -165,9 +169,9 @@ namespace PokemonGo.RocketBot.Logic.Tasks

                 await eggWalker.ApplyDistance(distance, cancellationToken);

-                if (++stopsHit >= storeRI) //TODO: OR item/pokemon bag is full //check stopsHit against storeRI random without dividing.
+                if (++stopsHit >= _storeRi) //TODO: OR item/pokemon bag is full //check stopsHit against storeRI random without dividing.
                 {
-                    storeRI = rc.Next(6, 12); //set new storeRI for new random value
+                    _storeRi = rc.Next(6, 12); //set new storeRI for new random value
                     stopsHit = 0;

                     await RecycleItemsTask.Execute(session, cancellationToken);
@@ -231,5 +235,12 @@ namespace PokemonGo.RocketBot.Logic.Tasks

             return pokeStops.ToList();
         }
+
+        private static void OnLootPokestopEvent(FortData pokestop)
+        {
+            LootPokestopEvent?.Invoke(pokestop);
+        }
+
+        public static event LootPokestopDelegate LootPokestopEvent;
     }
 }
diff --git a/PokemonGo.RocketBot.Window/Forms/MainForm.cs b/PokemonGo.RocketBot.Window/Forms/MainForm.cs
index f7dc5ee..7e1b92a 100644
--- a/PokemonGo.RocketBot.Window/Forms/MainForm.cs
+++ b/PokemonGo.RocketBot.Window/Forms/MainForm.cs
@@ -34,6 +34,8 @@ using POGOProtos.Inventory;
 using POGOProtos.Inventory.Item;
 using POGOProtos.Map.Fort;
 using POGOProtos.Networking.Responses;
+using PokemonGo.RocketAPI.Extensions;
+using PokemonGo.RocketBot.Logic.Tasks;

 namespace PokemonGo.RocketBot.Window.Forms
 {
@@ -98,7 +100,7 @@ namespace PokemonGo.RocketBot.Window.Forms
             gMapControl1.Overlays.Add(_playerOverlay);

             _playerMarker = new GMapMarkerTrainer(new PointLatLng(lat, lng),
-                (Image) Properties.Resources.ResourceManager.GetObject("Trainer"));
+                (Image)Properties.Resources.ResourceManager.GetObject("Trainer"));
             _playerOverlay.Markers.Add(_playerMarker);
             _playerMarker.Position = new PointLatLng(lat, lng);
             _searchAreaOverlay.Polygons.Clear();
@@ -209,13 +211,17 @@ namespace PokemonGo.RocketBot.Window.Forms
             Logger.SetLoggerContext(_session);

             _session.Navigation.UpdatePositionEvent +=
-                (lat, lng) => _session.EventDispatcher.Send(new UpdatePositionEvent {Latitude = lat, Longitude = lng});
+                (lat, lng) => _session.EventDispatcher.Send(new UpdatePositionEvent { Latitude = lat, Longitude = lng });
             _session.Navigation.UpdatePositionEvent += Navigation_UpdatePositionEvent;

             RouteOptimizeUtil.RouteOptimizeEvent +=
                 optimizedroute =>
-                    _session.EventDispatcher.Send(new OptimizeRouteEvent {OptimizedRoute = optimizedroute});
+                    _session.EventDispatcher.Send(new OptimizeRouteEvent { OptimizedRoute = optimizedroute });
             RouteOptimizeUtil.RouteOptimizeEvent += Visualize;
+
+            FarmPokestopsTask.LootPokestopEvent +=
+                pokestop => _session.EventDispatcher.Send(new LootPokestopEvent { Pokestop = pokestop });
+            FarmPokestopsTask.LootPokestopEvent += Update;
         }

         private async Task StartBot()
@@ -234,34 +240,46 @@ namespace PokemonGo.RocketBot.Window.Forms

         private async void Visualize(List<FortData> pokeStops)
         {
-            Logger.Write("Visualize call");
-
-            lock (_pokestopsOverlay)
+            _pokestopsOverlay.Markers.Clear();
+            var routePoint =
+                (from pokeStop in pokeStops
+                 where pokeStop != null
+                 select new PointLatLng(pokeStop.Latitude, pokeStop.Longitude)).ToList();
+            _pokestopsOverlay.Routes.Clear();
+            var route = new GMapRoute(routePoint, "Walking Path");
+            route.Stroke = new Pen(Color.FromArgb(128, 0, 179, 253), 4);
+            _pokestopsOverlay.Routes.Add(route);
+
+            foreach (var pokeStop in pokeStops)
             {
-                _pokeStops = pokeStops;
-                _pokestopsOverlay.Markers.Clear();
-                var routePoint =
-                    (from pokeStop in pokeStops
-                        where pokeStop != null
-                        select new PointLatLng(pokeStop.Latitude, pokeStop.Longitude)).ToList();
-                _pokestopsOverlay.Routes.Clear();
-                var route = new GMapRoute(routePoint, "Walking Path");
-                route.Stroke = new Pen(Color.FromArgb(128, 0, 179, 253), 4);
-                _pokestopsOverlay.Routes.Add(route);
+                var pokeStopLoc = new PointLatLng(pokeStop.Latitude, pokeStop.Longitude);
+                var pokestopMarker = new GMapMarkerPokestops(pokeStopLoc,
+                    (Image)Properties.Resources.ResourceManager.GetObject("Pokestop"));
+                _pokestopsOverlay.Markers.Add(pokestopMarker);
             }
-            Update();
+
         }

-        private new void Update()
+        private new void Update(FortData pokestop = null)
         {
             SynchronizationContext.Post(o =>
             {
-                _pokestopsOverlay.Markers.Clear();
-                foreach (var pokeStop in _pokeStops)
+                if (pokestop != null)
                 {
-                    var pokeStopLoc = new PointLatLng(pokeStop.Latitude, pokeStop.Longitude);
-                    var pokestopMarker = new GMapMarkerPokestops(pokeStopLoc,
-                        (Image) Properties.Resources.ResourceManager.GetObject("Pokestop_Inrange"));
+                    var pokeStopLoc = new PointLatLng(pokestop.Latitude, pokestop.Longitude);
+
+                    lock (_pokestopsOverlay.Markers)
+                    {
+                        for (int i = 0; i < _pokestopsOverlay.Markers.Count; i++)
+                        {
+                            var marker = _pokestopsOverlay.Markers[i];
+                            if (marker.Position == pokeStopLoc)
+                                _pokestopsOverlay.Markers.Remove(marker);
+                        }
+                    }
+
+                    GMapMarker pokestopMarker = new GMapMarkerPokestops(pokeStopLoc,
+                        (Image)Properties.Resources.ResourceManager.GetObject("Pokestop_looted"));
                     //pokestopMarker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
                     //pokestopMarker.ToolTip = new GMapBaloonToolTip(pokestopMarker);
                     _pokestopsOverlay.Markers.Add(pokestopMarker);
@@ -276,12 +294,12 @@ namespace PokemonGo.RocketBot.Window.Forms
             }, null);
         }

-        private async void Navigation_UpdatePositionEvent(double lat, double lng)
+        private void Navigation_UpdatePositionEvent(double lat, double lng)
         {
             var latlng = new PointLatLng(lat, lng);
             _playerLocations.Add(latlng);
             _playerMarker.Position = latlng;
-            await Task.Run(() => Update());
+            Update();
             SaveLocationToDisk(lat, lng);
         }

@@ -392,20 +410,20 @@ namespace PokemonGo.RocketBot.Window.Forms
         {
             //olvPokemonList.ButtonClick += PokemonListButton_Click;

-            pkmnName.ImageGetter = delegate(object rowObject)
+            pkmnName.ImageGetter = delegate (object rowObject)
             {
                 var pokemon = rowObject as PokemonObject;

                 var key = pokemon.PokemonId.ToString();
                 if (!olvPokemonList.SmallImageList.Images.ContainsKey(key))
                 {
-                    var img = GetPokemonImage((int) pokemon.PokemonId);
+                    var img = GetPokemonImage((int)pokemon.PokemonId);
                     olvPokemonList.SmallImageList.Images.Add(key, img);
                 }
                 return key;
             };

-            olvPokemonList.FormatRow += delegate(object sender, FormatRowEventArgs e)
+            olvPokemonList.FormatRow += delegate (object sender, FormatRowEventArgs e)
             {
                 var pok = e.Model as PokemonObject;
                 if (olvPokemonList.Objects.Cast<PokemonObject>()
@@ -423,7 +441,7 @@ namespace PokemonGo.RocketBot.Window.Forms
                 }
             };

-            cmsPokemonList.Opening += delegate(object sender, CancelEventArgs e)
+            cmsPokemonList.Opening += delegate (object sender, CancelEventArgs e)
             {
                 e.Cancel = false;
                 cmsPokemonList.Items.Clear();
@@ -679,7 +697,7 @@ namespace PokemonGo.RocketBot.Window.Forms

         private Image GetPokemonImage(int pokemonId)
         {
-            return (Image) Properties.Resources.ResourceManager.GetObject("Pokemon_" + pokemonId);
+            return (Image)Properties.Resources.ResourceManager.GetObject("Pokemon_" + pokemonId);
         }

         private async Task ReloadPokemonList()
@@ -724,7 +742,7 @@ namespace PokemonGo.RocketBot.Window.Forms
                 {
                     var pokemonObject = new PokemonObject(pokemon);
                     var family =
-                        _families.Where(i => (int) i.FamilyId <= (int) pokemon.PokemonId)
+                        _families.Where(i => (int)i.FamilyId <= (int)pokemon.PokemonId)
                             .First();
                     pokemonObject.Candy = family.Candy_;
                     pokemonObjects.Add(pokemonObject);
@@ -778,7 +796,7 @@ namespace PokemonGo.RocketBot.Window.Forms

         private async void ItemBox_ItemClick(object sender, EventArgs e)
         {
-            var item = (ItemData) sender;
+            var item = (ItemData)sender;

             using (var form = new ItemForm(item))
             {
diff --git a/PokemonGo.RocketBot.Window/Images/Pokestop_Inrange.png b/PokemonGo.RocketBot.Window/Images/Markers/Pokestop.png
similarity index 100%
rename from PokemonGo.RocketBot.Window/Images/Pokestop_Inrange.png
rename to PokemonGo.RocketBot.Window/Images/Markers/Pokestop.png
diff --git a/PokemonGo.RocketBot.Window/Images/Markers/Pokestop_looted.png b/PokemonGo.RocketBot.Window/Images/Markers/Pokestop_looted.png
new file mode 100644
index 0000000..7ca76bc
Binary files /dev/null and b/PokemonGo.RocketBot.Window/Images/Markers/Pokestop_looted.png differ
diff --git a/PokemonGo.RocketBot.Window/Images/Trainer.png b/PokemonGo.RocketBot.Window/Images/Markers/Trainer.png
similarity index 100%
rename from PokemonGo.RocketBot.Window/Images/Trainer.png
rename to PokemonGo.RocketBot.Window/Images/Markers/Trainer.png
diff --git a/PokemonGo.RocketBot.Window/PokemonGo.RocketBot.Window.csproj b/PokemonGo.RocketBot.Window/PokemonGo.RocketBot.Window.csproj
index a5f7fe9..21fe0e8 100644
--- a/PokemonGo.RocketBot.Window/PokemonGo.RocketBot.Window.csproj
+++ b/PokemonGo.RocketBot.Window/PokemonGo.RocketBot.Window.csproj
@@ -325,6 +325,9 @@
     <Content Include="Images\Items\ItemTroyDisk.png" />
     <Content Include="Images\Items\ItemUltraBall.png" />
     <Content Include="Images\Items\ItemWeparBerry.png" />
+    <None Include="Images\Markers\Pokestop.png" />
+    <None Include="Images\Markers\Pokestop_looted.png" />
+    <None Include="Images\Markers\Trainer.png" />
     <Content Include="Images\Pokemon\Pokemon_1.png" />
     <Content Include="Images\Pokemon\Pokemon_10.png" />
     <Content Include="Images\Pokemon\Pokemon_100.png" />
diff --git a/PokemonGo.RocketBot.Window/Properties/Resources.Designer.cs b/PokemonGo.RocketBot.Window/Properties/Resources.Designer.cs
index 8d068ee..c2d8172 100644
--- a/PokemonGo.RocketBot.Window/Properties/Resources.Designer.cs
+++ b/PokemonGo.RocketBot.Window/Properties/Resources.Designer.cs
@@ -1813,9 +1813,19 @@ namespace PokemonGo.RocketBot.Window.Properties {
         /// <summary>
         ///   查找 System.Drawing.Bitmap 类型的本地化资源。
         /// </summary>
-        internal static System.Drawing.Bitmap Pokestop_Inrange {
+        internal static System.Drawing.Bitmap Pokestop {
             get {
-                object obj = ResourceManager.GetObject("Pokestop_Inrange", resourceCulture);
+                object obj = ResourceManager.GetObject("Pokestop", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+
+        /// <summary>
+        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
+        /// </summary>
+        internal static System.Drawing.Bitmap Pokestop_looted {
+            get {
+                object obj = ResourceManager.GetObject("Pokestop_looted", resourceCulture);
                 return ((System.Drawing.Bitmap)(obj));
             }
         }
diff --git a/PokemonGo.RocketBot.Window/Properties/Resources.resx b/PokemonGo.RocketBot.Window/Properties/Resources.resx
index 84b84bc..3795cd2 100644
--- a/PokemonGo.RocketBot.Window/Properties/Resources.resx
+++ b/PokemonGo.RocketBot.Window/Properties/Resources.resx
@@ -1984,10 +1984,13 @@
   <data name="Pokemon_99" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>..\Images\Pokemon\Pokemon_99.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
-  <data name="Pokestop_Inrange" type="System.Resources.ResXFileRef, System.Windows.Forms">
-    <value>..\Images\Pokestop_Inrange.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  <data name="Pokestop" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Images\Markers\Pokestop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
+  <data name="Pokestop_looted" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>..\Images\Markers\Pokestop_looted.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
   <data name="Trainer" type="System.Resources.ResXFileRef, System.Windows.Forms">
-    <value>..\Images\Trainer.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+    <value>..\Images\Markers\Trainer.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
 </root>
\ No newline at end of file
You may download the files in Public Git.