#e[Player]
#ScriptVersion[3]	//XNvgo[W3K{ł
#ID["Default_Rumia"]
#Title["Q[X^[g"]
#Text["Q[X^[g"]
#Image["./Default_Player_Rumia_Select.png"]
#ReplayName["Marisa"]

#include"./Gauge.txt"
#include"./Shield.txt"

let PlayerEnd=false;

let objPlayer = GetPlayerObjectID();
let objSlowShot = ID_INVALID;
let current = GetCurrentScriptDirectory();

let OnSpellCard=false;

let CharaDirection=0;

let PlayerShield=true;

let ShieldCount=0;

let SpellPoint=0;

let SpiritPoint=100;

let SpiritPointLackDrawing=false;

let HiSpeed=3.0;
let LowSpeed=1.0;
let OnDash=false;

let MagicShotNum=0;
let MagicShotNumMax=3;
let MagicNapalmNum=0;
let MagicNapalmNumMax=1;
let OrreryNum=0;
let OrreryNumMax=1;
let MagicMissileNum=0;
let MagicMissileNumMax=2;

let ShieldGaugeMax=200;

let PlayerLevel=1;
let Status_MagicPower=120;
let Status_ShieldRecover=80;
let Status_ShieldReduce=100;
let Status_SpellCardRecover=60;
let Status_SpellCardReduce=120;
let Status_SpiritRecover=80;
let Status_SpiritReduce=120;
let Status_Luck=50;
let Status_Critical=40;

let ShieldRecover=0.3*0;
let SpellRecover=0.02;
let SpiritRecover=0.02;


let ShieldReduce=1;
let SpellReduce=1;
let SpiritReduce=1;

let MagicShotDelay=0;

let ExpandRangeFlag=false;

let ExpTable=[0];
ascent(i in 1..100)
{
	ExpTable=ExpTable~[(i*3+7)^2+ExpTable[i-1]];
}
/*
let ExpTable=[
100,286,540,874,1300,1833,2486,3273,4210,5313,



0
];
*/

task Texp
{
loop
{
//WriteLog(ShieldReduce);
//DrawText(GetCommonData("Status_MagicPower",1),50, 80,16,255,[]);
//DrawText(GetIntersectionRegistedEnemyID,50, 110,16,255,[]);
	if(GetCommonData("Exp",0)>=ExpTable[GetCommonData("Level",1)])
	{
		SetCommonData("Level",GetCommonData("Level",1)+1);
		PlayerLevel+=1;
		LevelUp;
	}
	SetCommonData("NextExp",ExpTable[GetCommonData("Level",1)]-GetCommonData("Exp",0));
	yield;
}

}

task LevelUp
{
	SetPlayerInvincibilityFrame(120);//GԂݒ
	LevelUpLearn;
	LevelUpEffect;
	Obj_PlaySE(GetCurrentScriptDirectory~"se/tm2_power001.wav");

	let UP_MagicPower=4.5;
	let UP_ShieldRecover=1.25;
	let UP_ShieldReduce=1.25;
	let UP_SpellCardRecover=0.5;
	let UP_SpellCardReduce=1.75;
	let UP_SpiritRecover=0.75;
	let UP_SpiritReduce=1.5;
	let UP_Luck=0.5;
	let UP_Critical=0.25;

	SetCommonData("MagicPower",GetCommonData("MagicPower",120)+UP_MagicPower);
	SetCommonData("ShieldRecover",GetCommonData("ShieldRecover",80)+UP_ShieldRecover);
	SetCommonData("ShieldReduce",GetCommonData("ShieldReduce",80)+UP_ShieldReduce);
	SetCommonData("SpellCardRecover",GetCommonData("SpellCardRecover",60)+UP_SpellCardRecover);
	SetCommonData("SpellCardReduce",GetCommonData("SpellCardReduce",120)+UP_SpellCardReduce);
	SetCommonData("SpiritRecover",GetCommonData("SpiritRecover",80)+UP_SpiritRecover);
	SetCommonData("SpiritReduce",GetCommonData("SpiritReduce",120)+UP_SpiritReduce);
	SetCommonData("Luck",GetCommonData("Luck",50)+ UP_Luck);
	SetCommonData("Critical",GetCommonData("Critical",40)+UP_Critical);

	StatasValueSet;
}

