Jump to content
This site uses cookies! Learn More

This site uses cookies!

By continuing to use this site, you agree to allow us to store cookies on your computer. :)

Zer0

How can I force a fight?

Recommended Posts

Related to the bug : 

 

This bug annoys me to no end. The bot , when on its way to quest enemies/objectives just basically runs into¬†other hostile mobs which not only is very bot-like in terms of behavior, but also stress-inducing to watch ūüôā.

Since I'm working on a Fight Class in C#, I thought I might as well give it a try and fix it directly in the FC for now. I've created a simple radar which is able to detect the closest hostile units around every 500ms. When the closest unit is under a certain distance, I target it. But then I can't seem to start a fight. Fight.StartFight(); doesn't work (it says that the Target is not valid), I've tried a lot of other stuff, like manually setting Fight.InFight to true, but nothing seems to work and the bot keeps walking. Is there a way for me to interrupt the pathing and start a fight? Any help would be very appreciated.

Share this post


Link to post
Share on other sites
Posted (edited)

Would something like this work?

if(ObjectManager.GetWoWUnitAttackables().Any(x=> x.Position.DistanceTo(ObjectManager.Me.Position) < 20))
{
    MovementManager.StopMove();
    Fight.StartFight(ObjectManager.GetWoWUnitAttackables().OrderBy(x => x.Position.DistanceTo(ObjectManager.Me.Position)).FirstOrDefault().Guid);
}

Edit: Untested, just a suggestion, also changed getwowunit to attackables

Edit2: looking at the above the if statement i have is bad, you probably already have a filter though

Edited by Marsbar

Share this post


Link to post
Share on other sites

Hey, thanks for the quick answer.

The problem was that I didn't know you could pass a WowUnit.Guid argument to the overloaded StartFight function. Now I feel stupid :). Also I'm new to C# and decompiling dll, so don't judge me too harshly.

I do have a filter and it works pretty well so far. So now the detection works, but there's still bugs to fix. Especially when looting nearby hostiles, the bot will start moving erratically between 'I wanna go loot" and "I wanna start a fight". I'll look into it tomorrow.

Quick question : I put the detection into a method ( private void AggroRadar() ), that is executed every 500ms.
If I instantiate an object inside my method ( WoWUnit closestUnit = new WoWUnit(1234); ), is it destroyed once the method is over, or am I causing a memory leak?

Thanks a lot for your help!

Share this post


Link to post
Share on other sites

Ok, so I'll keep posting here for updates in case anyone's around and is willing to provide a little help.

I've made it into a plugin and it's working very well so far, although it still needs a lot of testing. Basically the plugin creates a background task which updates every 500ms and checks for close units. I've made the Range of the radar, the lvl of the enemies and the option to attack passive enemies into settings. The detection works very well and the bots enters combat without issue, now. So far the bugs I have are :

- When the bot is on its way to a NPC vendor in Town and is interrupted by a fight caused by a radar detection, the bot then states that "the NPC couldn't be reached" and then blacklists the vendor. I'm clearing the blacklist when it happens as a quick fix but it's ugly and potentially harmful. Any idea?

- Same problem with looting. When the bot is on its way to loot a corps and is interrupted by a radar detection, it states that it can't reach the corpse and blacklists it. I don't think it's the worst bug, but I'd like to get it fixed anyway.

Share this post


Link to post
Share on other sites
7 minutes ago, zeroots said:

Ok, so I'll keep posting here for updates in case anyone's around and is willing to provide a little help.

I've made it into a plugin and it's working very well so far, although it still needs a lot of testing. Basically the plugin creates a background task which updates every 500ms and checks for close units. I've made the Range of the radar, the lvl of the enemies and the option to attack passive enemies into settings. The detection works very well and the bots enters combat without issue, now. So far the bugs I have are :

