task MagicNapalm
{
	let x=GetPlayerX;
	let y=GetPlayerY;
	let speed=4.0;
	let angle=CharaDirection*45-90;
	let damage=Status_MagicPower/5*4.0;
	if(IsPermitPlayerShot==false){return;}
	if(GetCommonData("SceneChange",false)==true){return;}
	let ShotDamageType=4;
	let ExRange=1;
	if(MagicNapalmNum>=MagicNapalmNumMax){return;}

	if(SpiritPoint>=10*SpiritReduce)
	{
		SpiritPoint-=10*SpiritReduce;
	}
	else
	{
		SpiritPointLack;
		return;
	}

	Obj_PlaySE(GetCurrentScriptDirectory~"../se/don20.wav");
	MagicNapalmNum+=1;

	let imgWhite = GetCurrentScriptDirectory() ~ "../img/Marisa_shots.png";
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetTexture(obj, imgWhite);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjPrim_SetVertexCount(obj, 4);
	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	Obj_SetRenderPriorityI(obj,30);
	ObjRender_SetAngleZ(obj,0);

	ObjPrim_SetVertexPosition(obj, 0, -32, -32, 0);
	ObjPrim_SetVertexPosition(obj, 1,32, -32, 0);
	ObjPrim_SetVertexPosition(obj, 2, 32, 32, 0);
	ObjPrim_SetVertexPosition(obj, 3,-32, 32, 0);

	ObjPrim_SetVertexUVT(obj, 0, 0, 257);
	ObjPrim_SetVertexUVT(obj, 1, 128, 257);
	ObjPrim_SetVertexUVT(obj, 2, 128, 384);
	ObjPrim_SetVertexUVT(obj, 3, 0, 384);

	ObjRender_SetPosition(obj,x,y,0);

	ObjRender_SetAlpha(obj,255);
	ObjRender_SetScaleXYZ(obj,ExRange,ExRange,ExRange);
	let Scale=1;

	let Bspeed=speed;
	let Zangle=rand(0,360);

	DummyShot;

	ShotForbitTime(30);

	task DummyShot
	{
	let objD = ObjShot_Create(OBJ_SHOT);
	ObjMove_SetX(objD, x);//x座標設定
	ObjMove_SetY(objD, y);//y座標設定;
	ObjMove_SetSpeed(objD, speed);//x座標設定
	ObjMove_SetAngle(objD, angle);//y座標設定;
	ObjShot_SetGraphic(objD, 100);//画像設定
	ObjShot_SetDamage(objD, 0);//ダメージを設定
	ObjShot_SetPenetration(objD, 1);//貫通力は適当に大きく
	ObjShot_Regist(objD);

	ObjRender_SetAlpha(objD,255);

	while( !Obj_IsDeleted(objD))
	{
		ObjMove_SetSpeed(objD, speed);//x座標設定
		if(ObjCol_IsIntersected(objD))
		{
			speed=0;
		}
		yield;
	}	
	}

	loop(60)
	{
		let sr=Obj_GetValue(GetPlayerObjectID,"Move_Right");
		let sl=Obj_GetValue(GetPlayerObjectID,"Move_Left");
		let su=Obj_GetValue(GetPlayerObjectID,"Move_Up");
		let sd=Obj_GetValue(GetPlayerObjectID,"Move_Down");
		if(sr!=0)
		{
			ObjRender_SetX(obj, ObjRender_GetX(obj)-sr);
		}
		if(sl!=0)
		{
			ObjRender_SetX(obj, ObjRender_GetX(obj)-sl);
		}
		if(su!=0)
		{
			ObjRender_SetY(obj, ObjRender_GetY(obj)-su);
		}
		if(sd!=0)
		{
			ObjRender_SetY(obj, ObjRender_GetY(obj)-sd);
		}
		if(speed>0)
		{
		speed-=Bspeed/60;
		}
		ObjRender_SetPosition(obj,ObjRender_GetX(obj)+speed*cos(angle),ObjRender_GetY(obj)+speed*sin(angle),0);
		ObjRender_SetAngleXYZ(obj,0,0,Zangle);
		Zangle+=6;
		if(GetCommonData("SceneChange",false)==true){break;}
		yield;
	}
	loop(60)
	{
		let sr=Obj_GetValue(GetPlayerObjectID,"Move_Right");
		let sl=Obj_GetValue(GetPlayerObjectID,"Move_Left");
		let su=Obj_GetValue(GetPlayerObjectID,"Move_Up");
		let sd=Obj_GetValue(GetPlayerObjectID,"Move_Down");
		if(sr!=0)
		{
			ObjRender_SetX(obj, ObjRender_GetX(obj)-sr);
		}
		if(sl!=0)
		{
			ObjRender_SetX(obj, ObjRender_GetX(obj)-sl);
		}
		if(su!=0)
		{
			ObjRender_SetY(obj, ObjRender_GetY(obj)-su);
		}
		if(sd!=0)
		{
			ObjRender_SetY(obj, ObjRender_GetY(obj)-sd);
		}
		ObjRender_SetAngleXYZ(obj,0,0,Zangle);
		Zangle+=6;
		if(GetCommonData("SceneChange",false)==true){break;}
		yield;
	}
	if(GetCommonData("SceneChange",false)==false)
	{
	Obj_PlaySE(GetCurrentScriptDirectory~"../se/tm2_bom003.wav");
	ExEffect;
	DamageShotFire;

	}
	Scale=0;
	loop(45)
	{
		let sr=Obj_GetValue(GetPlayerObjectID,"Move_Right");
		let sl=Obj_GetValue(GetPlayerObjectID,"Move_Left");
		let su=Obj_GetValue(GetPlayerObjectID,"Move_Up");
		let sd=Obj_GetValue(GetPlayerObjectID,"Move_Down");
		if(sr!=0)
		{
			ObjRender_SetX(obj, ObjRender_GetX(obj)-sr);
		}
		if(sl!=0)
		{
			ObjRender_SetX(obj, ObjRender_GetX(obj)-sl);
		}
		if(su!=0)
		{
			ObjRender_SetY(obj, ObjRender_GetY(obj)-su);
		}
		if(sd!=0)
		{
			ObjRender_SetY(obj, ObjRender_GetY(obj)-sd);
		}
		ObjRender_SetAngleXYZ(obj,0,0,Zangle);
		ObjRender_SetScaleXYZ(obj,Scale,Scale,Scale);
		Zangle+=6;
		if(GetCommonData("SceneChange",false)==true){break;}
		yield;
	}
	
	Obj_Delete(obj);
	MagicNapalmNum-=1;

	task DamageShotFire
	{
		loop(5)
		{
		DamageShot(ObjRender_GetX(obj),ObjRender_GetY(obj));
		wait(7);
		}
	}

	task DamageShot(x,y)
	{
		let objShot = ObjShot_Create(OBJ_SHOT);
		ObjMove_SetX(objShot, x);//x座標設定
		ObjMove_SetY(objShot, y);//y座標設定;
		ObjShot_SetGraphic(objShot, ShotDamageType);//画像設定
		ObjShot_SetDamage(objShot, damage);//ダメージを設定
		ObjShot_SetPenetration(objShot, 10000);//貫通力は適当に大きく
		ObjShot_Regist(objShot);

		ObjRender_SetAlpha(objShot,0);

		let ShotCount=0;
	//	while( !Obj_IsDeleted(objShot) )
		loop(1)
		{
			let sr=Obj_GetValue(GetPlayerObjectID,"Move_Right");
			let sl=Obj_GetValue(GetPlayerObjectID,"Move_Left");
			let su=Obj_GetValue(GetPlayerObjectID,"Move_Up");
			let sd=Obj_GetValue(GetPlayerObjectID,"Move_Down");
			if(sr!=0)
			{
				ObjMove_SetX(objShot, ObjMove_GetX(objShot)-sr);
			}
			if(sl!=0)
			{
				ObjMove_SetX(objShot, ObjMove_GetX(objShot)-sl);
			}
			if(su!=0)
			{
				ObjMove_SetY(objShot, ObjMove_GetY(objShot)-su);
			}
			if(sd!=0)
			{
				ObjMove_SetY(objShot, ObjMove_GetY(objShot)-sd);
			}
			ShotCount+=1;
			if(ShotCount>=45){Obj_Delete(objShot);}
			yield;
		}
		Obj_Delete(objShot);
	}

	task ExEffect
	{
		loop(15)
		{
			ShotEffect(ObjRender_GetX(obj),ObjRender_GetY(obj));
			yield;
		}
	}

	task ShotEffect(x,y)
	{
		let imgWhite = GetCurrentScriptDirectory() ~ "../img/effects.png";
		let obje = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obje, imgWhite);
		ObjPrim_SetPrimitiveType(obje, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obje, 4);
		ObjRender_SetBlendType(obje, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obje,30);
		ObjRender_SetAngleZ(obje,0);

		ObjPrim_SetVertexPosition(obje, 0, -64, -64, 0);
		ObjPrim_SetVertexPosition(obje, 1, 64, -64, 0);
		ObjPrim_SetVertexPosition(obje, 2, 64, 64, 0);
		ObjPrim_SetVertexPosition(obje, 3,-64, 64, 0);

		ObjPrim_SetVertexUVT(obje, 0, 0, 0);
		ObjPrim_SetVertexUVT(obje, 1, 128, 0);
		ObjPrim_SetVertexUVT(obje, 2, 128, 128);
		ObjPrim_SetVertexUVT(obje, 3, 0, 128);

		let ox=GetPlayerX;
		let oy=GetPlayerY;
		let Speed=rand(2,10);
		let Angle=rand(0,360);

		let Scale=1.0*ExRange;

		let Xangle=rand(0,360)*0;
		let Yangle=rand(0,360)*0;
		let Zangle=rand(0,360)*0;

		let XanglePlus=rand(-10,10);
		let YanglePlus=rand(-10,10);
		let ZanglePlus=rand(-10,10);

		ObjRender_SetPosition(obje,ox,oy,0);

		let Alpha=1;
		ObjRender_SetColor(obje,64,64,128*Alpha);

		ObjRender_SetPosition(obje,x,y,0);

		loop(30)
		{
			let sr=Obj_GetValue(GetPlayerObjectID,"Move_Right");
			let sl=Obj_GetValue(GetPlayerObjectID,"Move_Left");
			let su=Obj_GetValue(GetPlayerObjectID,"Move_Up");
			let sd=Obj_GetValue(GetPlayerObjectID,"Move_Down");
			if(sr!=0)
			{
				ObjRender_SetX(obje, ObjRender_GetX(obje)-sr);
			}
			if(sl!=0)
			{
				ObjRender_SetX(obje, ObjRender_GetX(obje)-sl);
			}
			if(su!=0)
			{
				ObjRender_SetY(obje, ObjRender_GetY(obje)-su);
			}
			if(sd!=0)
			{
				ObjRender_SetY(obje, ObjRender_GetY(obje)-sd);
			}
			ObjRender_SetAngleXYZ(obje,Xangle,Yangle,Zangle);
			ObjRender_SetScaleXYZ(obje,Scale,Scale,Scale);
			ObjRender_SetColor(obje,64*Alpha,64*Alpha,255*Alpha);
			Alpha-=1/30;
			Xangle+=XanglePlus;
			Yangle+=YanglePlus;
			Zangle+=ZanglePlus;
			yield;
		}
		Obj_Delete(obje);
	}

	task ChangeErase
	{
		while(!Obj_IsDeleted(obj))
		{
			if(GetCommonData("SceneChange",false)==true)
			{
				Obj_Delete(obj);
				MagicNapalmNum-=1;
			}
			yield;
		}
	}
}