function StatasValueSet
{
	PlayerLevel=GetCommonData("Level",1);
	Status_MagicPower=GetCommonData("MagicPower",120);
	Status_ShieldRecover=GetCommonData("ShieldRecover",80);
	Status_ShieldReduce=GetCommonData("ShieldReduce",80);
	Status_SpellCardRecover=GetCommonData("SpellCardRecover",60);
	Status_SpellCardReduce=GetCommonData("SpellCardReduce",120);
	Status_SpiritRecover=GetCommonData("SpiritRecover",80);
	Status_SpiritReduce=GetCommonData("SpiritReduce",120);
	Status_Luck=GetCommonData("Luck",50);
	Status_Critical=GetCommonData("Critical",40);

	EquipStatusAdjust;

	ShieldRecover=(Status_ShieldRecover/2+50)/100;
	SpellRecover=0.015*(Status_SpellCardRecover/2+50)/100;
	SpiritRecover=0.015*(Status_SpiritRecover/2+50)/100;

	ShieldReduce=200/(Status_ShieldReduce+100);
	SpellReduce=200/(Status_SpellCardReduce+100);
	SpiritReduce=200/(Status_SpiritReduce+100);

	SetCommonData("Sum_Luck",Status_Luck);
	SetCommonData("Sum_Critical",Status_Critical);

}

#include"./EquipStatusAdjust.txt"

@Initialize
{
	Obj_SetValue(GetPlayerObjectID,"Move_Right",0);
	Obj_SetValue(GetPlayerObjectID,"Move_Left",0);
	Obj_SetValue(GetPlayerObjectID,"Move_Up",0);
	Obj_SetValue(GetPlayerObjectID,"Move_Down",0);

	let path = current ~ "ShotData.txt";
	LoadPlayerShotData(path); //e摜[h

	ObjPlayer_AddIntersectionCircleA1(objPlayer, 0, 0, 8, 20); //蔻o^
	SetPlayerRebirthFrame(1);
	SetPlayerRebirthLossFrame(0);
	SetPlayerSpeed(HiSpeed,LowSpeed);

	ShieldGauge;
	ShieldTask;
	SpellPointGauge;
	SpellPointTask;
	SpiritPointGauge;
	SpiritPointTask;
	CriticalHitTask;
	TAction;
	Texp;

	TInitial;

	TImage();//@`p^XNN
	TMagicCircle();//GԖ@w^XNN
}

task TInitial
{
		yield;
	StatasValueSet;
}

@MainLoop
{
	MagicShotDelay-=1;
	yield;
}

@Finalize
{
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_SPELL)
	{
		//XyJ[hv
		let spell = GetPlayerSpell();//cXy
		if(IsPlayerLastSpellWait)
		{

		if(PlayerShield)
		{
			SetCommonData("PlayerBreakFlag",GetCommonData("PlayerBreakFlag",0)+1);
			SetScriptResult(true);//Xy\
			TSpell();//Xy^XNN
			Obj_PlaySE(GetCurrentScriptDirectory~"se/crash_grass.wav");
			ShieldBreakEffect;
			PlayerShield=false;
		}
		else
		{
			Obj_PlaySE(GetCurrentScriptDirectory~"se/hit50.wav");
			SetCommonData("PlayerMissFlag",GetCommonData("PlayerMissFlag",0)+1);
			SetScriptResult(true);//Xy\
			TSpell();//Xy^XNN
			SetPlayerLife(GetPlayerLife-1);
		}

		}
		else
		{
			SetScriptResult(false);//Xys	
		}
	}
	case(EV_HIT)
	{
		if(GetPlayerLife()>=1)
		{
		//e
		CallSpell;
		}
		else if(PlayerShield)
		{
		//e
		CallSpell;
		}
		else
		{
			Obj_PlaySE(GetCurrentScriptDirectory~"se/don11.wav");
			PlayerEnd=true;
			EndEffect;
			SetCommonData("PlayerEnd",true);
		}
	}
	case(EV_PLAYER_REBIRTH)
	{
		//A
		SetPlayerSpell(3);
		SetPlayerInvincibilityFrame(180);
	}
	case(EV_GET_ITEM)
	{
		//ACe擾ʒm
		let itemType = GetEventArgument(0);
		alternative(itemType)
		case(ITEM_SPELL)
		{
			WriteLog("ITEM_SPELL");
		}
		case(ITEM_SPELL_S)
		{
			WriteLog("ITEM_SPELL_S");
		}
		case(ITEM_POWER)
		{
			WriteLog("ITEM_POWER");
		}
		case(ITEM_POWER_S)
		{
			WriteLog("ITEM_POWER_S");
		}
	}

}

