let SE_SPELL1 = current ~ "./se/spellB1.wav";
let SE_SPELL2 = current ~ "./se/spellB2.wav";
let SE_SPELL3 = current ~ "./se/spellB3.wav";

function LoadSpellData{
	LoadSound(SE_SPELL1);
	LoadSound(SE_SPELL2);
	LoadSound(SE_SPELL3);
}

task TSpell
{
	let current = GetCurrentScriptDirectory();
	let imgEffect = current ~ "./img/marisa_spellB.png";

	SetPlayerInvincibilityFrame(420);//無敵時間を設定
	Spell;
	loop(300){
		yield;
	}
	Obj_Delete(GetSpellManageObject());

	task Spell(){
		let objSpell = ObjShot_Create(OBJ_STRAIGHT_LASER);
		ObjShot_SetSpellFactor(objSpell, true);
		ObjShot_SetEraseShot(objSpell, true);
		ObjStLaser_SetAngle(objSpell, 270);
		ObjLaser_SetLength(objSpell, 480);
		ObjLaser_SetRenderWidth(objSpell, 300);
		ObjLaser_SetIntersectionWidth(objSpell, 300);
		ObjShot_SetGraphic(objSpell, 3);
		ObjShot_SetDamage(objSpell, 12);
		ObjLaser_SetInvalidLength(objSpell, 0, 0);


		Effect(objSpell);
		SetPlayerSpeed(0.5, 0.5);
		loop(3){
			PlaySE(SE_SPELL3);
			RingConcentration(GetPlayerX, GetPlayerY, 3.0, [255,255,255], [rand(30,90), rand(30,90), rand(0,180)]);
			RingConcentration(GetPlayerX, GetPlayerY, 3.0, [255,255,255], [rand(30,90), rand(30,90), rand(0,180)]);
			loop(10){
				yield;
			}
		}
		PlaySE(SE_SPELL3);
		RingConcentration(GetPlayerX, GetPlayerY, 5.0, [255,255,255], [0, 0, 0]);
		loop(30){
			yield;
		}
		ObjShot_Regist(objSpell);
		PlaySE(SE_SPELL1);
		PlaySE(SE_SPELL2);
		loop(240){
			ObjMove_SetPosition(objSpell, GetPlayerX, GetPlayerY);
			DeleteShotInCircle(TYPE_SHOT, TYPE_ITEM, GetPlayerX, GetPlayerY, 60);
			Set2DCameraFocusX(192 + rand(-8, 8));
			Set2DCameraFocusY(224 + rand(-8, 8));
			yield;
		}

		SetPlayerSpeed(5, 2);
		Reset2DCamera();
		Obj_Delete(objSpell);

		//エフェクト
		task Effect(obj){
			let objEfc = ObjPrim_Create(OBJ_PRIMITIVE_2D);
			let Rect = 128;
			let rate = 24;
			let C = 64;
			let ScaleX = 0;
			let ScaleY = 0.05;

			ObjPrim_SetTexture(objEfc, imgEffect);
			ObjPrim_SetPrimitiveType(objEfc, PRIMITIVE_TRIANGLESTRIP);
			Obj_SetRenderPriority(objEfc, 0.6);
			ObjPrim_SetVertexCount(objEfc, 2*rate + 2);
			ObjRender_SetBlendType(objEfc, BLEND_ADD_RGB);
			ObjRender_SetAngleZ(objEfc, -90);
			ObjRender_SetScaleX(objEfc, ScaleX);
			ObjRender_SetScaleY(objEfc, ScaleY);

			ObjPrim_SetVertexPosition(objEfc, 0, 0, 1, 0);
			ObjPrim_SetVertexPosition(objEfc, 1, 0, -1, 0);
			ascent(i in 1 .. rate){
				ObjPrim_SetVertexPosition(objEfc, 2*i  , C*i/(rate-1),  64*sin(90*i/(rate-1)), 0);
				ObjPrim_SetVertexPosition(objEfc, 2*i+1, C*i/(rate-1), -64*sin(90*i/(rate-1)), 0);
			}
			ObjPrim_SetVertexPosition(objEfc, 2*rate  , 128,  64, 0);
			ObjPrim_SetVertexPosition(objEfc, 2*rate+1, 128, -64, 0);

			ascent(i in 0 .. 60){
				ObjRender_SetScaleX(objEfc, ScaleX);
				ObjPrim_SetVertexUVT(objEfc, 0, Rect, 128);
				ObjPrim_SetVertexUVT(objEfc, 1, Rect, 0);
				ascent(i in 1 .. rate){
					ObjPrim_SetVertexUVT(objEfc, 2*i  , Rect+C*i/(rate-1), 128);
					ObjPrim_SetVertexUVT(objEfc, 2*i+1, Rect+C*i/(rate-1), 0);
				}
				ObjPrim_SetVertexUVT(objEfc, 2*rate  , Rect+128, 128);
				ObjPrim_SetVertexUVT(objEfc, 2*rate+1, Rect+128, 0);

				ObjRender_SetX(objEfc, GetPlayerX);
				ObjRender_SetY(objEfc, GetPlayerY-15);

				ScaleX = 4.0*i/60;
				yield;
			}
			ObjRender_SetScaleX(objEfc, 4.0);
			ascent(i in 0 .. 10){
				ObjRender_SetScaleY(objEfc, ScaleY);
				ObjPrim_SetVertexUVT(objEfc, 0, Rect, 128);
				ObjPrim_SetVertexUVT(objEfc, 1, Rect, 0);
				ascent(i in 1 .. rate){
					ObjPrim_SetVertexUVT(objEfc, 2*i  , Rect+C*i/(rate-1), 128);
					ObjPrim_SetVertexUVT(objEfc, 2*i+1, Rect+C*i/(rate-1), 0);
				}
				ObjPrim_SetVertexUVT(objEfc, 2*rate  , Rect+128, 128);
				ObjPrim_SetVertexUVT(objEfc, 2*rate+1, Rect+128, 0);

				ObjRender_SetX(objEfc, GetPlayerX);
				ObjRender_SetY(objEfc, GetPlayerY-15);

				Rect -= 9;
				ScaleY = 5.0*i/10;
				if(Rect < 0){Rect -= 128;}
				yield;
			}
			ascent(i in 10 .. 240){
				ObjRender_SetScaleY(objEfc, ScaleY);
				ObjPrim_SetVertexUVT(objEfc, 0, Rect, 128);
				ObjPrim_SetVertexUVT(objEfc, 1, Rect, 0);
				ascent(i in 1 .. rate){
					ObjPrim_SetVertexUVT(objEfc, 2*i  , Rect+C*i/(rate-1), 128);
					ObjPrim_SetVertexUVT(objEfc, 2*i+1, Rect+C*i/(rate-1), 0);
				}
				ObjPrim_SetVertexUVT(objEfc, 2*rate  , Rect+128, 128);
				ObjPrim_SetVertexUVT(objEfc, 2*rate+1, Rect+128, 0);

				ObjRender_SetX(objEfc, GetPlayerX);
				ObjRender_SetY(objEfc, GetPlayerY-15);

				Rect -= 9;
				ScaleY = 4.5+0.5*(i%2);
				if(Rect < 0){Rect -= 128;}
				yield;
			}
			descent(i in 1 .. 11){
				ObjRender_SetScaleY(objEfc, ScaleY);
				ObjRender_SetColor(objEfc, 255*i/10, 255*i/10, 255*i/10);
				ObjPrim_SetVertexUVT(objEfc, 0, Rect, 128);
				ObjPrim_SetVertexUVT(objEfc, 1, Rect, 0);
				ascent(i in 1 .. rate){
					ObjPrim_SetVertexUVT(objEfc, 2*i  , Rect+C*i/(rate-1), 128);
					ObjPrim_SetVertexUVT(objEfc, 2*i+1, Rect+C*i/(rate-1), 0);
				}
				ObjPrim_SetVertexUVT(objEfc, 2*rate  , Rect+128, 128);
				ObjPrim_SetVertexUVT(objEfc, 2*rate+1, Rect+128, 0);

				ObjRender_SetX(objEfc, GetPlayerX);
				ObjRender_SetY(objEfc, GetPlayerY-15);

				Rect -= 9;
				ScaleY = 4.5+0.5*(i%2);
				if(Rect < 0){Rect -= 128;}
				yield;
			}
			Obj_Delete(objEfc);
		}
	}
}

