#TouhouDanmakufu[Player]
#ScriptVersion[2]
#Menu[Another World's Chaos]
#Text[Character override menu: you can choose any additional Danmakufu player script you put in the "player" directory (as well as the default Reimu and Marisa players) to use it instead of the normal ones. Your scores and records won't save, though.
If you just want to start the game, press Z again.]
#Image[]
#ReplayName[ ]

script_player_main{

  #include_function ".\playerfunctions.txt"
  #include_function ".\effects.txt"
  #include_function ".\lymia.txt"
  #include_function ".\lymia_functions.txt"
  #include_function ".\lymia_functions_main.txt"
  #include_function ".\raibys.txt"
  #include_function ".\raibys_functions.txt"
  #include_function ".\nhimor.txt"
  #include_function ".\nhimor_functions.txt"
  #include_function ".\ender.txt"
  #include_function ".\ender_functions.txt"

  defaulthitbox=0;  // 0 = burst (Castle Shikigami-type), 1 = normal (standard Touhou), 2 = none
                    // usually is changed in-game, but for use in other scripts, just change this


  let playernum=-1;


  let count=-1;
  let i=0;
  let angleshot=0;
  let color=0;
  let shottype=0;

  let Pose=0;
  let Dir=0;
  let Frame=0;
  let Rot=0;
  let Focus=0;
  let playershot=-1;
  let deadframes=0;
  let locky=-1;

  let XOffset=[0,-2,2];
  let YOffset=[-1,-2,-2];
  let Left=[0,42,42];
  let Right=[42,76,76];
  let Flip=[1,-1,1];

  @Initialize{
    InitDelay;
    SetAutoEffect(false);
    PlayerForbidShotOff;
    DeleteCommonData("FakeDeath");
    SetRebirthFrame(9);
    SetRebirthFrameReduction(3);
  }

  let initialbombs=[3,3,4,0,0,0,0];

  task InitDelay{
	yield;
//	SetCommonData("AWCPlayerNum",6);
	playernum=GetPlayer;

	if(playernum==0){LymiaInit(0);}
	else if(playernum==1){RaibysInit(0);}
	else if(playernum==2){NhimorInit(0);}
	else if(playernum==6){EnderInit(0);}
	if(playernum>=0){
		SetInitialBombCount(initialbombs[playernum]);
	}
	LoadGraphic(img_effects);
	EffectTask;
  }

let angle1=[30,35,30,20,15,20];
let angle2=[20,15,20,30,35,30];

  @MainLoop{
    if(GetCommonDataDefault("FakeDeath",0)==1){
	PlaySE("se\sePlayerCollision.wav");
	let k=1;
	loop(3){
		RainbowExplosion(GetPlayerX,GetPlayerY,k*10,k+2,1);
		k++;
	}
	RainbowExplosion(GetPlayerX,GetPlayerY,30,5,0);
	RainbowExplosion(GetPlayerX,GetPlayerY,60,50,0);
	SetY(800);
	ResetPositions(1);
	ResetPositions(0);
	DeleteCommonData("FakeDeath");
    }
    if(GetCommonDataDefault("ResetAWCBombs",false)==true){
	if(playernum>=0&&playernum!=6){
		if(initialbombs[playernum]>GetPlayerBomb){
			AddBomb(initialbombs[playernum]-GetPlayerBomb);
		}
	}
	DeleteCommonData("ResetAWCBombs");

    }

    if(playernum==0){LymiaMainLoop;}
    else if(playernum==1){RaibysMainLoop;}
    else if(playernum==2){NhimorMainLoop;}
    else if(playernum==6){EnderMainLoop;}

    dead=0;
    deadframes=0;

    if(GetCommonDataDefault("Dialogue",0)==0){
	SetIntersectionCircle(GetPlayerX, GetPlayerY, 0);
    }

    if(locky!=-1){
	SetY(locky);
    }
    if(GetCommonDataDefault("DialogueChoice",0)==1){
	locky=GetPlayerY;
    }else{
	locky=-1;
    }

    yield;
  }
  task HandleSwitch{
	loop(5){yield;}
	let playernumsave=0;
	let GetPlayerNumsave=0;
	loop{
		if(GetPlayer!=playernum&&GetCommonDataDefault("InAWCMenu",0)==0){
			SpellCardEffectStatic;
			playernumsave=playernum;
			GetPlayerNumsave=GetPlayer;
			playernum=-1;
			yield;
			yield;
			if(playernumsave==0){LymiaFinalize;}
			else if(playernumsave==1){RaibysFinalize;}
			else if(playernumsave==2){NhimorFinalize;}
			else if(playernumsave==6){EnderFinalize;}
			yield;
			yield;
			if(GetPlayerNumsave==0){LymiaInit(120);}
			else if(GetPlayerNumsave==1){RaibysInit(120);}
			else if(GetPlayerNumsave==2){NhimorInit(120);}
			else if(GetPlayerNumsave==6){EnderInit(120);}
			yield;
			yield;
			playernum=GetPlayerNumsave;
			yield;
		}
		yield;
		yield;
	}
  }

  let nodrawfocus=0;
  @Missed{
	frame++;
	if(playernum!=6){
		HandleDeath;
	}else{
		HandleDeath2;
	}
	deadframes++;
	if(deadframes==60&&playernum!=6){
		if(GetPlayerBomb==0){
			SetInitialBombCount(1);
		}else{
			SetInitialBombCount(GetPlayerBomb);	//keep bombs even after death
		}
	}
	yield;
  }
  @SpellCard{
	if(playernum==0){LymiaSpell;}
	else if(playernum==1){RaibysSpell;}
	else if(playernum==2){NhimorSpell;}
	else if(playernum==6){EnderSpell;}
  }

  @DrawLoop{
	if(playernum==0){LymiaDrawLoop;}
	else if(playernum==1){RaibysDrawLoop;}
	else if(playernum==2){NhimorDrawLoop;}
	else if(playernum==6){EnderDrawLoop;}
	if(playernum>=0){
		DrawFocus;
	}
  }

  @Finalize{
	if(playernum==0){LymiaFinalize;}
	else if(playernum==1){RaibysFinalize;}
	else if(playernum==2){NhimorFinalize;}
	else if(playernum==6){EnderFinalize;}
	DeleteGraphic(img_effects);
  }
}

script_spell LymiaU{
	#include_function ".\lymia_spell1.txt"
}
script_spell LymiaF{
	#include_function ".\lymia_spell2.txt"
}
script_spell RaibysU{
	#include_function ".\raibys_spell1.txt"
}
script_spell RaibysF{
	#include_function ".\raibys_spell2.txt"
}
script_spell NhimorU{
	#include_function ".\nhimor_spell1.txt"
}
script_spell NhimorF{
	#include_function ".\nhimor_spell2.txt"
}
script_spell Ender{
	#include_function ".\ender_spell.txt"
}