- When the bot is on its way to a NPC vendor in Town and is interrupted by a fight caused by a radar detection, the bot then states that "the NPC couldn't be reached" and then blacklists the vendor. I'm clearing the blacklist when it happens as a quick fix but it's ugly and potentially harmful. Any idea?

- Same problem with looting. When the bot is on its way to loot a corps and is interrupted by a radar detection, it states that it can't reach the corpse and blacklists it. I don't think it's the worst bug, but I'd like to get it fixed anyway.

Check for looting events and currently running the totown state and deactivate your radar for the time being. 

Share this post


Link to post
Share on other sites
1 hour ago, Matenia said:

Check for looting events and currently running the totown state and deactivate your radar for the time being.¬†ÔĽŅ

That would indeed fix the issue, but also kill the purpose of the plugin. I really like the idea that the radar is still on when a toTown or looting event is on. So far it's only inactive when the player is flagged in combat or on a taxi.

Share this post


Link to post
Share on other sites

Maybe cancel those 2 states if your radar triggers? then it shouldn't blacklist and after combat attempt them again?

Share this post


Link to post
Share on other sites
Posted (edited)

That wouldn't work. 
The problem is GoToTask being aborted (and returning false) leads to the ToTown state being cancelled.

Edited by Matenia

Share this post


Link to post
Share on other sites
Posted (edited)

Ah, well I see that it takes the general setting wManagerSetting.CurrentSetting.BlackListIfNotCompletePath into account so maybe turn that off temporarily?
That is, if that setting is what's causing the blacklists

Edited by Marsbar

Share this post


Link to post
Share on other sites
26 minutes ago, Marsbar said:

Ah, well I see that it takes the general setting wManagerSetting.CurrentSetting.BlackListIfNotCompletePath into account so maybe turn that off temporarily?
That is, if that setting is what's causing the blacklists

I will try that and let you guys know how it went. Thank you both!

Share this post


Link to post
Share on other sites

For some reason, even turning wManagerSetting.CurrentSetting.BlackListIfNotCompletePath to false (and in the UI) doesn't do the trick and the vendor still gets blacklisted.

I've found a workaround though. It's a bit shaky but so far it's working as intended. Works for both Vendor and Repair. Maybe there's a way to hook blacklist events directly? If not I'll clean up the code and use this for now.

    private string vendorNpc = "";

	// Manage blacklist (inside Initialize())
    robotManager.Events.LoggingEvents.OnAddLog += delegate (Logging.Log log)
    {
    	ManageNpcBlacklist(log);
    };

    private void ManageNpcBlacklist(Logging.Log log)
    {
        if (log.Text.Contains("[ToTown] Go to vendor"))
        {
            vendorNpc = log.Text.Substring(22);
            vendorNpc = vendorNpc.Remove(vendorNpc.Length - 9);
        }

        if (inRadarCombat && log.Text.Contains("[ToTown] Unable to reach the vendor, blacklist it 120 minutes (you can disable this NPC in NPC DB tab 'Tools')."))
        {
            foreach (var n in NpcDB.ListNpc)
            {
                if (n.Name == vendorNpc)
                {
                    Logging.WriteDebug("Removing " + n.Name + " from vendor Blacklist");
                    n.BlackList(-1);
                }
            }
        }
    }

 

Share this post


Link to post
Share on other sites

I've asked @Droidz in the past to add blacklist events, I don't think it has happened (or maybe I missed it). Precisely because I didn't want to go down the house that you did.
Your solution likely is the best one though.

Share this post


Link to post
Share on other sites

I'm getting very close to what I want. There's one more bug that I can't seem to shake off. When the bot detects an enemy to attack, I run :

MovementManager.StopMove();
Fight.StartFight(closestUnit.Guid);

Then, if the bot is not in combat range, it starts moving erratically back and forth. I think it's still running its current move to the next node, as well as its move in range towards the enemy, both at the same time, or one after the other, or they keep interfering with each other, I don't know. 

