script_spell Die {
	@MainLoop { yield; }
	Start;
	task Start { SetCommonData("JustDied", true); ExtendPlayer(-1); loop(60) { yield; } End; }
}

script_spell FantasySeal {
	let GCSD = GetCurrentScriptDirectory;
	let imgPlayer = GCSD ~ "pl00.png";
	@Initialize {
		StartBomb;
		//DeleteEnemyShotToItemInCircle(SHOT, GetPlayerX, GetPlayerY, 1000);
	}
	@Finalize {
	}
	@MainLoop { yield; }
	task StartBomb {
		PlaySE(GCSD~"se_bomb.wav");
		SetPlayerInvincibility(330);
		ascent(i in 0..8) { Seal(i*360/8); }
		loop(270) { yield; } End;
	}
	task Seal(a) {
		let obj = Obj_Create(OBJ_SPELL);
		ObjEffect_SetTexture(obj,imgPlayer); ObjEffect_SetRenderState(obj,ADD);
		ObjEffect_CreateVertex(obj,4); ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN); ObjEffect_SetLayer(obj, 5);
		ObjEffect_SetVertexUV(obj,0,160,160); ObjEffect_SetVertexUV(obj,1,256,160); ObjEffect_SetVertexUV(obj,2,256,256); ObjEffect_SetVertexUV(obj,3,160,256);
		ObjEffect_SetVertexXY(obj,0,-48,-48); ObjEffect_SetVertexXY(obj,1,48,-48); ObjEffect_SetVertexXY(obj,2,48,48); ObjEffect_SetVertexXY(obj,3,-48,48);
		task FadeColor {
			let ang = a; let c = a;
			let x = 0; let y = 0;
			while(!Obj_BeDeleted(obj)) {
				x = Obj_GetX(obj); y = Obj_GetY(obj);
				ObjEffect_SetAngle(obj, 0, 0, ang);
				ascent(i in 0..4) { ObjEffect_SetVertexColor(obj, i, 255, 128+127*sin(c), 128+127*sin(c-120), 128+127*sin(c-240)); }
				ang+=31; ang%=360; c+=8; c%=360;
			yield; }
			SealDie(x,y,128+127*sin(c), 128+127*sin(c-120), 128+127*sin(c-240));
			loop(15) { SealDie2(x,y); }
		} FadeColor;
		task Position {
			let x = GetPlayerX; let y = GetPlayerY; let x2 = GetPlayerX; let y2 = GetPlayerY;
			task Move {
				let ang = a;
				descent(i in 0..120) {
					SetIntersectionCircle(Obj_GetX(obj), Obj_GetY(obj), 40, 4, true);
					x2 = GetPlayerX+80*cos(ang);
					y2 = GetPlayerY+80*sin(ang);
					ang+=15*i/120;
					yield;
				}
				let angF = ang; let r2 = 80;
				let currangle = a; let r = 0;
				ascent(i in 0..90) {
					SetIntersectionCircle(Obj_GetX(obj), Obj_GetY(obj), 40, 5/2, true);
					let eid = 0;
					let edist = 1000;
					if(GetEnemyNum > 0) {
						ascent(enemy in EnumEnemyBegin..EnumEnemyEnd) {
							let enemyID = EnumEnemyGetID(enemy);
							let enemyX = GetEnemyInfo(enemyID, ENEMY_X);
							let enemyY = GetEnemyInfo(enemyID, ENEMY_Y);
							let enemyDist = ((enemyX-Obj_GetX(obj))^2+(enemyY-Obj_GetY(obj))^2)^0.5;
							if(enemyDist < edist) { eid = enemyID; edist = enemyDist; }
						}
						let ex = GetEnemyInfo(eid, ENEMY_X);
						let ey = GetEnemyInfo(eid, ENEMY_Y);
						let ang = currangle; ang = atan2(sin(ang), cos(ang));
						let angt = atan2(ey-Obj_GetY(obj),ex-Obj_GetX(obj));
						if((|angt|) >= 90) {
							while(ang < 0) { ang+=360; } ang%=360;
							while(angt < 0) { angt+=360; } angt%=360;
						}
						currangle = angt;
						if(r < 10) { r+=1/2; }
						if((|ex-GetCenterX|) < 224 && (|ey-GetCenterY|) < 256) {
							x = Obj_GetX(obj)+r*cos(currangle);
							y = Obj_GetY(obj)+r*sin(currangle);
							x2 = x; y2 = y;
						} else {
							x2 = GetPlayerX+(r2)*cos(angF);
							y2 = GetPlayerY+(r2)*sin(angF);
							angF+=10*i/90; r2+=6*i/90;
						}
					} else {
						x2 = GetPlayerX+(r2)*cos(angF);
						y2 = GetPlayerY+(r2)*sin(angF);
						angF+=10*i/90; r2+=6*i/90;
					}
					yield;
				}
				PlaySE(GCSD~"se_tan00b.wav");
				Obj_Delete(obj);
			} Move;
			while(!Obj_BeDeleted(obj)) {
				Obj_SetPosition(obj, x, y);
				x+=(x2-x)/4;
				y+=(y2-y)/4;
				yield;
			}
		} Position;
	}
	task SealDie(x,y,r,g,b) {
		let obj = Obj_Create(OBJ_SPELL);
		ObjEffect_SetTexture(obj,imgPlayer); ObjEffect_SetRenderState(obj,ADD);
		ObjEffect_CreateVertex(obj,4); ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN); ObjEffect_SetLayer(obj, 5);
		ObjEffect_SetVertexUV(obj,0,160,160); ObjEffect_SetVertexUV(obj,1,256,160); ObjEffect_SetVertexUV(obj,2,256,256); ObjEffect_SetVertexUV(obj,3,160,256);
		ObjEffect_SetVertexXY(obj,0,-48,-48); ObjEffect_SetVertexXY(obj,1,48,-48); ObjEffect_SetVertexXY(obj,2,48,48); ObjEffect_SetVertexXY(obj,3,-48,48);
		ascent(i in 0..4) { ObjEffect_SetVertexColor(obj, i, 255, r, g, b); }
		Obj_SetPosition(obj, x, y);
		descent(i in 0..15) {
			SetIntersectionCircle(Obj_GetX(obj), Obj_GetY(obj), 40, 12, true);
			ObjEffect_SetScale(obj, i/15, i/15);
			yield;
		}
	}
	task SealDie2(x,y) {
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,imgPlayer); ObjEffect_SetRenderState(obj,ADD);
		ObjEffect_CreateVertex(obj,4); ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN); ObjEffect_SetLayer(obj, 5);
		ObjEffect_SetVertexUV(obj,0,160,160); ObjEffect_SetVertexUV(obj,1,256,160); ObjEffect_SetVertexUV(obj,2,256,256); ObjEffect_SetVertexUV(obj,3,160,256);
		ObjEffect_SetVertexXY(obj,0,-48,-48); ObjEffect_SetVertexXY(obj,1,48,-48); ObjEffect_SetVertexXY(obj,2,48,48); ObjEffect_SetVertexXY(obj,3,-48,48);
		Obj_SetPosition(obj, x, y);
		let a = rand(0,360); let v = rand(1, 7); let c = rand(0,360); let t = 40;
		let r = 128+64*sin(c); let g = 128+64*sin(c-120); let b = 128+64*sin(c-240);
		descent(i in 0..t) {
			ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 255, r*i/t, g*i/t, b*i/t); }
			Obj_SetPosition(obj, Obj_GetX(obj)+v*cos(a), Obj_GetY(obj)+v*sin(a));
			ObjEffect_SetScale(obj, i/t, i/t);
			yield;
		}
	}
}

