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

	local effectIndex = ParticleManager:CreateParticle("particles/heroes/thtd_hatate/ability_hatate_01_news.vpcf",PATTACH_CUSTOMORIGIN,caster)
	ParticleManager:SetParticleControl(effectIndex, 0, caster:GetOrigin()+caster:GetForwardVector()*60)
	ParticleManager:DestroyParticleSystem(effectIndex,false)

	local targets = THTD_FindUnitsInRadius(caster,targetPoint,keys.range)
	for _,v in pairs(targets) do
		if v:HasModifier("modifier_hatate01_news_buff") == false and v:HasModifier("modifier_aya01_news_buff") == false then	
   			
		end
	end	
	local deal_damage = caster:THTD_GetAbilityPowerDamage(keys.ability)
	for k,v in pairs(targets) do
		local modifier = v:FindModifierByName("modifier_hatate01_news_buff")
		if modifier == nil then
			modifier = v:FindModifierByName("modifier_aya01_news_buff")
		end
		if modifier == nil then
			modifier = keys.ability:ApplyDataDrivenModifier(caster,v,"modifier_hatate01_news_buff", nil)
		elseif modifier:GetStackCount() < 999 then
			modifier:IncrementStackCount()
		end
		local crit = 1.0
		if modifier ~= nil then	
			local effectIndex = ParticleManager:CreateParticle("particles/heroes/thtd_hatate/ability_hatate_01.vpcf",PATTACH_CUSTOMORIGIN,caster)
			ParticleManager:SetParticleControl(effectIndex, 0, v:GetOrigin())
			ParticleManager:DestroyParticleSystem(effectIndex,false)
			crit = crit + modifier:GetStackCount() * caster:GetAbilityValue("thtd_hatate_01", "damage_up", true)
		end

		local damage_table = {
			ability = keys.ability,
			victim = v,
			attacker = caster,
			damage = deal_damage * crit,
			damage_type = keys.ability:GetAbilityDamageType(), 
			damage_flags = 0
		}
		UnitDamageTarget(damage_table)
	end
end

function OnHatate01AttackLanded(keys)
	local caster = EntIndexToHScript(keys.caster_entindex)
	local target = keys.target

	if caster.__thtd_hatate_01_lock == true then return end
	caster.__thtd_hatate_01_lock = true

	local entities = THTD_FindUnitsAll(caster)
	for k,v in pairs(entities) do		
		if v:HasModifier("modifier_hatate01_news_buff") or v:HasModifier("modifier_aya01_news_buff") then
			local modifier = v:FindModifierByName("modifier_hatate01_news_buff")
			if modifier == nil then
				modifier = v:FindModifierByName("modifier_aya01_news_buff")
			end
			if modifier == nil then
				modifier = keys.ability:ApplyDataDrivenModifier(caster,v,"modifier_hatate01_news_buff", nil)
			elseif modifier:GetStackCount() < 999 then
				modifier:IncrementStackCount()
			end
		end
	end

	caster.__thtd_hatate_01_lock = false
end

function OnHatate02SpellStart(keys)
	if GameRules:IsGamePaused() then return end
	local caster = EntIndexToHScript(keys.caster_entindex)
	local inners = THTD_FindUnitsInner(caster)
	local outers = THTD_FindUnitsOuter(caster)

	for k,v in pairs(outers) do
		table.insert(inners,v)
	end

	local deal_damage = caster:THTD_GetAbilityPowerDamage(keys.ability) * keys.tick_time	
	for k,v in pairs(inners) do
		local modifier = v:FindModifierByName("modifier_hatate01_news_buff")
		if modifier == nil then
			modifier = v:FindModifierByName("modifier_aya01_news_buff")
		end
		if modifier == nil then
			modifier = keys.ability:ApplyDataDrivenModifier(caster,v,"modifier_hatate01_news_buff", nil)
		elseif modifier:GetStackCount() < 999 then
			modifier:IncrementStackCount()
		end
		if RandomInt(1,5) == 1 then
			local effectIndex = ParticleManager:CreateParticle("particles/heroes/thtd_hatate/ability_hatate_01.vpcf",PATTACH_CUSTOMORIGIN,caster)
			ParticleManager:SetParticleControl(effectIndex, 0, v:GetOrigin())
			ParticleManager:DestroyParticleSystem(effectIndex,false)
		end
		local crit = 1.0
		if modifier ~= nil then				
			crit = crit + modifier:GetStackCount() * caster:GetAbilityValue("thtd_hatate_01", "damage_up", true)
		end

		local damage_table = {
				ability = keys.ability,
			    victim = v,
			    attacker = caster,
			    damage = deal_damage * crit,
			    damage_type = keys.ability:GetAbilityDamageType(), 
	    	    damage_flags = 0
		}
		UnitDamageTarget(damage_table)		
	end
end