let pss = SoundSFX(GetCurrentScriptDirectory ~ "./../../../SFX/Special02.wav");
let shat = SoundSFX(GetCurrentScriptDirectory ~ "./../../../SFX/Shot01.wav");
let wuon = SoundSFX(GetCurrentScriptDirectory ~ "./../../../SFX/Special05.wav");
let shet = SoundSFX(GetCurrentScriptDirectory ~ "./../../../SFX/Shot02.wav");
let ptooy = SoundSFX(GetCurrentScriptDirectory ~ "./../../../SFX/Special04.wav");
let laser = SoundSFX(GetCurrentScriptDirectory ~ "./../../../SFX/Laser03.wav");
let lazer = SoundSFX(GetCurrentScriptDirectory ~ "./../../../SFX/Laser02.wav");
let shesh = SoundSFX(GetCurrentScriptDirectory ~ "./../../../SFX/Delete.wav");
let beamer = SoundSFX(GetCurrentScriptDirectory ~ "./../../../SFX/Laser01.wav");
let kaboom = SoundSFX(GetCurrentScriptDirectory ~ "./../../../SFX/Burst.wav");

task AT01(){
	let x = rand(-40, 40);
	PlaySFX_V(shet, 60);
	ascent(i in -2..9+2){
		let a = rand(270-15, 270+15);
		
		let B = CreateShotA2(x + i*stgw/9, stgh+30, rand(0,3), a, 1/60, 6, 422, 2); raba(B);
	}
	
	task raba(me){
		let x = getx(me); let y = gety(me);
		let a = geta(me) + 180;
		
		let o = rand(-0.1, 0.1);
		ObjShot_SetSpellResist(me, true); ObjMove_SetAngularVelocity(me, o); 
		ObjShot_SetAutoDelete(me, false); ObjShot_SetDeleteFrame(me, 60*5);
		ascent(i in 1..6){
			let n = 20*i;
			
			let d = CreateShotA2(x + n*cos(a), y + n*sin(a), getsp(me), a-180, 1/60, 6, 62, 2);
			ObjShot_SetAutoDelete(d, false); ObjShot_SetDeleteFrame(d, 60*5);
			ObjMove_SetAngularVelocity(d, o); yield;
		}
	}
}

task AT02(obj){
	let x = getrx(obj); let y = getry(obj);
	let a = atan2(py - getry(obj), px - getrx(obj));
	
	PlaySFX_V(beamer, 55); DelayedPlaySFX_V(lazer, 45, 75);
	CreateSTLaser(x, y, a, 700, 135, 4, [45, 90]);
}

task AT03(obj){
	let x = getrx(obj); let y = getry(obj);
	let a = atan2(py - getry(obj), px - getrx(obj));
	
	let B = CreateShotA2(x, y, -2, a, 1/6, 8, 262, 3); 
	ObjRender_SetBlendType(B, BLEND_ADD_ARGB); ObjShot_SetSpellResist(B, true);
	
	let r = rand(0,360); let l = 0;
	while(!Obj_IsDeleted(B)){
		r = rand(0,360); PlaySFX_V(shat, 55);
		ascent(i in 0..3){
			a = r + 360/3*i;
			
			let an = geta(B); x = getx(B); y = gety(B);
			
			let C = CreateShotA1(x + 14*cos(a), y + 14*sin(a), rand(1,3), an+180, 842, 2);
			ObjMove_AddPatternA3(C, 15, NO_CHANGE, rand(0,360), -1/5, 0, 1, 842+l);
			l++; if(l > 2){l = 0;} ObjRender_SetBlendType(C, BLEND_ADD_ARGB);
		}
		wait(60*1/10);
	}
}