task RingConcentration(x, y, last_scale, color, angle){
	let current = GetCurrentScriptDirectory();
	let imgEffect = current ~ "./img/ring.png";

	let scale = last_scale;
	let alpha_r = 0;

	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	ObjPrim_SetTexture(obj, imgEffect);//オブジェクトとテスクチャを関連付け
	Obj_SetRenderPriority(obj, 0.29);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 128, 128);
	ObjSprite2D_SetDestRect(obj, -64, -64, 64, 64);
	ObjRender_SetAngleXYZ(obj, angle[0], angle[1], angle[2]);
	ObjRender_SetAlpha(obj, 255);
	ObjRender_SetPosition(obj, x, y, 0);
	ascent(i in 0 .. 30){
		ObjRender_SetColor(obj, alpha_r*color[0], alpha_r*color[1], alpha_r*color[2]);
		ObjRender_SetScaleXYZ(obj, scale, scale, 1.0);
		scale -= last_scale/30;
		alpha_r += 1.0/30;
		yield;
	}
	ObjRender_SetColor(obj, color[0]/2, color[1]/2, color[2]/2);
	ascent(i in 30 .. 30){
		ObjRender_SetScaleXYZ(obj, scale, scale, 1.0);
		scale -= last_scale/30;
		yield;
	}
	Obj_Delete(obj);
}
