scope BlessedHammers initializer INIT
globals
private hashtable HASH = InitHashtable()
private string CAST_SOUND = "BlessedHammerCast.wav"
private string LOOP_SOUND = "BlessedHammerLoop.wav"
private string HIT_SOUND = "BlessedHammerHit.wav"
private integer ABILITY = 'A000'
private integer DUMMY_ID = 'hamm'
private integer SOUND_VOLUME = 127
private real SPEED = 45
private real ANGLE_SPEED = 9.5
private real HIT_AOE = 80
private real LOOP_TIME = 0.03125
private real DURATION = 6
private real UNDEAD_BONUS = 1.5
private attacktype ATTACK = ATTACK_TYPE_MAGIC
public trigger Blessed_Hammer = CreateTrigger()
endglobals
private function DAMAGE takes unit a returns real
return 10 + GetHeroInt(a, true) * .5 + GetUnitAbilityLevel(a, ABILITY) * 8
endfunction
private function FILTER takes unit uu, player p returns boolean
return IsPlayerEnemy(p, GetOwningPlayer(uu)) and IsUnitType(uu, UNIT_TYPE_GROUND) and GetUnitState(uu, UNIT_STATE_LIFE) > 0
endfunction
private function CONDITION takes nothing returns boolean
return GetSpellAbilityId()==ABILITY
endfunction
private function LOOP takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer i = GetHandleId(t)
local unit uu
local real dam = LoadReal(HASH, i, 0)
local unit u = LoadUnitHandle( HASH, i, 2)
local player p = GetOwningPlayer(u)
local unit d = LoadUnitHandle( HASH, i, 3)
local real r = LoadReal(HASH, i, 10)
local real ti = LoadReal(HASH, i, 9)
local real a = GetUnitFacing(d)
local integer h = GetHandleId(d)
local integer lol
local sound s
if ti < DURATION then
call SaveReal(HASH, i, 9, ti + LOOP_TIME)
call SaveReal(HASH, i, 10, r + SPEED * LOOP_TIME)
call SetUnitFacing(d, a + ANGLE_SPEED)
call SetUnitX(d, LoadReal(HASH, i, 4) + r * Cos(a * bj_DEGTORAD))
call SetUnitY(d, LoadReal(HASH, i, 5) + r * Sin(a * bj_DEGTORAD))
call GroupEnumUnitsInRange(bj_lastCreatedGroup, GetUnitX(d), GetUnitY(d), HIT_AOE, null)
loop
set uu = FirstOfGroup(bj_lastCreatedGroup)
exitwhen null == uu
call GroupRemoveUnit(bj_lastCreatedGroup, uu)
set lol = GetHandleId(uu)
if LoadInteger(HASH, h, lol) != 1 and FILTER(uu, p) then
set s = CreateSound(HIT_SOUND, false, true, true, 0, 0, "")
call SaveInteger(HASH, h, lol, 1)
call SetSoundDistances( s, 750, 100000 )
call SetSoundDistanceCutoff( s, 2000 )
call AttachSoundToUnit( s, d)
call SetSoundVolume( s, SOUND_VOLUME)
call StartSound(s)
call KillSoundWhenDone(s)
if IsUnitType(uu, UNIT_TYPE_UNDEAD) then
call UnitDamageTarget(u, uu, dam * UNDEAD_BONUS, true, false, ATTACK, DAMAGE_TYPE_NORMAL, null)
else
call UnitDamageTarget(u, uu, dam, true, false, ATTACK, DAMAGE_TYPE_NORMAL, null)
endif
endif
endloop
call StartSound(LoadSoundHandle(HASH, i, 6))
else
set s = LoadSoundHandle(HASH, i, 6)
call RemoveUnit(d)
call StopSound(s, false, false)
call KillSoundWhenDone(s)
call DestroyTimer(t)
call FlushChildHashtable(HASH, i)
call FlushChildHashtable(HASH, h)
endif
set t = null
set u = null
set d = null
set s = null
endfunction
private function CAST takes nothing returns nothing
local unit u = GetTriggerUnit()
local real a = GetUnitFacing(u) - 45
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local unit d = CreateUnit( GetTriggerPlayer(), DUMMY_ID, x, y, a)
local timer t = CreateTimer()
local integer it = GetHandleId(t)
local sound s = CreateSound(CAST_SOUND, false, true, true, 0, 0, "")
local sound l = CreateSound(LOOP_SOUND, false, true, true, 0, 0, "")
call SetSoundDistances( s, 750, 100000 )
call SetSoundDistances( l, 750, 100000 )
call SetSoundDistanceCutoff( s, 2000 )
call SetSoundDistanceCutoff( l, 2000 )
call AttachSoundToUnit( s, d)
call AttachSoundToUnit( l, d)
call SetSoundVolume( s, SOUND_VOLUME)
call SetSoundVolume( l, SOUND_VOLUME)
call StartSound(s)
call StartSound(l)
call KillSoundWhenDone(s)
call TimerStart( t, LOOP_TIME, true, function LOOP )
call SaveReal( HASH, it, 0, DAMAGE(u) )
call SaveUnitHandle( HASH, it, 2, u)
call SaveUnitHandle( HASH, it, 3, d)
call SaveReal(HASH, it, 4, x)
call SaveReal(HASH, it, 5, y)
call SaveSoundHandle( HASH, it, 6, l)
call SaveTimerHandle( HASH, it, 7, t)
call SaveReal(HASH, it, 10, SPEED * 2)
set u = null
set d = null
set t = null
set s = null
set l = null
endfunction
private function INIT takes nothing returns nothing
call TriggerRegisterAnyUnitEventBJ( Blessed_Hammer, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( Blessed_Hammer, Condition( function CONDITION ) )
call TriggerAddAction( Blessed_Hammer, function CAST )
endfunction
endscope