task AT04(obj){
	let x = getrx(obj); let y = getry(obj); let dx = px;
	let a = atan2(0 - getry(obj), dx - getrx(obj));
	
	PlaySFX_V(shet, 60);
	let B = CreateShotA2(x, y, -2, a, 1/6, 8, 874, 3); 
	ObjRender_SetBlendType(B, BLEND_ADD_ARGB); ObjShot_SetSpellResist(B, true);
	while(gety(B) > -8){yield;} 
	let n = 20; let o = 0; let v = rand(90-10, 90+10);
	PlaySFX_V(shet, 60);
	ascent(i in -10..11){
		a = v + 9*i;
		
		CreateShotA2(dx, 2, 6, a, -1/20, rand(1,2), 264, 2);
		CreateShotA2(dx, 2, 5, a, -1/20, rand(1,2), 264, 2);
	}
	ascent(j in 0..60){
		PlaySFX_V(shet, 40+j);
		ascent(i in -1..2){
			let g = round(rand(142, 144));
			
			let b = CreateShotA2(dx + n*i, 2, 0, rand(90-4, 90+4), 6, 4 + j/5, g, 2);
			ObjRender_SetBlendType(b, BLEND_ADD_ARGB);
		}
		
		n = 20 + sin(o)*31; o += 10;
		yield;
	}
}

task AT05(obj){
	let x = getrx(obj); let y = getry(obj);
	let r = rand(0,360);
	
	let B = [];	PlaySFX_V(ptooy, 55);
	ascent(j in 0..3){
		B = B ~ [PolygonShot(x, y, 5.5 - j*1.45, r, 8, 22, 2, 128, 2)];
		yield;
	}
	
	ascent(i in 0..length(B)){
		let T = B[i];
		ascent(j in 0..length(T)){
			let sv = Obj_GetValue(T[i], "sv");
			let av = Obj_GetValue(T[i], "av");
			
			if(!Obj_IsDeleted(T[j])){
				ObjMove_AddPatternA3(T[j], 50, 0, rand(0,360)*av, (1/15)*sv, 0, rand(2,5)*sv, 61);
				ObjRender_SetBlendType(T[j], BLEND_ADD_ARGB);
				ObjShot_SetFadeDeleteAtFrame(T[j], 70 + (j/30));
			}
		}
	}
	DelayedPlaySFX_V(shesh, 50, 65);
}

task AT06(obj){
	let x = getrx(obj); let y = getry(obj);
	let z = rand(-1, 1); z = z/absolute(z);
	
	PlaySFX_V(shet, 60);
	let B = CreateShotA2(x, y, 0, rand(270-20, 270+20), 1, 11, 243, 3); ObjShot_SetSpellResist(B, true);
	ObjMove_AddPatternA2(B, 3, NO_CHANGE, NO_CHANGE, 0, 7*z, 0); 
	wait(45); ObjMove_SetAngularVelocity(B, 0); 
	
	let a = atan2(py - gety(B), px - getx(B)); DelayedPlaySFX_V(wuon, 3, 65);
	let cl = CreateCurveLaserA1(getx(B), gety(B), 2, a, 25, 50, 403, 2); ObjCrLaser_SetTipDecrement(cl, 0.0);
	ObjMove_AddPatternA2(cl, 3, NO_CHANGE, atan2(py - gety(cl), px - getx(cl)), 1/2, 3*z, 20); Obj_Delete(B);
	while(getx(cl) > 0 && getx(cl)< stgw && gety(cl)>0 && gety(cl)<stgh){x = getx(cl); y = gety(cl); yield;} let v = rand(270-10, 270+10);
	ObjShot_SetFadeDeleteAtFrame(cl, 30);
	ascent(j in 0..4){
		PlaySFX_V(shat, 40);
		ascent(i in 0..30){
			a = v + 360/30*i;
			
			CreateShotA2(x, y, 6, a, -1/4, 2+j*0.6, 64, 5);
		}
		yield;
	}
}

task AT07(){
	let z = rand(-40, 40);

	ascent(i in -1..6+1){
		let x = z + stgw/6*i;
		
		PlaySFX_V(laser, 46);
		let a = atan2(py - 1, px - x);
		ascent(j in -4..5){
			CreateLooseLaserA1(x + 2*j, 1, 18, a, 543, 20, 302, 3); 
			yield;
		}
	}
}

