//Graphical Effect Script

let CSD = GetCurrentScriptDirectory;
let MD = GetModuleDirectory;

#include"./../LIB/SE_Const.dnh"
#include"./../LIB/Function_Misc.dnh"
#include"./../LIB/Function_Audio.dnh"

let END_FAILED = 1;
let END_SUCCESS = 2;
let typeEnd = END_FAILED;
let SpellID = "";

@Initialize {
	
}

@MainLoop {
	yield;
}

@Event {
	alternative(GetEventType)
	case(EV_DELETE_SHOT) {
		let eventParam = GetEventArgument(0);
		BulletDeleteEffect(eventParam[0],eventParam[1],eventParam[2]);
		// BulletDelete(eventParam);
	}
	case(EV_DELETE_LASER) {
		let eventParam = GetEventArgument(0);
		LaserDelete(eventParam[0],eventParam[1]);
	}
	case(EV_DELETE_WAVE) {
		let eventParam = GetEventArgument(0);
		DeleteShotWave(eventParam[0],eventParam[1],eventParam[2],eventParam[3]);
	}
	case(EV_EXPLODE) {
		let eventParam = GetEventArgument(0);
		let objEnemy = eventParam[1][0];
		let type = eventParam[0][0];
		alternative(type)
		case(1) { ExplosionA1(objEnemy,eventParam[2],eventParam[3]); }
		case(2) { ExplosionA2(objEnemy,eventParam[2],eventParam[3]); }
		case(3) { ExplosionB1(objEnemy,eventParam[2],eventParam[3]); }
		case(4) { ExplosionB2(objEnemy,eventParam[2],eventParam[3]); }
		case(5) { ExplosionB3(objEnemy,eventParam[2],eventParam[3]); }
		case(6) { ExplosionB4(objEnemy,eventParam[2],eventParam[3]); }
		case(7) { ExplosionRainbow(objEnemy); }
		case(8) { PPCExplode(objEnemy,eventParam[2]); }
		case(9) { PPCExplodeRainbow(objEnemy); }
	}
	case(EV_CONCENTRATION) {
		let eventParam = GetEventArgument(0);
		let objEnemy = eventParam[1][0];
		let type = eventParam[0][0];
		alternative(type)
		case(1) { ConcentrationA1(objEnemy,eventParam[2][0],eventParam[3][0],eventParam[4][0],eventParam[5]); }
		case(2) { ConcentrationA2(objEnemy,eventParam[2][0],eventParam[3][0],eventParam[4][0],eventParam[5]); }
		case(3) { ConcentrationA3(objEnemy,eventParam[2][0],eventParam[3][0],eventParam[4][0]); }
		case(4) { ConcentrationA4(objEnemy,eventParam[2][0],eventParam[3][0],eventParam[4][0],eventParam[5]); }
		case(5) { ConcentrationRainbowA1(objEnemy,eventParam[2][0],eventParam[3][0],eventParam[4][0]); }
		case(6) { ConcentrationB1(objEnemy,eventParam[2][0],eventParam[3][0],eventParam[4][0],eventParam[5]); }
		case(7) { ConcentrationB2(objEnemy,eventParam[2][0],eventParam[3][0],eventParam[4][0],eventParam[5]); }
	}
	case(EV_BOSS_EFFECT) {
		let eventParam = GetEventArgument(0);
		BossEffects(eventParam);
	}
	case(EV_GAIN_SPELL){
		let objScene = GetEnemyBossSceneObjectID;
		let score = ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE);
		if(!IsReplay) {
			SetAreaCommonData(SpellID,"Success",GetAreaCommonData(SpellID,"Success",0)+1);
		}
		GotSpellCard(round(score/10)*10);
		AddScore(round(score/10)*10);
		typeEnd = END_SUCCESS;
	}
	case(EV_START_BOSS_SPELL){
		SpellID = Obj_GetValueD(GetEnemyBossObjectID[0],"Spell ID","000");
		let SpellCardName = Obj_GetValueD(GetEnemyBossObjectID[0],"Spell Name","??????????");
		let CutImg = Obj_GetValueD(GetEnemyBossObjectID[0],"Cut Image",[""]);
		let CutType = Obj_GetValueD(GetEnemyBossObjectID[0],"Cut Type","TABLE");
		if(!IsReplay) {
			SetAreaCommonData(SpellID,"Attempt",GetAreaCommonData(SpellID,"Attempt",0)+1);
		}
		cutin(SpellID,CutType,SpellCardName,CutImg);
		MagicCircle;
		Nullity;
		typeEnd = 0;
	}
	case(EV_END_BOSS_STEP) {
		if(typeEnd == 0) {
			typeEnd = END_FAILED;
			BonusFailed;
		}
	}
	case(EV_EXTEND) {
		Extend;
	}
	case(EV_GET_SPELL) {
		GetSpell;
	}
	case(EV_MAX_BALANCE) {
		MaxBalance;
	}
	case(EV_FULL_POWER) {
		FullPowerUp;
	}
	case(EV_HISCORE) {
		HiScore;
	}
}
task DeleteShotWave(type,x,y,speed) {
	let r = 0;
	if(type==1) {
		loop(120) {
			DeleteShotInCircle(TYPE_ALL,TYPE_ITEM,x,y,r);
			r+=speed;
			yield;
		}
	}
	if(type==2) {
		loop(120) {
			let ShotAll = GetShotIdInCircleA2(GetStgFrameWidth/2,GetStgFrameHeight/2,r,TARGET_ENEMY);
			ascent(i in 0..length(ShotAll)) {
				BulletDeleteEffect(ObjMove_GetX(ShotAll[i]),ObjMove_GetY(ShotAll[i]),ObjShot_GetImageID(ShotAll[i]));
				Obj_Delete(ShotAll[i]);
			}
			r+=speed;
			yield;
		}
	}
}
task BulletDelete(obj) {
	let xpos = 0;
	let ypos = 0;
	let graphic = 0;
	while(!Obj_IsDeleted(obj)) {
		xpos = ObjMove_GetX(obj);
		ypos = ObjMove_GetY(obj);
		graphic = ObjShot_GetImageID(obj);
		yield;
	}
	BulletDeleteEffect(xpos,ypos,graphic);
}
task LaserDelete(obj,width) {
	let xpos = 0;
	let ypos = 0;
	let angle = 0;
	let length = 0;
	let graphic = 0;
	while(!Obj_IsDeleted(obj)) {
		xpos = ObjMove_GetX(obj);
		ypos = ObjMove_GetY(obj);
		angle = ObjMove_GetAngle(obj);
		length = ObjLaser_GetLength(obj);
		graphic = ObjShot_GetImageID(obj);
		yield;
	}
	let deletelength = length/20;
	let deletewidth = width/40;
	let DelayColor = GetShotDataInfoA1(graphic,TARGET_ENEMY,INFO_DELAY_COLOR);
	ascent(i in 3..deletelength+3) {
		loop(deletewidth) {
			if(xpos-deletelength*i*cos(angle)+rand(-width/2+16,width/2-16)<GetStgFrameWidth+20 && xpos-deletelength*i*cos(angle)+rand(-width/2+16,width/2-16)>-20 && ypos-deletelength*i*sin(angle)+rand(-width/2+16,width/2-16)<GetStgFrameHeight+20 && ypos-deletelength*i*sin(angle)+rand(-width/2+16,width/2-16)>-20) {
				BulletBreak(xpos-deletelength*i*cos(angle)+rand(-width/2+16,width/2-16),ypos-deletelength*i*sin(angle)+rand(-width/2+16,width/2-16),DelayColor[0],DelayColor[1],DelayColor[2]);
				NotifyEventAll(EV_DELETE_ITEM,[xpos-deletelength*i*cos(angle),ypos-deletelength*i*sin(angle)]);
			}
		}
	}
}
function BulletDeleteEffect(xpos,ypos,graphic) {
	let DelayColor = GetShotDataInfoA1(graphic,TARGET_ENEMY,INFO_DELAY_COLOR);
	if(xpos<GetStgFrameWidth+20 && xpos>-20 && ypos<GetStgFrameHeight+20 && ypos>-20) {
		if(graphic>=284 && graphic<=291) {
			loop(3) { BulletBreak(xpos+rand(-10,10),ypos+rand(-8,8),DelayColor[0],DelayColor[1],DelayColor[2]); }
		}
		if(graphic>=265 && graphic<=272) {
			loop(3) { BulletBreak(xpos+rand(-10,10),ypos+rand(-8,8),DelayColor[0],DelayColor[1],DelayColor[2]); }
		}
		if(graphic>=324 && graphic<=331) {
			loop(3) { BulletBreak(xpos+rand(-10,10),ypos+rand(-8,8),DelayColor[0],DelayColor[1],DelayColor[2]); }
		}
		if(graphic>=292 && graphic<=307) {
			loop(8) { BulletBreak(xpos+rand(-20,20),ypos+rand(-23,23),DelayColor[0],DelayColor[1],DelayColor[2]); }
		}
		if(graphic>=383 && graphic<=390) {
			loop(5) { BulletBreak(xpos+rand(-20,20),ypos+rand(-18,18),DelayColor[0],DelayColor[1],DelayColor[2]); }
		}
		if(graphic>=399 && graphic<=408) {
			loop(5) { BulletBreak(xpos+rand(-20,20),ypos+rand(-18,18),DelayColor[0],DelayColor[1],DelayColor[2]); }
		}
		if(graphic>=272 && graphic<287) {
			loop(5) { BulletBreak(xpos+rand(-20,20),ypos+rand(-18,18),DelayColor[0],DelayColor[1],DelayColor[2]); }
		}
		if(graphic>=355 && graphic<=370) {
			loop(8) { BulletBreak(xpos+rand(-25,25),ypos+rand(-23,23),DelayColor[0],DelayColor[1],DelayColor[2]); }
		}
		else { BulletBreak(xpos,ypos,DelayColor[0],DelayColor[1],DelayColor[2]); }
	}
}
task BulletBreak(xpos,ypos,RED,GREEN,BLUE) {
	let objbreak = ObjPrim_Create(OBJ_SPRITE_2D);
	let w = 3;
	let count = 0;
	let speed = rand(1.3,2);
	let dir = rand(0,360);
	
	Obj_SetRenderPriorityI(objbreak,49);
	ObjPrim_SetTexture(objbreak,PSD ~ "IMG/Effect/BulletBreak.png");
	ObjRender_SetBlendType(objbreak,BLEND_ADD_RGB);
	ObjRender_SetPosition(objbreak,xpos,ypos,0);
	ObjRender_SetAngleXYZ(objbreak,0,0,rand(0,360));
	ObjRender_SetColor(objbreak,RED,GREEN,BLUE);
	
	loop(24) {
		if(count>=w*0) { ObjSprite2D_SetSourceRect(objbreak,0,0,32,32); }
		if(count>=w*1) { ObjSprite2D_SetSourceRect(objbreak,32,0,64,32); }
		if(count>=w*2) { ObjSprite2D_SetSourceRect(objbreak,64,0,96,32); }
		if(count>=w*3) { ObjSprite2D_SetSourceRect(objbreak,96,0,128,32); }
		if(count>=w*4) { ObjSprite2D_SetSourceRect(objbreak,128,0,160,32); }
		if(count>=w*5) { ObjSprite2D_SetSourceRect(objbreak,160,0,192,32); }
		if(count>=w*6) { ObjSprite2D_SetSourceRect(objbreak,192,0,224,32); }
		if(count>=w*7) { ObjSprite2D_SetSourceRect(objbreak,224,0,256,32); }
		ObjSprite2D_SetDestCenter(objbreak);
	
		ObjRender_SetPosition(objbreak,xpos,ypos,0);
		if(speed>0) { speed-=0.10; }
		xpos+=speed*cos(dir);
		ypos+=speed*sin(dir);
		count++;
		yield;
	}
	Obj_Delete(objbreak);
}
task Nullity {
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj, 90);
	ObjPrim_SetTexture(obj, CSD ~ "IMG/Nullity.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 242, 69);
	ObjSprite2D_SetDestCenter(obj);
	
	ObjRender_SetScaleXYZ(obj,0.9,0.9,0.9);
	
	ObjRender_SetPosition(obj,532,116,0);
	
	let objScene = GetEnemyBossSceneObjectID;
	
	while(!Obj_IsDeleted(objScene)) {
		if(ObjEnemyBossScene_GetInfo(objScene,INFO_IS_LAST_SPELL)) { Obj_SetVisible(obj,true); }
		else { Obj_SetVisible(obj,false); }
		yield;
	}
	Obj_Delete(obj);
}
task MagicCircle {
	let countVertex = 64;
	let listRadius = [];
	loop(countVertex) {
		listRadius = listRadius ~ [0];
	}

	let path = CSD ~ "IMG/Default_MagicCircle.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetVertexCount(obj, countVertex);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriority(obj, 0.3);
	ObjPrim_SetTexture(obj, path);
	ascent(iVert in 0..countVertex / 2)	{
		let left = iVert * 128;
		let indexVert = iVert * 2;
		ObjPrim_SetVertexUVT(obj, indexVert + 0, left, 0);
		ObjPrim_SetVertexUVT(obj, indexVert + 1, left, 64);		
	}

	let objScene = GetEnemyBossSceneObjectID();
	let objBoss = GetEnemyBossObjectID()[0];
	let timerOrg = ObjEnemyBossScene_GetInfo(objScene, INFO_ORGTIMERF);
	let bLastSpell = ObjEnemyBossScene_GetInfo(objScene, INFO_IS_LAST_SPELL);

	let cx = 0;
	let cy = 0;
	let maxRadius = 256 * 1.2;
	let alpha = 0;
	let frame = 0;
	let angleRender = 0;

	function GetPlayerX {
		let objPlayer = GetPlayerObjectID();
		return ObjRender_GetX(objPlayer);
	}

	function GetPlayerY {
		let objPlayer = GetPlayerObjectID();
		return ObjRender_GetY(objPlayer);
	}

	function UpdateVertex {
		if(bLastSpell) {
			ObjRender_SetColor(obj, 255 * alpha, 192 * alpha, 192 * alpha);
		}
		else {
			ObjRender_SetColor(obj, 192 * alpha, 192 * alpha, 255 * alpha);
		}

		ObjRender_SetPosition(obj, cx, cy, 0);
		ObjRender_SetAngleZ(obj, angleRender);
	}

	PlaySoundEffect(spell,100);

	while(typeEnd == 0) {
		if(!Obj_IsDeleted(objBoss)) {
			cx = ObjRender_GetX(objBoss);
			cy = ObjRender_GetY(objBoss);
			if(cx<-400) { cx = GetStgFrameWidth/2; cy = GetStgFrameHeight/2; }
		}

		alpha += 1 / 120;
		alpha = min(alpha, 1);
		angleRender += 360 / countVertex / 4;

		let timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMERF);
		let rRate = timer / timerOrg;
		let bMiss = ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) > 0 ||
					 ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) > 0 ;

		ascent(iVert in 0..countVertex / 2)	{
			let indexVert = iVert * 2;
			let angle = 360 / (countVertex / 2 - 1) * iVert;

			let vx1 = listRadius[indexVert] * cos(angle);
			let vy1 = listRadius[indexVert] * sin(angle);
			ObjPrim_SetVertexPosition(obj, indexVert + 0, vx1, vy1, 0);

			let vx2 = listRadius[indexVert+1] * cos(angle);
			let vy2 = listRadius[indexVert+1] * sin(angle);
			ObjPrim_SetVertexPosition(obj, indexVert + 1, vx2, vy2, 0);

			if(frame >= 0) {
				let dr = (maxRadius * rRate - listRadius[indexVert]) / 16;
				listRadius[indexVert] = listRadius[indexVert] + dr;
			}
			if(frame > 45) {
				let rRateIn = rRate - 0.08;
				if(bMiss)
				{
					rRateIn = rRate - 0.04;
				}
				if(rRateIn < 0){rRateIn=0;}
				let dr= (maxRadius * rRateIn - listRadius[indexVert + 1]) / 64;
				listRadius[indexVert + 1] = listRadius[indexVert + 1] + dr;
			}

		}

		UpdateVertex();
		frame++;

		yield;
	}

	if(typeEnd == END_FAILED) {
		Obj_Delete(obj);
		loop(150) { yield; }
		return;
	}

	PlaySoundEffect(cardget,100);

	let rRate = 1.0;
	frame = 0;
	alpha = 1;
	loop(105) {
		angleRender += 360 / countVertex / 4;
		let dx = (GetPlayerX() - cx) / 16;
		let dy = (GetPlayerY() - cy) / 16;
		cx += dx;
		cy += dy;
		if(frame >= 45)
		{
			alpha -= 1 / 45;
			alpha = max(alpha, 0);
		}

		ascent(iVert in 0..countVertex / 2) {
			let indexVert = iVert * 2;
			let angle = 360 / (countVertex / 2 - 1) * iVert;

			let vx1 = listRadius[indexVert] * cos(angle);
			let vy1 = listRadius[indexVert] * sin(angle);
			ObjPrim_SetVertexPosition(obj, indexVert + 0, vx1, vy1, 0);

			let vx2 = listRadius[indexVert+1] * cos(angle);
			let vy2 = listRadius[indexVert+1] * sin(angle);
			ObjPrim_SetVertexPosition(obj, indexVert + 1, vx2, vy2, 0);

			let drOut = 0;
			let drIn = 0;
			if(frame <= 45)	{
				let rRateOut = 1.0;
				drOut = (maxRadius * rRateOut - listRadius[indexVert]) / 8;

				let rRateIn = rRateOut - 0.08;
				if(rRateIn<0){rRateIn=0;}
				drIn = (maxRadius * rRateIn - listRadius[indexVert+1]) / 8;
			}
			else {
				cx = GetPlayerX();
				cy = GetPlayerY();

				rRate -= 1.0 / 60.0;
				let rRateOut = rRate * sin(angle % 60);
				drOut = (maxRadius * rRateOut - listRadius[indexVert]) / 16;

				let rRateIn = rRate * sin(angle % 60)-0.08;
				if(rRateIn<0){rRateIn=0;}
				drIn=(maxRadius * rRateIn - listRadius[indexVert+1])/16;
			}
			listRadius[indexVert] = listRadius[indexVert] + drOut;
			listRadius[indexVert + 1] = listRadius[indexVert + 1] + drIn;
		}

		UpdateVertex;
		frame++;
		yield;
	}

	Obj_Delete(obj);
}
task GotSpellCard(score){
	let path = CSD ~ "IMG/system.png";
	let objText = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let maxscale = 2;
	let scale = 0;
	let alpha = 0;
	
	ObjPrim_SetTexture(objText, path);
	ObjSprite2D_SetSourceRect(objText, 0, 96, 256, 136);
	ObjSprite2D_SetDestCenter(objText);
	Obj_SetRenderPriorityI(objText, 80);
	ObjRender_SetPosition(objText, GetStgFrameWidth/2, 98, 0);
	
	let objScore = ObjText_Create;
	ObjText_SetFontSize(objScore,26);
	ObjText_SetFontType(objScore, "Crystal clear");
	ObjText_SetFontColorTop(objScore,255,255,255);
	ObjText_SetFontColorBottom(objScore,180,180,180);
	ObjText_SetFontBorderType(objScore,BORDER_FULL);
	ObjText_SetFontBorderWidth(objScore,2);
	ObjText_SetFontBorderColor(objScore,0,0,0);
	ObjText_SetHorizontalAlignment(objScore,ALIGNMENT_CENTER);
	ObjText_SetMaxWidth(objScore,300);
	Obj_SetRenderPriorityI(objScore,80);
	
	ObjText_SetText(objScore,ToCommas(score));
	ObjRender_SetPosition(objScore,GetStgFrameWidth/2-150,120,0);
	
	ObjText_SetAutoTransCenter(objScore,false);
	ObjText_SetTransCenter(objScore,GetStgFrameWidth/2*(3/4),12);
	
	ascent(i in 0..30){
		alpha+=255/25;
		scale = maxscale - scale*sin(90*i/30);
		ObjRender_SetScaleXYZ(objScore, scale, scale, scale);
		ObjRender_SetScaleXYZ(objText, scale, scale, scale);
		ObjRender_SetAlpha(objScore, alpha);
		ObjRender_SetAlpha(objText, alpha);
		yield;
	}
	
	loop(120){ yield; }
	
	loop(25){
		ObjRender_SetScaleXYZ(objScore, 1, scale, 1);
		ObjRender_SetScaleXYZ(objText, 1, scale, 1);
		scale-=1/25;
		yield;
	}
	
	
	Obj_Delete(objText);
	Obj_Delete(objScore);
}
function ToCommas(input) {
	let number = "";
	let num = length(IntToString(input));
	let digit = num%3;
		descent(i in 0..num) {
			number = number ~ ToString(IntToString(input)[num-i-1]);
			if(num>3) {
				if(i%3 == 0 && i != 0) {
					number = number ~ ",";
				}
			}
		}
	return number;
}
task cutin(SpellID,type,SpellCardName,CutImg) {
	let objScene = GetEnemyBossSceneObjectID;
	let objEnemy = ID_INVALID;
	if(length(GetEnemyBossObjectID)>0) { objEnemy = GetEnemyBossObjectID[0]; }
	descent(i in 0..length(CutImg)) { Cut(i); }
	SpellText;
	if(GetAreaCommonData("Options","ScrollingText",true)) { ScrollingText; }

	task Cut(num) {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let alpha = 220;
		let count = 0;
		let x = 0;
		let y = 0;

		let s = 0.8;
		let f = 0;
		let g = 0;
		if(type=="NAZRIN") {
			x = GetStgFrameWidth+256;
			y = GetStgFrameHeight/2-100;
		}
		if(num==0) { 
			if(type=="TABLE") {
				x = -40;
				y = GetStgFrameHeight/2+10;
			}
		}
		if(num==1) { 
			if(type=="TABLE") {
				x = GetStgFrameWidth+40;
				y = GetStgFrameHeight/2+10;
			}
		}
		if(num==2) { 
			if(type=="TABLE") {
				x = GetStgFrameWidth/2-25;
				y = GetStgFrameHeight+20;
			}
		}
		ObjRender_SetBlendType(obj,BLEND_ALPHA);
		ObjPrim_SetTexture(obj,CutImg[num]);
		Obj_SetRenderPriorityI(obj,27);
		ObjSprite2D_SetSourceRect(obj,0,0,GetTextureWidth(CutImg[num]),GetTextureHeight(CutImg[num]));
		ObjSprite2D_SetDestCenter(obj);


		while(!Obj_IsDeleted(obj)){
			if(type=="NAZRIN") {
				if(count<21){x-=20; y+=5}
				if(count>=21 && count<100){ x--; y+=0.5; }
				if(count>=100){x-=20; y+=5;}
				if(count>120){ Obj_Delete(obj); }
				ObjRender_SetScaleXYZ(obj,s,s,0);
				ObjRender_SetPosition(obj,x,y,0);
				ObjRender_SetAlpha(obj,alpha);
			}
			if(num==0) { 
				if(type=="TABLE") {
					if(count<30){ x+=20-g; g+=20/30; }
					if(count>=95){ s+=0.02-f; f+=0.0005; alpha-=220/40; }
					if(count>185){ Obj_Delete(obj); }
					ObjRender_SetScaleXYZ(obj,s,s,0);
					ObjRender_SetPosition(obj,x,y,0);
					ObjRender_SetAlpha(obj,alpha);
				}
			}
			if(num==1) { 
				if(type=="TABLE") {
					if(count<30){ x-=20-g; g+=20/30; }
					if(count>=95){ s+=0.02-f; f+=0.0005; alpha-=220/40; }
					if(count>185){ Obj_Delete(obj); }
					ObjRender_SetScaleXYZ(obj,s,s,0);
					ObjRender_SetPosition(obj,x,y,0);
					ObjRender_SetAlpha(obj,alpha);
				}
			}
			if(num==2) { 
				if(type=="TABLE") {
					if(count<30){ y-=20-g; g+=20/30; }
					if(count>=95){ s+=0.02-f; f+=0.0005; alpha-=220/40; }
					if(count>185){ Obj_Delete(obj); }
					ObjRender_SetScaleXYZ(obj,s,s,0);
					ObjRender_SetPosition(obj,x,y,0);
					ObjRender_SetAlpha(obj,alpha);
				}
			}
			count++;
			yield;
		}
	
	}
	task ScrollingText {
		ascent(i in -6..12) {
			Text(-200+i*120,-200,135);
			Text(-200+i*120+30,-200+30,315);
		}
		task Text(x,y,dir) {
			let objAttack = ObjPrim_Create(OBJ_SPRITE_2D);
			let a = 0;
			
			ObjRender_SetBlendType(objAttack,BLEND_ALPHA);
			Obj_SetRenderPriorityI(objAttack,26);
			ObjPrim_SetTexture(objAttack,CSD ~ "IMG/SpellCardAttack.png");
			ObjSprite2D_SetSourceRect(objAttack,-192*8,0,192*8,16);
			ObjSprite2D_SetDestCenter(objAttack);
			if(dir == 135) { ObjRender_SetAngleZ(objAttack,dir-180); }
			if(dir == 315) { ObjRender_SetAngleZ(objAttack,dir); }
			
			loop(30) {
				ObjRender_SetAlpha(objAttack,a);
				ObjRender_SetPosition(objAttack,x,y,0);
				x+=2.5*cos(dir);
				y+=2.5*sin(dir);
				a+=255/30;
				yield;
			}
			loop(70) {
				ObjRender_SetPosition(objAttack,x,y,0);
				x+=3*cos(dir);
				y+=3*sin(dir);
				yield;
			}
			loop(30) {
				ObjRender_SetAlpha(objAttack,a);
				ObjRender_SetPosition(objAttack,x,y,0);
				x+=3*cos(dir);
				y+=3*sin(dir);
				a-=255/30;
				yield;
			}
			Obj_Delete(objAttack);
		}
	}
	task SpellText {
		let objtext = ObjText_Create;
		let x1 = GetStgFrameWidth/2-115;
		let a = 0;
		let a2 = 0;
		let y1 = 370;
		let scale = 1.5;
		
		ObjText_SetText(objtext,SpellCardName);
		ObjText_SetFontSize(objtext,12);
		ObjText_SetFontColorTop(objtext,255,255,255);
		ObjText_SetFontColorBottom(objtext,180,0,255);
		ObjText_SetFontBorderType(objtext,BORDER_SHADOW);
		ObjText_SetFontBorderWidth(objtext,1);
		ObjText_SetFontBorderColor(objtext,0,0,0);
		ObjText_SetHorizontalAlignment(objtext,ALIGNMENT_RIGHT);
		ObjText_SetMaxWidth(objtext,300);
		Obj_SetRenderPriorityI(objtext,70);
		
		SpellBG;
		SpellBonus;
		SpellHistory;
		
		loop(20) {
			ObjRender_SetPosition(objtext,x1,y1,0);
			ObjRender_SetAlpha(objtext,a);
			if(a<255) { a+=255/20; }
			if(x1>GetStgFrameWidth/2-20) { x1-=30/20; }
			if(scale>1) { scale-=0.5/20; }
			yield;
		}
		loop(45) { yield; }
		a2 = a;
		if(GetAreaCommonData("Options","LifeBar",true)) { SetMovePosition01(objtext,x1,30,6,9); }
		else { SetMovePosition01(objtext,x1,30+7,6,9); }
		while(!Obj_IsDeleted(objEnemy)) {
			//ObjRender_SetY(objtext,y1);
			ObjText_SetText(objtext,SpellCardName);
			ObjRender_SetAlpha(objtext,a2);
			if(GetPlayerY<90 && a2>a-180) {
				a2-=10;
			}
			else if(a2<a) {
				a2+=10;
			}
			//if(y1>30) { y1-=365/60; }
			yield;
		}
		loop(20) {
			ObjRender_SetX(objtext,ObjRender_GetX(objtext)+15);
			yield;
		}
		Obj_Delete(objtext);
		
		task SpellBG {
			let objbg = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjRender_SetBlendType(objbg,BLEND_ALPHA);
			Obj_SetRenderPriorityI(objbg,69);
			ObjPrim_SetTexture(objbg,GetCurrentScriptDirectory ~ "IMG/SpellBG.png");
			ObjSprite2D_SetSourceRect(objbg,0,0,256,35);
			ObjSprite2D_SetDestRect(objbg,-256,0,0,35);
			
			loop(20) {
				ObjRender_SetPosition(objbg,GetStgFrameWidth,356,0);
				ObjRender_SetAlpha(objbg,a);
				ObjRender_SetScaleXYZ(objbg,scale,scale,0);
				yield;
			}
			loop(45) { yield; }
			if(GetAreaCommonData("Options","LifeBar",true)) { SetMovePosition01(objbg,GetStgFrameWidth,30-14,6,9); }
			else { SetMovePosition01(objbg,GetStgFrameWidth,30-14+7,6,9); }
			while(!Obj_IsDeleted(objEnemy)) {
				//ObjRender_SetY(objbg,y1-14);
				ObjRender_SetAlpha(objbg,a2);
				yield;
			}
			loop(20) {
				ObjRender_SetX(objbg,ObjRender_GetX(objbg)+15);
				yield;
			}
			Obj_Delete(objbg);
		}
		task SpellBonus {
			let objtext2a = ObjText_Create;
			let y2 = 385;
			
			ObjText_SetText(objtext2a,"Bonus");
			ObjText_SetFontSize(objtext2a,10);
			ObjText_SetFontColorTop(objtext2a,255,255,255);
			ObjText_SetFontColorBottom(objtext2a,0,0,255);
			ObjText_SetFontBorderType(objtext2a,BORDER_SHADOW);
			ObjText_SetFontBorderWidth(objtext2a,1);
			ObjText_SetFontBorderColor(objtext2a,0,0,0);
			ObjText_SetHorizontalAlignment(objtext2a,ALIGNMENT_RIGHT);
			ObjText_SetMaxWidth(objtext2a,200);
			Obj_SetRenderPriorityI(objtext2a,70);
			
			let objtext2b = ObjText_Create;
			
			ObjText_SetFontSize(objtext2b,10);
			ObjText_SetFontColorTop(objtext2b,255,255,255);
			ObjText_SetFontColorBottom(objtext2b,150,150,150);
			ObjText_SetFontBorderType(objtext2b,BORDER_SHADOW);
			ObjText_SetFontBorderWidth(objtext2b,1);
			ObjText_SetFontBorderColor(objtext2b,0,0,0);
			ObjText_SetHorizontalAlignment(objtext2b,ALIGNMENT_RIGHT);
			ObjText_SetMaxWidth(objtext2b,200);
			Obj_SetRenderPriorityI(objtext2b,70);
			
			loop(20) {
				ObjRender_SetPosition(objtext2a,GetStgFrameWidth/2-160,y2,0);
				ObjRender_SetPosition(objtext2b,GetStgFrameWidth/2-110,y2,0);
				ObjRender_SetAlpha(objtext2a,a);
				ObjRender_SetAlpha(objtext2b,a);
				if(ObjEnemyBossScene_GetInfo(objScene,INFO_PLAYER_SHOOTDOWN_COUNT)>0 || ObjEnemyBossScene_GetInfo(objScene,INFO_PLAYER_SPELL_COUNT)>0) {
					ObjText_SetText(objtext2b,"Failed");
				}
				else {
					ObjText_SetText(objtext2b,rtos("0",ObjEnemyBossScene_GetInfo(objScene,INFO_SPELL_SCORE)));
				}
				yield;
			}
			loop(45) {
				if(ObjEnemyBossScene_GetInfo(objScene,INFO_PLAYER_SHOOTDOWN_COUNT)>0 || ObjEnemyBossScene_GetInfo(objScene,INFO_PLAYER_SPELL_COUNT)>0) {
					ObjText_SetText(objtext2b,"Failed");
				}
				else {
					ObjText_SetText(objtext2b,rtos("0",ObjEnemyBossScene_GetInfo(objScene,INFO_SPELL_SCORE)));
				}
				yield;
			}
			if(GetAreaCommonData("Options","LifeBar",true)) { 
				SetMovePosition01(objtext2a,GetStgFrameWidth/2-160,45,6,9);
				SetMovePosition01(objtext2b,GetStgFrameWidth/2-110,45,6,9);
			}
			else {
				SetMovePosition01(objtext2a,GetStgFrameWidth/2-160,45+7,6,9);
				SetMovePosition01(objtext2b,GetStgFrameWidth/2-110,45+7,6,9);
			}
			while(!Obj_IsDeleted(objEnemy)) {
				//ObjRender_SetY(objtext2a,y2);
				//ObjRender_SetY(objtext2b,y2);
				ObjRender_SetAlpha(objtext2a,a2);
				ObjRender_SetAlpha(objtext2b,a2);
				if(ObjEnemyBossScene_GetInfo(objScene,INFO_PLAYER_SHOOTDOWN_COUNT)>0 || ObjEnemyBossScene_GetInfo(objScene,INFO_PLAYER_SPELL_COUNT)>0) {
					ObjText_SetText(objtext2b,"Failed");
				}
				else {
					ObjText_SetText(objtext2b,rtos("0",ObjEnemyBossScene_GetInfo(objScene,INFO_SPELL_SCORE)));
				}
				//if(y2>45) { y2-=365/60; }
				yield;
			}
			loop(20) {
				ObjRender_SetX(objtext2a,ObjRender_GetX(objtext2a)+15);
				ObjRender_SetX(objtext2b,ObjRender_GetX(objtext2b)+15);
				yield;
			}
			Obj_Delete(objtext2a);
			Obj_Delete(objtext2b);
		}
		task SpellHistory {
			let objtext3a = ObjText_Create;
			let y2 = 385;
			
			ObjText_SetText(objtext3a,"History");
			ObjText_SetFontSize(objtext3a,10);
			ObjText_SetFontColorTop(objtext3a,255,255,255);
			ObjText_SetFontColorBottom(objtext3a,0,0,255);
			ObjText_SetFontBorderType(objtext3a,BORDER_SHADOW);
			ObjText_SetFontBorderWidth(objtext3a,1);
			ObjText_SetFontBorderColor(objtext3a,0,0,0);
			ObjText_SetHorizontalAlignment(objtext3a,ALIGNMENT_RIGHT);
			ObjText_SetMaxWidth(objtext3a,200);
			Obj_SetRenderPriorityI(objtext3a,70);
			
			let objtext3b = ObjText_Create;
			
			ObjText_SetText(objtext3b,rtos("00",GetAreaCommonData(SpellID,"Success",0)));
			ObjText_SetFontSize(objtext3b,10);
			ObjText_SetFontColorTop(objtext3b,255,255,255);
			ObjText_SetFontColorBottom(objtext3b,150,150,150);
			ObjText_SetFontBorderType(objtext3b,BORDER_SHADOW);
			ObjText_SetFontBorderWidth(objtext3b,1);
			ObjText_SetFontBorderColor(objtext3b,0,0,0);
			ObjText_SetHorizontalAlignment(objtext3b,ALIGNMENT_RIGHT);
			ObjText_SetMaxWidth(objtext3b,200);
			Obj_SetRenderPriorityI(objtext3b,70);
			
			let objtext3c = ObjText_Create;
			
			ObjText_SetText(objtext3c,"/");
			ObjText_SetFontSize(objtext3c,10);
			ObjText_SetFontColorTop(objtext3c,255,255,255);
			ObjText_SetFontColorBottom(objtext3c,150,150,150);
			ObjText_SetFontBorderType(objtext3c,BORDER_SHADOW);
			ObjText_SetFontBorderWidth(objtext3c,1);
			ObjText_SetFontBorderColor(objtext3c,0,0,0);
			ObjText_SetHorizontalAlignment(objtext3c,ALIGNMENT_RIGHT);
			ObjText_SetMaxWidth(objtext3c,200);
			Obj_SetRenderPriorityI(objtext3c,70);
			
			let objtext3d = ObjText_Create;
			
			ObjText_SetText(objtext3d,rtos("00",GetAreaCommonData(SpellID,"Attempt",0)));
			ObjText_SetFontSize(objtext3d,10);
			ObjText_SetFontColorTop(objtext3d,255,255,255);
			ObjText_SetFontColorBottom(objtext3d,150,150,150);
			ObjText_SetFontBorderType(objtext3d,BORDER_SHADOW);
			ObjText_SetFontBorderWidth(objtext3d,1);
			ObjText_SetFontBorderColor(objtext3d,0,0,0);
			ObjText_SetHorizontalAlignment(objtext3d,ALIGNMENT_RIGHT);
			ObjText_SetMaxWidth(objtext3d,200);
			Obj_SetRenderPriorityI(objtext3d,70);
			
			loop(20) {
				ObjRender_SetPosition(objtext3a,GetStgFrameWidth/2-70,y2,0);
				ObjRender_SetPosition(objtext3b,GetStgFrameWidth/2-52,y2,0);
				ObjRender_SetPosition(objtext3c,GetStgFrameWidth/2-42,y2,0);
				ObjRender_SetPosition(objtext3d,GetStgFrameWidth/2-26,y2,0);
				ObjRender_SetAlpha(objtext3a,a);
				ObjRender_SetAlpha(objtext3b,a);
				ObjRender_SetAlpha(objtext3c,a);
				ObjRender_SetAlpha(objtext3d,a);
				yield;
			}
			loop(45) {
				yield;
			}
			if(GetAreaCommonData("Options","LifeBar",true)) { 
				SetMovePosition01(objtext3a,GetStgFrameWidth/2-70,45,6,9);
				SetMovePosition01(objtext3b,GetStgFrameWidth/2-52,45,6,9);
				SetMovePosition01(objtext3c,GetStgFrameWidth/2-42,45,6,9);
				SetMovePosition01(objtext3d,GetStgFrameWidth/2-26,45,6,9);
			}
			else {
				SetMovePosition01(objtext3a,GetStgFrameWidth/2-70,45+7,6,9);
				SetMovePosition01(objtext3b,GetStgFrameWidth/2-52,45+7,6,9);
				SetMovePosition01(objtext3c,GetStgFrameWidth/2-42,45+7,6,9);
				SetMovePosition01(objtext3d,GetStgFrameWidth/2-26,45+7,6,9);
			}
			while(!Obj_IsDeleted(objEnemy)) {
				// ObjRender_SetY(objtext3a,y2);
				// ObjRender_SetY(objtext3b,y2);
				// ObjRender_SetY(objtext3c,y2);
				// ObjRender_SetY(objtext3d,y2);
				ObjText_SetText(objtext3d,rtos("00",GetAreaCommonData(SpellID,"Attempt",0)));
				ObjRender_SetAlpha(objtext3a,a2);
				ObjRender_SetAlpha(objtext3b,a2);
				ObjRender_SetAlpha(objtext3c,a2);
				ObjRender_SetAlpha(objtext3d,a2);
				//yif(y2>45) { y2-=365/60; }
				yield;
			}
			loop(20) {
				ObjRender_SetX(objtext3a,ObjRender_GetX(objtext3a)+15);
				ObjRender_SetX(objtext3b,ObjRender_GetX(objtext3b)+15);
				ObjRender_SetX(objtext3c,ObjRender_GetX(objtext3c)+15);
				ObjRender_SetX(objtext3d,ObjRender_GetX(objtext3d)+15);
				yield;
			}
			Obj_Delete(objtext3a);
			Obj_Delete(objtext3b);
			Obj_Delete(objtext3c);
			Obj_Delete(objtext3d);
		}
	}
}
task BonusFailed {
	let path = GetCurrentScriptDirectory ~ "IMG/system.png";
	let objText = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let maxscale = 2;
	let scale = 0;
	let alpha = 0;
	
	ObjPrim_SetTexture(objText, path);
	ObjSprite2D_SetSourceRect(objText, 0, 329, 256, 361);
	ObjSprite2D_SetDestCenter(objText);
	Obj_SetRenderPriorityI(objText, 80);
	ObjRender_SetPosition(objText, GetStgFrameWidth/2, 98, 0);
	
	ascent(i in 0..30){
		alpha+=255/30;
		scale = maxscale - scale*sin(90*i/30);
		ObjRender_SetScaleXYZ(objText, scale, scale, scale);
		ObjRender_SetAlpha(objText, alpha);
		yield;
	}
	
	loop(120){ yield; }
	
	loop(25){
		ObjRender_SetScaleXYZ(objText, 1, scale, 1);
		scale-=1/25;
		yield;
	}
	Obj_Delete(objText);
}
task Extend {
	let path = GetCurrentScriptDirectory ~ "IMG/system.png";
	let objText = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let maxscale = 2;
	let scale = 0;
	let alpha = 0;
	
	ObjPrim_SetTexture(objText, path);
	ObjSprite2D_SetSourceRect(objText, 0, 233, 256, 260);
	ObjSprite2D_SetDestCenter(objText);
	Obj_SetRenderPriorityI(objText, 80);
	ObjRender_SetPosition(objText, GetStgFrameWidth/2, 70, 0);
	
	ascent(i in 0..20){
		alpha+=255/20;
		scale = maxscale - scale*sin(90*i/20);
		ObjRender_SetScaleXYZ(objText, scale, scale, scale);
		ObjRender_SetAlpha(objText, alpha);
		yield;
	}
	
	loop(90){ yield; }
	
	loop(25){
		ObjRender_SetScaleXYZ(objText, 1, scale, 1);
		scale-=1/25;
		yield;
	}
	Obj_Delete(objText);
}
task GetSpell {
	let path = GetCurrentScriptDirectory ~ "IMG/system.png";
	let objText = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let maxscale = 2;
	let scale = 0;
	let alpha = 0;
	
	ObjPrim_SetTexture(objText, path);
	ObjSprite2D_SetSourceRect(objText, 0, 265, 256, 295);
	ObjSprite2D_SetDestCenter(objText);
	Obj_SetRenderPriorityI(objText, 80);
	ObjRender_SetPosition(objText, GetStgFrameWidth/2, 70, 0);
	
	ascent(i in 0..20){
		alpha+=255/20;
		scale = maxscale - scale*sin(90*i/20);
		ObjRender_SetScaleXYZ(objText, scale, scale, scale);
		ObjRender_SetAlpha(objText, alpha);
		yield;
	}
	
	loop(90){ yield; }
	
	loop(25){
		ObjRender_SetScaleXYZ(objText, 1, scale, 1);
		scale-=1/25;
		yield;
	}
	Obj_Delete(objText);
}
task MaxBalance {
	let path = GetCurrentScriptDirectory ~ "IMG/system.png";
	let objText = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let maxscale = 2;
	let scale = 0;
	let alpha = 0;
	
	ObjPrim_SetTexture(objText, path);
	ObjSprite2D_SetSourceRect(objText, 0, 133, 256, 167);
	ObjSprite2D_SetDestCenter(objText);
	Obj_SetRenderPriorityI(objText, 80);
	ObjRender_SetPosition(objText, GetStgFrameWidth/2, 100, 0);
	
	ascent(i in 0..20){
		alpha+=255/20;
		scale = maxscale - scale*sin(90*i/20);
		ObjRender_SetScaleXYZ(objText, scale, scale, scale);
		ObjRender_SetAlpha(objText, alpha);
		yield;
	}
	
	loop(90){ yield; }
	
	loop(25){
		ObjRender_SetScaleXYZ(objText, 1, scale, 1);
		scale-=1/25;
		yield;
	}
	Obj_Delete(objText);
}
task FullPowerUp {
	let path = GetCurrentScriptDirectory ~ "IMG/system.png";
	let objText = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let maxscale = 2;
	let scale = 0;
	let alpha = 0;
	
	ObjPrim_SetTexture(objText, path);
	ObjSprite2D_SetSourceRect(objText, 0, 168, 256, 198);
	ObjSprite2D_SetDestCenter(objText);
	Obj_SetRenderPriorityI(objText, 80);
	ObjRender_SetPosition(objText, GetStgFrameWidth/2, 70, 0);
	
	ascent(i in 0..20){
		alpha+=255/20;
		scale = maxscale - scale*sin(90*i/20);
		ObjRender_SetScaleXYZ(objText, scale, scale, scale);
		ObjRender_SetAlpha(objText, alpha);
		yield;
	}
	
	loop(90){ yield; }
	
	loop(25){
		ObjRender_SetScaleXYZ(objText, 1, scale, 1);
		scale-=1/25;
		yield;
	}
	Obj_Delete(objText);
}
task HiScore {
	let path = GetCurrentScriptDirectory ~ "IMG/system.png";
	let objText = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let maxscale = 2;
	let scale = 0;
	let alpha = 0;
	
	ObjPrim_SetTexture(objText, path);
	ObjSprite2D_SetSourceRect(objText, 0, 201, 256, 232);
	ObjSprite2D_SetDestCenter(objText);
	Obj_SetRenderPriorityI(objText, 80);
	ObjRender_SetPosition(objText, GetStgFrameWidth/2, 70, 0);
	
	ascent(i in 0..20){
		alpha+=255/20;
		scale = maxscale - scale*sin(90*i/20);
		ObjRender_SetScaleXYZ(objText, scale, scale, scale);
		ObjRender_SetAlpha(objText, alpha);
		yield;
	}
	
	loop(90){ yield; }
	
	loop(25){
		ObjRender_SetScaleXYZ(objText, 1, scale, 1);
		scale-=1/25;
		yield;
	}
	Obj_Delete(objText);
}

