Hekili Priority Helper

Hekili Priority Helper

44M Downloads

Trying to get Balance Working but...

thunderchylde opened this issue · 6 comments

commented

More newbie questions:

For the Moon spell the spend and cast change depending on which is up, but the script only looks at the first one in there and uses that spend/cast. How would I have it dynamically update the spend/cast? Ideally I need to be able to reference the spend in the script as the astral power deficit vs. gain from the moon spell is the trigger in simc.

/script local spellid=202771;if select(7,GetSpellInfo(GetSpellInfo(spellid)))~=spellid then print("replaced") else print("not replaced") end;

202771 is the Full Moon spell id - if you run this script after casting Full Moon it will trigger the replaced (thanks interwebz) but I can't see how I would integrate this into the script - I can't run GetSpellInfo within an addHandler().

commented

So, these are three separate spells and should probably be implemented accordingly. The simc action lists have separate entries for new_moon, half_moon, and full_moon. You can specify their costs individually and use modifyAbility() as needed to account for haste.

In terms of which spell is actually usable, you probably have to work around a few issues.

  1. At login, we don't know which spell is enabled by default.
  2. After casting a spell, we need to make the next spell usable and the previous spell unusable.

For the first part, we can use a couple of API functions to see which is active.

local FindSpellBookSlotBySpellID, GetSpellBookItemName = FindSpellBookSlotBySpellID, GetSpellBookItemName

registerCustomVariable( 'active_moon', 'new_moon' )

addHook( 'reset_precast', function( x )
    if state.spec.balance then
        local slot = FindSpellBookSlotBySpellID( 202767 )
        local currName = GetSpellBookItemName( slot, "spell" )

        if currName == class.abilities.new_moon.name then
            state.active_moon = 'new_moon'
        elseif currName == class.abilities.half_moon.name then
            state.active_moon = 'half_moon'
        elseif currName == class.abilities.full_moon.name then
            state.active_moon = 'full_moon'
        else
            state.active_moon = 'new_moon' -- should never get here.
        end
    end 
end )

The above hook fires when the addon resets itself to start deciding its next recommendation. Basically, New Moon is the baseline spell and Half Moon and Full Moon override it in the spell book. So using New Moon's spell ID, we can find the slot in the spell book, and then retrieve the name of that entry in the spell book to find out which spell is actually active at the moment.

Now, we need each ability to only be usable when active_moon matches its token.

Assuming you have used addAbility for each of the spells, we can do the following:

addAbility( 'new_moon', {
    id = 202767,
    -- cast time, cost, etc. etc.
    usable = function () return active_moon == 'new_moon' end,
} )

Similarly, you can add a usable function for half_moon and new_moon that checks to see that active_moon matches that particular spell.

Now, if you want the addon to make accurate recommendations after its first recommendation (or even to be correct for its first recommendation while you are mid-cast), each of these abilities needs to have a handler that will update active_moon when you cast a spell.

For example:

addHandler( 'new_moon', function ()
    active_moon = 'half_moon'
end )

For half_moon's handler, you'd want it to set active_moon to 'full_moon', and then full_moon's handler would set it to 'new_moon'.

The handler function is what tells the addon what happens to the game state when that ability is cast. So if you need to have it apply buffs or debuffs, that's where that would happen anyway.

This is all drycoded here, so there may be syntax/formatting or other issues you'd need to troubleshoot, but this should get you going for the Legion version.

Fair warning: class/spec modules are changing for BfA and this will have to be rebuilt in the near future. But the handler/reset elements here will be similar.

commented

Thanks! I’ll have a play around tonight. The odd thing is that although they are the different spells they all trigger off the same one - hopefully the usable bit will help

commented

(And I only started coding this after they put moon back in as a talent)

commented

I tried to be kinda clever with:

` registerCustomVariable( 'moon_cast_time', 0 )
registerCustomVariable( 'moon_spend', 0 )
registerCustomVariable( 'moon_id', 0 )

    RegisterUnitEvent( "UNIT_SPELLCAST_SUCCEEDED", function( _, unit, spell, _, spellID )

        if unit ~= 'player' then return end
        
        if spellID == 202771 then
            state.moon_cast_time = 2
            state.moon_spend     = -20
            state.moon_id        = 202768
            modifyAbility( "moon", "id", 202768 )
            modifyAbility( "moon", "spend", -20 )
            modifyAbility( "moon", "cast_time", 2 )    
        elseif spellID == 202767 then
            state.moon_cast_time = 3
            state.moon_spend     = -40
            state.moon_id        = 202771
            modifyAbility( "moon", "id", 202771 )
            modifyAbility( "moon", "spend", -40 )
            modifyAbility( "moon", "cast_time", 3 )
        elseif spellID == 202768 then
            state.moon_cast_time = 1
            state.moon_spend     = -10
            state.moon_id        = 202767
            modifyAbility( "moon", "id", 202767 )
            modifyAbility( "moon", "spend", -10 )
            modifyAbility( "moon", "cast_time", 1 )
        end

    end )`

but that didn't seem to change it (calling class.abilities.moon.cast didn't change the value)

commented

I've got it working mostly.

There is still the fact that, although I have all 3 spells defined the script says I only "know" New Moon. I still seem to cast Full Moon and Half Moon, and the addHandler to set "active_moon" work as expected but I can't actually use the other two in the APL. It's not hard to work around but it does mean that the icons don't match (if I have Half Moon and then Full Moon in my APL it uses the Half Moon icon for both, even though it's the New Moon ability in the APL)

commented

That's more of the magic of sharing spellbook entries.

You can hardcode the textures in each ability.

Use GetSpellTexture for each one (when the spell is available) and then put texture = ####, in each entry, where #### is the appropriate texture ID for each.