Help Optimize My Spell?

overload119

New Member
Reaction score
5
This spell:

Is supposed to increase a custom stat by a certain amount. The thing I want to be careful about is that, even when it is used, the user can add/remove that custom stat. I want to be careful that it doesn't mess with the spell's ability to temporaility increase the stat by 200%.

There are a lot of custom functions in here, but those are not the parts that need to be optimized. I was just wondering if there is a better way to go about this.

JASS:
scope BattleShout

private struct data 
    unit caster
    group g
    Table table
endstruct

private function Filt takes nothing returns boolean
    local boolean b = GetWidgetLife(GetFilterUnit())>0.405
    set b = b and IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO)
    set b = b and IsUnitAlly(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit()))
    set b = b and GetUnitAbilityLevel(GetFilterUnit(), 'A00Q') == 0
    return b
endfunction

function Trig_Battle_Shout_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00P'
endfunction

private function DisFect takes nothing returns nothing 
    local timer t = GetExpiredTimer()
    local data d = GetTimerData(t)
    local integer amount = d.table[GetHandleId(GetEnumUnit())]
    
    call UnitRemoveAbility( GetEnumUnit(), 'A00Q' )
    call AddSingleAttribute(GetEnumUnit(), ATTACK_POWER,  -1*amount, FALSE )
    call UpdateAttributes(GetEnumUnit())    
endfunction

private function Callback takes nothing returns nothing 
    local timer t = GetExpiredTimer()
    local data d = GetTimerData(t)
    
    call ForGroup(d.g, function DisFect)    
    
    call ReleaseGroup(d.g)
    call d.table.destroy()
    call d.destroy()
    call PauseTimer(t)
    call ReleaseTimer(t)
endfunction

function Trig_Battle_Shout_Actions takes nothing returns nothing
    local timer t = NewTimer()
    local data d = data.create()
    local unit u = GetTriggerUnit()
    local boolexpr filter = Condition(function Filt)
    local unit tt
    local real amount
    local group g = NewGroup()
    local real healAmount = 50+18*GetHeroLevel(u)+GetHeroStr(u, true)
    
    call HealUnit(u, u, healAmount)
    
    set d.caster = u
    set d.g = NewGroup()
    set d.table = Table.create()
    
    call GroupEnumUnitsInRange(g, GetUnitX(u), GetUnitY(u), 400, filter)
    call GroupAddUnit(g, u)
    
    call GroupAddGroup(g, d.g)
    
    // Add the buff to the group first
    loop
    set tt = FirstOfGroup(g)
    exitwhen tt == null
        set amount = GetUnitStat(tt, ATTACK_POWER)
        set d.table[GetHandleId(tt)] = R2I(amount)
        call UnitAddAbility( tt, 'A00Q' )
        call AddSingleAttribute(tt, ATTACK_POWER, amount, FALSE )    
        call UpdateAttributes(tt)
        call GroupRemoveUnit(g, tt)
    endloop
    
    call SetTimerData(t, d)
    call TimerStart(t, 10., false, function Callback)
    
    call DestroyBoolExpr(filter)
endfunction

//===========================================================================
function InitTrig_Battle_Shout takes nothing returns nothing
    set gg_trg_Battle_Shout = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Battle_Shout, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Battle_Shout, Condition( function Trig_Battle_Shout_Conditions ) )
    call TriggerAddAction( gg_trg_Battle_Shout, function Trig_Battle_Shout_Actions )
endfunction

endscope
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top