Skip to content

Instantly share code, notes, and snippets.

@Lajt
Created January 7, 2017 14:40
Show Gist options
  • Save Lajt/e551c30ca5e9cdde8bb5552e3f42ed47 to your computer and use it in GitHub Desktop.
Save Lajt/e551c30ca5e9cdde8bb5552e3f42ed47 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading.Tasks;
using Buddy.Coroutines;
using Loki;
using Loki.Common;
using Loki.Game;
using Loki.Game.GameData;
using Loki.Bot;
using Loki.Bot.Pathfinding;
using log4net;
using System.IO;
using Loki.Game.NativeWrappers;
using Loki.Game.Objects;
using Loki.Game.Objects.Items;
public class RuntimeCode
{
private static readonly ILog Log = Logger.GetLoggerInstanceForType();
private Coroutine _coroutine;
public void Execute()
{
using (LokiPoe.AcquireFrame())
{
ExilePather.Reload();
}
// Create the coroutine
_coroutine = new Coroutine(() => MainCoroutine());
// Run the coroutine while it's not finished.
while (!_coroutine.IsFinished)
{
try
{
using (LokiPoe.AcquireFrame())
{
_coroutine.Resume();
Log.DebugFormat("Started");
foreach (var aura in Loki.Game.LokiPoe.Me.Auras)
Log.Error(aura);
var kappa = LokiPoe.Memory.Process.ProcessName;
Log.DebugFormat(kappa.ToString());
}
}
catch (Exception ex)
{
Log.ErrorFormat("[Execute] {0}.", ex);
break;
}
}
// Cleanup the coroutine if it already exists
if (_coroutine != null)
{
_coroutine.Dispose();
_coroutine = null;
}
}
private async Task<bool> UserCoroutine()
{
return false;
}
private int InstantFlaskCharges()
{
var inv = LokiPoe.InGameState.QuickFlaskHud.InventoryControl.Inventory.Items;
int nbAvailableFlasks = inv
.Cast<Flask>()
.Where(f => f != null && f.Rarity != Rarity.Unique && f.HealthRecover > 0 && f.CanUse && f.IsInstantRecovery)
.Sum(f => f.CurrentCharges / f.ChargesPerUse);
return nbAvailableFlasks;
}
private async Task MainCoroutine()
{
while (true)
{
if (LokiPoe.IsInLoginScreen)
{
// Offload auto login logic to a plugin.
foreach (var plugin in PluginManager.EnabledPlugins)
{
await plugin.Logic("login_screen");
}
}
else if (LokiPoe.IsInCharacterSelectionScreen)
{
// Offload character selection logic to a plugin.
foreach (var plugin in PluginManager.EnabledPlugins)
{
await plugin.Logic("character_selection");
}
}
else if (LokiPoe.IsInGame)
{
// Execute user logic until false is returned.
if (!await UserCoroutine())
break;
}
else
{
// Most likely in a loading screen, which will cause us to block on the executor,
// but just in case we hit something else that would cause us to execute...
await Coroutine.Sleep(1000);
continue;
}
// End of the tick.
await Coroutine.Yield();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment