function GetStageID { return GetCommonData("GetStageScriptID", 0); }

function wait(time){
	loop(time){
	yield;
	}
}

task PlaySound(str,v,w){
	let string;
	if(str == "smbullet"){string = 0;}
	if(str == "labullet"){string = 1;}
	if(str == "spirit"){string = 2;}
	if(str == "damage1"){string = 3;}
	if(str == "damage2"){string = 4;}
	if(str == "timeout"){string = 5;}
	if(str == "timeout2"){string = 6;}
	if(str == "explode"){string = 7;}
	if(str == "explodebig"){string = 8;}
	if(str == "charge"){string = 9;}
	if(str == "item"){string = 10;}
	if(str == "extend"){string = 11;}
	if(str == "bombget"){string = 12;}
	if(str == "lensmbullet"){string = 13;}
	if(str == "lenlabullet"){string = 14;}
	if(str == "lensmlaser"){string = 15;}
	if(str == "lenlalaser"){string = 16;}
	if(str == "summon"){string = 17;}
	if(str == "warning"){string = 18;}
	if(str == "spawn"){string = 19;}
	if(str == "fire"){string = 20;}
	if(str == "fly"){string = 21;}
	wait(w);
	NotifyEvent(GetCommonData("SoundScript", GetOwnScriptID), EV_USER, [string, v*2]);
}

task HitSound(obj,vol,cap){
	while(!Obj_IsDeleted(obj)) {
	if(ObjEnemy_GetInfo(obj,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(obj,INFO_LIFE)>cap){
	PlaySound("damage1",vol,0);
	yield;
	}
	if(ObjEnemy_GetInfo(obj,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(obj,INFO_LIFE)<cap){
	PlaySound("damage2",vol,0);
	yield;
	}
	yield;
	}
}

task TimerCountdown{
	let objScene = GetEnemyBossSceneObjectID();
	let timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER);
	while(!Obj_IsDeleted(objScene)){
	timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER);
	if(timer<11){break;}
	yield;}
	
	loop(11){
	if(Obj_IsDeleted(objScene)){break;}
	timer = ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER);
	if(timer < 11 && timer > 4){PlaySound("timeout",150,0);}
	if(timer < 5 && timer > -1){PlaySound("timeout2",150,0);}
	wait(60);
	}
}

task Extend{
	let text = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriorityI(text, 30);
	ObjPrim_SetTexture(text,GetCurrentScriptDirectory ~ "/img/System.png");
	ObjSprite2D_SetSourceRect(text,372,182,372+146,182+55);
	ObjSprite2D_SetDestCenter(text);
	ObjRender_SetPosition(text, GetStgFrameWidth/2, 125, 0);
	ObjRender_SetAlpha(text, 0);
	ObjRender_SetScaleXYZ(text, 1, 1, 1);
	
	let text2 = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriorityI(text2, 30);
	ObjPrim_SetTexture(text2,GetCurrentScriptDirectory ~ "/img/System.png");
	ObjSprite2D_SetSourceRect(text2,372,182,372+146,182+55);
	ObjSprite2D_SetDestCenter(text2);
	ObjRender_SetPosition(text2, GetStgFrameWidth/2, 125, 0);
	ObjRender_SetScaleXYZ(text2, 0, 0, 1);
	ObjRender_SetAlpha(text, 255);

	ascent(i in 0..120){
	ObjRender_SetAlpha(text, 0+i*10);
	ObjRender_SetAlpha(text2, 255-i*15);
	ObjRender_SetScaleXYZ(text2, i/2, i/2, 1);
	yield;
	}
	
	let scale = 1;
	ascent(i in 0..60){
	ObjRender_SetScaleY(text, scale);
	scale-=1/10;
	if(scale<=0.1){Obj_Delete(text);}
	yield;
	}
	Obj_Delete(text); Obj_Delete(text2);
	
}

