#TouhouDanmakufu
#Title[Puppeteer "Dolls of Mischief"]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let frame=-100;
	let move_count=0;
    	let BossCutIn = GetCurrentScriptDirectory~"img\alice.png";
	#include_function ".\aliceanim.txt";
	#include_function ".\spellcard.txt";
task Dolls
{
	ascent(i in 0..8)
	{
	CreateEnemyFromScript("Doll", GetX+50*cos(i*45), GetY+50*sin(i*45), 0, 0, i*45);
	}
}	
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(10,10);
		LoadGraphic(BossCutIn);

		SetMovePosition02(GetCenterX,120,20);
		Concentration01(150);
		CutIn(YOUMU, " Puppeteer ''Dolls of Mischief'' ",BossCutIn,0,0,128,512);
		LoadUserShotData(GetCurrentScriptDirectory~"supershot.txt");

		SetCommonData("ONSPELL", "TRUE");
		spellbonus(3000000);
		timer;
		SetCommonData("timercount", 3600);
	}
	
	@MainLoop
	{
		SetDamageRate(10+floor(30-30*GetCommonData("timercount")/3600),5);
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
		frame++;
		yield;
		if(frame==0)
		{
		Dolls;
		}
		if(frame>0 && frame%60==0)
		{
		PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
		ascent(i in 0..6)
		{
		CreateShot01(GetX, GetY, 3, GetAngleToPlayer+i*60, 232, 20);
		}
		}
}
	
	@Finalize
	{
		AddScore(spellbonustotal);
		if(spellbonustotal>0)
		{
		PlaySE(GetCurrentScriptDirectory~"sound\se_cardget.wav");
		loop(50)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
		}
		}else{
		loop(15)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
		}
		}
		DeleteGraphic(BossCutIn);
		SetCommonData("ONSPELL", "FALSE");
	}
	
	@DrawLoop
	{
	spellbg;
	animation;
	}
}