task TAction
{
yield;
yield;

let KeyArray=[VK_SHOT,VK_BOMB,VK_USER1,VK_USER2];
let SkillKeyArray=["Shot_Key","Bomb_Key","User1_Key","User2_Key"];

SetCommonData("Shot_Key",GetCommonData("Shot_Key","}WbNVbg"));
SetCommonData("Bomb_Key",GetCommonData("Bomb_Key","}WbNip["));
SetCommonData("User1_Key",GetCommonData("User1_Key","X^[_Xg"));
SetCommonData("User2_Key",GetCommonData("User2_Key","_bV"));
let ExpandRangeKey=[];

let DashKey=[];

loop
{

ascent(i in 0..4)
{
SetAction(KeyArray[i],SkillKeyArray[i]);
}

task SetAction(SET_KEY,SET_SKILL_KEY)
{
	alternative(GetCommonData(SET_SKILL_KEY,"}WbNVbg"))
	case("}WbNVbg")
	{
		MagicShotTask(SET_KEY);
	}
	case("}WbNip[")
	{
		MagicNapalmTask(SET_KEY);
	}
	case("}WbN~TC")
	{
		MagicMissileTask(SET_KEY);
	}
	case("sbhVbg")
	{
		RappidShotTask(SET_KEY);
	}
	case("_bV")
	{

		DashKey=DashKey~[SET_KEY];
		DashTask(SET_KEY);
	}
	case("I[[")
	{
		OrreryTask(SET_KEY);
	}
	case("R[hCtFm")
	{
		ColdInfernoTask(SET_KEY);
	}
	case("VI[[YT")
	{
		OrrerysSunTask(SET_KEY);
	}
	case("C[W[U[")
	{
		IllusionLaserTask(SET_KEY);
	}
	case("Xg[[U[")
	{
		StreamLaserTask(SET_KEY);
	}
	case("CY[U[")
	{
		RiseLaserTask(SET_KEY);
	}
	case("X^[_Xg")
	{
		StarDustTask(SET_KEY);
	}
	case("X^[_Xg@G")
	{
		StarDustReverieTask(SET_KEY);
	}
}

while(GetCommonData("Pause",false)==false){yield;}

Obj_PlaySE(GetCurrentScriptDirectory~"se/cursor8.wav");

StatasValueSet;
SetCommonData("Pause",false);
ExpandRangeKey=[];
ExpandRangeFlag=false;
DashKey=[];
}

task DashTask(SET_KEY)
{
loop
{
	if(OnDash==false)
	{
	if(GetVirtualKeyState(SET_KEY) == KEY_PUSH || GetVirtualKeyState(SET_KEY) == KEY_HOLD)
	{

	//	Obj_PlaySE(GetCurrentScriptDirectory~"se/tm2_sonic004.wav");
		OnDash=true;
		SetPlayerSpeed(HiSpeed*1.5,LowSpeed*1.5);
	}
	else
	{
		OnDash=false;
		SetPlayerSpeed(HiSpeed,LowSpeed);
	}
	}
		else
		{
			let KeyFreeCheck=true;
			ascent(i in 0..length(DashKey))
			{
			if(GetVirtualKeyState(DashKey[i])!=KEY_FREE)
			{
				KeyFreeCheck=false;
				break;
			}
			}
			if(KeyFreeCheck==true)
			{
				OnDash=false;
			}	
		}
	if(GetCommonData("Pause",false)){break;}
	if(PlayerEnd){OnDash=false;break;}
yield;
}

}

	task IllusionLaserTask(SET_KEY)
	{let a=0;
	let shotCount = -1;
	loop
	{//DrawText(a,50, 80,16,255,[]);
		if((GetVirtualKeyState(SET_KEY)==KEY_PUSH || GetVirtualKeyState(SET_KEY)==KEY_HOLD) && shotCount==-1)
		{
			shotCount = 0;
		}

		if(shotCount%5 == 0 && MagicShotDelay<=0)
		{//if(IsPermitPlayerShot!=false){a+=1;}
			IllusionLaser(SET_KEY);
			MagicShotDelay=5;
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 4)
		{
			shotCount=-1;
		}
		if(GetCommonData("Pause",false)){break;}
		if(PlayerEnd){break;}
		yield;
	}
	}

	task StreamLaserTask(SET_KEY)
	{let a=0;
	let shotCount = -1;
	loop
	{//DrawText(a,50, 80,16,255,[]);
		if((GetVirtualKeyState(SET_KEY)==KEY_PUSH || GetVirtualKeyState(SET_KEY)==KEY_HOLD) && shotCount==-1)
		{
			shotCount = 0;
		}

		if(shotCount%5 == 0 && MagicShotDelay<=0)
		{//if(IsPermitPlayerShot!=false){a+=1;}
			StreamLaser(SET_KEY);
			MagicShotDelay=5;
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 4)
		{
			shotCount=-1;
		}
		if(GetCommonData("Pause",false)){break;}
		if(PlayerEnd){break;}
		yield;
	}
	}

	task RiseLaserTask(SET_KEY)
	{let a=0;
	let shotCount = -1;
	loop
	{//DrawText(a,50, 80,16,255,[]);
		if((GetVirtualKeyState(SET_KEY)==KEY_PUSH || GetVirtualKeyState(SET_KEY)==KEY_HOLD) && shotCount==-1)
		{
			shotCount = 0;
		}

		if(shotCount%30 == 0 && MagicShotDelay<=0)
		{//if(IsPermitPlayerShot!=false){a+=1;}
			RiseLaser(SET_KEY);
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 30)
		{
			shotCount=-1;
		}
		if(GetCommonData("Pause",false)){break;}
		if(PlayerEnd){break;}
		yield;
	}
	}

	task MagicShotTask(SET_KEY)
	{let a=0;
	let shotCount = -1;
	loop
	{//DrawText(a,50, 80,16,255,[]);
		if((GetVirtualKeyState(SET_KEY)==KEY_PUSH || GetVirtualKeyState(SET_KEY)==KEY_HOLD) && shotCount==-1)
		{
			shotCount = 0;
		}

		if(shotCount%5 == 0 && MagicShotDelay<=0)
		{//if(IsPermitPlayerShot!=false){a+=1;}
			MagicShot;
			MagicShotDelay=6;
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 5)
		{
			shotCount=-1;
		}
		if(GetCommonData("Pause",false)){break;}
		if(PlayerEnd){break;}
		yield;
	}
/*
loop
{
DrawText(a,50, 80,16,255,[]);
yield;
}
*/
	}

	task RappidShotTask(SET_KEY)
	{let a=0;
	let shotCount = -1;
	loop
	{//DrawText(a,50, 80,16,255,[]);
		if((GetVirtualKeyState(SET_KEY)==KEY_PUSH || GetVirtualKeyState(SET_KEY)==KEY_HOLD) && shotCount==-1)
		{
			shotCount = 0;
		}

		if(shotCount%5 == 0 && MagicShotDelay<=0)
		{//if(IsPermitPlayerShot!=false){a+=1;}
			RappidShot;
			MagicShotDelay=6;
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 5)
		{
			shotCount=-1;
		}
		if(GetCommonData("Pause",false)){break;}
		if(PlayerEnd){break;}
		yield;
	}
	}

	task MagicNapalmTask(SET_KEY)
	{
	let shotCount = -1;
	loop
	{
		if((GetVirtualKeyState(SET_KEY)==KEY_PUSH || GetVirtualKeyState(SET_KEY)==KEY_HOLD) && shotCount==-1)
		{
			shotCount = 0;
		}

		if(shotCount%10 == 0)
		{
			MagicNapalm;
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 9)
		{
			shotCount=-1;
		}
		if(GetCommonData("Pause",false)){break;}
		if(PlayerEnd){break;}
	yield;
	}
	}

	task MagicMissileTask(SET_KEY)
	{
	let shotCount = -1;
	loop
	{
		if((GetVirtualKeyState(SET_KEY)==KEY_PUSH || GetVirtualKeyState(SET_KEY)==KEY_HOLD) && shotCount==-1)
		{
			shotCount = 0;
		}

		if(shotCount%10 == 0)
		{
			MagicMissile;
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 9)
		{
			shotCount=-1;
		}
		if(GetCommonData("Pause",false)){break;}
		if(PlayerEnd){break;}
	yield;
	}
	}

	task OrreryTask(SET_KEY)
	{
	let shotCount = -1;
	loop
	{
		if((GetVirtualKeyState(SET_KEY)==KEY_PUSH || GetVirtualKeyState(SET_KEY)==KEY_HOLD) && shotCount==-1)
		{
			shotCount = 0;
		}

		if(shotCount%10 == 0)
		{
			Orrery(GetPlayerX(), GetPlayerY(), 4, CharaDirection*45-90, 1.0, 1, 3);
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 9)
		{
			shotCount=-1;
		}
		if(GetCommonData("Pause",false)){break;}
		if(PlayerEnd){break;}
	yield;
	}
	}

	task ColdInfernoTask(SET_KEY)
	{
	let shotCount = -1;
	loop
	{
		if((GetVirtualKeyState(SET_KEY)==KEY_PUSH || GetVirtualKeyState(SET_KEY)==KEY_HOLD) && shotCount==-1)
		{
			shotCount = 0;
		}

		if(shotCount%10 == 0)
		{
			ColdInferno(GetPlayerX(), GetPlayerY(), 4, CharaDirection*45-90, 1.0, 1, 3);
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 9)
		{
			shotCount=-1;
		}
		if(GetCommonData("Pause",false)){break;}
		if(PlayerEnd){break;}
	yield;
	}
	}

	task OrrerysSunTask(SET_KEY)
	{
	let shotCount = -1;
	loop
	{
		if((GetVirtualKeyState(SET_KEY)==KEY_PUSH || GetVirtualKeyState(SET_KEY)==KEY_HOLD) && shotCount==-1)
		{
			shotCount = 0;
		}

		if(shotCount%10 == 0)
		{
			OrrerysSun(SET_KEY);
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 9)
		{
			shotCount=-1;
		}
		if(GetCommonData("Pause",false)){break;}
		if(PlayerEnd){break;}
	yield;
	}
	}

	task StarDustTask(SET_KEY)
	{
	let shotCount = -1;
	loop
	{
		if((GetVirtualKeyState(SET_KEY)==KEY_PUSH || GetVirtualKeyState(SET_KEY)==KEY_HOLD) && shotCount==-1)
		{
			shotCount = 0;
		}

		if(shotCount%10 == 0)
		{
			StarDust;
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 9)
		{
			shotCount=-1;
		}
		if(GetCommonData("Pause",false)){break;}
		if(PlayerEnd){break;}
	yield;
	}
	}

	task StarDustReverieTask(SET_KEY)
	{
	let shotCount = -1;
	loop
	{
		if((GetVirtualKeyState(SET_KEY)==KEY_PUSH || GetVirtualKeyState(SET_KEY)==KEY_HOLD) && shotCount==-1)
		{
			shotCount = 0;
		}

		if(shotCount%10 == 0)
		{
			StarDustReverie;
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 9)
		{
			shotCount=-1;
		}
		if(GetCommonData("Pause",false)){break;}
		if(PlayerEnd){break;}
	yield;
	}
	}

#include"./skill/MagicShot.txt"
#include"./skill/RappidShot.txt"
#include"./skill/MagicNapalm.txt"
#include"./skill/MagicMissile.txt"
#include"./skill/Orrery.txt"
#include"./skill/ColdInferno.txt"
#include"./spell/OrrerysSun.txt"
#include"./skill/IllusionLaser.txt"
#include"./skill/StreamLaser.txt"
#include"./skill/RiseLaser.txt"
#include"./spell/StarDust.txt"
#include"./spell/StarDustReverie.txt"
}

