Apexx 60 Posted July 28, 2017 Share Posted July 28, 2017 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 More sharing options...
reapler 154 Posted July 29, 2017 Share Posted July 29, 2017 (edited) 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 July 29, 2017 by reapler Link to comment https://wrobot.eu/forums/topic/6624-random-time-to-use-ability/#findComment-30043 Share on other sites More sharing options...
Droidz 2738 Posted July 29, 2017 Share Posted July 29, 2017 Hello, https://wrobot.eu/forums/topic/3749-how-to-add-random-delay-to-cast-interrupt/?do=findComment&comment=17612 Link to comment https://wrobot.eu/forums/topic/6624-random-time-to-use-ability/#findComment-30044 Share on other sites More sharing options...
Apexx 60 Posted July 29, 2017 Author Share Posted July 29, 2017 Thanks guys. I will mess around with it. I appreciate your help. Link to comment https://wrobot.eu/forums/topic/6624-random-time-to-use-ability/#findComment-30061 Share on other sites More sharing options...
Apexx 60 Posted July 29, 2017 Author Share Posted July 29, 2017 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 } Link to comment https://wrobot.eu/forums/topic/6624-random-time-to-use-ability/#findComment-30065 Share on other sites More sharing options...
reapler 154 Posted July 29, 2017 Share Posted July 29, 2017 @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. Link to comment https://wrobot.eu/forums/topic/6624-random-time-to-use-ability/#findComment-30069 Share on other sites More sharing options...
Apexx 60 Posted July 29, 2017 Author Share Posted July 29, 2017 Thanks! So guess something like the following will work alright? Thread.Sleep(_r.Next(300, 650)); Revenge.Launch(); Link to comment https://wrobot.eu/forums/topic/6624-random-time-to-use-ability/#findComment-30071 Share on other sites More sharing options...
reapler 154 Posted July 29, 2017 Share Posted July 29, 2017 11 minutes ago, Apexx said: Thanks! So guess something like the following will work alright? Thread.Sleep(_r.Next(300, 650)); Revenge.Launch(); Yep Link to comment https://wrobot.eu/forums/topic/6624-random-time-to-use-ability/#findComment-30073 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now