
function OnLyrica01SpellStart(keys)
	local caster = EntIndexToHScript(keys.caster_entindex)
	local targetPoint = keys.target_points[1]

	local isEnabled = false
	if caster:FindAbilityByName("thtd_lyrica_02"):GetLevel() >= 1 then 
		isEnabled = true
	end
	
	local targets = THTD_FindUnitsInRadius(caster,targetPoint,keys.radius)
	for k,v in pairs(targets) do
		UpdatePrismriverComboName(caster,v)
	
		if isEnabled then 			
			if v:HasModifier("modifier_lunasa_01_debuff") then			
				local effectIndex = ParticleManager:CreateParticle("particles/heroes/lunasa/ability_lunasa_music_buff.vpcf", PATTACH_CUSTOMORIGIN, caster)
				ParticleManager:SetParticleControl(effectIndex, 0, v:GetOrigin())
				ParticleManager:DestroyParticleSystem(effectIndex,false)
			end
			if v:HasModifier("modifier_merlin_01_debuff") then				
				local effectIndex = ParticleManager:CreateParticle("particles/heroes/merlin/ability_merlin_music_buff.vpcf", PATTACH_CUSTOMORIGIN, caster)
				ParticleManager:SetParticleControl(effectIndex, 0, v:GetOrigin())
				ParticleManager:DestroyParticleSystem(effectIndex,false)
			end
		end

		local damage = caster:THTD_GetAbilityPowerDamage(keys.ability, 1) 
		if caster:HasModifier("modifier_lyrica_lunasa_merlin_combo") then
			damage = damage * (1 + keys.damage_up/100)
		end		
		
		local DamageTable = {
			ability = keys.ability,
			victim = v, 
			attacker = caster, 
			damage = damage, 
			damage_type = keys.ability:GetAbilityDamageType(), 
			damage_flags = DOTA_DAMAGE_FLAG_NONE
	   	}  
	   	UnitDamageTarget(DamageTable)
		   
		if THTD_IsValid(v) then
			local count = GetCountPrismriver(v)
			local comboName = GetPrismriverComboName(v)		
			if comboName == "merlinlunasalyrica" then
				OnMerlinLunasaLyrica(keys,caster,v,count)
				ResetPrismriverComboName(v)
			elseif comboName == "lunasamerlinlyrica" then
				OnLunasaMerlinLyrica(keys,caster,v,count)
				ResetPrismriverComboName(v)		
			end
		end		
	end
	
	caster:EmitSound("Sound_THTD.thtd_lyrica_01")

	local effectIndex = ParticleManager:CreateParticle("particles/heroes/lyrica/ability_lyrica_01.vpcf", PATTACH_CUSTOMORIGIN, caster)
	ParticleManager:SetParticleControl(effectIndex, 0, targetPoint)
	ParticleManager:DestroyParticleSystem(effectIndex,false)
end

function OnMerlinLunasaLyrica(keys,caster,target,count)
	local targets = THTD_FindUnitsInRadius(caster,target:GetOrigin(),keys.radius)

	local damage = caster:THTD_GetAbilityPowerDamage(keys.ability, 2) * (1 + keys.damage_up/100) * (1 + count)
	for k,v in pairs(targets) do		
		local DamageTable = {
				ability = keys.ability,
				victim = v, 
				attacker = caster, 
				damage = damage, 
				damage_type = keys.ability:GetAbilityDamageType(), 
				damage_flags = DOTA_DAMAGE_FLAG_NONE
		}
		UnitDamageTarget(DamageTable)		
	end
	
	local effectIndex = ParticleManager:CreateParticle("particles/heroes/lyrica/ability_lyrica_01.vpcf", PATTACH_CUSTOMORIGIN, caster)
	ParticleManager:SetParticleControl(effectIndex, 0, target:GetOrigin())
	ParticleManager:DestroyParticleSystem(effectIndex,false)
end

function OnLunasaMerlinLyrica(keys,caster,target,count)	
	local damage = caster:THTD_GetAbilityPowerDamage(keys.ability, 3) * (1 + keys.damage_up/100) * (1 + count)
	local DamageTable = {
		ability = keys.ability,
		victim = target, 
		attacker = caster, 
		damage = damage, 
		damage_type = keys.ability:GetAbilityDamageType(), 
		damage_flags = DOTA_DAMAGE_FLAG_NONE
   	}
   	UnitDamageTarget(DamageTable)
end