script_spell WildExorcismDance {
	let GCSD = GetCurrentScriptDirectory;
	let imgPlayer = GCSD ~ "pl00.png";
	@Initialize {
		StartBomb;
		//DeleteEnemyShotToItemInCircle(SHOT, GetPlayerX, GetPlayerY, 1000);
	}
	@Finalize {
	}
	@MainLoop { yield; }
	task StartBomb {
		PlaySE(GCSD~"se_bomb.wav");
		SetPlayerInvincibility(330);
		ascent(i in 0..70) { PlaySE(GCSD~"se_tan00.wav"); Seal(48*(sin(i*45))^2); Seal(-48*(sin(i*45))^2); loop(3) { yield; } }
		loop(60) { yield; } End;
	}
	task Seal(a) {
		let obj = Obj_Create(OBJ_SPELL);
		ObjEffect_SetTexture(obj,imgPlayer); ObjEffect_SetRenderState(obj,ADD);
		ObjEffect_CreateVertex(obj,4); ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN); ObjEffect_SetLayer(obj, 5);
		ObjEffect_SetVertexUV(obj,0,128,240); ObjEffect_SetVertexUV(obj,1,128,256); ObjEffect_SetVertexUV(obj,2,0,256); ObjEffect_SetVertexUV(obj,3,0,240);
		ObjEffect_SetVertexXY(obj,0,-16,0); ObjEffect_SetVertexXY(obj,1,16,0); ObjEffect_SetVertexXY(obj,2,16,256); ObjEffect_SetVertexXY(obj,3,-16,256);
		ObjEffect_SetVertexColor(obj, 0, 255, 255, 255, 255);
		ObjEffect_SetVertexColor(obj, 1, 255, 255, 255, 255);
		ObjEffect_SetVertexColor(obj, 2, 255, 55, 55, 55);
		ObjEffect_SetVertexColor(obj, 3, 255, 55, 55, 55);
		task Position {
			let y = GetClipMaxY;
			loop(60) {
				ObjSpell_SetIntersecrionLine(obj, GetPlayerX+a, Obj_GetY(obj), GetPlayerX+a, Obj_GetY(obj)+128, 16, 10, true);
				Obj_SetPosition(obj, GetPlayerX+a, y);
				y-=32;
				yield;
			} Obj_Delete(obj);
		} Position;
	}
}

