// 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_SetValue(shot,"ShotEffectOrNot",0);
	Obj_SetVisible(shot,false);
	ObjShot_SetIntersectionEnable(shot,false);
	ObjShot_SetSpellResist(shot,true);
	Trail;
	return shot;
		task Trail{
		let c = 1;
		let count = 0;
			wait(delay);
			while(!Obj_IsDeleted(shot)){
				LaserEffect(w,count%2);
				wait(2);
				count++;
			}
				task LaserEffect(w,count){
				let obj = CreateStraightLaserA1(ObjMove_GetX(shot),ObjMove_GetY(shot),ObjMove_GetAngle(shot),( (|ObjMove_GetSpeed(shot)|)*l+10)*c,w,w,graphic,0);
				Obj_SetValue(obj,"ShotEffectOrNot",count);
					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);
				}
		}
}

function PagodarLaser(x,y,dir,length,delay,time,color){
		let shot = ShotA1(x,y,0,dir,1,0,0);
		let co = [0,0,0];
		ObjShot_SetIntersectionEnable(shot,false);
		ObjShot_SetSpellResist(shot,true);
		Obj_SetVisible(shot,false);
		if(color=="RED"){co = [255,0,0];}
		if(color=="GREEN"){co = [0,255,0];}
		if(color=="BLUE"){co = [0,0,255];}
		if(color=="ORANGE"){co = [255,128,0];}
		if(color=="YELLOW"){co = [255,255,0];}
		if(color=="AQUA"){co = [0,255,255];}
		if(color=="PURPLE"){co = [255,0,255];}
		CoreLaser(255,255,255,1,-30);
		CoreLaser(co[0],co[1],co[2],1.5,0);
		LineLaser(224,224,224,1);
		LineLaser(co[0],co[1],co[2],1.2);
		LineLaser(co[0],co[1],co[2],1.2);
		return shot;
		task CoreLaser(r,g,b,size,px){
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		let img=GCSD~"img/Slaser.png";
		ObjPrim_SetTexture(obj,img);
		ObjRender_SetAngleXYZ(obj,0,0,ObjMove_GetAngle(shot));
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjRender_SetColor(obj,r,g,b);
		ObjRender_SetScaleXYZ(obj,size,size,0);
		ManageEffect;
		CheckDelete(obj,px,0);
			task ManageEffect{
				let c = 0;
				while(!Obj_IsDeleted(obj) && c<time && !Obj_IsDeleted(shot)){
				ObjSprite2D_SetSourceRect(obj,1,256-133,124,256);
				ObjSprite2D_SetDestCenter(obj);
				yield;
				yield;
				c+=2;
				ObjSprite2D_SetSourceRect(obj,126,256-133,253,256);
				ObjSprite2D_SetDestCenter(obj);
				yield;
				yield;
				c+=2
				}
				descent(i in 0..50){
				if(Obj_IsDeleted(shot)){break;}
				ObjRender_SetScaleXYZ(obj,size,size*(i/50),0);
				yield;
				}
				Obj_Delete(obj);
			}
			}
		task LineLaser(r,g,b,size){
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		let img=GCSD~"img/Slaser.png";
		let t = 0; // specific counter
		ObjPrim_SetTexture(obj,img);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjRender_SetPosition(obj,x+63*cos(dir),y+63*sin(dir),0);
		ObjRender_SetColor(obj,r,g,b);
		ObjRender_SetScaleXYZ(obj,1,0.2,1);
		ManageEffect;
		CheckDelete(obj,0,1);
		if(delay!=999){
			loop(delay){
			if(Obj_IsDeleted(shot)){break;}
			yield;
			}
		}
		else{
		while(Obj_GetValueD(shot,"time",0)==0 && t<time){
		if(Obj_IsDeleted(shot)){break;}
		t++;
		yield;
		}
		}
			ascent(i in 20..100){
			if(t>time-40){break;}
			if(Obj_IsDeleted(shot)){break;}
			ObjRender_SetScaleXYZ(obj,1,i/100,1);
			SetShotIntersectionLine(ObjMove_GetX(shot)-10*cos(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)-10*sin(ObjMove_GetAngle(shot)),ObjMove_GetX(shot)+length*cos(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)+length*sin(ObjMove_GetAngle(shot)),i/8-2.5);
			wait(i%2);
			}
			if(delay!=999){
				loop(time-delay-40){
				if(Obj_IsDeleted(shot)){break;}
				SetShotIntersectionLine(ObjMove_GetX(shot)-10*cos(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)-10*sin(ObjMove_GetAngle(shot)),ObjMove_GetX(shot)+length*cos(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)+length*sin(ObjMove_GetAngle(shot)),10);
				yield;
				}
			}
			else{
			loop(time-t-40){
				if(Obj_IsDeleted(shot)){break;}
				SetShotIntersectionLine(ObjMove_GetX(shot)-10*cos(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)-10*sin(ObjMove_GetAngle(shot)),ObjMove_GetX(shot)+length*cos(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)+length*sin(ObjMove_GetAngle(shot)),10);
				yield;
				}
			}
			if(t<time){
				descent(i in 0..100){
				if(Obj_IsDeleted(shot)){break;}
				ObjRender_SetScaleXYZ(obj,1,i/100,1);
				ObjRender_SetColor(obj,(i/60)*r,(i/60)*g,(i/60)*b);
				SetShotIntersectionLine(ObjMove_GetX(shot)-10*cos(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)-10*sin(ObjMove_GetAngle(shot)),ObjMove_GetX(shot)+length*cos(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)+length*sin(ObjMove_GetAngle(shot)),i/8-2.5);
				wait(i%2);
				}
			}
			else{
				descent(i in 0..20){
				if(Obj_IsDeleted(shot)){break;}
				ObjRender_SetScaleXYZ(obj,1,i/100,1);
				ObjRender_SetColor(obj,(i/60)*r,(i/60)*g,(i/60)*b);
				SetShotIntersectionLine(ObjMove_GetX(shot)-10*cos(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)-10*sin(ObjMove_GetAngle(shot)),ObjMove_GetX(shot)+length*cos(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)+length*sin(ObjMove_GetAngle(shot)),i/8-2.5);
				wait(i%2);
				}
			}
			Obj_Delete(shot);
				task ManageEffect{
				let p = 0;
				while(!Obj_IsDeleted(obj) && !Obj_IsDeleted(shot)){
				ObjSprite2D_SetSourceRect(obj,p,0,255*3.5+p,32);
				ObjSprite2D_SetDestRect(obj,128-length,-16,128,16);
				p+=11;
				yield;
				}
				}
		}
		task CheckDelete(obj,px,type){
			while(!Obj_IsDeleted(objBoss) && !Obj_IsDeleted(obj) && !Obj_IsDeleted(shot)){
			if(type==0){
			ObjRender_SetPosition(obj,ObjMove_GetX(shot)+px*cos(ObjMove_GetAngle(shot))+90*cos(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)+px*sin(ObjMove_GetAngle(shot))+90*sin(ObjMove_GetAngle(shot)),0);
			ObjRender_SetAngleXYZ(obj,0,0,ObjMove_GetAngle(shot));
			}
			if(type==1){
			ObjRender_SetPosition(obj,ObjMove_GetX(shot)+63*cos(ObjMove_GetAngle(shot))+90*cos(ObjMove_GetAngle(shot)),ObjMove_GetY(shot)+63*sin(ObjMove_GetAngle(shot))+90*sin(ObjMove_GetAngle(shot)),0);
			ObjRender_SetAngleXYZ(obj,0,0,ObjMove_GetAngle(shot)+180);
			}
			yield;
			}
			Obj_Delete(obj);
		}
	}
	
function ScalingBullet(x,y,v,dir,graphic,hitbox,scale,cloud,delay){
	let shot = ShotA1(x,y,v,dir,hitbox,0,0);
	Obj_SetVisible(shot,false);
		ManageGraphic;
		return shot;
			task ManageGraphic{
			let dummy = ShotOA1(shot,0,0,graphic,cloud,delay);
			ObjRender_SetScaleXYZ(dummy,scale,scale,scale);
			ObjShot_SetIntersectionEnable(dummy,false);
				while(!Obj_IsDeleted(shot) && !Obj_IsDeleted(dummy)){
					ObjMove_SetPosition(dummy,ObjMove_GetX(shot),ObjMove_GetY(shot));
					yield;
				}
				Obj_Delete(dummy);
			}
	}
	
	
	
	