Jump to content

Spell::KnownSpell always returns true


Recommended Posts

Hi!

When creating a spell like new Spell("Regrowth", false) it'll get the first rank of the spell. So i thought id list all spellid's and iterate through tem and get the highest one by checking KnownSpell, but it seems to always be returning true.

Is this intended behavior? This is kinda related to the Mana issue i faced in another thread. (I've implemented reading DBC files extracted from the client, so i can get all spellinfo available, but now i must know the highest rank (spellid) known to the player)

When this starts to look like something somewhat useful i'm thinking that i'll opensource this and make a fightclass (hopefully together with other people) that'll work good for all classes! :)

 

Best Regards
Carl

Link to comment
Share on other sites

Hello @LilleCarl, i don't think that's the actual behavior of "new Spell("Regrowth", false).Id" to get the first rank and ".KnownSpell" shouldn't return always true. Maybe @Droidz can look into it.

On 3.3.5a i have only experienced the second issue.

But you may try this:

    public List<uint> GetKnownSpellIds(string name)
    {
        return new Spell(name).Ids.Where(SpellManager.KnowSpell).OrderBy(i => i).Distinct().ToList();
    }
    
    public uint GetHighestKnownSpell(string name)
    {
        return new Spell(name).Ids.Where(SpellManager.KnowSpell).OrderByDescending(i => i).FirstOrDefault();
    }

Usage:

        var s = GetKnownSpellIds("Regrowth");
        for (var i = 0; i < s.Count; i++)
        {
            robotManager.Helpful.Logging.Write("\nId: "+s[i] +"    Rank: "+(i+1));
        }
        
        robotManager.Helpful.Logging.Write("Id: "+GetHighestKnownSpell("Regrowth"));

 

Link to comment
Share on other sites

11 minutes ago, reapler said:

Hello @LilleCarl, i don't think that's the actual behavior of "new Spell("Regrowth", false).Id" to get the first rank and ".KnownSpell" shouldn't return always true. Maybe @Droidz can look into it.

On 3.3.5a i have only experienced the second issue.

But you may try this:


    public List<uint> GetKnownSpellIds(string name)
    {
        return new Spell(name).Ids.Where(SpellManager.KnowSpell).OrderBy(i => i).Distinct().ToList();
    }
    
    public uint GetHighestKnownSpell(string name)
    {
        return new Spell(name).Ids.Where(SpellManager.KnowSpell).OrderByDescending(i => i).FirstOrDefault();
    }

Usage:


        var s = GetKnownSpellIds("Regrowth");
        for (var i = 0; i < s.Count; i++)
        {
            robotManager.Helpful.Logging.Write("\nId: "+s[i] +"    Rank: "+(i+1));
        }
        
        robotManager.Helpful.Logging.Write("Id: "+GetHighestKnownSpell("Regrowth"));

 

Aah thanks, i didn't even know SpellManager.KnowSpell existed, nice snippet there! =)

Link to comment
Share on other sites

2.4.3 DBC (fightclass will create DBC folder in bot root)
https://mega.nz/#!Fl1nVRyC!w6szGtAhEGUvho1Du5n1ZMB834L28Fg08oFYgOcjU6U

FightClass that loads Spell DBC files and a child class to Spell where you easily can access this spelldata from https://github.com/Lillecarl/FightClass1

That's all i've got for now, thanks for your help reapler! :)

Link to comment
Share on other sites

15 minutes ago, LilleCarl said:

2.4.3 DBC (fightclass will create DBC folder in bot root)
https://mega.nz/#!Fl1nVRyC!w6szGtAhEGUvho1Du5n1ZMB834L28Fg08oFYgOcjU6U

FightClass that loads Spell DBC files and a child class to Spell where you easily can access this spelldata from https://github.com/Lillecarl/FightClass1

That's all i've got for now, thanks for your help reapler! :)

It looks excellent Carl. I'm looking forward that this will be added soon to the WRobot's lib ;)

Link to comment
Share on other sites

I might be too late here, but I use this helper class, that allows me to easily iterate over ranks and break the loop if (highest to lowest) I know a spell or (lowest to highest) I don't know a spell anymore.

