thanks for your reply. I just found the plugin can also manipulate the poimanage and thus be able to do a lot of things, so I don't need to code every thing myself.
Hi, pushedx. I got a problem when i try to get a reward item from npc or bandit, there is no coroutine doing thisYeap! The idea is to try and allow more reuse and code sharing, but some Pois have to be kept internal because they are built on global state that can't be shared across different bot implementations.
Hi, pushedx. I got a problem when i try to get a reward item from npc or bandit, there is no coroutine doing this
using System.Linq;
using System.Threading.Tasks;
using Buddy.Coroutines;
using log4net;
using Loki.Bot.Logic.Bots.ExilebuddyBot.Poi;
using Loki.Bot.v2;
using Loki.Game;
using Loki.Utilities;
namespace QuestRewards
{
internal class QuestRewardsPoi : IPoi
{
private static readonly ILog Log = Logger.GetLoggerInstanceForType();
/// <summary>The name of this poi.</summary>
public string Name
{
get { return "quest_rewards"; }
}
/// <summary>A description of what this poi does.</summary>
public string Description
{
get { return "A poi to execute quest reward logic."; }
}
/// <summary>
/// Can this poi execute this tick?
/// </summary>
/// <returns>true if the poi can execute, and false if not.</returns>
public bool CanExecute()
{
// We don't need to execute when we are not in town.
if (!LokiPoe.Me.IsInTown)
return false;
// Whenever we have a 2nd level gui window open, check to see if it's ofering rewards.
// Ideally, the logic for execution would be based on other things as well, such as quest state,
// and who we need to talk to in the current town, but this is just a simple example showing accepting
// a quest reward.
return LokiPoe.Gui.DialogWindowDepth == 2;
}
/// <summary>
/// The poi's execution logic.
/// </summary>
/// <returns>true if the poi executed, and false if it did not.</returns>
public async Task<bool> Execute()
{
// Some debugging.
foreach (var inventory in LokiPoe.NpcInventory.AllInventories)
{
foreach (var item in inventory.Items)
{
Log.DebugFormat("[Execute] Quest Reward: {0}", item.FullName);
}
}
// Loop through the inventories the NPC provides.
foreach (var inventory in LokiPoe.NpcInventory.AllInventories)
{
// Now check each item.
foreach (var inventoryItem in inventory.Items)
{
if (inventoryItem.FullName == "Flameblast")
{
Log.DebugFormat("[Execute] A Flameblast quest reward was found! Now taking it.");
var res = inventoryItem.TakeFromRewardWindow();
Log.DebugFormat("[Execute] TakeFromRewardWindow returned {0}.", res);
await Coroutine.Sleep(Utility.LatencySafeValue(1000));
return res;
}
}
}
return false;
}
/// <summary>The bot Start event.</summary>
public void Start()
{
}
/// <summary>The bot Tick event.</summary>
public void Tick()
{
}
/// <summary>The bot Stop event.</summary>
public void Stop()
{
}
}
}
// Check to see if there is an option to sell.
var option = LokiPoe.Gui.Npc.DialogOptions.FirstOrDefault(o => o.DialogText == "Sell Items");
if (option == null)
{
Log.DebugFormat(
"[Execute] No \"Sell Items\" menu item detected. Closing the current gui to try again.");
await Coroutines.CloseBlockingWindows();
return true;
}
Log.DebugFormat("[Execute] A \"Sell Items\" menu entry was found. Now selecting it.");
LokiPoe.Gui.Npc.SelectDialogOption(option.DialogId);
await Coroutine.Sleep(Utility.LatencySafeValue(1000));