Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

Commit

Permalink
Add specific delay for item recycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian committed Aug 23, 2016
1 parent 4e041ee commit 625f8eb
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 42 deletions.
2 changes: 1 addition & 1 deletion PokemonGo.RocketBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public interface ILogicSettings
bool SnipePokemonNotInPokedex { get; }
bool RandomizeRecycle { get; }
int RandomRecycleValue { get; }
bool DelayBetweenRecycleActions { get; }
int DelayBetweenRecycle{ get; }
int TotalAmountOfPokeballsToKeep { get; }
int TotalAmountOfPotionsToKeep { get; }
int TotalAmountOfRevivesToKeep { get; }
Expand Down
4 changes: 2 additions & 2 deletions PokemonGo.RocketBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public class GlobalSettings

[DefaultValue(2000)] public int DelayBetweenPokemonCatch;

[DefaultValue(true)] public bool DelayBetweenRecycleActions;
[DefaultValue(500)] public int DelayBetweenRecycle;

[DefaultValue(true)] public bool DetailedCountsBeforeRecycling;

Expand Down Expand Up @@ -1380,6 +1380,7 @@ public LogicSettings(GlobalSettings settings)
public int ForceExcellentThrowOverCp => _settings.ForceExcellentThrowOverCp;
public int DelayBetweenPokemonCatch => _settings.DelayBetweenPokemonCatch;
public int DelayBetweenPlayerActions => _settings.DelayBetweenPlayerActions;
public int DelayBetweenRecycle => _settings.DelayBetweenRecycle;
public bool UsePokemonToNotCatchFilter => _settings.UsePokemonToNotCatchFilter;
public bool UsePokemonSniperFilterOnly => _settings.UsePokemonSniperFilterOnly;
public int KeepMinDuplicatePokemon => _settings.KeepMinDuplicatePokemon;
Expand Down Expand Up @@ -1440,7 +1441,6 @@ public LogicSettings(GlobalSettings settings)
public bool SnipePokemonNotInPokedex => _settings.SnipePokemonNotInPokedex;
public bool RandomizeRecycle => _settings.RandomizeRecycle;
public int RandomRecycleValue => _settings.RandomRecycleValue;
public bool DelayBetweenRecycleActions => _settings.DelayBetweenRecycleActions;
public int TotalAmountOfPokeballsToKeep => _settings.TotalAmountOfPokeballsToKeep;
public int TotalAmountOfPotionsToKeep => _settings.TotalAmountOfPotionsToKeep;
public int TotalAmountOfRevivesToKeep => _settings.TotalAmountOfRevivesToKeep;
Expand Down
22 changes: 10 additions & 12 deletions PokemonGo.RocketBot.Logic/Tasks/RecycleItemsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
cancellationToken.ThrowIfCancellationRequested();

var currentTotalItems = await session.Inventory.GetTotalItemCount();
if (session.Profile.PlayerData.MaxItemStorage*session.LogicSettings.RecycleInventoryAtUsagePercentage/100.0f >
if (session.Profile.PlayerData.MaxItemStorage * session.LogicSettings.RecycleInventoryAtUsagePercentage / 100.0f >
currentTotalItems)
return;

Expand Down Expand Up @@ -91,7 +91,7 @@ await session.Inventory.GetItemAmountByType(ItemId.ItemIncenseCool) +

await session.Inventory.RefreshCachedInventory();
currentTotalItems = await session.Inventory.GetTotalItemCount();
if (session.Profile.PlayerData.MaxItemStorage*session.LogicSettings.RecycleInventoryAtUsagePercentage/100.0f >
if (session.Profile.PlayerData.MaxItemStorage * session.LogicSettings.RecycleInventoryAtUsagePercentage / 100.0f >
currentTotalItems)
return;

Expand All @@ -104,9 +104,8 @@ await session.Inventory.GetItemAmountByType(ItemId.ItemIncenseCool) +
await session.Client.Inventory.RecycleItem(item.ItemId, item.Count);

if (session.LogicSettings.VerboseRecycling)
session.EventDispatcher.Send(new ItemRecycledEvent {Id = item.ItemId, Count = item.Count});
if (session.LogicSettings.DelayBetweenRecycleActions)
DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 500);
session.EventDispatcher.Send(new ItemRecycledEvent { Id = item.ItemId, Count = item.Count });
DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 500);
}