task AT08(obj){
	let x = getrx(obj); let y = getry(obj);
	let a = atan2(py - getry(obj), px - getrx(obj));
	
	PlaySFX_V(shat, 60);
	let B = CreateShotA2(x, y, -5, a, 1/3, 12, 806, 3); 
	ObjRender_SetBlendType(B, BLEND_ADD_ARGB); ObjShot_SetSpellResist(B, true);
	
	let r = rand(0,360); let l = 0;
	while(!Obj_IsDeleted(B)){
		r = rand(0,360); 
		
		x = getx(B); y = gety(B);
		let A = CreateShotA1(x, y, 0, r, 65, 3); bang(A);
		wait(60*1/35);
	}
	
	task bang(me){
		ObjShot_SetSpellResist(me, true);
		wait(15);
		let x = getx(me); let y = gety(me); let v = rand(0,360); PlaySFX_V(pss, 40);
		ascent(i in 0..10){
			a = v + 360/10*i;
			
			let d = CreateShotA1(x, y, 6, a, 646, 5); 
			ObjMove_AddPatternB2(d, 5, 4*cos(a), NO_CHANGE, 0, 1/10, 0, rand(2, 5));
			ObjShot_SetFadeDeleteAtFrame(d, 20); ObjRender_SetBlendType(d, BLEND_ADD_ARGB);
		}
		Obj_Delete(me);
	}	
}

task AT09(obj){
	let x = getrx(obj); let y = getry(obj);
	let mx = [0, 0];
	//-3, -2, -1, 0, 1, 2, 3
	
	let n = 4;
	ascent(i in 0..20){
		mx[0] = (x + n*i); mx[1] = (x - n*i); let g = rand(40,70);
		CreateDLaser(x + n*i, stgh, 270, g, 20, 284, 30+i*1.25);
		CreateDLaser(x - n*i, stgh, 270, g, 20, 284, 30+i*1.25);
	}
	wait(30);
	
	let r = rand(0,360); PlaySFX_V(kaboom, 60);
	descent(j in 0..270){
		let a = r + 360/270*j;
		
		ascent(i in 0..2){
			let l = rand(mx[0], mx[1]);
			let seed = rand(2,50);
			
			let H = 1/(j/60);
			
			let B = CreateShotB2(l, stgh, 0, -20, 0, H, 0, 1, 423+i, 2); lel(B, a, seed, H*2, i);
			ObjRender_SetBlendType(B, BLEND_ADD_ARGB); ObjShot_SetSpellResist(B, true);	
		}
		
		//yield;
	}
	
	task lel(tt, a, s, ac, po){
		while(getsp_xy(tt)[1] < 0){yield;} let g = [263, 63]; let i = rand_int(0, 1);
		ObjMove_AddPatternB2(tt, 1, 0, rand(0,5), 1/2, ac, 0.5*cos(a), s);
		ObjShot_SetGraphic(tt, g[i]+po);
	}
}

task AT10(obj){
	let x = getrx(obj); let y = getry(obj);
	let z = rand(-1, 1); z = z/absolute(z);
	
	let r = rand(0,360); let s = r;
	ascent(j in 0..8){
		PlaySFX_V(shat, 70);
		ascent(i in 0..19){
			let a = r + 360/19*i;
			
			let B = CreateShotA1(x, y, 10, a, 27, 3);
			ObjRender_SetBlendType(B, BLEND_ADD_ARGB); ObjShot_SetSpellResist(B, true);	
			ObjMove_AddPatternA2(B, 15, 0, NO_CHANGE, 1/20, +z*0.75, 10);
			
			a = s + 360/19*i;
			
			B = CreateShotA1(x, y, 10, a, 21, 3);
			ObjRender_SetBlendType(B, BLEND_ADD_ARGB); ObjShot_SetSpellResist(B, true);	
			ObjMove_AddPatternA2(B, 15+j, -3, NO_CHANGE, 1/20, -z*0.75, 10);
		}
		r += 2*z; s -= 2*z;
		wait(5);
	}
}

task AT11(){
	let z = rand(-1, 1); z = z/absolute(z);
	
	PlaySFX_V(shet, 60);
	let B = CreateWheelA2(px, 3, 0, 90, 1/20, 8, 901, 2, z*3);
	ObjShot_SetSpellResist(B, true);
}