let current = GetCurrentScriptDirectory()~"./../img/";
let bSpell =false;


@Initialize{
    TNonBackground1;
	TNonBackground2;
	TSpellBackground1;
	TSpellBackground2;
	TSpellBackground3;
    TSpellBackground4;
	TSpellBackgroundDave;
}


@MainLoop{
	let objScene = GetEnemyBossSceneObjectID();
	if(objScene != ID_INVALID && ObjEnemyBossScene_GetInfo(objScene, INFO_IS_SPELL)){bSpell=true;}
        else{bSpell= false;}
	yield;
}


task TNonBackground1 {
    let path1 = current ~ "non1.png";
    let obj = ObjPrim_Create(OBJ_SPRITE_2D);
    ObjRender_SetBlendType(obj, BLEND_ALPHA);
    Obj_SetRenderPriority(obj, 0.21);
    ObjPrim_SetTexture(obj, path1);
    ObjSprite2D_SetSourceRect(obj, 0, 0, 444, 448);
    ObjSprite2D_SetDestRect(obj, -222, -224, 222, 224);
    ObjRender_SetPosition(obj, 222, 224, 1);
    Obj_SetVisible(obj, true);
    let frameInvisible = 0;
    let alpha = 240;
    
    loop {
        if(bSpell){
            frameInvisible+=2;
			if(frameInvisible >= 200){Obj_SetVisible(obj, false);}
        }
		if(GetCommonData("non1", "") == "yes"){Obj_SetVisible(obj, true);}
	    else if(GetCommonData("change", "") == "yes"){
			ObjRender_SetAlpha(obj, alpha); Obj_SetVisible(obj, alpha>0);
			alpha-=8;
        }
		else{
            frameInvisible = 0;
			Obj_SetVisible(obj, true);
		}
        if(GetCommonData("change", "") == "yes"){loop(6){yield;}} 
        else{yield;}
    }
}


task TNonBackground2{
    let path1 = current ~ "non2.png";
    let obj = ObjPrim_Create(OBJ_SPRITE_2D);
    ObjRender_SetBlendType(obj, BLEND_ALPHA);
    Obj_SetRenderPriority(obj, 0.21);
    ObjPrim_SetTexture(obj, path1);
    ObjSprite2D_SetSourceRect(obj, 0, 10, 465, 427);
    ObjSprite2D_SetDestRect(obj, -243, -228, 243, 228);
    ObjRender_SetPosition(obj, 222, 224, 1);
    Obj_SetVisible(obj, false);
    let frameInvisible = 0;
    let alpha = 0;
    
    loop {
        if(bSpell){
            frameInvisible+=2;
			if(frameInvisible >= 200){Obj_SetVisible(obj, false);}
        }
		if(GetCommonData("non1", "") == "yes"){Obj_SetVisible(obj, false);}
		else if(GetCommonData("change", "") == "yes"){
			ObjRender_SetAlpha(obj, alpha); Obj_SetVisible(obj, alpha>10);
			alpha+=8;
        }
        else{
            frameInvisible = 0;
			Obj_SetVisible(obj, true);
		}
        if(GetCommonData("change", "") == "yes"){loop(6){yield;}}
        else{yield;}
    }
}


task TSpellBackground1 {
    let path2 = current ~ "spell1.png";
    let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
    ObjRender_SetBlendType(obj2, BLEND_ALPHA);
    Obj_SetRenderPriority(obj2, 0.21);
    ObjPrim_SetTexture(obj2, path2);
    ObjSprite2D_SetSourceRect(obj2, 0, 0, 520, 520);
    ObjSprite2D_SetDestRect(obj2, -340, -340, 340, 340);
    
    ObjRender_SetPosition(obj2, 222, 224, 1);
 
    let ang = ObjRender_GetAngleZ(obj2);
    let alpha = 0;
    loop {
        if(bSpell && (GetCommonData("spell", "") == "Quotient")){alpha += 6;}
	else{alpha = 0;}
        ang+=0.2;
        ObjRender_SetAlpha(obj2, alpha);
        Obj_SetVisible(obj2, alpha > 0);
        ObjRender_SetAngleZ(obj2, ang);
        yield; yield;
    }
}


task TSpellBackground2{
    let path2 = current ~ "spell2.png";
    let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
    ObjRender_SetBlendType(obj2, BLEND_ALPHA);
    Obj_SetRenderPriority(obj2, 0.21);
    ObjPrim_SetTexture(obj2, path2);
    ObjSprite2D_SetSourceRect(obj2, 200, 0, 644, 448);
    ObjSprite2D_SetDestRect(obj2, -222, -224, 222, 224);

    let path = current ~ "eff4.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriority(obj, 0.21);
	ObjPrim_SetTexture(obj, path);
	ObjSprite2D_SetSourceRect(obj,0,0,520,520);
	ObjSprite2D_SetDestRect(obj,-256,-256,256,256);

    ObjRender_SetPosition(obj2, 222, 224, 1);
    ObjRender_SetPosition(obj, 222, 224, 1);
    let frame = 0;
    let alpha = 0;
    loop {
        if(bSpell && (GetCommonData("spell", "")== "CW" || GetCommonData("spell", "")== "Homotopy")){alpha += 6;}
	    else{alpha = 0;}
        ObjRender_SetAlpha(obj2, alpha);
        Obj_SetVisible(obj2, alpha > 0);

        ObjRender_SetAlpha(obj, alpha); if(alpha>=100){ObjRender_SetAlpha(obj, 80);}
        Obj_SetVisible(obj, alpha > 0);
        ObjSprite2D_SetSourceRect(obj, 0+frame,0+frame,256+frame,256+frame);

        frame++;
        yield; yield;
    }
}