task SpellPointTask
{
yield;
while(GetCommonData("Title",false)){yield;}
loop
{
	if(!OnDash && GetCommonData("SceneChange",false)==false)
	{
	SpellPoint+=SpellRecover;
	}
	if(SpellPoint>=100){SpellPoint=100;}
yield;
}

}

task SpiritPointTask
{
loop
{
	if(!OnDash && GetCommonData("SceneChange",false)==false)
	{
	SpiritPoint+=SpiritRecover;
	}
	if(SpiritPoint>=100){SpiritPoint=100;}
yield;
}

}



task ShieldTask
{
loop
{
	if(PlayerShield==false)
	{
		if(GetCommonData("SceneChange",false)==false)
		{
		ShieldCount+=ShieldRecover;
		}
		if(ShieldCount>=ShieldGaugeMax)
		{
			PlayerShield=true;
			ShieldRebirthEffect;
			ShieldGaugeMax+=100*ShieldReduce;
			ShieldCount=0;
		}
	}
	else
	{
		ShieldCount=0;
	}
yield;
}
}

task CriticalHitTask
{
Obj_SetValue(GetPlayerObjectID,"CriticalHit",false);
yield;
while(GetCommonData("Title",false)){yield;}
loop
{
	if(Obj_GetValue(GetPlayerObjectID,"CriticalHit"))
	{
		ShieldCount+=1;
		SpiritPoint+=1;
		SpellPoint+=1;
		Obj_SetValue(GetPlayerObjectID,"CriticalHit",false);
	}
yield;
}

}

#include"./PlayerSystem.txt"

task Obj_PlaySE(path)
{
	let obj = ObjSound_Create;
	ObjSound_Load(obj,path);
	ObjSound_SetSoundDivision(obj,SOUND_SE);
	ObjSound_SetLoopEnable(obj,false);
	ObjSound_Play(obj);

	ObjSound_SetVolumeRate(obj,GetCommonData("SEVolume",100));
}
