modifier_bosses_alice = class({})

local public = modifier_bosses_alice

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

function public:IsDebuff()
	return false
end

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

function public:IsHidden()
	return false
end

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

function public:IsPurgable()
	return false
end

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

-- 分裂效果造成游戏卡顿崩溃，改为免死符
function public:OnCreated(kv)
	if IsServer() then
		local caster = self:GetParent()
		if caster.left_death_count == nil then 
			caster.left_death_count = 3
		end
		if caster.effect_index == nil then 
			local effectName = "particles/units/heroes/hero_monkey_king/monkey_king_quad_tap_stack.vpcf"
			local effectIndex = ParticleManager:CreateParticle(effectName, PATTACH_OVERHEAD_FOLLOW, caster) 
			ParticleManager:SetParticleControlEnt(effectIndex , 0, caster, PATTACH_OVERHEAD_FOLLOW, "attach_hitloc", Vector(0, 0, 0), true)			
			ParticleManager:SetParticleControl(effectIndex, 1, Vector(0, caster.left_death_count, 0))
			caster.effect_index = effectIndex	
		else
			ParticleManager:SetParticleControl(caster.effect_index, 1, Vector(0, caster.left_death_count, 1))	
		end
		self:SetStackCount(caster.left_death_count)
	end
end

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

function public:OnDestroy(kv)
	if IsServer() then
		local caster = self:GetParent()		
		if caster.diseble_buff == true then return end

		caster.thtd_damage_lock = true

		local health = caster:GetMaxHealth()
		if caster.left_death_count == 3 then
			health = health * 0.33
		end
		caster:SetBaseMaxHealth(health)
		caster:SetMaxHealth(health)
		caster:SetHealth(health)
		caster:SetModelScale(caster:GetModelScale() * 0.9)

		local effectIndex = ParticleManager:CreateParticle("particles/econ/events/ti6/hero_levelup_ti6_godray.vpcf", PATTACH_CUSTOMORIGIN_FOLLOW, caster)
		ParticleManager:SetParticleControl(effectIndex, 0, caster:GetOrigin())
		ParticleManager:DestroyParticleSystem(effectIndex, false)

		caster.left_death_count = caster.left_death_count - 1				
		if caster.left_death_count <= 0 then 
			ParticleManager:DestroyParticleSystem(caster.effect_index, true)
		else
			caster:AddNewModifier(caster, nil, "modifier_bosses_alice", {})		
		end

		caster.thtd_damage_lock = nil			
	end
end