Skip to content
View in the app

A better way to browse. Learn more.

WRobot

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C# Interrupt Cast Random Time

Featured Replies

I am wondering if this if-statement will return a random time of interrupting an interruptible spell from my target using C# custom fight class:

if (ShieldBash.KnownSpell && ShieldBash.IsSpellUsable && ShieldBash.IsDistanceGood &&
            Fight.InFight && target.CanInterruptCasting)
        {
            System.Threading.Thread.Sleep(robotManager.Helpful.Others.Random(0, target.CastingTimeLeft - 350));
            ShieldBash.Launch();
            Thread.Sleep(SpellManager.GlobalCooldownTimeLeft());
            return;
        }

 

Hello, this snippet should work but Thread.Sleep will locking your rotation. I recommend to use "EventsLuaWithArgs.OnEventsLuaWithArgs" & "Task.Run" to also checking more enemies at the same time:

    private readonly Spell _shieldBash = new Spell("Shield Bash");
    private readonly Random _r = new Random();

    private void EventsLuaWithArgsOnOnEventsLuaWithArgs(LuaEventsId id, List<string> args)
    {
        if (id == LuaEventsId.COMBAT_LOG_EVENT_UNFILTERED && args[1] == "SPELL_CAST_START")
        {
            ulong guid;
            ulong.TryParse(args[2].Replace("x", string.Empty), System.Globalization.NumberStyles.HexNumber, null, out guid);
            var caster = (WoWUnit) ObjectManager.GetObjectByGuid(guid);
            if (
                caster.Reaction < Reaction.Neutral && 
                _shieldBash.KnownSpell
                )
            {
                Interrupt(_shieldBash, caster, _r.Next(150, ((int)caster.CastingSpell.CastTime-200)*1000));
            }
        }
    }
    
    private void Interrupt(Spell spell, WoWUnit caster, int interruptTime)
    {
        Task.Run(delegate
        {
            while (caster.CastingTimeLeft != 0  && Products.IsStarted)
            {
                Logging.Write("CastingTimeLeft: "+caster.CastingTimeLeft +"ms\nInterrupt at: "+interruptTime+"ms");
                if (caster.CastingTimeLeft > interruptTime
                    && caster.GetDistance < _shieldBash.MaxRange
                    && _shieldBash.IsSpellUsable
                    && SpellManager.GetSpellCooldownTimeLeft(_shieldBash.Id) == 0
                    && caster.CanInterruptCasting
                )
                {
                    Logging.Write("Interrupt with " + spell.Name);
                    //cast without targeting behavior
                    var tmp = ObjectManager.Me.FocusGuid;
                    ObjectManager.Me.FocusGuid = caster.Guid;
                    spell.Launch(false, false, false, "focus");
                    ObjectManager.Me.FocusGuid = tmp;
                }
                Thread.Sleep(300);
            }
        });
    }

    public void Initialize()
    {
        EventsLuaWithArgs.OnEventsLuaWithArgs += EventsLuaWithArgsOnOnEventsLuaWithArgs;
        //...
    }

This is not fully tested, otherwise you can also play around with other parameters & at problems it's a good idea to use "Logging.Write();".

  • Author

Very cool! Thanks for the reply! I will definitely test this out and report back with any issues or questions.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.