Jump to content

Recommended Posts

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;
        }

 

Link to comment
https://wrobot.eu/forums/topic/6592-c-interrupt-cast-random-time/
Share on other sites

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();".

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