class RotationSpell
{
    public Spell Spell;
    private string Name;
    private int? Rank;

    public RotationSpell(string name, int? rank = null)
    {
        this.Name = name;
        this.Rank = rank;
        this.Spell = new Spell(name);
    }

    public bool IsUsable()
    {
        return Spell.IsSpellUsable;
        //return Lua.LuaDoString<bool>("usable = (IsUsableSpell(\""  + Name + "\") and true or false)", "usable");
    }

    public bool CanCast()
    {
        return Lua.LuaDoString<bool>("return (IsUsableSpell(\"" + FullName() + "\") and GetSpellCooldown(\"" + FullName() + "\") == 0)");
    }

    public float GetCooldown()
    {
        string luaString = @"
        cooldownLeft = 0;

        local start, duration, enabled = GetSpellCooldown(""{0}"");
        if enabled == 1 and start > 0 and duration > 0 then
            cooldownLeft = duration - (GetTime() - start)
        end";
        return Lua.LuaDoString<float>(string.Format(luaString, FullName()), "cooldownLeft");
    }

    public void UpdateRank(int rank)
    {
        this.Rank = rank;
    }

    public string FullName()
    {
        return Rank != null ? (Name + "(Rank " + Rank + ")") : Name;
    }

    public bool IsKnown()
    {
        return Lua.LuaDoString<bool>("return (GetSpellInfo(\"" + FullName() + "\") ~= nil)");
    }

}

 

Link to comment
Share on other sites

9 hours ago, Matenia said:

I might be too late here, but I use this helper class, that allows me to easily iterate over ranks and break the loop if (highest to lowest) I know a spell or (lowest to highest) I don't know a spell anymore.


class RotationSpell
{
    public Spell Spell;
    private string Name;
    private int? Rank;

    public RotationSpell(string name, int? rank = null)
    {
        this.Name = name;
        this.Rank = rank;
        this.Spell = new Spell(name);
    }

    public bool IsUsable()
    {
        return Spell.IsSpellUsable;
        //return Lua.LuaDoString<bool>("usable = (IsUsableSpell(\""  + Name + "\") and true or false)", "usable");
    }

    public bool CanCast()
    {
        return Lua.LuaDoString<bool>("return (IsUsableSpell(\"" + FullName() + "\") and GetSpellCooldown(\"" + FullName() + "\") == 0)");
    }

    public float GetCooldown()
    {
        string luaString = @"
        cooldownLeft = 0;

        local start, duration, enabled = GetSpellCooldown(""{0}"");
        if enabled == 1 and start > 0 and duration > 0 then
            cooldownLeft = duration - (GetTime() - start)
        end";
        return Lua.LuaDoString<float>(string.Format(luaString, FullName()), "cooldownLeft");
    }

    public void UpdateRank(int rank)
    {
        this.Rank = rank;
    }

    public string FullName()
    {
        return Rank != null ? (Name + "(Rank " + Rank + ")") : Name;
    }

    public bool IsKnown()
    {
        return Lua.LuaDoString<bool>("return (GetSpellInfo(\"" + FullName() + "\") ~= nil)");
    }

}

 

That Lua thingy was useful to know though (How you call Lua) :)

Link to comment
Share on other sites

On 8/8/2017 at 0:28 AM, reapler said:

It looks excellent Carl. I'm looking forward that this will be added soon to the WRobot's lib ;)

Yes it would be really cool if the dbcreader was implemented into wrobot, but the loading was optional (because distributing DBC files isn't very legal iirc)

I'm also looking into exporting data about all items (from TBC-DB) into a CSV or smth, and another table that handles "classlevelstats" or whatever it's called.

Maybe you can get this with Lua, but my idea is that with this we could implement a way to predict things better (damage to be caused by a spell before it's casted, healing done by a spell).

With this one could eliminate "all" (not taking criticals into account probably) overhealing, start popping rogue finishing moves when they're predicted to kill (good to optimize leveling classes).

I'm really shit with the actual AI part, since i barely can play WoW. But this could be a fun project! :)

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