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

	if target:GetUnitName() == "minoriko" or target:GetUnitName() == "sizuha" then
		return
	end

	if target:THTD_IsTower() and target:GetOwner() == caster:GetOwner() and target:GetUnitName() ~= caster:GetUnitName() then
		local hero = caster:GetOwner()
		if hero.thtd_minoriko_02_change == nil then
			hero.thtd_minoriko_02_change = 0
		end	

		if GameRules:GetCustomGameDifficulty() >= FUNNY_MODE then
			if SpawnSystem.CurWave < 11 then 				
				CustomGameEventManager:Send_ServerToPlayer(caster:GetPlayerOwner(), "display_custom_error", {msg="minoriko_cannot_be_change"})
				return
			end
			if SpawnSystem.CurWave < 21 and hero.thtd_minoriko_02_change >= 1 then 		
				CustomGameEventManager:Send_ServerToPlayer(caster:GetPlayerOwner(), "display_custom_error", {msg="minoriko_change_one_tip"})	
				return
			end
		end
			
		if hero.thtd_minoriko_02_change >= keys.max_count then
			CustomGameEventManager:Send_ServerToPlayer( caster:GetPlayerOwner() , "show_message", {msg="minoriko_max_change", duration=5, params={count=1}, color="#0ff"} )
			return
		end		
		hero.thtd_minoriko_02_change = hero.thtd_minoriko_02_change + 1		

		local star = target:THTD_GetStar()
		target:THTD_SetStar(caster:THTD_GetStar())
		target:THTD_SetLevel(THTD_MAX_LEVEL)

		caster.thtd_is_changed = true
		caster.thtd_star = star
		caster:THTD_OpenAbility()
		caster:THTD_DestroyLevelEffect()
		caster:THTD_CreateLevelEffect()

		if (target:GetUnitName() == "kaguya" and target:THTD_GetStar() < 4) then
			if target.thtd_kaguya_03_treasure_table ~= nil and target.thtd_kaguya_03_treasure_table[1] ~= nil and target.thtd_kaguya_03_treasure_table[1]["effectIndex"] ~= nil then
				local friends = THTD_FindFriendlyUnitsAll(target)
				local enemies = THTD_FindUnitsAll(target)
		
				for i=1,4 do
					local buff = "modifier_kaguya_03_"..i.."_buff"
					local debuff = "modifier_kaguya_03_"..i.."_debuff"
					for k,v in pairs(friends) do
						if v:FindModifierByNameAndCaster(buff,target)~=nil then
							v:RemoveModifierByName(buff)
						end
					end
					for k,v in pairs(enemies) do
						if v:FindModifierByNameAndCaster(debuff,target)~=nil then
							v:RemoveModifierByName(debuff)
						end
					end
		
					if target.thtd_kaguya_03_treasure_table[i]["effectIndex"] ~= nil then
						ParticleManager:DestroyParticleSystem(target.thtd_kaguya_03_treasure_table[i]["effectIndex"],true)
						target.thtd_kaguya_03_treasure_table[i]["effectIndex"] = nil
					end
				end
			end
		end
		
	end
end