script_enemy Doll {
	#include_function ".\dollanim.txt";
	let frame=0;
	let angle=GetArgument;
task bullets
{
	loop
	{
	ascent(i in 0..30)
	{
	if(i%2==0)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	CreateShotA(1, GetX, GetY, 20);
	SetShotDataA(1, 0, 2, angle+180+i, 0, -0.01, 0, 14);
	SetShotDataA(1, 50+i, 2, angle+135-i*2, 0, -0.01, 0, 2);
	SetShotDataA(1, 120-i, 2, angle-45+i*3, 0, 0, 0, 7);
	FireShot(1);
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	CreateShotA(1, GetX, GetY, 20);
	SetShotDataA(1, 0, 2, angle+180-i, 0, -0.01, 0, 14);
	SetShotDataA(1, 50-i, 2, angle+135+i*2, 0, -0.01, 0, 2);
	SetShotDataA(1, 120+i, 2, angle-45-i*3, 0, 0, 0, 7);
	FireShot(1);
	PlaySEWait(50-i);
	PlaySEWait(120+i);
	PlaySEWait(50+i);
	PlaySEWait(120-i);
	}
	loop(2){yield;}
	}
	loop(60){yield;}
	descent(i in 0..30)
	{
	if(i%2==0)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	CreateShotA(1, GetX, GetY, 20);
	SetShotDataA(1, 0, 2, angle+180-i, 0, -0.01, 0, 14);
	SetShotDataA(1, 50-i, 2, angle+135+i*2, 0, -0.01, 0, 2);
	SetShotDataA(1, 120+i, 2, angle-45-i*3, 0, 0, 0, 7);
	FireShot(1);
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	CreateShotA(1, GetX, GetY, 20);
	SetShotDataA(1, 0, 2, angle+180+i, 0, -0.01, 0, 14);
	SetShotDataA(1, 50+i, 2, angle+135-i*2, 0, -0.01, 0, 2);
	SetShotDataA(1, 120-i, 2, angle-45+i*3, 0, 0, 0, 7);
	FireShot(1);
	PlaySEWait(50+i);
	PlaySEWait(120-i);
	PlaySEWait(50-i);
	PlaySEWait(120+i);
	}
	loop(2){yield;}
	}
	loop(60){yield;}
	descent(i in 0..30)
	{
	if(i%2==0)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	CreateShotA(1, GetX, GetY, 20);
	SetShotDataA(1, 0, 2, angle+180-i*4, 0, -0.01, 0, 14);
	SetShotDataA(1, 50+i, 2, angle-135+i*3, 0, -0.01, 0, 2);
	SetShotDataA(1, 180-i*3, 2, angle+45-i*2, 0, 0, 0, 7);
	FireShot(1);
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	CreateShotA(1, GetX, GetY, 20);
	SetShotDataA(1, 0, 2, angle+180-i*4, 0, -0.01, 0, 14);
	SetShotDataA(1, 50-i, 2, angle-135-i*3, 0, -0.01, 0, 2);
	SetShotDataA(1, 60+i*3, 2, angle+45+i*2, 0, 0, 0, 7);
	FireShot(1);
	PlaySEWait(50+i);
	PlaySEWait(60+i*3);
	PlaySEWait(50-i);
	PlaySEWait(180-i*3);
	}
	loop(2){yield;}
	}
	loop(60){yield;}
	ascent(i in 0..30)
	{
	if(i%2==0)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	CreateShotA(1, GetX, GetY, 20);
	SetShotDataA(1, 0, 2, angle+180-i*4, 0, -0.01, 0, 14);
	SetShotDataA(1, 50-i, 2, angle-135-i*3, 0, -0.01, 0, 2);
	SetShotDataA(1, 70+i*2, 2, angle+45+i*2, 0, 0, 0, 7);
	FireShot(1);
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	CreateShotA(1, GetX, GetY, 20);
	SetShotDataA(1, 0, 2, angle+180+i*4, 0, -0.01, 0, 14);
	SetShotDataA(1, 50+i, 2, angle-135+i*3, 0, -0.01, 0, 2);
	SetShotDataA(1, 170-i*3, 2, angle+45-i*2, 0, 0, 0, 7);
	FireShot(1);
	PlaySEWait(50+i);
	PlaySEWait(170-i*3);
	PlaySEWait(50-i);
	PlaySEWait(70+i*2);
	}
	loop(2){yield;}
	}
	loop(60){yield;}
	}
}
task PlaySEWait(frames)
{
	loop(frames){yield;}
	PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");
}

	@Initialize
	{
	SetLife(500);
	SetDamageRateEx(50, 20, 50, 0);
}
	@MainLoop
	{
	SetX(GetEnemyX+50*cos(angle));
	SetY(GetEnemyY+50*sin(angle));
	SetCollisionA(GetX(),GetY(),24);
	SetCollisionB(GetX(),GetY(),24);
	yield;
	angle++;
	if(frame==0)
	{
	bullets;
	}
	frame++;
}
	@DrawLoop
	{
	anim2;
}
	@Finalize
	{
	ascent(k in 3..6)
	{
	ascent(i in -1..2)
	{
	CreateShotA(1, GetX, GetY, k*10);
	SetShotDataA(1, 0, 0, GetAngleToPlayer, 0, 0, 0, 2);
	SetShotDataA(1, 20, 1, NULL, i*0.2, 0.03, 5, 2);
	FireShot(1);
	ascent(j in -2..3)
	{
	CreateShotA(1, GetX+25*cos(GetAngleToPlayer+j*72+180), GetY+25*sin(GetAngleToPlayer+j*72+180), k*10);
	SetShotDataA(1, 0, 0, GetAngleToPlayer+j*25, 0, 0, 0, 2);
	SetShotDataA(1, 20, 1, NULL, i*0.2, 0.05, 4, 2);
	FireShot(1);
	}
	}
	}
	}

}