function SpiritBearSpawn( event )
local caster = event.caster
local player = caster:GetPlayerID()
local ability = event.ability
local level = ability:GetLevel()
local origin = caster:GetAbsOrigin() + RandomVector(100)
-- Set the unit name, concatenated with the level number
local unit_name = event.unit_name
unit_name = unit_name..level
-- Synergy Level. Checks both the default and the datadriven Synergy
local synergyAbility = caster:FindAbilityByName("lone_druid_synergy_datadriven")
if synergyAbility == nil then
synergyAbility = caster:FindAbilityByName("lone_druid_synergy")
end
-- Check if the bear is alive, heals and spawns them near the caster if it is
if caster.bear and IsValidEntity(caster.bear) and caster.bear:IsAlive() then
FindClearSpaceForUnit(caster.bear, origin, true)
caster.bear:SetHealth(caster.bear:GetMaxHealth())
-- Spawn particle
local particle = ParticleManager:CreateParticle("particles/units/heroes/hero_lone_druid/lone_druid_bear_spawn.vpcf", PATTACH_ABSORIGIN_FOLLOW, caster.bear)
-- Re-Apply the synergy buff if we found one
if caster.bear:HasModifier("modifier_bear_synergy") then
caster.bear:RemoveModifierByName("modifier_bear_synergy")
synergyAbility:ApplyDataDrivenModifier(caster, caster.bear, "modifier_bear_synergy", nil)
end
else
if caster.bear then
local unit = caster.bear
item_table = {}
for i = 0, 5 do
local item = unit:GetItemInSlot( i )
if item ~= nil then
table.insert(item_table , item)
end
end
end
-- Create the unit and make it controllable
caster.bear = CreateUnitByName(unit_name, origin, true, caster, caster, caster:GetTeamNumber())
caster.bear:SetControllableByPlayer(player, true)
local items = item_table or {}
for _,item in pairs(items) do
caster.bear:AddItem(item)
end
-- Apply the backslash on death modifier
if ability ~= nil then
ability:ApplyDataDrivenModifier(caster, caster.bear, "modifier_spirit_bear", nil)
end
-- Apply the synergy buff if the ability exists
if synergyAbility ~= nil then
synergyAbility:ApplyDataDrivenModifier(caster, caster.bear, "modifier_bear_synergy", nil)
end
-- Learn its abilities: return lvl 2, entangle lvl 3, demolish lvl 4. By Index
LearnBearAbilities( caster.bear, 1 )
end
end