task StageClear(score){
AddScore(score);

	let text = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriority(text, 0.7);
	ObjPrim_SetTexture(text,GetCurrentScriptDirectory ~ "/img/System.png");
	ObjSprite2D_SetSourceRect(text,373,268,373+201,268+56);
	ObjSprite2D_SetDestCenter(text);
	ObjRender_SetPosition(text, GetStgFrameWidth/2, 125, 0);
	ObjRender_SetAlpha(text, 255);
	ObjRender_SetScaleXYZ(text, 1, 1, 1);

	let strScore = "+" ~ IntToString(score);
	let objScore = ObjText_Create();
	ObjText_SetText(objScore, strScore);
	ObjText_SetFontType(objScore, "Modern No. 20");
	ObjText_SetFontSize(objScore, 28);
	ObjText_SetFontBold(objScore, false);
	ObjText_SetFontColorTop(objScore, 255, 255, 255);
	ObjText_SetFontColorBottom(objScore, 255, 255, 255);
	ObjText_SetFontBorderType(objScore, BORDER_FULL);
	ObjText_SetFontBorderColor(objScore,0, 0, 0);
	ObjText_SetFontBorderWidth(objScore, 1);
	Obj_SetRenderPriority(objScore, 0.6);
	ObjRender_SetX(objScore, GetStgFrameWidth/2-100);
	ObjRender_SetY(objScore, 180);

}

task Difficulty(diff){
	let text = ObjPrim_Create(OBJ_SPRITE_2D);
	
	let X;
	if(diff == 0){X = [30, 38];}
	if(diff == 1){X = [0, 10];}
	if(diff == 2){X = [30, 30];}
	if(diff == 3){X = [35, 38];}
	
	Obj_SetRenderPriority(text, 1);
	ObjPrim_SetTexture(text,GetCurrentScriptDirectory ~ "/img/System.png");

	if(diff == 0){ObjSprite2D_SetSourceRect(text,11,405,11+171,405+36);}
	if(diff == 1){ObjSprite2D_SetSourceRect(text,12,447,12+171,447+36);}
	if(diff == 2){ObjSprite2D_SetSourceRect(text,11,488,11+171,488+36);}
	if(diff == 3){ObjSprite2D_SetSourceRect(text,11,531,11+171,531+36);}
	
	ObjSprite2D_SetDestCenter(text);
	ObjRender_SetPosition(text, GetStgFrameWidth/2+X[0], 50, 0);
	ObjRender_SetAlpha(text, 255);
	ObjRender_SetScaleXYZ(text, 0.75, 0.75, 1);
	
	loop(90){yield;}
	
	ascent(i in 0..30){
	ObjRender_SetAlpha(text, 255-(i*255/30));
	yield;
	}
	ObjRender_SetX(text, 428+30+75+35+X[1]);
	ObjRender_SetY(text, 30);
	ascent(i in 0..30){
	ObjRender_SetAlpha(text, 0+(i*255/30));
	yield;
	}
}

task Highscore{
	let text = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriorityI(text, 30);
	ObjPrim_SetTexture(text,GetCurrentScriptDirectory ~ "/img/System.png");
	ObjSprite2D_SetSourceRect(text,378,131,378+177,131+47);
	ObjSprite2D_SetDestCenter(text);
	ObjRender_SetPosition(text, GetStgFrameWidth/2, 75, 0);
	ObjRender_SetAlpha(text, 0);
	ObjRender_SetScaleXYZ(text, 1, 1, 1);
	
	ascent(i in 0..120){
	ObjRender_SetAlpha(text, 0+i*10);
	yield;
	}
}

task Screenshake(duration,range) {
let shake = range;
	loop(duration) {
		Set2DCameraFocusX(Get2DCameraX + rand(-shake, shake));
		Set2DCameraFocusY(Get2DCameraY + rand(-shake, shake));
		shake-=range/duration;
		yield;
		Reset2DCamera;
	}
}

task Slowdown(time){
StartSlow(20, TARGET_ALL);
wait(time);
StopSlow(TARGET_ALL);
}

task SetArmor(tar, defense, time){
ObjEnemy_SetDamageRate(tar, 0, 0);
wait(time);
ObjEnemy_SetDamageRate(tar, defense[0], defense[1]);
}

task EnemyMarker(tar){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);

	Obj_SetRenderPriority(obj, 0.9);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/System.png");
	ObjSprite2D_SetSourceRect(obj,0,643,25,644+21);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj, GetStgFrameWidth/2, 125, 0);
	ObjRender_SetAlpha(obj, 255);
	ObjRender_SetScaleXYZ(obj, 1, 1, 1);
	
	while(!Obj_IsDeleted(tar)){
	if(ObjEnemy_GetInfo(tar,INFO_SHOT_HIT_COUNT)>0){
	ObjRender_SetColor(obj, 0, 0, 0);
	}
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), GetStgFrameHeight-4, 0);
	yield;
	ObjRender_SetColor(obj, 255, 255, 255);
	}
}