Jump to content

Recommended Posts

I am noticing the wrotation product will immediately use an ability like "Execute" if the target.HealthPercent <= 20 for example. I know there is an option for Thread.Sleep
but instead of sleeping the full rotation, is there a good way to add a small random time _r.Next(300, 650) to robotManager.Helpful.Timer? And if so, how would I use it?

Thanks!

Link to comment
https://wrobot.eu/forums/topic/6624-random-time-to-use-ability/
Share on other sites

Hello @Apexx, so you would like to only delay the current cast or has it a special reason to do that?

Otherwise you can still use Thread.Sleep() if the fightclass shouldn't execute anything (for a small time / simple task it's ok i guess).

Edited by reapler

I am writing a protection warrior fight class, and there are no cast times. I was just wanted to delay abilities like Overpower, Execute, Revenge.
Once the ability is usable, it casts it immediately which is really not human-like at all. I try to write my fight classes as human-like as I can, adding
randomization, delays, etc.

pseudo example:
 

var _timer = new robotManager.Helpful.Timer(_r.Next(300, 650));
            if (_timer.IsReady)
            {
                // use Revenge
            }

 

@Apexx At your case i would use Thread.Sleep() since, you would need to block your rotation for a short time (but make sure that  the ability is really usable).

If you would use:

            var t = Task.Run(async delegate
            {
                await Task.Delay(1600);
				//cast spell
            });

It will be triggered more than one time if you have a reactive fightclass. So you would need then a boolean to check if any spells are going to be executed.

But instead of building such a system, which has most likely the same effect like a sleep, just use a sleep instead.

There are may scenarios which still need an active loop in fightclasses for example you have a status bar of all enemy players which updates with each loop(~100ms) so a sleep(long or short) would cause to delay also this update of the bar.

So in my eyes Task.Run would be worth if you want explicit to run the thread without lockouts.

In your case i wouldn't mind that, events like "EventsLuaWithArgs.OnEventsLuaWithArgs" are still working so you could theoretically interrupt the enemy cast even on a sleeping thread.

As i mentioned it's not a big issue to use a sleep here for this short time = > droidz example

At the end you can also do a check if it's still clever to cast this spell:

For example you have an heal rotation and casting a heal on a 100% health target & bot doesn't interrupt that, because you aren't checking after the cast. With the events you can also check if someone is already casting a heal, on your heal target, so your rotation wouldn't try that.

 

OR you can simply put the tickspeed lower at your fightclass:

        var timer = new Timer(1000);//tickspeed
        timer.ForceReady();
        while (_isLaunched)
        {
            try
            {
                if (
		Conditions.ProductIsStartedNotInPause
        	&& timer.IsReady
		//&& condition3
		)
                {
                    //do something every 1 sec
                }
            }
            catch (Exception e)
            {
                Logging.WriteError(e.ToString());
            }
            Thread.Sleep(30);
        }

You can also use other examples with a sleep instead of the timer (i don't think that it will change anything).

You may also add some other conditions this one is just a template on initialize.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...