What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

How to make the examplebot to explore the whole area like the exilebot does?

thunder

Member
Joined
Jul 8, 2012
Messages
143
Reaction score
2
I see only certain positions has been added to be explored in examplebot.
 
You have to code that in :p.

The point of ExampleBot is to give a real example of a user bot implementation using our API to do whatever you need it to. For ExampleBot, I showed some code I'll be using for the boss farming bot, which allows you to try and go directly to an area.

To make the bot explore the entire area, you can setup a system where you partition the entire area into a grid, for example, and then visit each node. THere's a lot of different ways to do this, but a grid is a simple basic way to start.

To access the same terrain data we use, you can use the LokiPoe.TerrainData class. You can get the Rows/Cols, TGT tiles, and the actual pathfinding data via GetPathfindingData.

The only only info you need which isn't really obvious without looking at a lot of the data is each cell is 23x23. The map's 0,0 is the bottom left corner (south-west cardinal direction). Their coordinate system is rotated counter-clockwise some for the isometric view, but that's pretty typical for these games. All that means is, "moving right" is not (1, 0), but rather (1, 1). Moving down is not 0, -1, but 1, -1 and so on.

For higher level pathfinding stuff, you can use the ExilePather class inside Loki.Bot.Pathfinding. Using that you can test walkability of points or try to pathfind, but keep in mind that the client only has info of its near surroundings. It's possible long paths are invalid once you get there, because the map data is now different (doors, quest objects, etc..)
 
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.
 
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.

Yeap! 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.

The Poi system can work really well, but you have to be aware of the problems that can arise if you make it really modular like we currently have it. The conditions for Pois execution, when left dynamic, can create circular execution loops that causes the bot to get stuck. I'm adding a new stuck plugin by request to try and identify these cases so the bot doesn't keep getting stuck like it does in Release, but the better fix is to rewrite the implementation of the Pois to prevent it from happening in the first place, which is possible, but just complex.
 
Yeap! 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
 
Hi, pushedx. I got a problem when i try to get a reward item from npc or bandit, there is no coroutine doing this

There's no coroutine for it, but coroutines are just fancy API wrappers that simplify a commonly used process. Since Beta doesn't have quest logic yet, that's pretty much why it doesn't exist yet.

Actually doing this with the API is pretty straight forward though. The next Beta version will include an example plugin called QuestRewards that shows a plugin setup of adding a Poi to accept quest rewards.

Here's the Poi code that shows how to use the API to do this:
Code:
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()
        {
        }
    }
}

That's about it. :) You just have to loop through the NPC items in each inventory until you find the one you want, and the use TakeFromRewardWindow. You can then have logic with quest item names for the quest stuff, and do some other non-skillgem logic for quests that give you item rewards.

If you want to code logic to go to NPCs and talk to them to receive a reward, that too is possible with a mix of existing coroutines and API.

To talk to a NPC, you need to find the object and get its id. You can then use Coroutines.TalkToNpcCoroutine to start the dialog.

Once the dialog menu is open, you need to find the quest reward dialog text from the NPC's options. This is something like (for Selling Items for example):
Code:
// 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));

You have to code in each of the reward text entries though. We don't have a list of that info yet. To know if the quest reward dialog is opened or not, you can use: LokiPoe.InGameState.IsRewardWindowOpen.

When we make coroutines to simplify a process like this, that's pretty much the underlying code behind it. Just use the API and other coroutines to create a simple to re/use coroutine to accomplish a task.
 
Back
Top