I've tried setting Fight.InFight to true, I've tried checking the movements events, I've tried different things with MovementManager and it's led to nothing so far. I'm probably missing something very obvious, so any input will be much appreciated.

Share this post


Link to post
Share on other sites

Hello, blacklist events is in "wManager.Events.OthersEvents"

And try

53 minutes ago, zeroots said:

FigÔĽŅht.StartFiÔĽŅghÔĽŅtÔĽŅ(closestUnit.Guid, false);

 

Share this post


Link to post
Share on other sites

Thanks for the blacklist events, I'll check that out.

Unfortunately, your solution still doesn't work. To give you more info, the bot goes erratic up until I actually am flagged in combat. Then it's back to normal.

Share this post


Link to post
Share on other sites

I've recorded a video demonstrating the bug. It seems like the bot is conflicted between moving to its next node and moving toward the enemy.

Hope it helps.

Share this post


Link to post
Share on other sites

My best guess is that you're currently running between 2 waypoints.
Try adding a MovementManager.StopMoveTo(false, 500) 

Check if MovementManager.CurrentMoveTo is being overwritten and potentially call MovementManager.CurrentPath.Clear()

Share this post


Link to post
Share on other sites

Thanks a lot for your help, but I'm still really stuck here. Here's what I tried :

Logging.Write("[Z.E.Radar] Enemy too close (" + closestUnit.GetDistance + "), attacking : " + closestUnit.Name);

// Start Fight
Logging.WriteDebug(MovementManager.CurrentMoveTo.ToString());
MovementManager.StopMove();
Logging.WriteDebug(MovementManager.CurrentMoveTo.ToString());
MovementManager.StopMoveTo(false, 500);
Logging.WriteDebug(MovementManager.CurrentMoveTo.ToString());
MovementManager.CurrentPath.Clear();
Logging.WriteDebug(MovementManager.CurrentMoveTo.ToString());

Fight.StartFight(closestUnit.Guid);

And here's my log :

21:18:07 - [Z.E.Radar] Enemy too close (48,20433), attacking : Kolkar Scout
[D] 21:18:07 - -776,1435 ; 1188,599 ; 98,48631 ; "None"
[D] 21:18:07 - -776,1435 ; 1188,599 ; 98,48631 ; "None"
[D] 21:18:07 - -776,1435 ; 1188,599 ; 98,48631 ; "None"
[D] 21:18:07 - -776,1435 ; 1188,599 ; 98,48631 ; "None"
21:18:12 - [Fight] Player Attacked by Kolkar Scout (lvl 31)

I'm really getting confused here. Nothing seems to work, yet it looks like it shouldn't be an issue at all. Any idea what is going on?

I've also noted that once I'm actually in combat (for example my pet attacks or is attacked), the bot starts acting normally again. To me it seems like when I force engage a fight, unless I'm actually "In fight" in the game, the bot tries to take back control and follow its normal path, and I can't find a way to cancel it.

Share this post


Link to post
Share on other sites

Start fight, then cancel all movement, then start fight again.
Maybe force fight by setting Fight.InFight = true;
maybe add a MovementManager.MoveTo(closestUnit.Position) for good measure. I have no idea how any of the interals work together.

Share this post


Link to post
Share on other sites

It looks like two working modules are sending different kind of orders to the player toon. Maybe you should suspend one and let other do the job. Now one is stating go left the other go right and well it looks like wrobot in action ^^.

Share this post


Link to post
Share on other sites
9 hours ago, Matenia said:

Start fight, then cancel all movement, then start fight again.
Maybe force fight by setting Fight.InFight = true;
maybe add a MovementManager.MoveTo(closestUnit.Position) for good measure. I have no idea how any of the interals work together.

From my observation, once you launch Fight.startFight(), the next line of code isn't executed until the fight is over.

I've tried setting Fight.InFight to true in many different places, and it doesn't work, unfortunately.

