let CUT_KOUMA = 0;
let CUT_YOUMU = 1;
let CUT_EIYA = 2;
let CUT_KAEI = 3;
let CUT_FUZIN = 4;
let CUT_TIREI = 5;

//------------------------------------------------------------------------------
//	ėpCutIn֐
//	@spell_type	JbgC@
//	@cutin_img	摜t@CpX
//	@l		`挳`
//	@t		`挳`
//	@r		`挳`E
//	@b		`挳`
//	@arg_angle	`px
//	@img_scale	`gx
//------------------------------------------------------------------------------
task SpellCard(spell_type,cutin_img,l,t,r,b,arg_angle,img_scale){
	let wait_time = 40;
	cutin;
	task cutin {
		let cut = cutin_img;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, cut);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetLayer(obj, 5);
		let wh = [l ,t, r, b];
		let xy = [-(wh[2] - wh[0]) / 2, (wh[2] - wh[0]) / 2, (wh[2] - wh[0]) / 2, -(wh[2] - wh[0]) / 2, -(wh[3] - wh[1]) / 2, -(wh[3] - wh[1]) / 2, (wh[3] - wh[1]) / 2, (wh[3] - wh[1]) / 2];
		let uv = [wh[0], wh[2], wh[2], wh[0], wh[1], wh[1], wh[3], wh[3]];
		ascent (i in 0..4) {
			ObjEffect_SetVertexXY(obj, i, xy[i], xy[i + 4]);
			ObjEffect_SetVertexUV(obj, i, uv[i], uv[i + 4]);
		}
		if (spell_type == CUT_KOUMA) {
			let start_x = GetClipMaxX + (absolute(r - l) / 2);
			let end_x = GetClipMaxX - (absolute(r - l) / 2) - 15;
			let move_x = (end_x - start_x) / wait_time;
			Obj_SetPosition(obj, start_x, GetCenterY);
			ObjEffect_SetScale(obj, img_scale, img_scale);
			let al = 255 / wait_time;
			ascent (i in 0..wait_time) {;
				ascent(j in 0..4) {
					ObjEffect_SetVertexColor(obj, j, i * al, 255, 255, 255);
				}
				Obj_SetPosition(obj, start_x + move_x * i, GetCenterY);
				yield;
			}
			loop( trunc(wait_time * 1.5) ){
				yield;
			}
			
			ascent (i in 0..wait_time) {;
				ascent(j in 0..4) {
					ObjEffect_SetVertexColor(obj, j, 255 - (i * al), 255, 255, 255);
				}
				ObjEffect_SetScale(obj, img_scale + i * (2 / wait_time), img_scale + i * (2 / wait_time));
				yield;
			}
		}
		if (spell_type == CUT_YOUMU) {
			let x = absolute(r - l) / 2;
			let start_y = GetCenterY - 125;
			let end_y = GetCenterY + 125;
			let move_y = (end_y - start_y) / (wait_time * 3);
			let get_y;
			Obj_SetPosition(obj, GetClipMaxX - 5 - x, start_y);
			ObjEffect_SetScale(obj, img_scale, img_scale);
			let al = 255 / wait_time;
			ascent (i in 0..wait_time * 1.5) {;
				ascent(j in 0..4) {
					ObjEffect_SetVertexColor(obj, j, i * al, 255, 255, 255);
				}
				Obj_SetPosition(obj, GetClipMaxX - 5 - x, start_y + move_y * (i * 0.75));
				yield;
			}
			get_y = Obj_GetY(obj);
			ascent(i in 0..wait_time * 1.5) {
				Obj_SetPosition(obj, GetClipMaxX - 5 - x, get_y + move_y * (i * 0.75));
				yield;
			}
			get_y = Obj_GetY(obj);
			ascent (i in 0..wait_time * 1.5) {;
				ascent(j in 0..4) {
					ObjEffect_SetVertexColor(obj, j, 255 - (i * al), 255, 255, 255);
				}
				Obj_SetPosition(obj, GetClipMaxX - 5 - x, get_y + move_y * (i * 0.75));
				yield;
			}
		}
		if (spell_type == CUT_EIYA) {
			let start_y = GetCenterY - 50;
			let end_y = GetCenterY + 50;
			let move_y = (end_y - start_y) / (wait_time * 3);
			let get_y;
			Obj_SetPosition(obj, GetCenterX, start_y);
			ObjEffect_SetScale(obj, img_scale, img_scale);
			let al = 255 / (wait_time * 1.5);
			ascent (i in 0..wait_time * 1.5) {;
				ascent(j in 0..4) {
					ObjEffect_SetVertexColor(obj, j, i * al, 255, 255, 255);
				}
				Obj_SetPosition(obj, GetCenterX, start_y + move_y * i);
				yield;
			}
			get_y = Obj_GetY(obj);
			ascent(i in 0..wait_time * 1.5) {
				Obj_SetPosition(obj, GetCenterX, get_y + move_y * i);
				yield;
			}
			get_y = Obj_GetY(obj);
			ascent (i in 0..wait_time * 1.5) {;
				ascent(j in 0..4) {
					ObjEffect_SetVertexColor(obj, j, 255 - (i * al), 255, 255, 255);
				}
				Obj_SetPosition(obj, GetCenterX, get_y + move_y * i);
				yield;
			}
		}
		if (spell_type == CUT_KAEI) {
			let x = absolute((r - l) / 2);
			let y = absolute((b - t) / 2);
			xy = [-x, x, x, -x, -y, -y, y, y];
			uv = [wh[0], wh[2], wh[2], wh[0], wh[1], wh[1], wh[3], wh[3]];
			ascent (i in 0..4) {
				ObjEffect_SetVertexXY(obj, i, xy[i], xy[i + 4]);
				ObjEffect_SetVertexUV(obj, i, uv[i], uv[i + 4]);
			}
			Obj_SetPosition(obj, GetCenterX, GetClipMinY + 50 + y);
			ObjEffect_SetScale(obj, img_scale, 0);
			let change_scale = img_scale / (wait_time * 0.22);
			ascent(i in 0..wait_time * 0.25) {
				ObjEffect_SetScale(obj, img_scale, 0 + change_scale * i);
				yield;
			}
			loop (wait_time * 2.5) {
				yield;
			}
			descent(i in 0..wait_time * 0.25) {
				ObjEffect_SetScale(obj, img_scale, 0 + change_scale * i);
				yield;
			}
		}
		if (spell_type == CUT_FUZIN) {
			let start_y = GetCenterY + 150;
			let end_y = GetCenterY - 50;
			let move_y = (end_y - start_y) / (wait_time * 3);
			let get_y;
			Obj_SetPosition(obj, GetCenterX + 50, start_y);
			ObjEffect_SetScale(obj, img_scale, img_scale);
			let al = 255 / wait_time;
			ascent (i in 0..wait_time) {;
				ascent(j in 0..4) {
					ObjEffect_SetVertexColor(obj, j, i * al, 255, 255, 255);
				}
				if (i < wait_time / 2) {
					Obj_SetPosition(obj, GetCenterX + 50, Obj_GetY(obj) + move_y * 0.5);
				} else {
					Obj_SetPosition(obj, GetCenterX + 50, Obj_GetY(obj) + move_y * 1.5);
				}
				yield;
			}
			get_y = Obj_GetY(obj);
			ascent(i in 0..wait_time) {
				Obj_SetPosition(obj, GetCenterX + 50, get_y + move_y * (i * 1.5));
				yield;
			}
			get_y = Obj_GetY(obj);
			ascent (i in 0..wait_time) {;
				ascent(j in 0..4) {
					ObjEffect_SetVertexColor(obj, j, 255 - (i * al), 255, 255, 255);
				}
				if (i < wait_time / 4) {
					Obj_SetPosition(obj, GetCenterX + 50, Obj_GetY(obj) + move_y * 1.5);
				} else {
					Obj_SetPosition(obj, GetCenterX + 50, Obj_GetY(obj) + move_y * 0.5);
				}
				yield;
			}
		}
		if (spell_type == CUT_TIREI) {
			let set_x = GetClipMaxX + ((r - l) / 2);
			let set_y = GetClipMinY - ((b - t) / 2);
			let set_radius = (absolute(GetCenterX - set_x) ^ 2 + absolute(GetCenterY - set_y) ^ 2) ^ 0.5;
			let start_x = GetCenterX + set_radius * cos(arg_angle);
			let start_y = GetCenterY + set_radius * sin(arg_angle);
			Obj_SetPosition(obj, start_x, start_y);
			ObjEffect_SetScale(obj, img_scale, img_scale);
			Obj_SetAngle(obj, atan2(GetCenterY - start_y, GetCenterX - start_x));
			Obj_SetSpeed(obj, ((absolute(GetCenterX - start_x) ^ 2 + absolute(GetCenterY - start_y) ^ 2) ^ 0.5) / wait_time);
			let al = 255 / (wait_time * 0.95);
			ascent (i in 0..wait_time * 0.95) {;
				ascent(j in 0..4) {
					ObjEffect_SetVertexColor(obj, j, i * al, 255, 255, 255);
				}
				yield;
			}
			ascent(i in 0..wait_time * 1.5) {
				Obj_SetSpeed(obj, 0.5);
				yield;
			}
			ascent(i in 0..wait_time) {
				Obj_SetSpeed(obj, 0 + i * 0.5);
				ascent(j in 0..4) {
					ObjEffect_SetVertexColor(obj, j, 355 - (i * al), 255, 255, 255);
				}
				yield;
			}
		}
		Obj_Delete(obj);
	}
}