thtd_lily_01 = class({})

LinkLuaModifier("modifier_lily_01_effect_think", "abilities/ability_lua/modifier_lily_01_effect_think", LUA_MODIFIER_MOTION_NONE)

function thtd_lily_01:GetIntrinsicModifierName()
    return "modifier_lily_01_effect_think"
end

function thtd_lily_01:GetAOERadius()
    return self:GetSpecialValueFor("radius")
end

function thtd_lily_01:OnSpellStart()
	if SpawnSystem.IsUnLimited then return end
	if GameRules:GetCustomGameDifficulty() >= FUNNY_MODE then return end
	local caster = self:GetCaster()
	local ability = self
	local targetPoint = self:GetCursorPosition()

	local targets = 
			FindUnitsInRadius(
				caster:GetTeamNumber(), 
				targetPoint, 
				nil, 
				ability:GetSpecialValueFor("radius"), 
				ability:GetAbilityTargetTeam(), 
				ability:GetAbilityTargetType(), 
				ability:GetAbilityTargetFlags(), 
				FIND_CLOSEST, 
				false
			)

	local exp = 1000 + caster:THTD_GetPower() * ability:GetSpecialValueFor("power_factor")

	for k,v in pairs(targets) do
		if v ~= nil and v:IsNull() == false and v:THTD_IsTower() and v ~= caster and v:GetOwner() == caster:GetOwner() and v:THTD_GetLevel() < THTD_MAX_LEVEL then 
			v:THTD_AddExp(exp)
		end
	end

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


thtd_lily_02 = class({})

LinkLuaModifier("modifier_lily_02_buff", "abilities/ability_lua/modifier_lily_02_buff", LUA_MODIFIER_MOTION_NONE)

function thtd_lily_02:OnSpellStart()	
	local caster = self:GetCaster()	
	
	caster:EmitSound("Sound_THTD.thtd_lily_02")	

	self.radius = self:GetSpecialValueFor("radius")
	self.duration = self:GetSpecialValueFor("duration")
	self.damage_up = self:GetSpecialValueFor("damage_up")

	local targets = 
			FindUnitsInRadius(
				caster:GetTeamNumber(), 
				caster:GetOrigin(), 
				nil, 
				self.radius, 
				self:GetAbilityTargetTeam(), 
				self:GetAbilityTargetType(), 
				self:GetAbilityTargetFlags(), 
				FIND_CLOSEST, 
				false
			)

	for k,v in pairs(targets) do
		if not v:HasModifier("modifier_lily_02_buff") then 
			v:AddNewModifier(caster, self, "modifier_lily_02_buff", {Duration = self.duration})
		end
	end

	local effectIndex = ParticleManager:CreateParticle("particles/heroes/lily/ability_lily_02.vpcf", PATTACH_CUSTOMORIGIN, caster)
	ParticleManager:SetParticleControl(effectIndex, 0, caster:GetOrigin())
	ParticleManager:SetParticleControl(effectIndex, 1, Vector(self.radius,self.radius,self.radius))
	ParticleManager:DestroyParticleSystemTime(effectIndex,self.duration)
end