script_enemy_main{

let moonradius=110;

let whitetime=-90;
let redtime=-90;
let greentime=-90;
let bluetime=-90;

let character="Amaya";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=10;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshots7=("\script\SoundEffects\shots7.wav");
let SEshotb5=("\script\SoundEffects\shotb5.wav");

let BG1=("\script\Images\BackgroundLayers\Witches1.png");
let BG2a=("\script\Images\BackgroundLayers\Amaya2a.png");
let BG2b=("\script\Images\BackgroundLayers\Amaya2b.png");
let GRboss=("\script\Images\CharacterSprites\Amaya.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsAmaya1.txt");

	LoadSE("\script\SoundEffects\shots7.wav");
	LoadSE("\script\SoundEffects\shotb5.wav");

	LoadGraphic(GRboss);
	LoadGraphic("\script\Images\BackgroundLayers\Witches1.png");
	LoadGraphic("\script\Images\BackgroundLayers\Amaya2a.png");
	LoadGraphic("\script\Images\BackgroundLayers\Amaya2b.png");

	SetScore(300000);
	SetLife(300);
	SetTimer(50);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(100,100,100,100);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=7; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Lunar Effect [Lunacy] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


if(time==45){ CreateEnemyFromFile(("script\Functions\spellcardwarning.txt"),0,0,0,0,0); }

if(time==150){
let a=0;
	SetCommonData("FamiliarType",1);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Amaya - Lunacy - Familiar.txt",minx,miny,0,0,0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Amaya - Lunacy - Familiar.txt",maxx,miny,0,0,0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Amaya - Lunacy - Familiar.txt",maxx,maxy,0,0,0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Amaya - Lunacy - Familiar.txt",minx,maxy,0,0,0);
	SetCommonData("FamiliarType",2);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Amaya - Lunacy - Familiar.txt",minx,miny,0,0,0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Amaya - Lunacy - Familiar.txt",maxx,miny,0,0,0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Amaya - Lunacy - Familiar.txt",maxx,maxy,0,0,0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Amaya - Lunacy - Familiar.txt",minx,maxy,0,0,0);
}


if(time>=150 && time%180==0){
let angle2=GetAngleToPlayer;
	loop(3){
		loop(13){
		CreateShot01(cx,cy,1,angle2,45,10);
		angle2+=360/13;
		}
	}
usespell=-30;
PlaySE(SEshotb5);
}


moonradius=100-60*cos(time/2);
SetCommonData("Radius",moonradius);


if(time<180){ whitetime+=0.5; redtime+=0.5; greentime+=0.5; bluetime+=0.5; }
if(time>=180){ whitetime+=0.5; redtime+=0.6; greentime+=0.7; bluetime+=0.4; }


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";
}

@BackGround{
	if(time>=120 && bgfade<255){ bgfade+=5; }

	SetGraphicRect(0,0,512,512);
	SetGraphicScale(1.5,1.5);
	SetTexture(BG1);
	SetAlpha(bgfade/2);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,time/50);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(moonradius/110,moonradius/110);
	SetTexture(BG2a);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,whitetime);
	DrawGraphic(cx,cy);


	SetGraphicRect(0,0,300,300);
	SetGraphicScale(moonradius/110,moonradius/110);
	SetTexture(BG2b);
	SetAlpha(bgfade);
	SetColor(bgfade,0,0);
	SetRenderState(ADD);
	SetGraphicAngle(0,0,redtime);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(moonradius/110,moonradius/110);
	SetTexture(BG2b);
	SetAlpha(bgfade);
	SetColor(0,bgfade,0);
	SetRenderState(ADD);
	SetGraphicAngle(0,0,greentime);
	DrawGraphic(cx,cy);

	SetGraphicRect(0,0,300,300);
	SetGraphicScale(moonradius/110,moonradius/110);
	SetTexture(BG2b);
	SetAlpha(bgfade);
	SetColor(0,0,bgfade);
	SetRenderState(ADD);
	SetGraphicAngle(0,0,bluetime);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
	
	if(Continued==false && GotSpellCardBonus && GetCommonData("TrumpCardUnlocked")[9]==0){
		let spellcarddataarray=GetCommonData("NewTrumpCardsUnlocked");
		spellcarddataarray[9]=1;
		SetCommonData("NewTrumpCardsUnlocked",spellcarddataarray);	

		let spellcarddataarray=GetCommonData("TrumpCardUnlocked");
		spellcarddataarray[9]=1;
		SetCommonData("TrumpCardUnlocked",spellcarddataarray);
		
		let spellcarddataarray=GetCommonData("SpellcardData");
		spellcarddataarray[76]=0.5;
		SetCommonData("SpellcardData",spellcarddataarray);
		
		SetCommonData("NewTrumpCardUnlocked",true);
		SaveCommonData;
	}
}

}