#include "../functions.txt"

@Initialize
	{
	SetAutoDeleteObject(true);
	}
@MainLoop{yield;}
@Event
{
	alternative(GetEventType())

	case(EV_EFFECT_EXPLOSION)
		{
		Event_Explosion(GetEventArgument(0)[0],GetEventArgument(0)[1]);
		}
	case(EV_EFFECT_CHARGE)
		{
		Event_Charge(GetEventArgument(0)[0],GetEventArgument(0)[1]);
		}
	case(EV_ICE_BREAK)
		{
		Event_IceBreak(GetEventArgument(0)[0],GetEventArgument(0)[1]);
		}
}
task Event_Explosion(x,y)
	{
	let obj = [];
	let count = 0;
	let angleM = rand(0,360);
	let angle = [];
	let graph = 1;
	ascent(i0 in 0..2)
		{
		ascent(i1 in 0..3)
			{
			angle = angle ~ [i1*120+i0*60+angleM+rand(-1,1)*0.25];
			obj = obj ~ [ObjPrim_Create(OBJ_SPRITE_2D)];
			ObjPrim_SetTexture(obj[count],GetCurrentScriptDirectory ~ "../img/RSS_Effect.png");
			ObjSprite2D_SetSourceRect(obj[count],(graph%4)*64,(floor(graph/4)%2)*64,(1+graph%4)*64,(1+floor(graph/4)%2)*64);
			ObjRender_SetAngleXYZ(obj[count],rand(-1,1)*45,rand(-1,1)*45,rand(0,360));
			ObjRender_SetScaleXYZ(obj[count],0.66,0.66,0);
			ObjRender_SetPosition(obj[count],x,y,0);
			Obj_SetRenderPriority(obj[count],0.38);
			ObjRender_SetAlpha(obj[count],45);
			ObjRender_SetBlendType(obj[count],BLEND_ADD_ARGB);		
			ObjRender_SetColorHSV(obj[count],180,105,255);
			count+=1;
			}
		}
	let speed = 10;
	let switch = false;
	loop(20)
		{
		speed-=10/20;
		count = 0;
		ascent(i0 in 0..2)
			{
			ascent(i1 in 0..3)
				{
				ObjRender_SetPosition(obj[count],ObjRender_GetX(obj[count])+speed*(0.5+i0*0.5)*cos(angle[count]),ObjRender_GetY(obj[count])+speed*(0.5+i0*0.5)*sin(angle[count]),0);
				ObjSprite2D_SetDestCenter(obj[count]);
				count+=1;
				}
			}
		yield;
		}
	count = 0;
	ascent(i0 in 0..2)	
		{
		ascent(i1 in 0..3)
			{
			angle[count] = 90+rand(-1,1)*30;
			count+=1;
			}
		}
	let alpha = 45;
	ascent(t in 1..13)
		{
		alpha-=45/12;
		count = 0;
		ascent(i0 in 0..2)
			{
			ascent(i1 in 0..3)
				{
				ObjRender_SetAlpha(obj[count],alpha);
				ObjSprite2D_SetDestCenter(obj[count]);
				count+=1;
				}
			}
		yield;
		}
	count = 0;
	ascent(i0 in 0..2)
		{
		ascent(i1 in 0..3)
			{
			Obj_Delete(obj[count]);
			count+=1;
			}
		}
	}

task Event_Charge(x,y)
	{
	if(Effect < 3)
		{
		let obj = [];
		let count = 0;;
		let angleM = rand(0,360);
		let angle = [];
		let graph = 1;
		ascent(i0 in 0..2)
			{
			ascent(i1 in 0..3)
				{
				angle = angle ~ [i1*120+i0*60+angleM+rand(-1,1)*0.25];
				obj = obj ~ [ObjPrim_Create(OBJ_SPRITE_2D)];
				ObjPrim_SetTexture(obj[count],GetCurrentScriptDirectory ~ "../img/RSS_Effect.png");
				ObjSprite2D_SetSourceRect(obj[count],(graph%4)*64,(floor(graph/4)%2)*64,(1+graph%4)*64,(1+floor(graph/4)%2)*64);
				ObjRender_SetAngleXYZ(obj[count],rand(-1,1)*45,rand(-1,1)*45,rand(0,360));
				ObjRender_SetScaleXYZ(obj[count],0.66,0.66,0);
				ObjRender_SetPosition(obj[count],x,y,0);
				Obj_SetRenderPriority(obj[count],0.38);
				ObjRender_SetAlpha(obj[count],85);
				ObjRender_SetBlendType(obj[count],BLEND_ADD_ARGB);		
				ObjRender_SetColorHSV(obj[count],180,105,255);
				count+=1;
				}
			}
		let speed = 10;
		ascent(t in 0..20)
			{
			speed-=10/20;
			count = 0;
			ascent(i0 in 0..2)
				{
				ascent(i1 in 0..3)
					{
					ObjRender_SetPosition(obj[count],ObjRender_GetX(obj[count])+speed*(0.5+i0*0.5)*cos(angle[count]),ObjRender_GetY(obj[count])+speed*(0.5+i0*0.5)*sin(angle[count]),0);
					ObjSprite2D_SetDestCenter(obj[count]);
					count+=1;
					}
				}
			}
		loop(20)
			{
			speed-=10/20;
			count = 0;
			ascent(i0 in 0..2)
				{
				ascent(i1 in 0..3)
					{
					ObjRender_SetPosition(obj[count],ObjRender_GetX(obj[count])+speed*(0.5+i0*0.5)*cos(angle[count]),ObjRender_GetY(obj[count])+speed*(0.5+i0*0.5)*sin(angle[count]),0);
					ObjSprite2D_SetDestCenter(obj[count]);
					count+=1;
					}
				}
			yield;
			}
		count = 0;
		ascent(i0 in 0..2)	
			{
			ascent(i1 in 0..3)
				{
				angle[count] = 90+rand(-1,1)*30;
				count+=1;
				}
			}
		let alpha = 65;
		ascent(t in 1..11)
			{
			alpha-=65/10;
			count = 0;
			ascent(i0 in 0..2)
				{
				ascent(i1 in 0..3)
					{
					ObjRender_SetAlpha(obj[count],alpha);
					ObjSprite2D_SetDestCenter(obj[count]);
					count+=1;
					}
				}
			yield;
			}
		count = 0;
		ascent(i0 in 0..2)
			{
			ascent(i1 in 0..3)
				{
				Obj_Delete(obj[count]);	
				count+=1;
				}
			}
		}
	}

task Event_IceBreak(x,y)
	{
	loop(2)
		{
		let shot = CreateBulletA1(x,y,rand(1,3.25),rand(0,360),DOT_YELLOW,0,1);
		ObjShot_SetSpellResist(shot,true);
		}
	}