#TouhouDanmakufu
#Title["Spirit of Sake"]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\spellcard.txt";
	let type=0;
	let frame=0;
    let cutin=GetCurrentScriptDirectory~"img\face03ct.png";
	#include_function ".\yuugianim.txt";
    
task shots{
    let angle=rand(-5, 5);
    loop{
        PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
        angle=rand(-5, 5);
        ascent(i in 0..16){
            CreateShotA(1, GetX, GetY, 15);
            SetShotDataA(1, 0, 7, 120+i*20+angle, 0, 0, 0, 157);
            SetShotDataA(1, 35, 4, 90, 0, 0, 0, 157);
            FireShot(1);
        }
        PlayDelaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav", 50);
    loop(5){yield;}
    }
}
task knock{
    let angle=rand(0, 359);
    type=1;
	Concentration01(100);
    loop(100){yield;}
    PlaySE(GetCurrentScriptDirectory~"sound\kaboom.wav");
    ascent(i in 0..30){
        PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
        ascent(j in 0..15){
                CreateShotA(1, GetX+(5+i*7)*cos(angle+j*24+i), GetY+(5+i*7)*sin(angle+j*24+i), 15);
                SetShotDataA(1, 0, 0, angle+j*24+i*2, 0, 0, 0, 77);
                SetShotDataA(1, 90-i, 1, NULL, rand(-0.05, 0.05), 0.01, 3, 77);
                FireShot(1);
        }
        yield;
    }
    loop(20){yield;}
    type=0;
    angle=rand(0, 359);
    ascent(i in 0..30){
        PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
        ascent(j in 0..15){
            CreateShotA(1, GetX+(30+i*7)*cos(angle+j*24-i*5), GetY+(30+i*7)*sin(angle+j*24-i*5), 15);
            SetShotDataA(1, 0, 0, angle+j*24-i*4, 0, 0, 0, 79);
            SetShotDataA(1, 40-i, 1, NULL, rand(-0.01, 0.01), 0.01, 3, 79);
            FireShot(1);
        }
        yield;
    }
    type=1;
	Concentration01(100);
    loop(100){yield;}
    PlaySE(GetCurrentScriptDirectory~"sound\kaboom.wav");
    ascent(i in 0..30){
        PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
        ascent(j in 0..15){
                CreateShotA(1, GetX+(5+i*7)*cos(angle+j*24-i), GetY+(5+i*7)*sin(angle+j*24-i), 15);
                SetShotDataA(1, 0, 0, angle+j*24-i*2, 0, 0, 0, 82);
                SetShotDataA(1, 90-i, 1, NULL, rand(-0.05, 0.05), 0.01, 3, 82);
                FireShot(1);
        }
        yield;
    }
    loop(20){yield;}
    type=0;
    angle=rand(0, 359);
    ascent(i in 0..30){
        PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
        ascent(j in 0..15){
            CreateShotA(1, GetX+(30+i*7)*cos(angle+j*24+i*5), GetY+(30+i*7)*sin(angle+j*24+i*5), 15);
            SetShotDataA(1, 0, 0, angle+j*24+i*4, 0, 0, 0, 89);
            SetShotDataA(1, 40-i, 1, NULL, rand(-0.01, 0.01), 0.01, 3, 89);
            FireShot(1);
        }
        yield;
    }
    knock;
}
task PlayDelaySE(sfx, time){
    loop(time){yield;}
    PlaySE(sfx);
}

	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(10,10);
        LoadGraphic(cutin);

		SetMovePosition02(GetCenterX,GetCenterY-100,20);
		Concentration01(150);
		CutIn(YOUMU, "''Spirit of Sake''",cutin,0,0,256,512);
		LoadUserShotData(GetCurrentScriptDirectory~"supershot.txt");

		SetCommonData("ONSPELL", "TRUE");
		spellbonus(10000000);
		timer;
		SetCommonData("timercount", 60*120);
        lastspell;
        PlayMusic(GetCurrentScriptDirectory~"bgm.mp3");
	}
	
	@MainLoop
	{
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
		frame++;
		yield;
        if(frame==150){shots;}
        if(frame==250){knock;}
}
	
	@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));
		}
		}
		SetCommonData("ONSPELL", "FALSE");
        if(spellbonustotal==0){SetCommonData("REDO", "TRUE");}
	}
	
	@DrawLoop
	{
        bg;
        if(type==0){anim2;}else{animcast;}
	}
}