modifier_mugiyousei_01 = class({})

local public = modifier_mugiyousei_01

--------------------------------------------------------------------------------

function public:IsDebuff()
	return false
end

--------------------------------------------------------------------------------

function public:IsHidden()
	return true
end

--------------------------------------------------------------------------------

function public:IsPurgable()
	return false
end

function public:GetTexture()
	return "touhoutd/thtd_mugiyousei_01"
end

--------------------------------------------------------------------------------

function public:DeclareFunctions()
	local funcs = {
			MODIFIER_EVENT_ON_ATTACK_LANDED,
	}
	return funcs
end

function public:OnAttackLanded( params )
	if IsServer() then
		if params.attacker ~= self:GetParent() or self:GetParent():IsIllusion() then return end
		if self:GetParent():PassivesDisabled() then	return	end	

		local caster = params.attacker
		local target = params.target
		local ability = self:GetAbility()		
		
		local damage = caster:THTD_GetAbilityPowerDamage(ability)

		local time = ability:GetSpecialValueFor("damage_duration")
		target:AddPoison(1, caster)
		target:SetContextThink(DoUniqueString("thtd_mugiyousei01_attack"), 
			function()
				if GameRules:IsGamePaused() then return 0.03 end
				if time <= 0 or THTD_IsValid(target) == false then 
					if target ~= nil and target:IsNull() == false then 
						target:AddPoison(-1)
					end
					return nil 
				end
				
				local DamageTable = {
						ability = ability,
						victim = target, 
						attacker = caster, 
						damage = damage, 
						damage_type = ability:GetAbilityDamageType(), 
						damage_flags = DOTA_DAMAGE_FLAG_NONE
				}
				UnitDamageTarget(DamageTable)
				
				time = time - 1.0
				return 1.0
			end, 
		0)
	end
end