task TShadow
	{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,"");	
	ObjSprite2D_SetSourceRect(obj,0,0,1,1);
	ObjSprite2D_SetDestRect(obj,-64,-64,GetStgFrameWidth+64,GetStgFrameHeight+64);
	ObjRender_SetColorHSV(obj,0,0,0);
	Obj_SetRenderPriority(obj,0.29);
	ascent(t in 1..36)
		{
		ObjRender_SetAlpha(obj,t*255/35);
		yield;
		}
	while(SpellSwitch == false){yield;}
	loop(25){yield;}
	descent(t in 0..20)
		{
		ObjRender_SetAlpha(obj,t*255/20);
		yield;
		}
	Obj_Delete(obj);
	}

task TMariSpell
{
	let spell = GetSpellManageObject();
	SpellSwitch = false;	
	ShotPermit = true;
	let MainSpeed = PlayerSpeed;
	PlayerSpeed = [MainSpeed[1],MainSpeed[1]];	
	HitboxForce = true;
	TShadow;
	
	let time = [90,45,45];
	let switch = false;
	SetPlayerInvincibilityFrame(time[0]+time[1]+time[2]+20+30+30);
	let xM = GetPlayerX;
	let yM = GetPlayerY;	
	let angleM = 0;	

	let wM = 24;
	let spd = GetStgFrameHeight*1.5/8;
	let vcount = 6;

	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetTexture(obj,"");
	Obj_SetRenderPriority(obj, 0.57);
	ObjPrim_SetVertexCount(obj, (vcount+1)*2);
	ObjSprite2D_SetSourceRect(obj,0,0,1,1);
	ObjRender_SetColorHSV(obj,0,0,0);

	let obj2 = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(obj2, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetTexture(obj2,"");
	Obj_SetRenderPriority(obj2, 0.57);
	ObjPrim_SetVertexCount(obj2, (vcount+1)*2);
	ObjSprite2D_SetSourceRect(obj2,0,0,1,1);
	ObjRender_SetBlendType(obj2,BLEND_ADD_ARGB);

	descent(t in -time[1]-time[2]..time[0])
		{
		let dist = 32+max(t,0)*(GetStgFrameHeight*1.5-32)/time[0];
		let array = GetShotIdInCircleA2(GetStgFrameWidth*0.5,GetStgFrameHeight*0.5,dist+64,TARGET_ENEMY);
		if(t > -time[1])
			{
			ascent(i in 0..length(array))
				{
				let shot = array[i];
				if(!Obj_IsDeleted(shot) && !ObjShot_IsSpellResist(shot))
					{
					ObjShot_ToItem(shot);
					}
				}
			}
		if(t == time[0]-20)
			{
			angleM = atan2(GetPlayerY-yM,GetPlayerX-xM);
			xM = GetPlayerX;
			yM = GetPlayerY;
			ascent(i in 0..4)
				{
				TShot(i*90+angleM,i);
				}
			}
		if(t == -time[1])
			{
			PlaySound("se_Laser",100);
			switch = true;
			}
		ascent(i in 0..vcount+1)
			{
			let ind = i*2;
			let angle = max(t,0)*360/time[0]+i*360/vcount-90;
			if(t > -time[1])
				{
				ObjPrim_SetVertexPosition(obj,ind,GetPlayerX+dist*cos(angle),GetPlayerY+dist*sin(angle),0);
				ObjPrim_SetVertexPosition(obj,ind+1,GetPlayerX+GetStgFrameHeight*1.5*cos(angle),GetPlayerY+GetStgFrameHeight*1.5*sin(angle),0);
				}
			else if(t == -time[1])
				{
				Obj_Delete(obj);
				}
			let s = 1;
			let alpha = 1;
			let a = rand(205/255,1);
			if(t <= -time[1])
				{
				let n = min(10,absolute(t+time[1]))/10;
				s = 1+n;
				alpha = 1-n;
				}
			ObjPrim_SetVertexPosition(obj2,ind,GetPlayerX+dist*s*cos(angle),GetPlayerY+dist*s*sin(angle),0);
			ObjPrim_SetVertexPosition(obj2,ind+1,GetPlayerX+(dist*s+5)*cos(angle),GetPlayerY+(dist*s+5)*sin(angle),0);
			ObjPrim_SetVertexAlpha(obj2,ind,a*alpha*255);
			ObjPrim_SetVertexAlpha(obj2,ind+1,a*alpha*255);
			}
		yield;
		}
	Obj_Delete(obj2);
	loop(30){yield;}
	PlaySound("se_Die5",120);
	SpellSwitch = true;
	PlayerSpeed = MainSpeed;	
	HitboxForce = false;
	Obj_Delete(spell);

	task TShot(angle,n)
		{
		let dist = 0;
		while(dist < GetStgFrameHeight*1.5)
			{
			if(dist >= spd || n == 0 || n == 1)
				{
				TLaser(xM+dist*cos(angle),yM+dist*sin(angle));
				}
			dist+=spd;
			if(n == 0)
				{
				PlaySound("se_LaserDelay",120);
				}
			loop(6){yield;}
			}
		
		task TLaser(xM,yM)
			{
			let x = xM;
			let y = yM;
			let dist = 0;
			let w = 4;
			let obj = ObjShot_Create(OBJ_STRAIGHT_LASER);
			ObjShot_Regist(obj);
			ObjShot_SetAutoDelete(obj,false);
			ObjShot_SetGraphic(obj,OVAL[SHOT_YELLOW]);
			ObjShot_SetDamage(obj,0);
			ObjShot_SetPenetration(obj,10^10);
			ObjStLaser_SetAngle(obj,angle-90);
			ObjStLaser_SetSource(obj,false);
			Obj_SetRenderPriority(obj,0.56);
	
			let counter = -1;
			while(counter < time[2])
				{
				if(switch == true)
					{
					counter+=1;
					}	
				let a = rand(205,255);
				dist = min(GetStgFrameHeight*1.5,dist+17.5);
				x = xM+dist*cos(angle+90);
				y = yM+dist*sin(angle+90);
				if(counter == 0)
					{
					ObjShot_SetDamage(obj,800/time[2]);
					ObjShot_SetSpellFactor(obj,true);
					}	
				if(counter >= 0)
					{
					if(counter < 5)
						{
						w = 4+counter*(wM-4)/4;
						}	
					else
						{
						w = wM*(1-(counter-4)/(time[2]-4));
						}
					}
				ObjMove_SetPosition(obj,x,y);
				ObjLaser_SetLength(obj,dist*2);
				ObjLaser_SetRenderWidth(obj,w);
				ObjLaser_SetIntersectionWidth(obj,w);
				ObjLaser_SetInvalidLength(obj,0,0);
				ObjRender_SetColorHSV(obj,60,255,a);
				yield;
				}
			Obj_Delete(obj);
			}
		}
}
