#TouhouDanmakufu
#Title[Bro Sign "Multi-Fist Smash"]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let frame=0;
    let BossCutIn=GetCurrentScriptDirectory~"FIST.png";
	#include_function ".\spellcard.txt";
	#include_function ".\fist_replace.txt";
    let alpha=255;
task attack{
    PlaySE(GetCurrentScriptDirectory~"sound\Charge.wav");
    Concentration01(60);
    loop(60){yield;}
    descent(i in 0..18){alpha=i*15; yield;}
    SetMovePosition02(GetCenterX, GetClipMinY-200, 1);
    loop(60){yield;}
    wave(1);
}
task wave(type){
    SetMovePosition02(GetPlayerX, GetClipMinY-30+rand(-10, 10), 1);
    yield;
    if(type==2){
        PlaySE(GetCurrentScriptDirectory~"sound\Charge.wav");
        Concentration01(60);
        loop(60){yield;}
    }
    SetMovePosition01(GetX, GetClipMaxY+50, 4);
    ascent(i in -4..5){shot(GetX+i*100);}
    while(GetY<GetClipMaxY+40){yield;}
    wave(2);
}
task shot(x){
    let counter=0;
    let obj=Obj_Create(OBJ_SHOT);
    Obj_SetPosition(obj, x, GetY);
    Obj_SetAngle(obj, 90);
    Obj_SetSpeed(obj, 0);
    ObjShot_SetGraphic(obj, RED04);
    ObjShot_SetBombResist(obj, true);
    while(Obj_BeDeleted(obj)==false){
        Obj_SetY(obj, GetY);
        counter++;
        if(counter%30==0){
            PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, 0, RED01, 0);
            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, 180, RED01, 0);
            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, 30, RED01, 0);
            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, 210, RED01, 0);
            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, -30, RED01, 0);
            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 2, 150, RED01, 0);
        }
        if(GetY>GetClipMaxY+40){Obj_Delete(obj);}
		SetCollisionA(Obj_GetX(obj),Obj_GetY(obj),15);
		SetCollisionB(Obj_GetX(obj),Obj_GetY(obj),15);
        yield;
    }
}
task bossgraphic{
    yield;
    let obj=Obj_Create(OBJ_EFFECT);
    Obj_SetPosition(obj, GetX, GetY);
    ObjEffect_SetTexture(obj, BossCutIn);
    ObjEffect_SetLayer(obj, 4);
    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
    ObjEffect_CreateVertex(obj, 4);
    ObjEffect_SetVertexUV(obj, 0, 0, 0);
    ObjEffect_SetVertexUV(obj, 1, 256, 0);
    ObjEffect_SetVertexUV(obj, 2, 0, 416);
    ObjEffect_SetVertexUV(obj, 3, 256, 416);
    ObjEffect_SetVertexXY(obj, 0, -128, -208);
    ObjEffect_SetVertexXY(obj, 1, 128, -208);
    ObjEffect_SetVertexXY(obj, 2, -128, 208);
    ObjEffect_SetVertexXY(obj, 3, 128, 208);
    while(Obj_BeDeleted(obj)==false){
        Obj_SetPosition(obj, GetX, GetY-121);
        ObjEffect_SetAngle(obj, 0, 0, 180);
        ascent(i in 0..4){ObjEffect_SetVertexColor(obj, i, alpha, 255, 255, 255);}
        if(alpha==0){Obj_Delete(obj);}
        yield;
    }
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		LoadGraphic(BossCutIn);
		SetMovePosition02(GetCenterX,120,20);
		CutIn(YOUMU, "Bro Sign ''Multi-Fist Smash''",BossCutIn,0,0,256,416);
		spellbonus(10000000);
		timer;
		SetCommonData("timercount", 5400);
        bossgraphic;
        SetCommonData("ONSPELL", "TRUE");
        if(GetCommonDataDefault("NOMISSCOUNT", -1)==-1){
            initmeh;
        }
	}
	
	@MainLoop
	{
        SetShotAutoDeleteClip(50, 50, 50, 50);
        if(OnBomb==true){SetDamageRate(0, 0);}else{SetDamageRate(10+floor(30-30*GetCommonData("timercount")/5400),5);}
		frame++;
		yield;
        if(frame==90){attack;}
}
	
	@Finalize
	{
        SetShotAutoDeleteClip(32, 32, 32, 32);
        SetCommonData("ONSPELL", "FALSE");
		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));
		}
		}
		 
        if(GetMissCountInThisSpell==0){
            SetCommonData("NOMISSCOUNT", GetCommonData("NOMISSCOUNT")+1);
        }
	}
	
	@DrawLoop
	{
	}
}