function OnToramaru01SpellStart(keys)
	if SpawnSystem.IsUnLimited then return end
	if GameRules:GetCustomGameDifficulty() >= FUNNY_MODE then return end
	local caster = EntIndexToHScript(keys.caster_entindex)
	local target = keys.target

	local gold = keys.BonusGold
	THTD_ModifyGoldEx(caster:GetPlayerOwnerID(), gold , true, DOTA_ModifyGold_CreepKill)
	SendOverheadEventMessage(caster:GetPlayerOwner(), OVERHEAD_ALERT_GOLD, target, gold, caster:GetPlayerOwner() )
	caster:EmitSound("Sound_THTD.thtd_nazrin_01")
	
	local effectIndex = ParticleManager:CreateParticle("particles/thd2/items/item_donation_box.vpcf", PATTACH_CUSTOMORIGIN, caster)
	ParticleManager:SetParticleControl(effectIndex, 0, caster:GetAbsOrigin())
	ParticleManager:SetParticleControl(effectIndex, 1, target:GetAbsOrigin())
	ParticleManager:DestroyParticleSystem(effectIndex,false)

	local damage_table = {
		ability = keys.ability,
		victim = target,
		attacker = caster,
		damage = caster:THTD_GetAbilityPowerDamage(keys.ability),
		damage_type = keys.ability:GetAbilityDamageType(), 
		damage_flags = 0
	}
	UnitDamageTarget(damage_table)
end

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

	if caster:HasModifier("modifier_byakuren_03_buff") then
		THTD_ModifyGoldEx(caster:GetPlayerOwnerID(), 500 * caster.thtd_byakuren_buff_toramaru/100 , true, DOTA_ModifyGold_CreepKill)
		caster.toramaru_cost_gold = (caster.toramaru_cost_gold or 0) + 500
	end

	local effectIndex = ParticleManager:CreateParticle("particles/thd2/items/item_donation_box.vpcf", PATTACH_CUSTOMORIGIN, caster)
	ParticleManager:SetParticleControl(effectIndex, 0, caster:GetAbsOrigin())
	ParticleManager:SetParticleControl(effectIndex, 1, target:GetAbsOrigin())
	ParticleManager:DestroyParticleSystem(effectIndex,false)

	local damage_table = {
		ability = keys.ability,
		victim = target,
		attacker = caster,
		damage = caster:THTD_GetAbilityPowerDamage(keys.ability),
		damage_type = keys.ability:GetAbilityDamageType(), 
		damage_flags = 0
	}	
	UnitDamageTarget(damage_table)	
end

function OnToramaru03SpellStart(keys)
	local caster = EntIndexToHScript(keys.caster_entindex)	

	if caster:HasModifier("modifier_byakuren_03_buff") then
		THTD_ModifyGoldEx(caster:GetPlayerOwnerID(), 5000 * caster.thtd_byakuren_buff_toramaru/100, true, DOTA_ModifyGold_CreepKill)
		caster.toramaru_cost_gold = (caster.toramaru_cost_gold or 0) + 5000
	end

	local inners = THTD_FindUnitsInner(caster)
	local damage = caster:THTD_GetAbilityPowerDamage(keys.ability)
	for k,v in pairs(inners) do
		local effectIndex = ParticleManager:CreateParticle("particles/thd2/items/item_donation_box.vpcf", PATTACH_CUSTOMORIGIN, caster)
		ParticleManager:SetParticleControl(effectIndex, 0, caster:GetAbsOrigin())
		ParticleManager:SetParticleControl(effectIndex, 1, v:GetAbsOrigin())
		ParticleManager:DestroyParticleSystem(effectIndex,false)

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

function OnSpellStartToramaru04(keys)
	local caster = EntIndexToHScript(keys.caster_entindex)
	
	local damage = caster:THTD_GetStarDamage() * 2
	damage = damage + (caster.toramaru_cost_gold or 0)*caster:THTD_GetStar()*0.02
	
	local targets = THTD_FindUnitsInRadius(caster,caster:GetAbsOrigin(),keys.ability:GetCastRange())
	for k,v in pairs(targets) do
		local effectIndex = ParticleManager:CreateParticle("particles/heroes/sunny/ability_sunny_01_laser.vpcf", PATTACH_CUSTOMORIGIN, caster)
		ParticleManager:SetParticleControlEnt(effectIndex , 0, v, 5, "attach_hitloc", Vector(0,0,0), true)
		ParticleManager:SetParticleControlEnt(effectIndex , 1, caster, 5, "attach_hitloc", Vector(0,0,0), true)
		ParticleManager:SetParticleControlEnt(effectIndex , 9, v, 5, "attach_hitloc", Vector(0,0,0), true)
		ParticleManager:DestroyParticleSystem(effectIndex,false)

		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
end