await session.Inventory.RefreshCachedInventory();
Expand All @@ -126,9 +125,8 @@ private static async Task RecycleItems(ISession session, CancellationToken cance
cancellationToken.ThrowIfCancellationRequested();
await session.Client.Inventory.RecycleItem(item, itemsToRecycle);
if (session.LogicSettings.VerboseRecycling)
session.EventDispatcher.Send(new ItemRecycledEvent {Id = item, Count = itemsToRecycle});
if (session.LogicSettings.DelayBetweenRecycleActions)
DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 500);
session.EventDispatcher.Send(new ItemRecycledEvent { Id = item, Count = itemsToRecycle });
DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 500);
}
}

Expand All @@ -140,7 +138,7 @@ private static async Task OptimizedRecycleBalls(ISession session, CancellationTo
var masterBallsCount = await session.Inventory.GetItemAmountByType(ItemId.ItemMasterBall);

var totalBallsCount = pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount;
var random = rnd.Next(-1*session.LogicSettings.RandomRecycleValue,
var random = rnd.Next(-1 * session.LogicSettings.RandomRecycleValue,
session.LogicSettings.RandomRecycleValue + 1);

if (totalBallsCount > session.LogicSettings.TotalAmountOfPokeballsToKeep)
Expand Down Expand Up @@ -181,7 +179,7 @@ private static async Task OptimizedRecyclePotions(ISession session, Cancellation
var maxPotionCount = await session.Inventory.GetItemAmountByType(ItemId.ItemMaxPotion);

var totalPotionsCount = potionCount + superPotionCount + hyperPotionsCount + maxPotionCount;
var random = rnd.Next(-1*session.LogicSettings.RandomRecycleValue,
var random = rnd.Next(-1 * session.LogicSettings.RandomRecycleValue,
session.LogicSettings.RandomRecycleValue + 1);
if (totalPotionsCount > session.LogicSettings.TotalAmountOfPotionsToKeep)
{
Expand Down Expand Up @@ -222,7 +220,7 @@ private static async Task OptimizedRecycleRevives(ISession session, Cancellation
var maxReviveCount = await session.Inventory.GetItemAmountByType(ItemId.ItemMaxRevive);

var totalRevivesCount = reviveCount + maxReviveCount;
var random = rnd.Next(-1*session.LogicSettings.RandomRecycleValue,
var random = rnd.Next(-1 * session.LogicSettings.RandomRecycleValue,
session.LogicSettings.RandomRecycleValue + 1);
if (totalRevivesCount > session.LogicSettings.TotalAmountOfRevivesToKeep)
{
Expand Down Expand Up @@ -255,7 +253,7 @@ private static async Task OptimizedRecycleBerries(ISession session, Cancellation
var wepar = await session.Inventory.GetItemAmountByType(ItemId.ItemWeparBerry);

var totalBerryCount = razz + bluk + nanab + pinap + wepar;
var random = rnd.Next(-1*session.LogicSettings.RandomRecycleValue,
var random = rnd.Next(-1 * session.LogicSettings.RandomRecycleValue,
session.LogicSettings.RandomRecycleValue + 1);
if (totalBerryCount > session.LogicSettings.TotalAmountOfBerriesToKeep)
{
Expand Down
2 changes: 2 additions & 0 deletions PokemonGo.RocketBot.Logic/Tasks/RecycleSpecificItemTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using PokemonGo.RocketBot.Logic.State;
using POGOProtos.Inventory.Item;
using POGOProtos.Networking.Responses;
using PokemonGo.RocketBot.Logic.Utils;

namespace PokemonGo.RocketBot.Logic.Tasks
{
Expand All @@ -23,6 +24,7 @@ public static async Task Execute(Session session, ItemId itemId, int count)
$"Unable to recycle {count}x {itemId.ToString().Substring(4)}",
LogLevel.Error);
}
DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 500);
}
}
}
50 changes: 30 additions & 20 deletions PokemonGo.RocketBot.Window/Forms/SettingForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions PokemonGo.RocketBot.Window/Forms/SettingForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private void SettingsForm_Load(object sender, EventArgs e)

tbDelayBetweenPlayerActions.Text = _setting.DelayBetweenPlayerActions.ToString();
tbDelayBetweenPokemonCatch.Text = _setting.DelayBetweenPokemonCatch.ToString();
cbDelayBetweenRecycleActions.Checked = _setting.DelayBetweenRecycleActions;
tbDelayBetweenRecycle.Text = _setting.DelayBetweenRecycle.ToString();

cbRandomizeRecycle.Checked = _setting.RandomizeRecycle;
tbRandomRecycleValue.Text = _setting.RandomRecycleValue.ToString();
Expand All @@ -291,14 +291,14 @@ private void SettingsForm_Load(object sender, EventArgs e)

protected override void OnLoad(EventArgs e)
{
var btn = new Button {Size = new Size(25, GoogleApiBox.ClientSize.Height + 2)};
var btn = new Button { Size = new Size(25, GoogleApiBox.ClientSize.Height + 2) };
btn.Location = new Point(GoogleApiBox.ClientSize.Width - btn.Width, -1);
btn.Cursor = Cursors.Default;
btn.Image = ResourceHelper.GetImage("question");
btn.Click += googleapihep_click;
GoogleApiBox.Controls.Add(btn);
// Send EM_SETMARGINS to prevent text from disappearing underneath the button
SendMessage(GoogleApiBox.Handle, 0xd3, (IntPtr) 2, (IntPtr) (btn.Width << 16));
SendMessage(GoogleApiBox.Handle, 0xd3, (IntPtr)2, (IntPtr)(btn.Width << 16));
base.OnLoad(e);
}

Expand Down Expand Up @@ -345,7 +345,7 @@ private static List<PokemonId> ConvertClbToList(CheckedListBox input)
/// </summary>
private void GetLanguageList()
{
var languages = new List<string> {"en"};
var languages = new List<string> { "en" };
var langFiles = Directory.GetFiles(LanguagePath, "*.json", SearchOption.TopDirectoryOnly);
languages.AddRange(langFiles.Select(
langFileName => Path.GetFileNameWithoutExtension(langFileName)?.Replace("translation.", ""))
Expand All @@ -362,7 +362,7 @@ private void UpdateLocationInfo()
tbLatitude.Text = gMapCtrl.Position.Lat.ToString(CultureInfo.InvariantCulture);
tbLongitude.Text = gMapCtrl.Position.Lng.ToString(CultureInfo.InvariantCulture);
//update trackbar
trackBar.Value = (int) Math.Round(gMapCtrl.Zoom);
trackBar.Value = (int)Math.Round(gMapCtrl.Zoom);
}

/// <summary>
Expand Down Expand Up @@ -619,7 +619,7 @@ private void saveBtn_Click(object sender, EventArgs e)

_setting.DelayBetweenPlayerActions = ConvertStringToInt(tbDelayBetweenPlayerActions.Text);
_setting.DelayBetweenPokemonCatch = ConvertStringToInt(tbDelayBetweenPokemonCatch.Text);
_setting.DelayBetweenRecycleActions = cbDelayBetweenRecycleActions.Checked;
_setting.DelayBetweenRecycle = ConvertStringToInt(tbDelayBetweenRecycle.Text);

_setting.RandomizeRecycle = cbRandomizeRecycle.Checked;
_setting.RandomRecycleValue = ConvertStringToInt(tbRandomRecycleValue.Text);
Expand Down Expand Up @@ -707,7 +707,7 @@ private void AdressBox_Leave(object sender, EventArgs e)

private void AdressBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != (char) Keys.Enter)
if (e.KeyChar != (char)Keys.Enter)
{
return;
}
Expand Down

0 comments on commit 625f8eb

Please sign in to comment.