#東方弾幕風[Player]
#ScriptVersion[2]
#Menu[Felicia B]
#Text[Shot: Bottomless Wallet
Bomb 1: Vezai Lottery
Bomb 2: A Penny Saved]
#Image[.\felicia_select.png]
#ReplayName[FeliciaB]

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()~"felicia_select.png";
	let count=-1;
	let OptIsSet = true;
	let mframe = 0;
	let optionxpos=30;
	let optionypos=0;
	let i=0;
	let bNextShot = false;
	let shotdmg = 1.375;
	let pointcheck = 0;
	function IsFocused {
		return GetKeyState(VK_SLOWMOVE) == KEY_PUSH || GetKeyState(VK_SLOWMOVE) == KEY_HOLD;
	}
	task PowerUp {
		loop {
			yield;
			if(GetPoint > pointcheck && GetCommonDataDefault("power", 128) < 128) {
				SetCommonData("power", GetCommonDataDefault("power", 128) + (GetPoint - pointcheck));
			}
			pointcheck = GetPoint;
		}
	}
	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)) {
				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(IsFocused == true) {
					if(count%6 == 3) {
						if(GetCommonDataDefault("power", 128) < 32) {
							if(count%12 == 3) {
								CreatePlayerShot01(GetPlayerX-optionxpos-1, GetPlayerY + optionypos, 11, 270, shotdmg * 3, 1, SP10);
							}
						}
						else if(GetCommonDataDefault("power", 128) < 96) {
							CreatePlayerShot01(GetPlayerX-optionxpos-1, GetPlayerY + optionypos, 11, 270, shotdmg * 2.5, 1, SP10);
						}
						else {
							ascent(a in -1..2) {
								CreatePlayerShot01(GetPlayerX-optionxpos-1, GetPlayerY + optionypos, 11, 270 + (a * 3), shotdmg * 1.75, 1, SP10);
							}
						}
					}
				}
				else {
					if(count%8 == 4) {
						if(GetCommonDataDefault("power", 128) < 32) {
							if(count%16 == 4) {
								ascent(a in -1..2) {
									CreatePlayerShot01(GetPlayerX-optionxpos-1, GetPlayerY + optionypos, 11, 262 + (a * 8), shotdmg, 1, SP10);
								}
							}
						}
						else if(GetCommonDataDefault("power", 128) < 96) {
							ascent(a in -1..2) {
								CreatePlayerShot01(GetPlayerX-optionxpos-1, GetPlayerY + optionypos, 11, 262 + (a * 8), shotdmg, 1, SP10);
							}
						}
						else if(GetCommonDataDefault("power", 128) < 128) {
							ascent(a in -2..2) {
								CreatePlayerShot01(GetPlayerX-optionxpos-1, GetPlayerY + optionypos, 11, 262 + (a * 8), shotdmg, 1, SP10);
							}
						}
						else {
							ascent(a in -2..3) {
								CreatePlayerShot01(GetPlayerX-optionxpos-1, GetPlayerY + optionypos, 11, 262 + (a * 8), shotdmg, 1, SP10);
							}
						}
					}
				}
				yield;
			}
		}else{
			while(!Obj_BeDeleted(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(IsFocused == true) {
					if(count%6 == 3) {
						if(GetCommonDataDefault("power", 128) < 32) {
							if(count%12 == 3) {
								CreatePlayerShot01(GetPlayerX+optionxpos, GetPlayerY + optionypos, 11, 270, shotdmg * 3, 1, SP10);
							}
						}
						else if(GetCommonDataDefault("power", 128) < 96) {
							CreatePlayerShot01(GetPlayerX+optionxpos, GetPlayerY + optionypos, 11, 270, shotdmg * 2.5, 1, SP10);
						}
						else {
							ascent(a in -1..2) {
								CreatePlayerShot01(GetPlayerX+optionxpos, GetPlayerY + optionypos, 11, 270 + (a * 3), shotdmg * 1.75, 1, SP10);
							}
						}
					}
				}
				else {
					if(count%8 == 4) {
						if(GetCommonDataDefault("power", 128) < 32) {
							if(count%16 == 4) {
								ascent(a in -1..2) {
									CreatePlayerShot01(GetPlayerX+optionxpos, GetPlayerY + optionypos, 11, 278 + (a * 8), shotdmg, 1, SP10);
								}
							}
						}
						else if(GetCommonDataDefault("power", 128) < 96) {
							ascent(a in -1..2) {
								CreatePlayerShot01(GetPlayerX+optionxpos, GetPlayerY + optionypos, 11, 278 + (a * 8), shotdmg, 1, SP10);
							}
						}
						else if(GetCommonDataDefault("power", 128) < 128) {
							ascent(a in -1..3) {
								CreatePlayerShot01(GetPlayerX+optionxpos, GetPlayerY + optionypos, 11, 278 + (a * 8), shotdmg, 1, SP10);
							}
						}
						else {
							ascent(a in -2..3) {
								CreatePlayerShot01(GetPlayerX+optionxpos, GetPlayerY + optionypos, 11, 278 + (a * 8), shotdmg, 1, SP10);
							}
						}
					}
				}
				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;
	}
	
	@MainLoop
	{
		if(!OnMissed) {
			mframe = 0;
		}
		if(GetCommonDataDefault("power", 128) > 128) {
			SetCommonData("power", 128);
		}
		if(!OptIsSet) {
			Option("LEFT");
			Option("RIGHT");
		}
		if(GetCommonDataDefault("power", 128) > 16) {
			OptIsSet = false;
		}
		if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD) && count==-1){
			count = 0;
		}
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
			let mod = 3;
			if(count%6 == 0){
				if(GetCommonDataDefault("power", 128) < 64) {
					ascent(a in 0..2) {
						CreatePlayerShot01(GetPlayerX, GetPlayerY - 8, 11, 270 + ((a%2 * 2 - 1) * mod), shotdmg, 2, SP09);
					}
				}
				else {
					ascent(a in -1..2) {
						CreatePlayerShot01(GetPlayerX, GetPlayerY - 8, 11, 270 + (a * mod), shotdmg, 2, SP09);
					}
				}
			}
			if(optionxpos>20){optionxpos--;}
			if(optionypos>-10){optionypos--;}
		}else{
			let mod = 8;
			if(count%8 == 0){
				if(GetCommonDataDefault("power", 128) < 64) {
					ascent(a in -1..2) {
						CreatePlayerShot01(GetPlayerX, GetPlayerY - 8, 11, 270 + (a * mod), shotdmg, 3, SP09);
					}
				}
				else {
					ascent(a in -2..3) {
						CreatePlayerShot01(GetPlayerX, GetPlayerY - 8, 11, 270 + (a * mod), shotdmg, 3, SP09);
					}
				}
			}
			if(optionxpos<20){optionxpos++;}
			if(optionypos<10){optionypos++;}
		}		

		if(count >= 0){
			count++;
		}
		if(count >= 48){
			count=-1;
		}
		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){
			CutIn(KOUMA,"「A Penny Saved」", img_cutin);
			UseSpellCard("APennySaved", 0);
		}else{
			CutIn(KOUMA,"「Vezai Lottery」", img_cutin);
			UseSpellCard("VezaiLottery", 0);
		}
	}
	@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 VezaiLottery{
	let end = false;
	task SpellShot(x, y, v, angle, radius, graphic) {
		let obj = Obj_Create(OBJ_SHOT);
		let spell = Obj_Create(OBJ_SPELL);
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, v);
		Obj_SetAlpha(obj, 182);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetDamage(obj, 1);
		ObjShot_SetPenetration(obj, 9001);
		ObjShot_SetDelay(obj, 0);
		DeleteEnemyShotToItemInCircle(SHOT, Obj_GetX(obj), Obj_GetY(obj), radius);
		yield;
	}
	task run{
		SetSpeed(0, 0);
		loop(45){yield;}
		ForbidShot(true);
		loop(265){
			loop(2) {
				SpellShot(GetPlayerX, GetPlayerY, 7, rand_int(0, 360), 5, rand_int(251, 253));
			}
			yield;
		}
		end = true;
		ForbidShot(false);
		loop(5) {yield;}
		End();
	}
	@Initialize{
		SetPlayerInvincibility(270);
		run();
	}
	@MainLoop{
		CollectItems();
		yield;
	}
	@Finalize{
		SetSpeed(4, 2.25);
	}
}
script_spell APennySaved{
	let hasgone = false;
	let end = false;
	task SpellShot(x, y, v, angle, radius, graphic) {
		let shot = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(shot, x, y);
		Obj_SetAngle(shot, angle);
		Obj_SetSpeed(shot, v);
		Obj_SetAlpha(shot, 182);
		ObjShot_SetGraphic(shot, graphic);
		ObjShot_SetDamage(shot, 0.5);
		ObjShot_SetPenetration(shot, 9001);
		ObjShot_SetDelay(shot, 0);
		DeleteEnemyShotToItemInCircle(SHOT, Obj_GetX(shot), Obj_GetY(shot), radius);
		yield;
	}
	task APennySaved(x, y) {
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, atan2(GetEnemyY - Obj_GetY(obj), GetEnemyX - Obj_GetX(obj)));
		Obj_SetSpeed(obj, 5);
		Obj_SetAlpha(obj, 182);
		Obj_SetAutoDelete(obj, false);
		ObjShot_SetGraphic(obj, 251);
		ObjShot_SetDamage(obj, 0);
		ObjShot_SetPenetration(obj, 9001);
		ObjShot_SetDelay(obj, 0);
		while(Obj_BeDeleted(obj) == false) {
			if(end == true) {
				ObjShot_FadeDelete(obj);
			}
			if(Obj_GetX(obj) < GetEnemyX + 10 && Obj_GetX(obj) > GetEnemyX - 10 && Obj_GetY(obj) < GetEnemyY + 10 && Obj_GetY(obj) > GetEnemyY - 10) {
				hasgone = true;
			}
			if(hasgone) {
				Obj_SetSpeed(obj, 0);
				SpellShot(Obj_GetX(obj), Obj_GetY(obj), 3, rand_int(0, 360), 5, 252);
			}
			else {
				Obj_SetAngle(obj, atan2(GetEnemyY - Obj_GetY(obj), GetEnemyX - Obj_GetX(obj)));
				Obj_SetSpeed(obj, 9);
			}
			yield;
		}
	}
	task run{
		loop(45){yield;}
		APennySaved(GetPlayerX, GetPlayerY);
		while(hasgone == false) {
			ForbidShot(true);
			yield;
		}
		ForbidShot(false);
		loop(240){yield;}
		end = true;
		loop(5) {yield;}
		End();
	}
	@Initialize{
		SetPlayerInvincibility(300);
		run();
	}
	@MainLoop{
		CollectItems();
		yield;
	}
	@Finalize{
	}
}