Jump to content
  • [All] GetDistance getter method for WoWUnit


    Matenia
    • Version: All Product: WRobot General Type: Bug Status: Confirmed

    This is ONLY for WoWUnit and WoWPlayer, not ANY other type of WoWObject. 

    @Droidz can you please fix WoWUnit.GetDistance.GetMethod? It needs to be this.Position.DistanceTo(ObjectManager.Me.Position) - this.CombatReach - ObjectManager.Me.CombatReach. ONLY on WoWUnit. I've tried creating a runtime patch for this, but unfortunately you cannot patch properties at runtime



    User Feedback

    Recommended Comments

    Hello, GetDistance retourn "PositionWithoutType.DistanceTo(ObjectManager.Me.PositionWithoutType);"

    You want than I add method to return "Position.DistanceTo(ObjectManager.Me.Position) - this.CombatReach - ObjectManager.Me.CombatReach"?

    Link to comment
    Share on other sites

    GetDistance is the method wRobot uses for CustomClass to get close to the enemy. Due to hitbox differences (combatreach) it sometimes doesn't get close enough, then just stands there and says "out of range, out of range!".

    There's 2 options:
    - Add a new method "GetCombatDistance" and use this in CustomClass, Spell.IsDistanceGood, etc (and users can use this in their own stuff too) 
    - for WoWUnit and WoWPlayer, fix GetDistance method and make it "PositionWithoutType.DistanceTo(ObjectManager.Me.PositionWithoutType) - this.CombatReach - ObjectManager.Me.CombatReach"

    (I didn't know currently it uses PositionWithoutType, I thought it was just Position).

    Currently this code returns real distance:

     

    var RealRange = ObjectManager.Target.GetDistance - ObjectManager.Target.CombatReach - ObjectManager.Me.CombatReach;

     

    Edited by Matenia
    Link to comment
    Share on other sites

    GetDistance is good it is distance from the center of player to the center of the unit.

    I use PositionWithoutType to avoid useless step (check if fly or swimming) (for performance, but that does not change the result).

    I'll add: 

            public float GeHitBoxtDistance
            {
                get
                {
                    try
                    {
                        var d = PositionWithoutType.DistanceTo(ObjectManager.Me.PositionWithoutType) - CombatReach - ObjectManager.Me.CombatReach;
                        if (d < 0)
                            d = 0;
                        return d;
                    }
                    catch (Exception e)
                    {
                        Logging.WriteError("WoWUnit > GeHitBoxtDistance: " + e);
                        return 0;
                    }
                }
            }

    Current, for spell.isgooddistance I use:

            public bool IsDistanceGood
            {
                get
                {
                    try
                    {
                        if (ObjectManager.ObjectManager.Target.IsValid)
                        {
                            float combatReach = 0;
                            if (wManagerSetting.CurrentSetting.CalcuCombatRange)
                                combatReach = ObjectManager.ObjectManager.Target.CombatReach;
                            if (ObjectManager.ObjectManager.Target.GetDistance <= MaxRange + combatReach && (ObjectManager.ObjectManager.Target.GetDistance >= MinRange - combatReach))
                            {
                                return true;
                            }
                        }
    
                        return false;
                    }
                    catch (Exception exception)
                    {
                        Logging.WriteError("Spell > IsDistanceGood: " + exception);
                        return true;
                    }
                }
            }

    And to get player combat range (from fightcalss settings):

            public static float GetRange
            {
                get
                {
                    try
                    {
                        if (_instanceFromOtherAssembly != null)
                        {
                            float range;
                            if (_instanceFromOtherAssembly.Range < 6.5f)
                            {
                                range = 2.7f;
                                if (wManagerSetting.CurrentSetting.CalcuCombatRange && ObjectManager.ObjectManager.Target.IsValid)
                                {
                                        range += ObjectManager.ObjectManager.Target.CombatReach;
                                }
                                if (range < 3.5)
                                    range = 3.5f;
                            }
                            else
                            {
                                range = _instanceFromOtherAssembly.Range;
                                if (wManagerSetting.CurrentSetting.CalcuCombatRange && ObjectManager.ObjectManager.Target.IsValid)
                                {
                                    range += ObjectManager.ObjectManager.Target.CombatReach - 1;
                                }
                            }
                            return range;
                        }
                            
                        return 4.5f;
                    }
                    catch (Exception exception)
                    {
                        Logging.WriteError("CustomClass > GetRange: " + exception);
                        return 5.0f;
                    }
                }
            }

    I will check that (GetRange and isgooddistance), I take note

    Link to comment
    Share on other sites

    I want to prevent stuttering movement from my fightclass starting a cast when the bot is in range but for Frostbolt, but the fightclass thinks it's not in range, so it walks closer.
    How do you decide when to walk closer to the target? You take CustomClass.GetRange and do (pseudo code) - I think?:

    while (Me.GetDistance(ObjectManager.Target) > CustomClass.GetRange){
      MovementManager.MoveTo(ObjectManager.Target.Position);
    }
    MovementManager.StopMoveTo(false, 500);

    So if I make my code:
     

    public Spell Frostbolt = new Spell("Frosbolt");
    public float HitBox => ObjectManager.Target.CombatReach + Me.CombatReach;
    public float Range => .MaxRange + HitBox;
    
    public void Rotation()
    {
      if(Fight.InFight && GetGlobalCooldown() == 0 && ObjectManager.Target.GetDistance - HitBox <= Range)
      {
        Lua.LuaDoString($"CastSpellByName('{spell.Name}')");
      }
    }

    it should work and never cast before it's close enough, right?

    Link to comment
    Share on other sites

    I realized why this works perfectly for TBC, btw.
    Warmane (only TBC server atm) calculates spell distance from center to center (like on Blizzard realms). Vanilla private servers calculate distance end to end (hitbox to hitbox). This is a bug that wRobot has to work around, unfortunately.
    After re-considering this, it's good if you add 

    GetHitBoxtDistance

    but I don't think this needs to be fixed really.

    Link to comment
    Share on other sites



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