I've also tried MovementManager.MoveTo(closestUnit.Position), but the bot takes over and tries to get back on its traveling path as soon as it starts moving to its target.

I've also hooked the wManager.Events.MovementEvents.OnMoveToPulse event and maybe there's some hope in there but it's getting really complicated for such a simple task.

 

I'm running out of ideas here. Do you think there is a way to temporarily deactivate the profile path, or the profile altogether?

Share this post


Link to post
Share on other sites
9 hours ago, Mykoplazma said:

It looks like two working modules are sending different kind of orders to the player toon. Maybe you should suspend one and let other do the job. Now one is stating go left the other go right and well it looks like wrobot in action ^^.

To me, it seems that it's a conflict within the same "module", actually. The MoveTo one. The bot is sending conflicting information to it when I try to force a fight. It's going "Go fight. Oh wait, no, go travel, no wait, go fight, no wait, go travel...". I'm pretty new to wRobot and I don't know the ins and outs of its engine, so if you have any more concrete info about all this, feel free to share :).

I'm willing to share the file if needed, since I'll release it for free once it's done.

Share this post


Link to post
Share on other sites

I found a solution. It's not the most elegant and a bit too crafty to my taste, but it works pretty well so far. Again, if anyone has a better idea, please let me know. I have done a ton of tests and I had to search and guess into the API until I found useful pieces of code.

What happens is pretty much what I suspected. When you call Fight.startFight on an enemy NPC that is not in the DB (profile) and that is not attacking you, the bot starts a new Move thread to approach the unit. After a second, during the approach, the bot thinks it's still traveling, despite Fight.InFight being true and starts a second Move thread to return to its travel path. Then the 2 threads run at the same time until somehow you're flagged in combat and the bot interrupts the travel Move thread.

Here's what I've done :

First :

MovementManager.StopMove();
Fight.StartFight(closestUnit.Guid);

Then the Event hook takes over whenever a new path is created during a pull. I pause the one that is not going to the enemy in a loop for the entire fight. Then, when the fight is over, I stop every movement and launch a new movement thread that will re-calculate the travel path. This last part is not absolutely necessary, but it keeps the bot from running back to its original place after every fight, which looks unnatural. In case you wonder, I tried to use cancelable.Cancel = true;... no dice, it makes the bot move eternally in a direction after reaching the first node, post-fight.

wManager.Events.OthersEvents.OnPathFinderFindPath += (Vector3 from, Vector3 to, string continentNameMpq, CancelEventArgs cancelable) =>
{
    if (inRadarCombat && Fight.InFight && enemyToFight.Position != to)
    {
        while (Fight.InFight && enemyToFight.IsAlive && inRadarCombat)
        {
            Thread.Sleep(250);
        }
        MovementManager.StopMove();
        MovementManager.StopMoveTo();
        MovementManager.LaunchThreadMovementManager();
        Thread.Sleep(2000);
    }
};

It works for both melee and ranged. I'll keep testing and adjusting. Feel free to share your inputs if any. Also if anyone wants to test the plugin, please let me know. I should mention I'm developing it on a TBC server. No idea if it would work on other versions.

Share this post


Link to post
Share on other sites

After further investigation, turns out there's a simpler way to handle the issue. Much cleaner, and works way better. It is confirmed that when you try to aggro a NPC that is not explicitly listed in the profile, AND when you're in a movement loop, the bot just tries to get back in the loop. The 3D radar helped a lot to understand what was going on. I still have a few (hopefully) minor bugs, and then I can release the plugin. Thanks again for your help, everyone.

        // Pull hook
        robotManager.Events.FiniteStateMachineEvents.OnBeforeCheckIfNeedToRunState += (engine, state, cancelable) =>
        {
            if (state.DisplayName == "Movement Loop" && inRadarCombat)
            {
                cancelable.Cancel = true;
            }
        };

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


√ó
√ó
  • Create New...