task TSpellBackground3{
    let path2 = current ~ "spell3.png";
    let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
    ObjRender_SetBlendType(obj2, BLEND_ALPHA);
    Obj_SetRenderPriority(obj2, 0.21);
    ObjPrim_SetTexture(obj2, path2);
    ObjSprite2D_SetSourceRect(obj2, 0, 0, 716, 448);
    ObjSprite2D_SetDestRect(obj2, -358, -224, 358, 224);

    let path = current ~ "eff2.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriority(obj, 0.21);
	ObjPrim_SetTexture(obj, path);
        ObjSprite2D_SetSourceRect(obj,0,0,256,256);
        ObjSprite2D_SetDestRect(obj,-256,-256,256,256);

    ObjRender_SetPosition(obj2, 222, 224, 1);
    ObjRender_SetPosition(obj, 222, 224, 1);
    let ang = ObjRender_GetAngleZ(obj2);
    let alpha = 0;
    loop {
        if(bSpell && (GetCommonData("spell", "")== "Size 1" || GetCommonData("spell", "")== "Size 2")){alpha += 6;}
	else{alpha = 0;}
        ObjRender_SetAlpha(obj2, alpha);
        Obj_SetVisible(obj2, alpha > 0);

        ObjRender_SetAlpha(obj, alpha); if(alpha>=150){ObjRender_SetAlpha(obj, 80);}
        Obj_SetVisible(obj, alpha > 0);
        ang-=0.2;
        ObjRender_SetAngleZ(obj, ang);
        yield; yield;
    }
}


task TSpellBackground4{
    let path2 = current ~ "spell4.png";
    let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
    ObjRender_SetBlendType(obj2, BLEND_ALPHA);
    Obj_SetRenderPriority(obj2, 0.21);
    ObjPrim_SetTexture(obj2, path2);
    ObjSprite2D_SetSourceRect(obj2, 0, 0, 716, 448);
    ObjSprite2D_SetDestRect(obj2, -358, -224, 358, 224);

    let path = current ~ "eff3.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriority(obj, 0.21);
	ObjPrim_SetTexture(obj, path);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestRect(obj,-256,-256,256,256);

    ObjRender_SetPosition(obj2, 222, 224, 1);
    ObjRender_SetPosition(obj, 222, 224, 1);
    let frame = 0;
    let alpha = 0;
    loop {
        if(bSpell && (GetCommonData("spell", "")== "Retraction")){alpha += 6;}
	else{alpha = 0;}
        ObjRender_SetAlpha(obj2, alpha);
        Obj_SetVisible(obj2, alpha > 0);

        ObjRender_SetAlpha(obj, alpha); if(alpha>=120){ObjRender_SetAlpha(obj, 130);}
        Obj_SetVisible(obj, alpha > 0);
        ObjSprite2D_SetSourceRect(obj, 0+frame,0,256+frame,256);

        frame++;
        yield; yield;
    }
}


task TSpellBackgroundDave{
    let path2 = current ~ "spelDave.png";
    let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
    ObjRender_SetBlendType(obj2, BLEND_ALPHA);
    Obj_SetRenderPriority(obj2, 0.21);
    ObjPrim_SetTexture(obj2, path2);
    ObjSprite2D_SetSourceRect(obj2, 0, 0, 458, 448);
    ObjSprite2D_SetDestRect(obj2, -229, -224, 229, 224);

    let path = current ~ "eff3.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriority(obj, 0.21);
	ObjPrim_SetTexture(obj, path);
        ObjSprite2D_SetSourceRect(obj,0,0,256,256);
        ObjSprite2D_SetDestRect(obj,-256,-256,256,256);

    ObjRender_SetPosition(obj2, 222, 224, 1);
    ObjRender_SetPosition(obj, 222, 224, 1);
    let frame = 0;
    let alpha = 0;
    loop {
        if(bSpell && (GetCommonData("spell", "")== "Dave")){alpha += 6;}
	else{alpha = 0;}
        ObjRender_SetAlpha(obj2, alpha);
        Obj_SetVisible(obj2, alpha > 0);

        ObjRender_SetAlpha(obj, alpha); if(alpha>=150){ObjRender_SetAlpha(obj, 150);}
        Obj_SetVisible(obj, alpha > 0);
        ObjSprite2D_SetSourceRect(obj, 0,0+frame,256,256+frame);

        frame++;
        yield; yield;
    }
}