task BossEffects(ID) {
	Aura(ID);
	BossLife(ID);
	BossMagicCircle(ID);
	function Aura(objEnemy) {
		loop(2) { yield; }
		let effect = CSD ~ "IMG/Aura.png";
		let scalecounter = 1.5;
		let objScene = GetEnemyBossSceneObjectID;
		let RED = 0;
		let GREEN = 0;
		let BLUE = 0;
		AuraA;

		task AuraA {
			yield;
			loop(5){
				AuraA;
				loop(6) { yield; }
			}

			task AuraA {
				let scale_0 = 4;
				let scale = scale_0;
				let scale_d = -3.5/30;
				let color = [0, 0, 0];
				let color_r_d = 224/30;
				let color_gb = 150;
				let color_gb_ang = 0;
				let color_gb_ang_d = 90/30;

				let obj = ObjPrim_Create(OBJ_SPRITE_2D);

				ObjPrim_SetTexture(obj, effect);
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				Obj_SetRenderPriorityI(obj, 24);
				ObjRender_SetAngleXYZ(obj, 0, 0, rand(0,360));
				ObjRender_SetScaleXYZ(obj, scale, scale * scalecounter, scale);
				ObjSprite2D_SetSourceRect(obj, 0, 0, 50, 50);
				ObjSprite2D_SetDestCenter(obj);

				while(!Obj_IsDeleted(objEnemy)){
					if(!Obj_IsDeleted(objEnemy)) {
						RED = Obj_GetValueD(objEnemy,"Aura Color",[100,100,100])[0];
						GREEN = Obj_GetValueD(objEnemy,"Aura Color",[100,100,100])[1];
						BLUE = Obj_GetValueD(objEnemy,"Aura Color",[100,100,100])[2];
					}
					loop(29){
						scale += scale_d;
						color_gb_ang += color_gb_ang_d;

						color[0] = color_gb * sin(color_gb_ang)^RED;
						color[1] = color_gb * sin(color_gb_ang)^GREEN;
						color[2] = color_gb * sin(color_gb_ang)^BLUE;

						ObjRender_SetColor(obj, color[0], color[1], color[2]);
						ObjRender_SetScaleXYZ(obj, scale, scale * scalecounter, scale);
						if(!Obj_IsDeleted(objEnemy)) { ObjRender_SetPosition(obj, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0); } else { break; }
						yield;
						//if(Obj_IsDeleted(objEnemy)) { break; }
					}
					scale = scale_0;
					color_gb_ang = 0;
					color = [0, 0, 0];

					ObjRender_SetColor(obj, color[0], color[1], color[2]);

					ObjRender_SetScaleXYZ(obj, scale, scale * scalecounter, scale);
					ObjRender_SetAngleXYZ(obj, 0, 0, rand(0,360));
					ObjRender_SetPosition(obj, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0);

					yield;
				}
				Obj_Delete(obj);
			}
		}
	}
	task BossLife(objEnemy) {
		let path = CSD ~ "IMG/lifebar.png";
		let countVertex = 64;
		
		loop(2) { yield; }
		// let objStar = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		// ObjPrim_SetTexture(objStar,path);
		// Obj_SetRenderPriority(objStar, 0.7);
		// ObjSpriteList2D_SetSourceRect(objStar, 17, 2, 30, 14);

		let objOutline = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetPrimitiveType(objOutline, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetVertexCount(objOutline, countVertex);
		ObjRender_SetBlendType(objOutline, BLEND_ALPHA);
		Obj_SetRenderPriority(objOutline, 0.69);
		ObjPrim_SetTexture(objOutline, path);
		
		let objLife = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetPrimitiveType(objLife, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetVertexCount(objLife, countVertex);
		ObjRender_SetBlendType(objLife, BLEND_ALPHA);
		Obj_SetRenderPriority(objLife, 0.68);
		ObjPrim_SetTexture(objLife, path);
		
		let objLife2 = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetPrimitiveType(objLife2, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetVertexCount(objLife2, countVertex);
		ObjRender_SetBlendType(objLife2, BLEND_ALPHA);
		Obj_SetRenderPriority(objLife2, 0.68);
		ObjPrim_SetTexture(objLife2, path);
		
		let objScene = GetEnemyBossSceneObjectID;
		let alpha = 0;
		let alpha2 = 0;
		let delaycount = 0;
		let LifeRatio = 0;
		let expand = 0;
		let angle = 0;
		let r1 = 58;
		let r2 = 62;
		let StartLife = ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
		
		// CreateStepInd;
		
		ascent (iVert in 0..countVertex/2){
			let vertex = iVert * 2;
			ObjPrim_SetVertexUVT(objOutline, vertex+0, 0, 0);
			ObjPrim_SetVertexUVT(objOutline, vertex+1, 4, 16);	
			ObjPrim_SetVertexUVT(objLife, vertex+0, 7, 0);
			ObjPrim_SetVertexUVT(objLife, vertex+1, 10, 16);	
			ObjPrim_SetVertexUVT(objLife2, vertex+0, 7, 0);
			ObjPrim_SetVertexUVT(objLife2, vertex+1, 10, 16);
		}
		
		ObjRender_SetScaleXYZ(objOutline, -1.0, 1.0, 1.0);
		ObjRender_SetScaleXYZ(objLife, -1.0, 1.0, 1.0);
		ObjRender_SetScaleXYZ(objLife2, -1.0, 1.0, 1.0);
		
		while(!Obj_IsDeleted(objEnemy)) {
			
			if(GetCommonData("Lifebar Delay",false)) {
				Obj_SetVisible(objOutline, false);
				Obj_SetVisible(objLife, false);
				Obj_SetVisible(objLife2, false);
			}
			else {
				Obj_SetVisible(objOutline, true);
				Obj_SetVisible(objLife, true);
				Obj_SetVisible(objLife2, true);
			}
			
			ObjRender_SetPosition(objOutline, ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), 0);
			ObjRender_SetPosition(objLife, ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), 0);
			ObjRender_SetPosition(objLife2, ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), 0);
			
			if(alpha2<255 && GetPlayerY>=115) { alpha2+=255/30; }
			if(alpha2>150 && GetPlayerY<115) { alpha2-=255/30; }
			// ObjRender_SetAlpha(objStar,alpha2);
			
			// ObjSpriteList2D_ClearVertexCount(objStar);
			// ascent(i in 0..ObjEnemyBossScene_GetInfo(objScene,INFO_REMAIN_STEP_COUNT)) {
				// ObjSpriteList2D_SetDestRect(objStar, 4+i*12, 16, 4+(i+1)*12, 28);
				// ObjSpriteList2D_AddVertex(objStar);
			// }
			
			ascent (i in 0..countVertex/2){
				let index = i * 2;
				angle = (360 / (countVertex/2 - 1) * i);
				ObjPrim_SetVertexPosition(objLife, index + 0 , r1*cos(angle-90), r1*sin(angle-90), 0);	
				ObjPrim_SetVertexPosition(objLife, index + 1 , (r1+1.5)*cos(angle-90), (r1+1.5)*sin(angle-90), 0);
				angle = (360 / (countVertex/2 - 1) * i);
				ObjPrim_SetVertexPosition(objLife2, index + 0 , r2*cos(angle-90), r2*sin(angle-90), 0);	
				ObjPrim_SetVertexPosition(objLife2, index + 1 , (r2+1.5)*cos(angle-90), (r2+1.5)*sin(angle-90), 0);
				angle = min(360*(LifeRatio), angle);
				ObjPrim_SetVertexPosition(objOutline, index + 0 , r2*cos(angle-90), r2*sin(angle-90), 0);	
				ObjPrim_SetVertexPosition(objOutline, index + 1 , r1*cos(angle-90), r1*sin(angle-90), 0);
			}
			if(expand<1 && delaycount>=45) { expand+=1/50; }
			if(delaycount>=100 && delaycount<120) { alpha+=255/20; }
			LifeRatio = ObjEnemy_GetInfo(objEnemy,INFO_LIFE)/StartLife*expand;
			if(!GetCommonData("Lifebar Delay",false)) { delaycount++; }
			
			// if(ObjEnemyBossScene_GetInfo(objScene,INFO_ACTIVE_STEP_TOTAL_LIFE)<=0) {
				// expand = 0;
				// delaycount = 0;
				// alpha = 0;
				// loop(2) { yield; }
				// CreateStepInd;
			// }
			
			
			yield;
		}
		Obj_Delete(objOutline);
		Obj_Delete(objLife);
		Obj_Delete(objLife2);
		
		// task CreateStepInd {
			// let listLifeDiv = ObjEnemyBossScene_GetInfo(objScene, INFO_ACTIVE_STEP_LIFE_RATE_LIST);
			// ascent(i in 0 .. length(listLifeDiv)-1){
				// let rate = listLifeDiv[i];
				// let angle = 360*(rate);
				// Separator(angle, rate);
			// }
			// task Separator(angle, rate){
				// let obj = ObjPrim_Create(OBJ_SPRITE_2D);
				// ObjRender_SetBlendType(obj, BLEND_ALPHA);
				// Obj_SetRenderPriority(obj, 0.69);
				// ObjPrim_SetTexture(obj, path);
				// ObjSprite2D_SetSourceRect(obj, 10, 0, 15, 8);
				// ObjSprite2D_SetDestCenter(obj);
				// ObjRender_SetScaleXYZ(obj, 1.3, 1.3, 1);
				// ObjRender_SetPosition(obj, ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), 0);
				// ObjRender_SetAngleZ(obj, angle);
				// yield;
				// let life = ObjEnemyBossScene_GetInfo(objScene,INFO_ACTIVE_STEP_TOTAL_LIFE)/ObjEnemyBossScene_GetInfo(objScene,INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
				// while(1-rate<life-0.000001){
					// life = ObjEnemyBossScene_GetInfo(objScene,INFO_ACTIVE_STEP_TOTAL_LIFE)/ObjEnemyBossScene_GetInfo(objScene,INFO_ACTIVE_STEP_TOTAL_MAX_LIFE);
					// ObjRender_SetPosition(obj, ObjRender_GetX(objEnemy)+(r1-1)*cos(angle-90), ObjRender_GetY(objEnemy)+(r1-1)*sin(angle-90), 0);
					// ObjRender_SetAlpha(obj, alpha);
					// if(GetCommonData("DurableSpell",false)) { Obj_SetVisible(obj, false); } else { Obj_SetVisible(obj, true); }
					// yield;
				// }
				// Obj_Delete(obj);
			// }
		// }
	}
	task BossMagicCircle(objEnemy) {
		loop(2) { yield; }
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj, CSD ~ "IMG/MC.png");
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj, 37);
		ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
		ObjSprite2D_SetDestCenter(obj);
		
		let objScene = GetEnemyBossSceneObjectID;
		let t = 0;
		let scale = 0.7;
		let spin = 0;
		let alpha = 0;
		
		while(!Obj_IsDeleted(objEnemy)) {
			ObjRender_SetPosition(obj, ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), 0);
			ObjRender_SetAngleXYZ(obj, 0, 0, spin);
			ObjRender_SetScaleXYZ(obj, scale, scale, 1);
			ObjRender_SetColor(obj, 255*alpha, 255*alpha, 255*alpha);
			scale+=0.0065*sin(3*t);
			spin+=5;
			t++;
			if(alpha<0.5) { alpha+=0.7/30; }
			yield;
		}
		Obj_Delete(obj);
		
	}
}

