#TouhouDanmakufu[Player]
#ScriptVersion[3]
#ID["MoFReimuB"]
#Title["MoF Reimu B"]
#Image["./img/slpl00b.png"]
#ReplayName["MoFReimuB"]

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
	Player Recreation Project: MoF Reimu B
	by Frenticpony
	
	Power 0 DPS: ~138
	Power 1 DPS: ~170
	Power 2 DPS: ~204
	Power 3 DPS: ~236
	Power 4 DPS: ~267
	
	This is a recreation of Reimu's second shot-type from Mountian of Faith.
	
	Below, there are several customization options to tweak the script to
	suit a variety of needs.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

/* --------------------------------------------
	If your script calls the player's
	EV_USER event, and you are experiencing 
	errors, set this variable to true.
	
	default = false;
-------------------------------------------- */
let disableEV_USER = false;

/* --------------------------------------------
	Damage Multiplier.  Increase/decrease if 
	the player is too weak/too powerful.
	
	default = 1;
-------------------------------------------- */
let player_DamageMultiplier = 1.2;

/* --------------------------------------------
	Bomb damage and Bomb Damage Multiplier.
	
	default      = 32;
	defaultMulti = 1;
-------------------------------------------- */
let player_BombDamage = 32;
let player_BombDamageMultiplier = 1;

/* --------------------------------------------
	Starting power level.
	
	default = 0;
-------------------------------------------- */
let playerPower = 100;

/* --------------------------------------------
	Starting life count
	
	default = 2;
-------------------------------------------- */
let playerLives = 2;

/* --------------------------------------------
	If true, draws th10 shot delete effects
	from bombing
	
	default = true;
-------------------------------------------- */
let showBreakEffect = true;

/* --------------------------------------------
	Use alternate bomb type?
	(Bombs for bombs, instead of -100 power)
	
	default = false;
-------------------------------------------- */
let useAlternateBombType = false;

/* --------------------------------------------
	Starting bomb count
	(Alternate bomb type only)
	
	default = 3;
-------------------------------------------- */
let playerBombs = 3;

/* --------------------------------------------
	Number of bombs to give on respawn
	(Alternate bomb type only)
	
	default = 3;
-------------------------------------------- */
let playerRebirthBombs = 3;

/* --------------------------------------------
	Take away bombs on respawn?
	(Alternate bomb type only)
	
	default = false;
-------------------------------------------- */
let playerRebirthResetBombs = false;

/* --------------------------------------------
	Power loss on death.
	First is normal MoF style
	Second is for alternate bomb type
	
	default    = 320;
	defaultAlt = 100;
-------------------------------------------- */
let playerPowerLoss = 320;
let playerPowerLossAlternate = 100;

/* --------------------------------------------
	Drop power items on death?
	
	default = true;
-------------------------------------------- */
let playerDropItems = true;

/* --------------------------------------------
	Small Power Item Value
	
	default = 5;
-------------------------------------------- */
let player_sPowerValue = 5;

/* --------------------------------------------
	Large Power Item Value
	
	default = 100;
-------------------------------------------- */
let player_lPowerValue = 100;

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
	End customization section
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

#include"./lib/image_lib.dnh"
#include"./lib/sound_lib.dnh"
#include"./lib/player_lib.dnh"
#include"./lib/playerB_lib.dnh"

@Initialize
{
	ObjPlayer_AddIntersectionCircleA1(GetPlayerObjectID, 0, 0, 2, 20);
	SetPlayerClip(8,11,GetStgFrameWidth-8,GetStgFrameHeight-16);
	SetPlayerAutoItemCollectLine(140);
	SetPlayerSpeed(4, 2);
	SetPlayerRebirthLossFrame(0);
	SetPlayerDownStateFrame(45);
	LoadPlayerShotData(GetCurrentScriptDirectory() ~ "player_shot.dnh");
	SetCommonData("FP_PLAYER_LIFE", 2);
	InitOptions();
	InitPlayer();
}

@Loading
{
	LoadPlayerTextures();
	LoadPlayerSounds();
}

@MainLoop
{
	if(playerDebugTimer == 1)
	{
		ShiftCheck();
		playerDebugTimer = -1;
	}
	else if(playerDebugTimer >= 0)
	{
		playerDebugTimer++;
	}
	
	if(isPlayerImmobile == true)
	{
		SetPlayerSpeed(0, 0);
	}
	else
	{
		SetPlayerSpeed(4, 2);
	}
	
	if(isPlayerInvincible == true)
	{
		SetPlayerInvincibilityFrame(2);
	}
	if(blink_counter > 100)
	{
		blink_counter = 0;
	}
	
	SetPlayerPower(playerPower);
	GetAngleToCenter = atan2(0 - GetPlayerY, GetStgFrameWidth/2 - GetPlayerX);
	blink_counter++;
	yield;
}

