#東方弾幕風[Player]
#ScriptVersion[2]
#Menu[Felicia A]
#Text[Shot: Five-Card Draw
Bomb 1: Five of a Kind
Bomb 2: Royal Flush]
#Image[.\felicia_select.png]
#ReplayName[FeliA]

script_player_main
{
	#include_function "lib\SHOT_REPLACE\playershot_replace.dnh"
	#include_function "p_config.txt"
	let img_sakuya = GetCurrentScriptDirectory()~"sakuya.png";
	let img_cutin = GetCurrentScriptDirectory()~"sakuya_select.png";
	let count=-1;
	let optionxpos=30;
	let optionypos=30;
	let hoptionxpos = 15;
	let hoptionypos = -30;
	let i=0;
	let bNextShot = false;
	let shotdmg = 3.3;
	let HighOptIsSet = true;
	let OptIsSet = true;
	let mframe = 0;
	let pointcheck = 0;
	task HighOption(position) {
		let objoption=Obj_Create(OBJ_EFFECT);
		Obj_SetAlpha(objoption,200);
		ObjEffect_SetTexture(objoption,img_sakuya);
		ObjEffect_SetRenderState(objoption,ALPHA);
		ObjEffect_SetPrimitiveType(objoption,PRIMITIVE_TRIANGLEFAN);
		ObjEffect_CreateVertex(objoption,4);
		ObjEffect_SetVertexUV(objoption,0,143,4);
		ObjEffect_SetVertexUV(objoption,1,160,4);
		ObjEffect_SetVertexUV(objoption,2,160,19);
		ObjEffect_SetVertexUV(objoption,3,143,19);
		if(position=="LEFT"){
			while(!Obj_BeDeleted(objoption)){
				if(GetCommonDataDefault("power", 128) < 16) {
					Obj_Delete(objoption);
				}
				HighOptIsSet = true;
				ObjEffect_SetVertexXY(objoption,0,GetPlayerX-hoptionxpos-8,GetPlayerY+hoptionypos-7);
				ObjEffect_SetVertexXY(objoption,1,GetPlayerX-hoptionxpos+6,GetPlayerY+hoptionypos-7);
				ObjEffect_SetVertexXY(objoption,2,GetPlayerX-hoptionxpos+6,GetPlayerY+hoptionypos+7);
				ObjEffect_SetVertexXY(objoption,3,GetPlayerX-hoptionxpos-8,GetPlayerY+hoptionypos+7);
				if(count%5 == 0) {
					CreatePlayerShot01(GetPlayerX-hoptionxpos-1, GetPlayerY + hoptionypos, 11, 270, 3, 2, RED56);
				}
				yield;
			}
		}else{
			while(!Obj_BeDeleted(objoption)){
				if(GetCommonDataDefault("power", 128) < 16) {
					Obj_Delete(objoption);
				}
				HighOptIsSet = true;
				ObjEffect_SetVertexXY(objoption,0,GetPlayerX+hoptionxpos-7,GetPlayerY+hoptionypos-7);
				ObjEffect_SetVertexXY(objoption,1,GetPlayerX+hoptionxpos+7,GetPlayerY+hoptionypos-7);
				ObjEffect_SetVertexXY(objoption,2,GetPlayerX+hoptionxpos+7,GetPlayerY+hoptionypos+7);
				ObjEffect_SetVertexXY(objoption,3,GetPlayerX+hoptionxpos-7,GetPlayerY+hoptionypos+7);
				if(count%5 == 0) {
					CreatePlayerShot01(GetPlayerX+hoptionxpos, GetPlayerY + hoptionypos, 11, 270, 3, 2, RED56);
				}
				yield;
			}
		}
	}
	task Option(position){
		let objoption=Obj_Create(OBJ_EFFECT);
		Obj_SetAlpha(objoption,200);
		ObjEffect_SetTexture(objoption,img_sakuya);
		ObjEffect_SetRenderState(objoption,ALPHA);
		ObjEffect_SetPrimitiveType(objoption,PRIMITIVE_TRIANGLEFAN);
		ObjEffect_CreateVertex(objoption,4);
		ObjEffect_SetVertexUV(objoption,0,143,4);
		ObjEffect_SetVertexUV(objoption,1,160,4);
		ObjEffect_SetVertexUV(objoption,2,160,19);
		ObjEffect_SetVertexUV(objoption,3,143,19);
		if(position=="LEFT"){
			while(!Obj_BeDeleted(objoption)){
				if(GetCommonDataDefault("power", 128) < 96) {
					Obj_Delete(objoption);
				}
				OptIsSet = true;
				ObjEffect_SetVertexXY(objoption,0,GetPlayerX-optionxpos-8,GetPlayerY+optionypos-7);
				ObjEffect_SetVertexXY(objoption,1,GetPlayerX-optionxpos+6,GetPlayerY+optionypos-7);
				ObjEffect_SetVertexXY(objoption,2,GetPlayerX-optionxpos+6,GetPlayerY+optionypos+7);
				ObjEffect_SetVertexXY(objoption,3,GetPlayerX-optionxpos-8,GetPlayerY+optionypos+7);
				if(count%5 == 0) {
					CreatePlayerShot01(GetPlayerX-optionxpos-1, GetPlayerY + optionypos, 11, 270, 3, 2, BLUE56);
				}
				yield;
			}
		}else{
			while(!Obj_BeDeleted(objoption)){
				if(GetCommonDataDefault("power", 128) < 96) {
					Obj_Delete(objoption);
				}
				OptIsSet = true;
				ObjEffect_SetVertexXY(objoption,0,GetPlayerX+optionxpos-7,GetPlayerY+optionypos-7);
				ObjEffect_SetVertexXY(objoption,1,GetPlayerX+optionxpos+7,GetPlayerY+optionypos-7);
				ObjEffect_SetVertexXY(objoption,2,GetPlayerX+optionxpos+7,GetPlayerY+optionypos+7);
				ObjEffect_SetVertexXY(objoption,3,GetPlayerX+optionxpos-7,GetPlayerY+optionypos+7);
				if(count%5 == 0) {
					CreatePlayerShot01(GetPlayerX+optionxpos, GetPlayerY + optionypos, 11, 270, 3, 2, BLUE56);
				}
				yield;
			}
		}
	}
	task PlayerLaser(x, y, l, w, angle, damage, graphic) {
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetAlpha(obj, 182);
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetDamage(obj, damage);
		ObjShot_SetPenetration(obj, 1);
		ObjLaser_SetLength(obj, l);
		ObjLaser_SetWidth(obj, w);
		ObjLaser_SetSource(obj, false);
		yield;
		Obj_Delete(obj);
	}
	@Initialize
	{	
		LoadGraphic(img_sakuya);
		LoadGraphic(img_cutin);
		SetPlayerLifeImage(img_sakuya, 96, 48, 143, 95);
		if(bombs > 3) { bombs = 3; }
		if(bombs < 0) { bombs = 0; }
		SetInitialBombCount(bombs);
		SetSpeed(4, 2.25);
		PowerUp;
		shotinit;
	}
	task PowerUp {
		loop {
			yield;
			if(GetPoint > pointcheck && GetCommonDataDefault("power", 128) < 128) {
				SetCommonData("power", GetCommonDataDefault("power", 128) + (GetPoint - pointcheck));
			}
			pointcheck = GetPoint;
		}
	}
	
	@MainLoop
	{
		if(!OnMissed) {
			mframe = 0;
		}
		if(GetCommonDataDefault("power", 128) > 128) {
			SetCommonData("power", 128);
		}
		if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD) && count==-1){
			count = 0;
		}
		if(GetCommonDataDefault("power", 128) < 32) {
			shotdmg = 3;
		}
		else {
			shotdmg = 3.5;
		}
		if(!HighOptIsSet) {
			HighOption("LEFT");
			HighOption("RIGHT");
		}
		if(!OptIsSet) {
			Option("LEFT");
			Option("RIGHT");
		}
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
			if(count%5 == 0){
				if(GetCommonDataDefault("power", 128) < 128) {
					CreatePlayerShot01(GetPlayerX(), GetPlayerY()-8, 11, 270+(i*2.5), shotdmg, 2, WHITE56);
				}
				else {
					ascent(p in 0..2) {
						CreatePlayerShot01(GetPlayerX() + (p%2 * 2 - 1) * 6, GetPlayerY()-8, 11, 270+(i*2.5), 2, 2, WHITE56);
					}
				}
			}
			if(optionxpos>20){optionxpos--;}
			if(optionypos>20){optionypos--;}
			if(hoptionypos<-20){hoptionypos++;}
		}else{
			if(count%5 == 0){
				if(GetCommonDataDefault("power", 128) < 32) {
					CreatePlayerShot01(GetPlayerX(), GetPlayerY()-8, 11, 270+(i*2.5), 2, 2, WHITE56);
				}
				else if(GetCommonDataDefault("power", 128) < 64) {
					CreatePlayerShot01(GetPlayerX(), GetPlayerY()-8, 11, 270+(i*2.5), 2, 2, WHITE56);
				}
				else if(GetCommonDataDefault("power", 128) < 128) {
					ascent(p in 0..2) {
						CreatePlayerShot01(GetPlayerX() + (p%2 * 2 - 1) * 6, GetPlayerY()-8, 11, 270+(i*2.5), 2, 2, WHITE56);
					}
				}
				else {
					ascent(p in 0..2) {
						CreatePlayerShot01(GetPlayerX() + (p%2 * 2 - 1) * 6, GetPlayerY()-8, 11, 270+(i*2.5), 2.2, 2, WHITE56);
					}
				}
			}
			if(optionxpos<40){optionxpos++;}
			if(optionypos<40){optionypos++;}
			if(hoptionypos>-30){hoptionypos--;}			
		}		
		if(count >= 0){
			count++;
		}
		if(count >= 10){
			count=-1;
		}
		if(GetCommonDataDefault("power", 128) >= 16) {
			HighOptIsSet = false;
		}
		if(GetCommonDataDefault("power", 128) >= 96) {
			OptIsSet = false;
		}
		SetIntersectionCircle(GetPlayerX, GetPlayerY, 0);
		yield;
	}
	@Missed{
		if(mframe == GetRebirthFrame + 1 && !OnBomb) {
			SetCommonData("power", GetCommonDataDefault("power", 128) - 16);
		}
		mframe++;
	}
	@SpellCard{	
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
			UseSpellCard("RoyalFlush", 0);
			CutIn(KOUMA,"「Royal Flush」", img_cutin);
		}else{
			UseSpellCard("FiveOfAKind", rand_int(0, 4));
			CutIn(KOUMA,"「Five of a Kind」", img_cutin);
		}
	}
	@DrawLoop{
		DrawText("Power: "~ToString(GetCommonDataDefault("power", 128)), GetClipMinX, GetClipMaxY - 36, 12, 255);
		SetTexture(img_sakuya);
		if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD){
			SetGraphicRect(49.5, 1.5, 95.5, 47.5);
		}else if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD){
			SetGraphicRect(97.5, 1.5, 143.5, 47.5);
		}else{
			SetGraphicRect(1.5, 1.5, 47.5, 47.5);
		}
		DrawGraphic(GetPlayerX(), GetPlayerY());
	}
	@Finalize{
		DeleteGraphic(img_sakuya);
		DeleteGraphic(img_cutin);
	}
}
script_spell FiveOfAKind{
	let img_spell = GetCurrentScriptDirectory()~"aceofhearts.png";
	if(GetArgument == 0) {
		img_spell = GetCurrentScriptDirectory()~"tenofdiamonds.png";
	}
	else if(GetArgument == 1) {
		img_spell = GetCurrentScriptDirectory()~"jackofspades.png";
	}
	else if(GetArgument == 2) {
		img_spell = GetCurrentScriptDirectory()~"queenofhearts.png";
	}
	else if(GetArgument == 3) {
		img_spell = GetCurrentScriptDirectory()~"kingofclubs.png";
	}
	task run{
		yield;
		SetPlayerInvincibility(300);
		loop(45) { yield; }
		Joker(GetPlayerX, GetPlayerY, 270, 2.5);
		ascent(a in 0..4) {
			SpellCard(GetPlayerX, GetPlayerY, a * 90 + 45, 2.5);
		}
		SetSpeed(3.5, 2.25);
		loop(255){yield;}
		End();
	}
	@Initialize{
		LoadGraphic(img_spell);
		LoadGraphic(GetCurrentScriptDirectory~"joker.png");
		run();
	}
	@MainLoop{
		CollectItems();
		yield;
	}
	@Finalize{
		DeleteGraphic(img_spell);
		DeleteGraphic(GetCurrentScriptDirectory~"joker.png");
	}
	task SpellCard(x,y,angle,scale){
		let obj=Obj_Create(OBJ_SPELL);
		let objknife = Obj_Create(OBJ_EFFECT);
		Obj_SetAlpha(objknife,200);
		ObjEffect_SetTexture(objknife,img_spell);
		ObjEffect_SetRenderState(objknife,ALPHA);
		ObjEffect_CreateVertex(objknife,4);
		ObjEffect_SetPrimitiveType(objknife,PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetVertexUV(objknife,0,0,0);
		ObjEffect_SetVertexUV(objknife,1,60,0);
		ObjEffect_SetVertexUV(objknife,2,60,100);
		ObjEffect_SetVertexUV(objknife,3,0,100);
		while(!Obj_BeDeleted(objknife)){
			Obj_SetPosition(objknife, x, y);
			ObjEffect_SetAngle(objknife, 0, 0, angle + 90);
			ObjEffect_SetVertexXY(objknife, 0, -30 * scale, -50 * scale);
			ObjEffect_SetVertexXY(objknife, 1, 30 * scale, -50 * scale);
			ObjEffect_SetVertexXY(objknife, 2, 30 * scale, 50 * scale);
			ObjEffect_SetVertexXY(objknife, 3, -30 * scale, 50 * scale);
			x += cos(angle) * 2;
			y += sin(angle) * 2;
			ObjSpell_SetIntersecrionCircle(obj, x, y, 30 * scale, 3 + GetArgument / 4, true);
			if(GetArgument == 0) {
				scale -= 0.01;
			}
			else if(GetArgument == 1) {
				scale -= 0.0085;
			}
			else if(GetArgument == 2) {
				scale -= 0.0075;
			}
			else {
				scale -= 0.0065;
			}
			yield;
		}
	}
	task Joker(x,y,angle,scale){
		let obj=Obj_Create(OBJ_SPELL);
		let objknife = Obj_Create(OBJ_EFFECT);
		Obj_SetAlpha(objknife,200);
		ObjEffect_SetTexture(objknife,GetCurrentScriptDirectory~"joker.png");
		ObjEffect_SetRenderState(objknife,ALPHA);
		ObjEffect_CreateVertex(objknife,4);
		ObjEffect_SetPrimitiveType(objknife,PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetVertexUV(objknife,0,0,0);
		ObjEffect_SetVertexUV(objknife,1,60,0);
		ObjEffect_SetVertexUV(objknife,2,60,100);
		ObjEffect_SetVertexUV(objknife,3,0,100);
		while(!Obj_BeDeleted(objknife)){
			Obj_SetPosition(objknife, x, y);
			ObjEffect_SetVertexXY(objknife, 0, -30 * scale, -50 * scale);
			ObjEffect_SetVertexXY(objknife, 1, 30 * scale, -50 * scale);
			ObjEffect_SetVertexXY(objknife, 2, 30 * scale, 50 * scale);
			ObjEffect_SetVertexXY(objknife, 3, -30 * scale, 50 * scale);
			x += cos(angle) * 2;
			y += sin(angle) * 2;
			ObjSpell_SetIntersecrionCircle(obj, x, y, 30 * scale, 3 + GetArgument / 4, true);
			if(GetArgument == 0) {
				scale -= 0.01;
			}
			else if(GetArgument == 1) {
				scale -= 0.0085;
			}
			else if(GetArgument == 2) {
				scale -= 0.0075;
			}
			else {
				scale -= 0.0065;
			}
			yield;
		}
	}
}
script_spell RoyalFlush{
	let end = false;
	let c = 0;
    task AimAmulet(x, y, sv, ev, angle, var, graphic1, graphic2, delay) {
	let obj = Obj_Create(OBJ_SHOT);
	let aim = false;
	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj, angle);
	Obj_SetSpeed(obj, sv);
	Obj_SetAlpha(obj, 182);
	ObjShot_SetGraphic(obj, graphic1);
	ObjShot_SetDamage(obj, 0);
	ObjShot_SetPenetration(obj, 9999);
	while(Obj_GetSpeed(obj) > 0) {
		DeleteEnemyShotToItemInCircle(SHOT, Obj_GetX(obj), Obj_GetY(obj), 5);
		Obj_SetSpeed(obj, Obj_GetSpeed(obj) - 0.05);
		yield;
	}
	while(delay > 0) {
		Obj_SetSpeed(obj, 0);
		delay--;
		yield;
	}
	ObjShot_SetDamage(obj, 1.96);
	Obj_SetAngle(obj, atan2(GetEnemyY - Obj_GetY(obj), GetEnemyX - Obj_GetX(obj)) + var);
	while(Obj_BeDeleted(obj) == false) {
		DeleteEnemyShotToItemInCircle(SHOT, Obj_GetX(obj), Obj_GetY(obj), 2.5);
		ObjShot_SetGraphic(obj, graphic2);
		if(Obj_GetSpeed(obj) < ev) {
			Obj_SetSpeed(obj, Obj_GetSpeed(obj) + 0.025);
		}
		if(end == true) {
			Obj_Delete(obj);
		}
		yield;
	}
  }
	task run{
		yield;
		ForbidShot(true);
		SetPlayerInvincibility(360);
		loop(48) { c++; yield; }
		ascent(a in 0..30) {
			AimAmulet(GetPlayerX, GetPlayerY, 1.82 + a%5 / 2, 3, a * 12, 0, 25 + a%2 * 5, 89 + a%2 * 5, 24);
		}
		loop(307) {
			c++;
			if(c == 120) {
				ForbidShot(false);
			}
			yield;
		}
		end = true;
		loop(5) { yield; }
		End();
	}
	@Initialize{
		run();
	}
	@MainLoop{
		CollectItems();
		yield;
	}
	@Finalize{
	}
}