// Custom delay function for ZUNShot.png

function ShotA1(x,y,spd,dir,graphic,cloud,delay){
	let shot = CreateShotA1(x,y,spd,dir,graphic,delay);
	ManageShot;
	return shot;
		task ManageShot{
		DelayCloud(shot,x,y,spd,dir,graphic,cloud,delay);
		}
	}
function ShotA2(x,y,spd,dir,acc,maxacc,graphic,cloud,delay){
	let shot = CreateShotA2(x,y,spd,dir,acc,maxacc,graphic,delay);
	ManageShot;
	return shot;
		task ManageShot{
		DelayCloud(shot,x,y,spd,dir,graphic,cloud,delay);
		}
	}

function ShotOA1(obj,spd,dir,graphic,cloud,delay){
	let shot = CreateShotOA1(obj,spd,dir,graphic,delay);
	ManageShot;
	return shot;
		task ManageShot{
		DelayCloud(shot,ObjMove_GetX(obj),ObjMove_GetY(obj),spd,dir,graphic,cloud,delay);
		}
	}
	
function ShotB2(x,y,xspd,yspd,xacc,yacc,xmax,ymax,graphic,cloud,delay){
	let angle = atan2(yspd,xspd);
	let shot = CreateShotB2(x,y,xspd,yspd,xacc,yacc,xmax,ymax,graphic,delay);
	DelayCloud(shot,x,y,0,angle,graphic,cloud,delay);
	return shot;
}
	
task TrailEffect(shot,let cloud,c,scale,p,t){
	 let img=GCSD~"Shot/ZUNShot.png";
	 let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	 let x = ObjMove_GetX(shot);
	 let y = ObjMove_GetY(shot);
	 scale += 0;
	 let value = scale/t;
	 ObjPrim_SetTexture(obj,img);
	 let rect = GetShotDataInfoA1(cloud,TARGET_ENEMY,INFO_RECT);
	 ObjSprite2D_SetSourceRect(obj,rect[0],rect[1],rect[2],rect[3]);
	 ObjSprite2D_SetDestCenter(obj);
	 ObjRender_SetPosition(obj,x,y,0);
	 ObjRender_SetAngleXYZ(obj,0,0,ang);
	 ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	 ObjRender_SetColor(obj,255,255,255);
	 loop(t){
	ObjRender_SetScaleXYZ(obj,scale+p,scale+p,0);
	ObjRender_SetAlpha(obj,c);
	scale -= value;
	c+=180/t;
	if(Obj_IsDeleted(objBoss)){break;}
	yield;
	 }
	 Obj_Delete(obj);
	}
	
task DelayShot(shot,cloud,s,value,time,delay){
	let cg = true;
	wait(delay);
	if(!Obj_IsDeleted(shot)){
	 let graphic = ObjShot_GetImageID(shot);
	 let result = s-1;
	 let adc = false;
	 let alpha = value;
	 let s_value = 255-value;
	 if(cloud==0){cloud=graphic;}
	 if( (cloud>=1 && cloud<=41) || (cloud>=58 && cloud<=73) || (cloud>=106 && cloud <=121)
	 || (cloud>=170 && cloud<=185) || (cloud>=233 && cloud<=239)
	 || (cloud>=248 && cloud <=252) || (cloud>=269 && cloud<=283)
	 || (cloud>=300 && cloud<=307) || (cloud>=340 && cloud<=346)
	 || (cloud>=355 && cloud<=362) || (cloud>=371 && cloud<=382)
	 || (cloud>=399 && cloud<=408)){
	 adc = true;
	 }
	ObjShot_SetGraphic(shot,cloud);
		loop(time){
		if(Obj_IsDeleted(objBoss)){break;}
		ObjRender_SetScaleXYZ(shot,s,s,0);
		if(adc==false){ObjRender_SetAlpha(shot,alpha);}
		else{
		ObjRender_SetColor(shot,alpha,alpha,alpha);
		}
		alpha += s_value/time;
		s -= result/time;
		yield;
		}
		if(cg==false){ObjShot_SetGraphic(shot,graphic);}
		}
	}

task DelayCloud(shot,x,y,spd,dir,graphic,cloud,delay){
	 let img=GCSD~"Shot/ZUNShot.png";
	 let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	 let s = 3;
	 let c = 0;
	 let v = false;
	 let px = 0;
	 let adc = false;
	 if(!Obj_IsDeleted(shot)){
	 ObjPrim_SetTexture(obj,img);
	 ObjRender_SetBlendType(obj,BLEND_ALPHA);
	 ObjRender_SetAngleXYZ(obj,0,0,dir+90);
	 if(cloud==0){cloud=graphic;}
	 if( (cloud>=1 && cloud<=41) || (cloud>=58 && cloud<=73) || (cloud>=106 && cloud <=121)
	 || (cloud>=170 && cloud<=185) || (cloud>=233 && cloud<=239)
	 || (cloud>=248 && cloud <=252) || (cloud>=269 && cloud<=283)
	 || (cloud>=300 && cloud<=307) || (cloud>=340 && cloud<=346)
	 || (cloud>=355 && cloud<=362) || (cloud>=371 && cloud<=382)
	 || (cloud>=399 && cloud<=408)){
	 adc = true;
	 ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	 }
	 let rect = GetShotDataInfoA1(cloud,TARGET_ENEMY,INFO_RECT);
	 ObjSprite2D_SetSourceRect(obj,rect[0],rect[1],rect[2],rect[3]);
	 ObjSprite2D_SetDestCenter(obj);
	 ObjRender_SetPosition(obj,x,y,0);
	 while(c<delay && !Obj_IsDeleted(objBoss) && !Obj_IsDeleted(shot)){
	 ObjRender_SetScaleXYZ(obj,s,s,0);
	 if(v==true){ ObjRender_SetAngleXYZ(obj,0,0,dir+90-c*3)};
	 if(s>=1){s -= 2.1/delay;}
	 c++;
	 ObjRender_SetAlpha(obj,c*255/(delay*1.25));
	 if(adc==true){ObjRender_SetColor(obj,c*255/(delay*1.25),c*255/(delay*1.25),c*255/(delay*1.25));}
	 yield;
	 }
	 Obj_Delete(obj);
	 }
	 }
	 
	function CurvyLaser(x,y,speed,dir,l,w,graphic,delay){
	let shot = CreateShotA1(x,y,speed,dir,graphic,delay);
	Obj_SetVisible(shot,false);
	ObjShot_SetIntersectionEnable(shot,false);
	Trail;
	return shot;
		task Trail{
		let c = 1;
			wait(delay);
			while(!Obj_IsDeleted(shot)){
				LaserEffect(w);
				wait(2);
			}
				task LaserEffect(w){
				let obj = CreateStraightLaserA1(ObjMove_GetX(shot),ObjMove_GetY(shot),ObjMove_GetAngle(shot),(ObjMove_GetSpeed(shot)*l+10)*c,w,w,graphic,0);
					descent(i in 5..w){
					if(i<w/2){ObjShot_SetIntersectionEnable(obj,false);}
					ObjLaser_SetRenderWidth(obj,i);
					ObjLaser_SetIntersectionWidth(obj,i/2);
					yield;
					}
					Obj_Delete(obj);
				}
		}
}