task ExplosionA1(objEnemy,starcolor,circlecolor) {
	let x = rand(-45,45);
	let y = rand(-45,45);
	let z = rand(-90,90);
	let dir = rand(0,360);
	PlaySoundEffect(death,90);
	DefaultCircle(objEnemy,2.0,circlecolor,x,y,z);
	DefaultCircle(objEnemy,2.0,circlecolor,x,y+90,z);
	loop(4) {
		ExplodeStar02(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), rand(2.5,3.5), dir+rand(-10,10), [255,255,255]);
		ExplodeStar02(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), rand(2.5,3.5), dir+rand(-10,10), starcolor);
		dir+=360/4;
	}
	ObjEnemy_SetLife(objEnemy, 0);
	Obj_Delete(objEnemy);
}
task ExplosionA2(objEnemy,starcolor,circlecolor) {
	let x = rand(-45,45);
	let y = rand(-45,45);
	let z = rand(-90,90);
	let dir = rand(0,360);
	PlaySoundEffect(death,90);
	DefaultCircle(objEnemy,2.0,circlecolor,x,y,z);
	DefaultCircle(objEnemy,2.0,circlecolor,x,y+90,z);
	loop(8) {
		ExplodeStar02(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(2.5,4.0), dir+rand(-10,10), [255,255,255]);
		ExplodeStar02(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(2.5,4.0), dir+rand(-10,10), starcolor);
		dir+=360/8;
	}
	ObjEnemy_SetLife(objEnemy, 0);
	Obj_Delete(objEnemy);
}
task ExplosionB1(objEnemy,circlecolor,starcolor) {
let angle = rand(0,360);
	ObjEnemy_SetLife(objEnemy, 1);
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	PlaySoundEffect(explode,100);
	ScreenShake(90,50);
	DefaultCircle(objEnemy,3.0,circlecolor,0,0,0);
	loop(35) {
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(2,6), angle, [255,255,255]);
		angle+=360/70;
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(2,6), angle, starcolor);
		angle+=360/70;
	}
	ObjEnemy_SetLife(objEnemy, 0);
	Obj_Delete(objEnemy);
}
task ExplosionB2(objEnemy,circlecolor,starcolor) {
	let angle = rand(0,360);
	ObjEnemy_SetLife(objEnemy, 1);
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	PlaySoundEffect(explode,100);
	DefaultCircle(objEnemy,3.0,circlecolor,0,0,0);
	ScreenShake(30,30);
	ObjMove_SetSpeed(objEnemy,0.2);
	ObjMove_SetAngle(objEnemy,195);
	loop(90/4) {
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(1.5,4.0), rand(0,360), [255,255,255]);
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(1.5,4.0), rand(0,360), starcolor);
		loop(4) { yield; }
	}
	PlaySoundEffect(explode,100);
	DefaultCircle(objEnemy,3.0,circlecolor,0,0,0);
	ScreenShake(90,50);
	loop(40) {
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(2,6), angle, [255,255,255]);
		angle+=360/80;
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(2,6), angle, starcolor);
		angle+=360/80;
	}
	ObjEnemy_SetLife(objEnemy, 0);
	Obj_Delete(objEnemy);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
}
task ExplosionB3(objEnemy,circlecolor,starcolor) {
let angle = rand(0,360);
	ObjEnemy_SetLife(objEnemy, 1);
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	PlaySoundEffect(explode,100);
	ScreenShake(30,30);
	DefaultCircle(objEnemy,3.0,circlecolor,0,0,0);
	MSDEffectExplode(objEnemy, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), starcolor);
	loop(150/3) {
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(3.5,6.5), rand(0,360), [255,255,255]);
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(3.5,6.5), rand(0,360), starcolor);
		loop(3) { yield; }
	}
	PlaySoundEffect(explode,100);
	ScreenShake(90,50);
	loop(25) {
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(3.5,6.5), angle, [255,255,255]);
		angle+=360/50;
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(3.5,6.5), angle, starcolor);
		angle+=360/50;
	}
	ObjEnemy_SetLife(objEnemy, 0);
	Obj_Delete(objEnemy);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
}
task ExplosionB4(objEnemy,circlecolor,starcolor) {
let angle = rand(0,360);
	ObjEnemy_SetLife(objEnemy, 1);
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	PlaySoundEffect(explode,100);
	DefaultCircle(objEnemy,3.0,circlecolor,0,0,0);
	loop(75/3) {
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(3.5,6.5), rand(0,360), [255,255,255]);
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(3.5,6.5), rand(0,360), starcolor);
		loop(3) { yield; }
	}
	PlaySoundEffect(explode,100);
	ScreenShake(90,50);
	loop(35) {
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(2,6), angle, [255,255,255]);
		angle+=360/70;
		ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(2,6), angle, starcolor);
		angle+=360/70;
	}
	ObjEnemy_SetLife(objEnemy, 0);
	Obj_Delete(objEnemy);
}
task ExplosionRainbow(objEnemy) {
let angle = rand(0,360);
let colors = [[255,0,0],[255,128,0],[255,255,0],[0,255,0],[0,0,255],[255,0,255]];
	ObjEnemy_SetLife(objEnemy, 1);
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	PlaySoundEffect(explode,100);
	ScreenShake(30,30);
	DefaultCircle(objEnemy,3.0,[255,255,255],0,0,0);
	MSDEffectRainbowExplode(objEnemy, 180, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy));
	loop(15) {
		ascent(i in 0..6) {
			ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(3.5,6.5), rand(0,360), [255,255,255]);
			ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(3.5,6.5), rand(0,360), colors[i]);
			loop(2) { yield; }
		}
	}
	PlaySoundEffect(explode,100);
	ScreenShake(90,50);
	loop(4) {
		ascent(i in 0..6) {
			ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(3.5,6.5), angle, [255,255,255]);
			angle+=360/48;
			ExplodeStar01(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(3.5,6.5), angle, colors[i]);
			angle+=360/48;
		}
	}
	ObjEnemy_SetLife(objEnemy, 0);
	Obj_Delete(objEnemy);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
}
task ConcentrationA1(objEnemy,duration,speed,radius,color) {
let w = round(1/speed*10);
	SpawnCircle;
	loop(duration/w) {
		if(!Obj_IsDeleted(objEnemy)) {
			ConcStar01(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, rand(0,360), -1, radius, [255,255,255], 180);
			ConcStar01(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, rand(0,360), 1, radius, color, 180);
		}
		loop(w) { yield; }
	}
	task SpawnCircle {
	let count = 0;
		loop(duration-10) {
			count++;
			if(count==20 && !Obj_IsDeleted(objEnemy)) { ConcCircle(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, radius, color); count = 0; }
			yield;
		}
	}
}
task ConcentrationA2(objEnemy,duration,speed,radius,color) {
let w = round(1/speed*10);
	MSDEffect(objEnemy,duration,color);
	loop(duration/w) {
		if(!Obj_IsDeleted(objEnemy)) {
			ConcStar01(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, rand(0,360), -1, radius, [255,255,255], 180);
			ConcStar01(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, rand(0,360), 1, radius, color, 180);
		}
		loop(w) { yield; }
	}
}
task ConcentrationA3(objEnemy,speed,radius,color) {
let angle = rand(0,360);
	ConcCircle(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, radius, color);
	loop(18) {
		ConcStar01(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, angle, -1, radius+rand(-50,50), [255,255,255], 230);
		ConcStar01(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, angle, 1, radius+rand(-50,50), color, 230);
		angle+=360/18;
	}
}
task ConcentrationA4(objEnemy,duration,speed,radius,color) {
let w = round(1/speed*10);
let angle = rand(0,360);
	SpawnCircle;
	loop(duration/w) {
		if(!Obj_IsDeleted(objEnemy)) {
			ConcStar01(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, rand(0,360), -1, radius, [255,255,255], 180);
			ConcStar01(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, rand(0,360), 1, radius, color, 180);
		}
		loop(w) { yield; }
	}
	wait(20);
	if(!Obj_IsDeleted(objEnemy)) {	PlaySoundEffect(explode2,100); }
	loop(30) {
		if(!Obj_IsDeleted(objEnemy)) {
			ExplodeStar03(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(2,8), angle, [255,255,255]);
			angle+=360/60;
			ExplodeStar03(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), rand(2,8), angle, color);
			angle+=360/60;
		}
	}
	task SpawnCircle {
		loop(duration-10) { yield; }
		if(!Obj_IsDeleted(objEnemy)) { ConcCircle(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, radius, color); }
		yield;
	}
}
task ConcentrationB1(objEnemy,duration,speed,layer,color) {
	let angle = rand(0,360);
	let color2 = [];
	ascent(i in 0..length(color)) {
		color2 = color2 ~ [color[i]/2];
	}
	loop(duration) {
		if(!Obj_IsDeleted(objEnemy)) {
			DarkConcentration(objEnemy,angle,1+rand(0.4,0.6),256+rand(0,128),speed,layer,color);
			DarkConcentration(objEnemy,angle,rand(0.4,0.6),256+rand(0,128),speed,layer,color2);
			DarkConcentration(objEnemy,angle+90,1+rand(0.4,0.6),256+rand(0,128),speed,layer,color);
			DarkConcentration(objEnemy,angle+90,rand(0.4,0.6),256+rand(0,128),speed,layer,color2);
			DarkConcentration(objEnemy,angle+180,1+rand(0.4,0.6),256+rand(0,128),speed,layer,color);
			DarkConcentration(objEnemy,angle+180,rand(0.4,0.6),256+rand(0,128),speed,layer,color2);
			DarkConcentration(objEnemy,angle+270,1+rand(0.4,0.6),256+rand(0,128),speed,layer,color);
			DarkConcentration(objEnemy,angle+270,rand(0.4,0.6),256+rand(0,128),speed,layer,color2);
		}
		yield;
	}
}
task ConcentrationB2(objEnemy,duration,speed,layer,color) {
	let angle = rand(0,360);
	let color2 = [];
	ascent(i in 0..length(color)) {
		color2 = color2 ~ [color[i]/2];
	}
	Stars;
	loop(duration) {
		if(!Obj_IsDeleted(objEnemy)) {
			DarkConcentration(objEnemy,angle,1+rand(0.4,0.6),256+rand(0,128),speed,layer,color);
			DarkConcentration(objEnemy,angle,rand(0.4,0.6),256+rand(0,128),speed,layer,color2);
			DarkConcentration(objEnemy,angle+90,1+rand(0.4,0.6),256+rand(0,128),speed,layer,color);
			DarkConcentration(objEnemy,angle+90,rand(0.4,0.6),256+rand(0,128),speed,layer,color2);
			DarkConcentration(objEnemy,angle+180,1+rand(0.4,0.6),256+rand(0,128),speed,layer,color);
			DarkConcentration(objEnemy,angle+180,rand(0.4,0.6),256+rand(0,128),speed,layer,color2);
			DarkConcentration(objEnemy,angle+270,1+rand(0.4,0.6),256+rand(0,128),speed,layer,color);
			DarkConcentration(objEnemy,angle+270,rand(0.4,0.6),256+rand(0,128),speed,layer,color2);
		}
		yield;
	}
	task Stars {
		let w = round(1/(speed+5)*10);
		let radius = 200;
		loop((duration+30)/w) {
			if(!Obj_IsDeleted(objEnemy)) {
				ConcStar02(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed+5, rand(0,360), -1, radius, color, 255);
				ConcStar02(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed+5, rand(0,360), 1, radius, color, 255);
			}
			loop(w) { yield; }
		}
	}
}
task ConcentrationB3(objEnemy,speed,radius,color) {
let angle = rand(0,360);
	ConcCircle(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, radius, color);
	loop(20) {
		ConcStar02(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, rand(0,360), -1, radius+rand(-50,50), [255,255,255], 230);
		ConcStar02(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, rand(0,360), 1, radius+rand(-50,50), color, 230);
	}
}
task ConcentrationRainbowA1(objEnemy,duration,speed,radius) {
let angle = rand(0,360);
let w = round(1/speed*10);
let colors = [[255,64,64],[255,128,64],[255,255,64],[64,255,64],[64,64,255],[64,64,255]];
	MSDEffectRainbow(duration,objEnemy);
	loop(duration/w/6-4) {
		ascent(i in 0..6) {
			if(!Obj_IsDeleted(objEnemy)) {
				ConcStar01(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, rand(0,360), -1, radius, [255,255,255], 180);
				ConcStar01(ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), speed, rand(0,360), 1, radius, colors[i], 180);
			}
			loop(w) { yield; }
		}
	}
}
task SpellBurst(x,y,maxscale,R,G,B) {
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	ObjPrim_SetTexture(obj, PSD ~ "IMG/Effect/ConcentrationCircle.png");
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj, 50);
	
	
	let alpha = 1.8;
	let scale = 0;
	let dscale = 0.15*maxscale;
	loop(30){
		scale += dscale;
		if(dscale>0){ dscale = dscale^1.05; }
		if(alpha>0) { alpha -= 1/15; }
		else { alpha = 0; }
		ObjRender_SetColor(obj, R*alpha, G*alpha, B*alpha);
		ObjRender_SetPosition(obj, x, y, 0);
		ObjRender_SetScaleXYZ(obj, scale, scale, 1);
		yield;
	}
	Obj_Delete(obj);
}
function PPCExplode(objEnemy,color) {
	loop(6) {
		MSDExplodeCircle(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),color);
	}
}
function PPCExplodeRainbow(objEnemy) {
	MSDExplodeCircle(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),[255,64,64]);
	MSDExplodeCircle(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),[255,128,64]);
	MSDExplodeCircle(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),[255,255,64]);
	MSDExplodeCircle(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),[128,255,128]);
	MSDExplodeCircle(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),[128,128,255]);
	MSDExplodeCircle(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),[128,64,255]);
}
task MSDExplodeCircle(x,y,RGB) {
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,41);
	ObjPrim_SetTexture(obj, PSD ~ "IMG/Effect/MSDEffect.png");
	ObjSprite2D_SetSourceRect(obj, 128, 0, 256, 128);
	ObjSprite2D_SetDestCenter(obj);

	let alpha = 255;
	let scale = 0;
	let dscale = 0.6;
	let anglex = rand(-90,90);
	let angley = rand(-90,90);
	let anglez = rand(-90,90);
	let dx = rand(-1,1);
	let dy = rand(-1,1);
	let dz = rand(-1,1);
	
	ObjRender_SetPosition(obj, x, y, 0);
	loop(40){
		scale += dscale;
		alpha -= 255/40;
		anglex+=dx; angley+=dy; anglez+=dz;
		if(dscale>0){ dscale-=0.55/40; }
		else { dscale = 0; }
		ObjRender_SetColor(obj,RGB[0]*(alpha/255),RGB[1]*(alpha/255),RGB[2]*(alpha/255));
		ObjRender_SetScaleXYZ(obj, scale, scale, 1);
		ObjRender_SetAngleXYZ(obj,anglex,angley,anglez);
		yield;
	}
	Obj_Delete(obj);
}
task ExplodeStar01(x,y,speed,dir,color) {
	let objStar = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 200;
	let spinA = rand(0,180);
	let spinB = rand(0,180);
	let RED = color[0];
	let GREEN = color[1];
	let BLUE = color[2];
	let scale = 0;
	
	ObjRender_SetBlendType(objStar, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(objStar,41);
	ObjPrim_SetTexture(objStar, PSD ~ "IMG/Effect/Star.png");
	ObjSprite2D_SetSourceRect(objStar, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(objStar);
	
	while(!Obj_IsDeleted(objStar)) {
		ObjRender_SetPosition(objStar, x, y, 0);
		ObjRender_SetScaleXYZ(objStar, scale, scale, scale);
		ObjRender_SetAngleXYZ(objStar, spinA, spinB, spinA);
		ObjRender_SetAlpha(objStar, alpha);
		ObjRender_SetColor(objStar, RED*(alpha/255), GREEN*(alpha/255), BLUE*(alpha/255));
		if(scale<0.38 && speed>0) { scale+=0.03; }
		if(speed>1.0) { speed-=0.038; }
		if(speed<=1.0 && alpha>0) { alpha-=15; scale-=0.035; }
		if(alpha<=0) { Obj_Delete(objStar); }
		spinA+=rand(1,2);
		spinB+=rand(-1,-2);
		x+=speed*cos(dir);
		y+=speed*sin(dir);
		yield;
	}
}
task ExplodeStar02(x,y,speed,dir,color) {
	let objStar = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 130;
	let spinA = rand(0,180);
	let spinB = rand(0,180);
	// let RED = rand(100,255);
	// let GREEN = rand(100,255);
	// let BLUE = rand(100,255);
	let RED = color[0];
	let GREEN = color[1];
	let BLUE = color[2];
	let scale = 0;
	
	ObjRender_SetBlendType(objStar, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(objStar,41);
	ObjPrim_SetTexture(objStar, PSD ~ "IMG/Effect/Star.png");
	ObjSprite2D_SetSourceRect(objStar, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(objStar);
	
	while(!Obj_IsDeleted(objStar)) {
		ObjRender_SetPosition(objStar, x, y, 0);
		ObjRender_SetScaleXYZ(objStar, scale, scale, scale);
		ObjRender_SetAngleXYZ(objStar, spinA, spinB, spinA);
		ObjRender_SetAlpha(objStar, alpha);
		ObjRender_SetColor(objStar, RED*(alpha/255), GREEN*(alpha/255), BLUE*(alpha/255));
		if(scale<0.19 && speed>0) { scale+=0.03; }
		if(speed>1.0) { speed-=0.094; }
		if(speed<=1.0 && alpha>0) { alpha-=16; scale-=0.008; }
		if(alpha<=0) { Obj_Delete(objStar); }
		spinA+=rand(1,2);
		spinB+=rand(-1,-2);
		x+=speed*cos(dir);
		y+=speed*sin(dir);
		yield;
	}
}
task ExplodeStar03(x,y,speed,dir,color) {
	let objStar = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 200;
	let spinA = rand(0,180);
	let spinB = rand(0,180);
	let RED = color[0];
	let GREEN = color[1];
	let BLUE = color[2];
	let scale = 0;
	
	ObjRender_SetBlendType(objStar, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(objStar,41);
	ObjPrim_SetTexture(objStar, PSD ~ "IMG/Effect/Star.png");
	ObjSprite2D_SetSourceRect(objStar, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(objStar);
	
	while(!Obj_IsDeleted(objStar)) {
		ObjRender_SetPosition(objStar, x, y, 0);
		ObjRender_SetScaleXYZ(objStar, scale, scale, scale);
		ObjRender_SetAngleXYZ(objStar, spinA, spinB, spinA);
		ObjRender_SetAlpha(objStar, alpha);
		ObjRender_SetColor(objStar, RED*(alpha/255), GREEN*(alpha/255), BLUE*(alpha/255));
		if(scale<0.38 && speed>0) { scale+=0.03; }
		if(speed>1.0) { speed-=0.09; }
		if(speed<=2.0 && alpha>0) { alpha-=15; scale-=0.035; }
		if(alpha<=0) { Obj_Delete(objStar); }
		spinA+=rand(1,2);
		spinB+=rand(-1,-2);
		x+=speed*cos(dir);
		y+=speed*sin(dir);
		yield;
	}
}
task DarkConcentration(objEnemy,angle,dangle,disp,ddisp,layer,color) { //Adapted from Mystical Power Plant
	let objEffect = ObjPrim_Create(OBJ_SPRITE_2D);
		
	ObjRender_SetBlendType(objEffect,BLEND_SUBTRACT);
	Obj_SetRenderPriorityI(objEffect,layer);
	ObjPrim_SetTexture(objEffect, PSD ~ "IMG/Effect/light.png");
	ObjSprite2D_SetSourceRect(objEffect,0,0,64,64);
	ObjSprite2D_SetDestCenter(objEffect);
	ObjRender_SetAngleXYZ(objEffect,0,0,rand(0,360));
	
	let dispmax = rand(disp-64,disp);
	let disp1 = 0;
	let dispA = 0;
	let alpha1 = 0;
	let alphaA = 0;
	let scalemax = rand(0.6,1.1);
	let angle2 = rand(-16,16);
	
	while(disp1<0.999) {
		angle2+=dangle;
		
		if(alpha1<1){ alphaA+=10; }
		alpha1 = 1*sin(alphaA);
		
		dispA+=ddisp;
		disp1 = 1*sin(dispA);
		
		ObjRender_SetPosition(objEffect,ObjMove_GetX(objEnemy)+(dispmax-disp1*dispmax)*cos(angle+angle2),ObjMove_GetY(objEnemy)+(dispmax-disp1*dispmax)*sin(angle+angle2),0);
		ObjRender_SetScaleXYZ(objEffect,disp1*scalemax,disp1*scalemax,0);
		ObjRender_SetColor(objEffect,alpha1*color[0],alpha1*color[1],alpha1*color[2]);
		yield;
	}
	alpha1 = 0;
	alphaA = 0;
	while(alpha1<1) {
		angle2+=dangle;
		
		alphaA+=2.5;
		alpha1 = 1*sin(alphaA);
		ObjRender_SetScaleXYZ(objEffect,disp1*scalemax*2,disp1*scalemax*2,0);
		ObjRender_SetColor(objEffect,color[0]-alpha1*color[0],color[1]-alpha1*color[1],color[2]-alpha1*color[2]);
		yield;
	}
	Obj_Delete(objEffect);
}
task ConcStar01(x,y,speed,dir,rot,r,color,opacity) {
	let objStar = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 0;
	let spin = rand(0,180);
	// let RED = rand(100,255);
	// let GREEN = rand(100,255);
	// let BLUE = rand(100,255);
	let RED = color[0];
	let GREEN = color[1];
	let BLUE = color[2];
	let scale = 0.75*(r/200);
	
	if(r > 200) { scale = 1.00; }
	
	ObjRender_SetBlendType(objStar, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(objStar,41);
	ObjPrim_SetTexture(objStar, PSD ~ "IMG/Effect/Star.png");
	ObjSprite2D_SetSourceRect(objStar, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(objStar);
	
	while(!Obj_IsDeleted(objStar)) {
		ObjRender_SetPosition(objStar, x+r*cos(dir), y+r*sin(dir), 0);
		ObjRender_SetScaleXYZ(objStar, scale, scale, scale);
		ObjRender_SetAngleXYZ(objStar, 0, 0, spin);
		ObjRender_SetAlpha(objStar, alpha);
		ObjRender_SetColor(objStar, RED*(alpha/255), GREEN*(alpha/255), BLUE*(alpha/255));
		if(alpha<opacity && r>=10) { alpha+=opacity/90*speed; }
		if(r<200) { scale-=0.75/200*speed; }
		if(r<10) { alpha-=opacity/10*speed; }
		if(alpha<=0) { Obj_Delete(objStar); }
		spin+=rand(3,4)*rot;
		r-=speed;
		yield;
	}
}
task ConcStar02(x,y,speed,dir,rot,r,color,opacity) {
	let objStar = ObjPrim_Create(OBJ_SPRITE_2D);

	let alpha = 0;
	let spin = rand(0,180);
	// let RED = rand(100,255);
	// let GREEN = rand(100,255);
	// let BLUE = rand(100,255);
	let RED = color[0];
	let GREEN = color[1];
	let BLUE = color[2];
	let scale = 0.75*(r/200);
	
	if(r > 200) { scale = 1.00; }
	
	ObjRender_SetBlendType(objStar, BLEND_SUBTRACT);
	Obj_SetRenderPriorityI(objStar,41);
	ObjPrim_SetTexture(objStar, PSD ~ "IMG/Effect/Star.png");
	ObjSprite2D_SetSourceRect(objStar, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(objStar);
	
	while(!Obj_IsDeleted(objStar)) {
		ObjRender_SetPosition(objStar, x+r*cos(dir), y+r*sin(dir), 0);
		ObjRender_SetScaleXYZ(objStar, scale, scale, scale);
		ObjRender_SetAngleXYZ(objStar, 0, 0, spin);
		ObjRender_SetAlpha(objStar, alpha);
		ObjRender_SetColor(objStar, RED*(alpha/255), GREEN*(alpha/255), BLUE*(alpha/255));
		if(alpha<opacity && r>=10) { alpha+=opacity/90*speed; }
		if(r<200) { scale-=0.75/200*speed; }
		if(r<10) { alpha-=opacity/10*speed; }
		if(alpha<=0) { Obj_Delete(objStar); }
		spin+=rand(3,4)*rot;
		r-=speed;
		yield;
	}
}
task ExplodeCircle01(objEnemy,color) {
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj,41);
	ObjPrim_SetTexture(obj, PSD ~ "IMG/Effect/Effect.png");
	if(color == "Orange") { ObjSprite2D_SetSourceRect(obj, 0, 0, 64, 64); }
	if(color == "Blue") { ObjSprite2D_SetSourceRect(obj, 64, 0, 128, 64); }
	if(color == "Yellow") { ObjSprite2D_SetSourceRect(obj, 128, 0, 192, 64); }
	if(color == "Green") { ObjSprite2D_SetSourceRect(obj, 192, 0, 256, 64); }
	ObjSprite2D_SetDestCenter(obj);

	let alpha = 220;
	let scale = 0;
	let dscale = 0.4;
	
	ObjRender_SetPosition(obj, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0);
	loop(40){
		scale += dscale;
		alpha -= 5;
		if(dscale>0){ dscale = dscale^1.13; }
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetScaleXYZ(obj, scale, scale, 1);
		yield;
	}
	Obj_Delete(obj);
}
task ExplodeCircle02(objEnemy,maxscale,color,x,y,z) {
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	ObjRender_SetBlendType(obj, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj,41);
	ObjPrim_SetTexture(obj, PSD ~ "IMG/Effect/Effect.png");
	if(color == "Orange") { ObjSprite2D_SetSourceRect(obj, 0, 0, 64, 64); }
	if(color == "Blue") { ObjSprite2D_SetSourceRect(obj, 64, 0, 128, 64); }
	if(color == "Yellow") { ObjSprite2D_SetSourceRect(obj, 128, 0, 192, 64); }
	if(color == "Green") { ObjSprite2D_SetSourceRect(obj, 192, 0, 256, 64); }
	ObjSprite2D_SetDestCenter(obj);

	let alpha = 200;
	let scale = 0;
	let dscale = 0.4;
	
	ObjRender_SetPosition(obj, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0);
	ObjRender_SetAngleXYZ(obj,x,y,z);
	ascent(i in 0..30) {
		scale = maxscale*sin(90*i/20);
		alpha -= 255/30;
		//if(dscale>0){ dscale = dscale^1.15; }
		ObjRender_SetAlpha(obj, alpha);
		ObjRender_SetScaleXYZ(obj, scale, scale, scale);
		yield;
	}
	Obj_Delete(obj);
}
task DefaultCircle(objEnemy,maxscale,color,x,y,z) {
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let RGB = color;
	
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,41);
	ObjPrim_SetTexture(obj, PSD ~ "IMG/Effect/Default_Effect.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 64, 64);
	ObjSprite2D_SetDestCenter(obj);

	let alpha = 255;
	let scale = 0;
	let dscale = 0.4;
	
	ObjRender_SetPosition(obj, ObjRender_GetX(objEnemy), ObjRender_GetY(objEnemy), 0);
	ObjRender_SetAngleXYZ(obj,x,y,z);
	ascent(i in 0..20) {
		scale = maxscale*sin(90*i/20);
		alpha -= 255/20;
		//if(dscale>0){ dscale = dscale^1.15; }
		ObjRender_SetColor(obj,(alpha/255)*RGB[0],(alpha/255)*RGB[1],(alpha/255)*RGB[2]);
		ObjRender_SetScaleXYZ(obj, scale, scale, scale);
		yield;
	}
	Obj_Delete(obj);
}
task ConcCircle(x,y,speed,r,color) {
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let RGB = color;
	
	let alpha = 0;
	let scale = 2.5*(r/200);
	
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,41);
	ObjPrim_SetTexture(obj, PSD ~ "IMG/Effect/ConcentrationCircle.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 256, 256);
	ObjSprite2D_SetDestCenter(obj);
	
	while(!Obj_IsDeleted(obj)) {
		ObjRender_SetPosition(obj, x, y, 0);
		ObjRender_SetScaleXYZ(obj, scale, scale, scale);
		ObjRender_SetColor(obj, (alpha/255)*RGB[0], (alpha/255)*RGB[1], (alpha/255)*RGB[2]);
		if(alpha<255) { alpha+=255/(r-90)*speed; }
		scale-=speed/100;
		if(scale<=0) { Obj_Delete(obj); }
		yield;
	}
}
task MSDEffect(objID,duration,color) { //Adapted from Magical Singular Day
	let scale = 22;
	let RGB = color;
	
	Concentration;
	loop(duration/5) {
		if(!Obj_IsDeleted(objID)) {
			loop(2) {
				Beam(ObjMove_GetX(objID),ObjMove_GetY(objID));
			}
		}
		loop(5) { yield; }
	}
	task Concentration {
		loop(duration/15) {
			if(!Obj_IsDeleted(objID)) {
				Concentrate(ObjMove_GetX(objID),ObjMove_GetY(objID));
			}
			loop(15) { yield; }
		}
	}
	task Concentrate(ex,ey) {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let scale = 1.6;
		let scaleX = rand(2,3);
		let scaleY = rand(2,3);
		let scaleZ = rand(2,3);
		let alpha = 0;
		let x = rand(-90,90);
		let y = rand(-90,90);
		let z = rand(-90,90);
		let dx = rand(-1,1);
		let dy = rand(-1,1);
		let dz = rand(-1,1);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj, 40);
		ObjSprite2D_SetSourceRect(obj,128,0,256,128);
		ObjSprite2D_SetDestCenter(obj);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(10) {
			ObjRender_SetPosition(obj, ex, ey, 0);
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,RGB[0]*(alpha/255),RGB[1]*(alpha/255),RGB[2]*(alpha/255));
			alpha+=255/10;
			scale-=1.6/60;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		loop(50) {
			ObjRender_SetPosition(obj, ex, ey, 0);
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			scale-=1.6/60;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
	task Beam(ex,ey) {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let maxscale = rand(1.5,2.5);
		let scale = 0;
		let alpha = 0;
		let x = rand(0,360);
		let y = rand(0,360);
		let z = rand(0,360);
		let dx = rand(-1,1);
		let dy = rand(-1,1);
		let dz = rand(-1,1);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj, 30);
		ObjSprite2D_SetSourceRect(obj,0,0,128,64);
		ObjSprite2D_SetDestRect(obj,0,-32,128,32);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(20) {
			ObjRender_SetPosition(obj, ex, ey, 0);
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,RGB[0]*(alpha/255),RGB[1]*(alpha/255),RGB[2]*(alpha/255));
			alpha+=255/20;
			x+=dx; y+=dy; z+=dz;
			scale+=maxscale/20;
			yield;
		}
		loop(30) {
			ObjRender_SetPosition(obj, ex, ey, 0);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		loop(30) {
			ObjRender_SetPosition(obj, ex, ey, 0);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,RGB[0]*(alpha/255),RGB[1]*(alpha/255),RGB[2]*(alpha/255));
			alpha-=255/30;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
}
task MSDEffectExplode(objID,ex,ey,color) {
	let scale = 22;
	let RGB = color;
	
	Concentration;
	loop(150/5) {
		loop(2) {
			Beam;
		}
		loop(5) { yield; }
	}
	loop(75) {
		loop(3) {
			if(scale>8) { Beam; }
		}
		loop(2) {
			Star(scale);
		}
		scale-=22/75;
		loop(2) { yield; }
	}
	task Concentration {
		loop(180/10) {
			Concentrate;
			loop(10) { yield; }
		}
	}
	task Star(maxscale) {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let scale = 0;
		let alpha = 255;
		let x = rand(-30,30);
		let y = rand(-30,30);
		let z = rand(-30,30);
		let dx = rand(-2,2);
		let dy = rand(-2,2);
		let dz = rand(-2,2);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjSprite2D_SetSourceRect(obj,0,64,64,128);
		ObjSprite2D_SetDestCenter(obj);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(60) {
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,RGB[0]*(alpha/255),RGB[1]*(alpha/255),RGB[2]*(alpha/255));
			alpha-=255/60;
			scale+=maxscale/60;
			//x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
	task Concentrate {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let scale = 1.6;
		let scaleX = rand(2,3);
		let scaleY = rand(2,3);
		let scaleZ = rand(2,3);
		let alpha = 0;
		let x = rand(-90,90);
		let y = rand(-90,90);
		let z = rand(-90,90);
		let dx = rand(-1,1);
		let dy = rand(-1,1);
		let dz = rand(-1,1);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjSprite2D_SetSourceRect(obj,128,0,256,128);
		ObjSprite2D_SetDestCenter(obj);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(10) {
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,RGB[0]*(alpha/255),RGB[1]*(alpha/255),RGB[2]*(alpha/255));
			alpha+=255/10;
			scale-=1.6/60;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		loop(50) {
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			scale-=1.6/60;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
	task Explode {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let scale = 0;
		let scaleX = rand(2,3);
		let scaleY = rand(2,3);
		let scaleZ = rand(2,3);
		let alpha = 0;
		let x = rand(0,360);
		let y = rand(0,360);
		let z = rand(0,360);
		let dx = rand(-1,1);
		let dy = rand(-1,1);
		let dz = rand(-1,1);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjSprite2D_SetSourceRect(obj,128,0,256,128);
		ObjSprite2D_SetDestCenter(obj);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(10) {
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			scale+=2.4/20;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		loop(10) {
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,RGB[0]*(alpha/255),RGB[1]*(alpha/255),RGB[2]*(alpha/255));
			alpha-=255/10;
			scale+=1.6/20;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
	task Beam {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let maxscale = rand(1.5,2.5);
		let scale = 0;
		let alpha = 0;
		let x = rand(0,360);
		let y = rand(0,360);
		let z = rand(0,360);
		let dx = rand(-1,1);
		let dy = rand(-1,1);
		let dz = rand(-1,1);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjSprite2D_SetSourceRect(obj,0,0,128,64);
		ObjSprite2D_SetDestRect(obj,0,-32,128,32);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(20) {
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,RGB[0]*(alpha/255),RGB[1]*(alpha/255),RGB[2]*(alpha/255));
			alpha+=255/20;
			x+=dx; y+=dy; z+=dz;
			scale+=maxscale/20;
			yield;
		}
		loop(30) {
			ObjRender_SetAngleXYZ(obj,x,y,z);
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		loop(30) {
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,RGB[0]*(alpha/255),RGB[1]*(alpha/255),RGB[2]*(alpha/255));
			alpha-=255/30;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
}
task MSDEffectRainbow(duration,objID) {
	let scale = 18;
	let RGB = [[255,64,64],[255,128,64],[255,255,64],[64,255,64],[64,64,255],[64,64,255]];
	let ex = ObjRender_GetX(objID);
	let ey = ObjRender_GetY(objID);
	
	loop(duration/30) {
		ascent(i in 0..6) {
			ex = ObjRender_GetX(objID);
			ey = ObjRender_GetY(objID);
			if(!Obj_IsDeleted(objID)) {
				Concentrate(RGB[i][0],RGB[i][1],RGB[i][2]);
				loop(2) {
					Beam(RGB[i][0],RGB[i][1],RGB[i][2]);
				}
				loop(5) { yield; }
			}
		}
	}
	task Star(maxscale,R,G,B) {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let scale = 0;
		let alpha = 255;
		let x = rand(-30,30);
		let y = rand(-30,30);
		let z = rand(-30,30);
		let dx = rand(-2,2);
		let dy = rand(-2,2);
		let dz = rand(-2,2);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj, 30);
		ObjSprite2D_SetSourceRect(obj,0,64,64,128);
		ObjSprite2D_SetDestCenter(obj);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(60) {
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,R*(alpha/255),G*(alpha/255),B*(alpha/255));
			alpha-=255/60;
			scale+=maxscale/60;
			//x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
	task Concentrate(R,G,B) {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let scale = 1.6;
		let scaleX = rand(2,3);
		let scaleY = rand(2,3);
		let scaleZ = rand(2,3);
		let alpha = 0;
		let x = rand(-90,90);
		let y = rand(-90,90);
		let z = rand(-90,90);
		let dx = rand(-1,1);
		let dy = rand(-1,1);
		let dz = rand(-1,1);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj, 30);
		ObjSprite2D_SetSourceRect(obj,128,0,256,128);
		ObjSprite2D_SetDestCenter(obj);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(10) {
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,R*(alpha/255),G*(alpha/255),B*(alpha/255));
			alpha+=255/10;
			scale-=1.6/40;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		loop(30) {
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			scale-=1.6/40;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
	task Explode(R,G,B) {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let scale = 0;
		let scaleX = rand(2,3);
		let scaleY = rand(2,3);
		let scaleZ = rand(2,3);
		let alpha = 255;
		let x = rand(-90,90);
		let y = rand(-90,90);
		let z = rand(-90,90);
		let dx = rand(-1,1);
		let dy = rand(-1,1);
		let dz = rand(-1,1);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj, 30);
		ObjSprite2D_SetSourceRect(obj,128,0,256,128);
		ObjSprite2D_SetDestCenter(obj);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(30) {
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,R*(alpha/255),G*(alpha/255),B*(alpha/255));
			scale+=3.0/40;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		loop(10) {
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,R*(alpha/255),G*(alpha/255),B*(alpha/255));
			alpha-=255/10;
			scale+=3.0/40;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
	task Beam(R,G,B) {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let maxscale = rand(1.5,2.5);
		let scale = 0;
		let alpha = 0;
		let x = rand(0,360);
		let y = rand(0,360);
		let z = rand(0,360);
		let dx = rand(-1,1);
		let dy = rand(-1,1);
		let dz = rand(-1,1);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj, 30);
		ObjSprite2D_SetSourceRect(obj,0,0,128,64);
		ObjSprite2D_SetDestRect(obj,0,-32,128,32);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(20) {
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,R*(alpha/255),G*(alpha/255),B*(alpha/255));
			alpha+=255/20;
			x+=dx; y+=dy; z+=dz;
			scale+=maxscale/20;
			yield;
		}
		loop(30) {
			ObjRender_SetAngleXYZ(obj,x,y,z);
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		loop(30) {
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,R*(alpha/255),G*(alpha/255),B*(alpha/255));
			alpha-=255/30;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
}
task MSDEffectRainbowExplode(objID,duration,ex,ey) {
	let scale = 18;
	let RGB = [[255,64,64],[255,128,64],[255,255,64],[128,255,128],[128,128,255],[128,64,255]];
	
	loop(duration/48) {
		ascent(i in 0..6) {
			Concentrate(RGB[i][0],RGB[i][1],RGB[i][2]);
			loop(2) {
				Beam(RGB[i][0],RGB[i][1],RGB[i][2]);
			}
			loop(8) { yield; }
		}
	}
	loop(12) {
		ascent(i in 0..6) {
			Explode(RGB[i][0],RGB[i][1],RGB[i][2]);
			loop(3) {
				if(scale>8) { Beam(RGB[i][0],RGB[i][1],RGB[i][2]); }
			}
			loop(2) {
				Star(scale,RGB[i][0],RGB[i][1],RGB[i][2]);
			}
			scale-=18/75;
			loop(2) { yield; }
		}
	}
	task Star(maxscale,R,G,B) {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let scale = 0;
		let alpha = 255;
		let x = rand(-30,30);
		let y = rand(-30,30);
		let z = rand(-30,30);
		let dx = rand(-2,2);
		let dy = rand(-2,2);
		let dz = rand(-2,2);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjSprite2D_SetSourceRect(obj,0,64,64,128);
		ObjSprite2D_SetDestCenter(obj);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(60) {
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,R*(alpha/255),G*(alpha/255),B*(alpha/255));
			alpha-=255/60;
			scale+=maxscale/60;
			//x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
	task Concentrate(R,G,B) {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let scale = 1.6;
		let scaleX = rand(2,3);
		let scaleY = rand(2,3);
		let scaleZ = rand(2,3);
		let alpha = 0;
		let x = rand(-90,90);
		let y = rand(-90,90);
		let z = rand(-90,90);
		let dx = rand(-1,1);
		let dy = rand(-1,1);
		let dz = rand(-1,1);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjSprite2D_SetSourceRect(obj,128,0,256,128);
		ObjSprite2D_SetDestCenter(obj);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(10) {
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,R*(alpha/255),G*(alpha/255),B*(alpha/255));
			alpha+=255/10;
			scale-=1.6/50;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		loop(40) {
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			scale-=1.6/50;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
	task Explode(R,G,B) {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let scale = 0;
		let scaleX = rand(2,3);
		let scaleY = rand(2,3);
		let scaleZ = rand(2,3);
		let alpha = 255;
		let x = rand(-90,90);
		let y = rand(-90,90);
		let z = rand(-90,90);
		let dx = rand(-1,1);
		let dy = rand(-1,1);
		let dz = rand(-1,1);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjSprite2D_SetSourceRect(obj,128,0,256,128);
		ObjSprite2D_SetDestCenter(obj);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(40) {
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,R*(alpha/255),G*(alpha/255),B*(alpha/255));
			scale+=3.0/50;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		loop(10) {
			ObjRender_SetScaleXYZ(obj,scaleX*scale,scaleY*scale,scaleZ*scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,R*(alpha/255),G*(alpha/255),B*(alpha/255));
			alpha-=255/10;
			scale+=3.0/50;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
	task Beam(R,G,B) {
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let path = PSD ~ "IMG/Effect/MSDEffect.png";
		
		let maxscale = rand(1.5,2.5);
		let scale = 0;
		let alpha = 0;
		let x = rand(0,360);
		let y = rand(0,360);
		let z = rand(0,360);
		let dx = rand(-1,1);
		let dy = rand(-1,1);
		let dz = rand(-1,1);
		
		ObjPrim_SetTexture(obj,path);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,40);
		ObjSprite2D_SetSourceRect(obj,0,0,128,64);
		ObjSprite2D_SetDestRect(obj,0,-32,128,32);
		
		ObjRender_SetPosition(obj, ex, ey, 0);
		
		loop(20) {
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,R*(alpha/255),G*(alpha/255),B*(alpha/255));
			alpha+=255/20;
			x+=dx; y+=dy; z+=dz;
			scale+=maxscale/20;
			yield;
		}
		loop(30) {
			ObjRender_SetAngleXYZ(obj,x,y,z);
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		loop(30) {
			ObjRender_SetAngleXYZ(obj,x,y,z);
			ObjRender_SetColor(obj,R*(alpha/255),G*(alpha/255),B*(alpha/255));
			alpha-=255/30;
			x+=dx; y+=dy; z+=dz;
			yield;
		}
		Obj_Delete(obj);
	}
}
task ScreenShake(duration,range) {
let shake = range;
	loop(duration) {
		Set2DCameraFocusX(Get2DCameraX + rand(-shake, shake));
		Set2DCameraFocusY(Get2DCameraY + rand(-shake, shake));
		shake-=range/duration;
		yield;
		Reset2DCamera;
	}
}