script_enemy_main{

let character="Mai";
let cutin=character;
let dispelled=0;
let spellcards=3;
if(GetCommonData("Difficulty")>=3){ spellcards=4; }
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=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 SEshots6=("script\SoundEffects\shots6.wav");
let SEshotm3=("script\SoundEffects\shotm3.wav");
let GRboss=("\script\Images\CharacterSprites\Mai.png");

#include_function "script/Functions/HealthBarLoad.txt";

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

	LoadSE("script\SoundEffects\shots6.wav");
	LoadSE("script\SoundEffects\shotm3.wav");
	LoadGraphic("\script\Images\CharacterSprites\Mai.png");

	SetLife(250);
	SetTimer(30);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	SetEnemyMarker(true);
	MagicCircle(true);

	SetX(GetCommonData("Boss2X"));
	SetY(GetCommonData("Boss2Y"));
	
	SetCommonData("Boss1Move",3);
	
	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

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

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

HealthBar();

if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}


if(GetCommonData("Difficulty")==1){
if(time>=60 && time%10==0){
let angle=time*2.23;
	loop(3){
	let shot1=0;
	let delay=0;
let radius=80;
	CreateShotA(shot1,GetX+radius*cos(-angle),GetY+radius*sin(-angle),10);
	SetShotDataA(shot1,0,1.5,-angle,0,0,0,16);
		loop(8){
		SetShotDataA(shot1,delay,NULL,NULL,0,0.02,1.5,16);
		SetShotDataA(shot1,60+delay,NULL,NULL,0,-0.02,0.5,160);
		delay+=120;
		}
	FireShot(shot1);
	angle+=360/3;
	}
PlaySE(SEshots6);
}
if(time%80==0&& time>=60){
SetShotDirectionType(PLAYER);
let angle=-10+rand(-3,3);
	loop(3){
	let speed=2.5;
		loop(2){
		CreateShot01(GetX-10,GetY-20,speed,angle,59,0);
		speed-=0.8;
		}
	angle+=20/2;
	}
PlaySE(SEshotm3);
SetShotDirectionType(ABSOLUTE);
usespell=20;
}
} //Easy

//=============================================================================================================

if(GetCommonData("Difficulty")==2){
if(time>=60 && time%8==0){
let angle=time*1.67;
	loop(4){
	let shot1=0;
	let delay=0;
let radius=80+10*cos(time);
	CreateShotA(shot1,GetX+radius*cos(angle),GetY+radius*sin(angle),10);
	SetShotDataA(shot1,0,1.5,angle,0,0,0,16);
		loop(8){
		SetShotDataA(shot1,delay,NULL,NULL,0,0.02,1.5,16);
		SetShotDataA(shot1,50+delay,NULL,NULL,0,-0.02,0.5,160);
		delay+=100;
		}
	FireShot(shot1);
	angle+=360/4;
	}
PlaySE(SEshots6);
}
if(time%80==0&& time>=60){
SetShotDirectionType(PLAYER);
let angle=-20+rand(-3,3);
	loop(5){
	let speed=2.5;
		loop(2){
		CreateShot01(GetX-10,GetY-20,speed,angle,59,0);
		speed-=0.8;
		}
	angle+=40/4;
	}
PlaySE(SEshotm3);
SetShotDirectionType(ABSOLUTE);
usespell=20;
}
} //Normal

//=============================================================================================================

if(GetCommonData("Difficulty")==3){
if(time>=60 && time%6==0){
let angle=time*1.13;
	loop(5){
	let shot1=0;
	let delay=0;
let radius=80+15*cos(time);
	CreateShotA(shot1,GetX+radius*cos(angle),GetY+radius*sin(angle),10);
	SetShotDataA(shot1,0,1.5,angle,0,0,0,16);
		loop(8){
		SetShotDataA(shot1,delay,NULL,NULL,0,0.02,1.5,16);
		SetShotDataA(shot1,45+delay,NULL,NULL,0,-0.02,0.5,160);
		delay+=90;
		}
	FireShot(shot1);
	angle+=360/5;
	}
PlaySE(SEshots6);
}
if(time%60==0&& time>=60){
SetShotDirectionType(PLAYER);
let angle=-15+rand(-2,2);
	loop(5){
	let speed=2.5;
		loop(3){
		CreateShot01(GetX-10,GetY-20,speed,angle,59,0);
		speed-=0.5;
		}
	angle+=30/4;
	}
PlaySE(SEshotm3);
SetShotDirectionType(ABSOLUTE);
usespell=20;
}
} //Hard

//=============================================================================================================

if(GetCommonData("Difficulty")==4){
if(time>=60 && time%4==0){
let angle=time*1.26;
	loop(6){
	let shot1=0;
	let delay=0;
let radius=80+20*cos(time);
	CreateShotA(shot1,GetX+radius*cos(angle),GetY+radius*sin(angle),10);
	SetShotDataA(shot1,0,1.5,angle,0,0,0,16);
		loop(8){
		SetShotDataA(shot1,delay,NULL,NULL,0,0.02,1.5,16);
		SetShotDataA(shot1,45+delay,NULL,NULL,0,-0.02,0.5,160);
		delay+=90;
		}
	FireShot(shot1);
	angle+=360/6;
	}
PlaySE(SEshots6);
}
if(time%60==0&& time>=60){
SetShotDirectionType(PLAYER);
let angle=-20+rand(-2,2);
	loop(7){
	let speed=2.5;
		loop(3){
		CreateShot01(GetX-10,GetY-20,speed,angle,59,0);
		speed-=0.4;
		}
	angle+=40/6;
	}
PlaySE(SEshotm3);
SetShotDirectionType(ABSOLUTE);
usespell=20;
}
} //Lunatic


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

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

@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); }
	}
	if(GetLife>0){ DrawGraphic(GetX,GetY); }
}
 
@Finalize{
}

}