script_spell Ancestors {
	let GCSD = GetCurrentScriptDirectory;
	let imgPlayer = GCSD ~ "pl00.png";
	@Initialize {
		StartBomb;
		//DeleteEnemyShotToItemInCircle(SHOT, GetPlayerX, GetPlayerY, 1000);
	}
	@Finalize {
	}
	@MainLoop { yield; }
	task StartBomb {
		PlaySE(GCSD~"se_bomb.wav");
		SetPlayerInvincibility(330);
		AimShot;
		ascent(i in 0..45) { Seal(sin(i*21)); Seal(-sin(i*21)); loop(4) { yield; } }
		loop(90) { yield; } End;
	}
	task AimShot {
		ascent(i in 0..60) {
			PlaySE(GCSD~"se_tan00.wav");
			Aim(i*26); loop(3) { yield; }
		}
	}
	task Seal(a) {
		let obj = Obj_Create(OBJ_SPELL);
		ObjEffect_SetTexture(obj,imgPlayer); ObjEffect_SetRenderState(obj,ADD);
		ObjEffect_CreateVertex(obj,4); ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN); ObjEffect_SetLayer(obj, 5);
		ObjEffect_SetVertexUV(obj,0,80,192); ObjEffect_SetVertexUV(obj,1,128,192); ObjEffect_SetVertexUV(obj,2,128,240); ObjEffect_SetVertexUV(obj,3,80,240);
		ObjEffect_SetVertexXY(obj,0,0,-12); ObjEffect_SetVertexXY(obj,1,0,12); ObjEffect_SetVertexXY(obj,2,-384,12); ObjEffect_SetVertexXY(obj,3,-384,-12);
		ObjEffect_SetAngle(obj, 0, 0, 90-a*2);
		task Position {
			let x = GetCenterX+168*a; let y = GetClipMinY;
			loop(60) {
				ObjSpell_SetIntersecrionLine(obj, x, Obj_GetY(obj), x, Obj_GetY(obj)-384, 20, 0, true);
				Obj_SetPosition(obj, x, y);
				x+=17*cos(90-a*2); y+=17*sin(90-a*2);
				yield;
			} Obj_Delete(obj);
		} Position;
	}
	task Aim(a) {
		let obj = Obj_Create(OBJ_SPELL);
		ObjEffect_SetTexture(obj,imgPlayer); ObjEffect_SetRenderState(obj,ADD);
		ObjEffect_CreateVertex(obj,4); ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN); ObjEffect_SetLayer(obj, 5);
		ObjEffect_SetVertexUV(obj,0,96,160); ObjEffect_SetVertexUV(obj,1,128,160); ObjEffect_SetVertexUV(obj,2,128,192); ObjEffect_SetVertexUV(obj,3,96,192);
		ObjEffect_SetVertexXY(obj,0,-16,-16); ObjEffect_SetVertexXY(obj,1,16,-16); ObjEffect_SetVertexXY(obj,2,16,16); ObjEffect_SetVertexXY(obj,3,-16,16);
		task Position {
			task Reaiming {
				loop(20) { yield; }
				angle = atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
			} Reaiming;
			let angle = a;
			let x = GetCommonDataDefault("X Koishi", 0);
			let y = GetCommonDataDefault("Y Koishi", 0);
			while(!Obj_BeDeleted(obj)) {
				ObjEffect_SetAngle(obj, 0, 0, angle);
				SetIntersectionCircle(x, y, 20, 0, true);
				Obj_SetPosition(obj, x, y);
				x+=8*cos(angle); y+=8*sin(angle);
				yield;
			} Obj_Delete(obj);
		} Position;
	}
}