HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Having Trouble With ABuff Auras

01-01-2011, 04:25 PM#1
ShadowDestroyer
The Aura works fine except:

When a hero levels the ability, units must leave and re-enter the range for the updated skill level to take effect (and therefore never updates on the hero himself). How do I fix this?

Note: I am using AHeroSkill, which I thought corrected this issue.

Collapse JASS:
library BashAura initializer Init requires ABuff, ABuffAura, ABuffHeroSkill, ABuffDisplay

    globals
    // BUFF EFFECT
        private constant integer BUFF_ABILITY = 'A08I' //the bash ability that units under the effect of the aura gain
        private constant integer BUFF_ABILITY_HOLDER = 'A08J'  //The spellbook containing bash
    // BUFF VISUALS
        private constant integer BUFF_AURA = 'A09S' //the self-targeting aura that places the buff in the unit's status card
        private constant integer BUFF = 'B01A' //the buff bestowed upon the unit by the aura

    // MAIN AURA HERO SKILL
        private constant integer AURA = 'A09Q' //the dummy aura ability on the hero
    endglobals
    

    private function Range takes integer level returns real
        // This is the area of effect of the aura.
        if (level < 6) then
            return 850.0 + level * 50
        else
            return 1200.0
        endif
    endfunction

    private function Targets takes unit affected, unit auraGiver returns boolean
        // This function follows the ABuffAuraTargets function interface
        // and defines what units can be affected by the aura.
        return not(IsUnitEnemy(affected, GetOwningPlayer(auraGiver))) and not(IsUnitType(affected, UNIT_TYPE_MECHANICAL)) and not(IsUnitType(affected, UNIT_TYPE_STRUCTURE))
    endfunction

// ================================================================

    // BUFF CODE
    globals
        private aBuffType auraBuff
    endglobals
    
    private function BuffApply takes aBuff eventBuff returns nothing
        //add the bash ability when the unit enters aura range.
        call UnitAddAbility(eventBuff.target.u, BUFF_ABILITY_HOLDER)
        call SetUnitAbilityLevel(eventBuff.target.u, BUFF_ABILITY, eventBuff.level)
        call UnitMakeAbilityPermanent(eventBuff.target.u, true, BUFF_ABILITY_HOLDER) //prevent morphing from removing the ability
    endfunction
    private function BuffCleanup takes aBuff eventBuff returns nothing
        //remove the bash ability when the unit leaves aura range.
        call UnitRemoveAbility(eventBuff.target.u, BUFF_ABILITY_HOLDER)
    endfunction

    // ABILITY CODE
    globals
        private aBuffType auraSource
    endglobals
    private function AuraSet takes aBuff eventBuff returns nothing
        call UnitSetABuffAura(eventBuff.target.u, auraBuff, eventBuff.level, Targets, Range(eventBuff.level))
    endfunction
    private function AuraRemove takes aBuff eventBuff returns nothing
        call UnitRemoveABuffAura(eventBuff.target.u, auraBuff)
    endfunction

// ================================================================

    // ABILITY INITIALIZATION
    private function Init takes nothing returns nothing
        //this is the aura buff which gives units the bash ability
        set auraBuff=aBuffType.create()
        set auraBuff.eventCreate = BuffApply
        set auraBuff.eventRefresh = BuffApply
        set auraBuff.eventCleanup = BuffCleanup
        set auraBuff.countsAsBuff = false
        
        set auraBuff.display = aBuffDisplay.create(BUFF_AURA, BUFF)

        //this is the hero buff which makes the hero a source of the aura
        //when he learns the AURA ability (thanks to ABuffHeroSkill)
        set auraSource=aBuffType.create()
        set auraSource.eventCreate = AuraSet
        set auraSource.eventRefresh = AuraSet
        set auraSource.eventCleanup = AuraRemove
        set auraSource.ignoreAsBuff = true
        
        call NewABuffHeroSkill(AURA, auraSource)
    endfunction
    
endlibrary
01-01-2011, 10:01 PM#2
Anitarf
Ah, I see, I forgot to force an aura refresh if the level changes. Here's the ABuffAura library with the bug fixed:
Expand JASS: