globals
constant integer MOUNT_ABILITY_ID =
'A002' constant integer UNMOUNT_ABILITY_ID =
'A001' constant integer MOUNTED_BUFF_ID =
'B000' constant integer FLY_ABILITY_ID =
'Amrf' endglobals
function Trig_Mount_Conditions takes nothing returns boolean
return GetSpellAbilityId() == MOUNT_ABILITY_ID
endfunction
struct MountingData
unit mounter
unit mount
static method create takes unit caster, unit created returns MountingData local MountingData d = MountingData.allocate()
set d.mounter = caster
set d.mount = created
return d
endmethod
method onDestroy takes nothing returns nothing
set .mounter = null
set .mount = null
endmethod
endstruct
function MoveMounter takes nothing returns nothing
local MountingData d = GetTimerData(GetExpiredTimer())
local real x = GetWidgetX
(d.mount
) +
20 *
Cos(GetUnitFacing
(d.mount
) * bj_DEGTORAD
) local real y = GetWidgetY
(d.mount
) +
20 *
Sin(GetUnitFacing
(d.mount
) * bj_DEGTORAD
) call SetUnitX(d.mounter,x)
call SetUnitY(d.mounter,y)
call SetUnitFacing(d.mounter,GetUnitFacing(d.mount))
endfunction
function Trig_Mount_Actions takes nothing returns nothing
local unit mounter = GetSpellAbilityUnit()
local unit mount = CreateUnit(GetOwningPlayer(mounter), MOUNT_UNIT_ID, GetWidgetX(mounter), GetWidgetY(mounter), GetUnitFacing(mounter))
local MountingData d = MountingData.create(mounter,mount)
call SetTimerData
(d.
time,d
)
if GetLocalPlayer() == GetOwningPlayer(mounter) then
call ClearSelection()
call SelectUnit(mount, true)
endif
call SetUnitPathing(mounter, false)
call UnitAddAbility(mounter, FLY_ABILITY_ID)
call SetUnitFlyHeight(mounter, 50.0, 0)
call PauseUnit(mounter, true)
set mounter = null
set mount = null
call TimerStart
(d.
time,
0.03,
true,
function MoveMounter
)endfunction
//===========================================================================
function InitTrig_Mount takes nothing returns nothing
local trigger mount = CreateTrigger()
local trigger unmount = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(mount, EVENT_PLAYER_UNIT_SPELL_FINISH)
call TriggerAddCondition(mount, Condition(function Trig_Mount_Conditions))
call TriggerAddAction(mount, function Trig_Mount_Actions)
endfunction