scope HunterToggle initializer init
	import SoundControl
	import RegisterPlayerUnitEvent

	constant string TOGGLE_SOUND = "Abilities\\Spells\\Human\\Defend\\DefendCaster.wav"

	constant integer TOGGLE_ID = 'A00D'
	constant integer BURST_ID  = 'A00B'
	constant integer AUTO_ID   = 'A00C'

	function act takes nothing returns nothing
		unit tU
		if GetSpellAbilityId() == TOGGLE_ID then
			tU = GetTriggerUnit()

			SoundControl.play3D(TOGGLE_SOUND, 2., GetUnitX(tU), GetUnitY(tU), 0.)

			if GetUnitAbilityLevel(tU, BURST_ID) > 0 then
				UnitRemoveAbility(tU, BURST_ID)
				UnitAddAbility(tU, AUTO_ID)
			else
				UnitRemoveAbility(tU, AUTO_ID)
				UnitAddAbility(tU, BURST_ID)
			end
		end
	end

	function init takes nothing returns nothing
		registerPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT, function act)
		SoundControl.preload(TOGGLE_SOUND)
	end
endscope