@Finalize
{
	RemovePlayerTextures();
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_SPELL) 
	{
		let spell = GetPlayerSpell();
		if(useAlternateBombType)
		{
			if(spell >= 1)
			{
				isPlayerHit = false;
				SetScriptResult(true);
				SpellcardBomb_th10();
				SetPlayerSpell(spell - 1);
			}
			else
			{
				SetScriptResult(false);
			}
		}
		else
		{
			if(playerPower >= 100 && playerPower != 500)
			{
				isPlayerHit = false;
				SetScriptResult(true);
				playerPower -= 100;
				SpellcardBomb_th10();
				PowerCheck(0, 1);
			}
			else if(playerPower == 500)
			{
				isPlayerHit = false;
				SetScriptResult(true);
				playerPower -= 100;
				SpellcardBomb_th10();
				PowerCheck(-1, 0);
			}
			else
			{
				SetScriptResult(false);
			}
		}
	}
	case(EV_HIT)
	{
		PlaySE(se_pldead);
		isPlayerHit = true;
		DeathExplosion();
		//SetScriptResult(false);
	}
	case(EV_PLAYER_SHOOTDOWN)
	{
		isPlayerDead = true;
		//DeathExplosionB();
		if(playerDropItems)
		{
			ascent(i in 0..7)
			{
				if(i == 1 || i == 3 || i == 5)
				{
					TItemCreateA2(ITEM_POWER, GetPlayerX, GetPlayerY, GetPlayerX + 250*cos(GetAngleToCenter + 30 + -10*i), GetPlayerY + 250*sin(GetAngleToCenter + 30 + -10*i), 100);
				}
				if(i == 0 || i == 2 || i == 4 || i == 6)
				{
					TItemCreateA2(ITEM_POWER_S, GetPlayerX, GetPlayerY, GetPlayerX + 250*cos(GetAngleToCenter + 30 + -10*i), GetPlayerY + 250*sin(GetAngleToCenter + 30 + -10*i), 100);
				}
			}
		}
		
		ascent(i in 0..length(optionArray))
		{
			if(optionArray[i] != 0)
			{
				OptionDeathEffect(optionArray[i]);
				OptionFinishFlags(optionArray[i]);
			}
		}
		SetCommonData("FP_EVENT_PLAYER_SHOOTDOWN", true);
		SetCommonData("FP_PLAYER_LIFE", GetCommonData("FP_PLAYER_LIFE", 0) - 1);
	}
	case(EV_PLAYER_REBIRTH)
	{
		PlayerRebirth();
		RenderPlayer();
		if(useAlternateBombType)
		{
			if(GetPlayerSpell() < playerRebirthBombs)
			{
				SetPlayerSpell(playerRebirthBombs);
			}
			else if(playerRebirthResetBombs)
			{
				SetPlayerSpell(playerRebirthBombs);
			}
			
			playerPower -= playerPowerLossAlternate;
			if(playerPower < 0)
			{
				playerPower = 0;
				powerState = -1;
			}
		}
		else
		{
			playerPower -= playerPowerLoss;
			if(playerPower < 0)
			{
				playerPower = 0;
				powerState = -1;
			}
		}
		SetPlayerInvincibilityFrame(300);
		isPlayerDead = false;
		isPlayerHit = false;
	}
	case(EV_GET_ITEM)
	{
		let itemType = GetEventArgument(0);
		alternative(itemType)
		case(ITEM_1UP)
		{
			WriteLog("ITEM_1UP");
			SetPlayerLife(GetPlayerLife + 1);
			PlaySE(se_item00);
		}
		case(ITEM_1UP_S)
		{
			WriteLog("ITEM_1UP_S");
			PlaySE(se_item00);
		}
		case(ITEM_SPELL)
		{
			WriteLog("ITEM_SPELL");
			SetPlayerSpell(GetPlayerSpell + 1);
			PlaySE(se_item00);
		}
		case(ITEM_SPELL_S)
		{
			WriteLog("ITEM_SPELL_S");
			PlaySE(se_item00);
		}
		case(ITEM_POINT)
		{
			WriteLog("ITEM_1UP");
			PlaySE(se_item00);
		}
		case(ITEM_POINT_S)
		{
			WriteLog("ITEM_1UP_S");
			PlaySE(se_item00);
		}
		case(ITEM_POWER)
		{
			WriteLog("ITEM_POWER");
			PlaySE(se_item00);
			playerPower += player_lPowerValue;
			if(playerPower > player_maxPower)
			{
				playerPower = player_maxPower;
			}
			SetPlayerPower(playerPower);
			PowerCheck(1, 0);
		}
		case(ITEM_POWER_S)
		{
			WriteLog("ITEM_POWER_S");
			PlaySE(se_item00);
			playerPower += player_sPowerValue;
			if(playerPower > player_maxPower)
			{
				playerPower = player_maxPower;
			}
			SetPlayerPower(playerPower);
			PowerCheck(1, 0);
		}
	}
	case(EV_GRAZE)
	{
		PlaySE(se_graze);
	}
	case(EV_USER)
	{
		if(!disableEV_USER)
		{
			let itemType = GetEventArgument(0);
			alternative(itemType)
			case(0) //Small Powerup
			{
				if(playerPower < player_maxPower)
				{
					playerPower += player_sPowerValue;
				}
				PowerCheck(1, 0);
				PlaySE(se_item00);
			}
			case(1) //Small Point
			{
				AddScore(5000);
				PlaySE(se_item00);
			}
			case(2) //Large Powerup
			{
				if(playerPower < player_maxPower)
				{
					playerPower += player_lPowerValue;
				}
				PowerCheck(1, 0);
				PlaySE(se_item00);
			}
			case(3) //Large Point
			{
				AddScore(5000);
				PlaySE(se_item00);
			}
			case(4) //Life piece
			{
				PlaySE(se_item00);
			}
			case(5) //Bomb piece
			{
				PlaySE(se_item00);
			}
			case(6) //1up
			{
				SetPlayerLife(GetPlayerLife + 1);
				PlaySE(se_extend);
			}
			case(7) //Bomb
			{
				SetPlayerSpell(GetPlayerSpell + 1);
				PlaySE(se_cardget);
			}
			case(8) //Full Powerup
			{
				if(playerPower < player_maxPower)
				{
					playerPower = player_maxPower;
				}
				PowerCheck(1, 0);
				PlaySE(se_item00);
			}
		}
	}
}
