#include "./Index.txt"

if(GetCommonData("IsStage", false)==true){
SetCommonData("Stacks",GetCommonData("LeftoverStacks",0));
}

task Disease(obj, scale, hitbox){
DiseaseCloud(obj, scale);
	while(!Obj_IsDeleted(obj)){
	let dist = GetObjectDistance(GetPlayerObjectID,obj);
	if(dist<hitbox){
	SE_Play(GetCurrentScriptDirectory ~ "sfx/down.wav", 255);
	SetCommonData("Stacks",GetCommonData("Stacks",0)+1);
	}
	yield;
	}
}

task DiseaseBoss(obj, scale, hitbox){
DiseaseCloudBoss(obj, scale);
	while(!Obj_IsDeleted(obj)){
	let dist = GetObjectDistance(GetPlayerObjectID,obj);
	if(dist<hitbox){
	SE_Play(GetCurrentScriptDirectory ~ "sfx/down.wav", 255);
	SetCommonData("Stacks",GetCommonData("Stacks",0)+1);
	}
	yield;
	}
}


task Diseasecontroller{
let triggering = 0;
	loop{
	if(GetCommonData("Stacks",0)>1&&triggering==0){DiseaseCloudPlayer(GetPlayerObjectID); triggering++;}
		if(GetCommonData("Stacks",0)>=300){
		ObjEnemy_SetIntersectionCircleToPlayer(objBoss,GetPlayerX,GetPlayerY,16);
		SetCommonData("Stacks",0);
		}
	yield;
	}
}

function DiseaseCloud(obj, scale){
let cloud = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(cloud);
Render(cloud, obj, scale);
return(cloud);
	task Render(cloud, obj, scale){
	let texture = GetCurrentScriptDirectory ~ "./img/Disease.png";
	ObjPrim_SetTexture(cloud, texture);
	Obj_SetRenderPriorityI(cloud, 40);
	ObjSprite2D_SetSourceRect(cloud,0,0,43,43);
	ObjSprite2D_SetDestCenter(cloud);	
	ObjRender_SetScaleXYZ(cloud,scale,scale,0);
	ObjRender_SetAlpha(cloud, 200);
	ObjRender_SetAngleXYZ(cloud,0,0,0);
	ObjRender_SetBlendType(cloud, BLEND_ADD_ARGB);
	ObjRender_SetColor(cloud, 255, 122, 255);
		while(!Obj_IsDeleted(obj)){
		ObjRender_SetPosition(cloud, ObjMove_GetX(obj), ObjMove_GetY(obj), 0);
		yield;
		}
	Obj_Delete(cloud);
	}
}

function DiseaseCloudBoss(obj, scale){
let cloud = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(cloud);
Render(cloud, obj, scale);
return(cloud);
	task Render(cloud, obj, scale){
	let texture = GetCurrentScriptDirectory ~ "./img/Disease.png";
	ObjPrim_SetTexture(cloud, texture);
	Obj_SetRenderPriorityI(cloud, 40);
	ObjSprite2D_SetSourceRect(cloud,0,0,43,43);
	ObjSprite2D_SetDestCenter(cloud);	
	ObjRender_SetScaleXYZ(cloud,scale,scale,0);
	ObjRender_SetAlpha(cloud, 90);
	ObjRender_SetAngleXYZ(cloud,0,0,0);
	ObjRender_SetBlendType(cloud, BLEND_ADD_ARGB);
	ObjRender_SetColor(cloud, 255, 122, 255);
		while(!Obj_IsDeleted(obj)){
		ObjRender_SetPosition(cloud, ObjMove_GetX(obj), ObjMove_GetY(obj), 0);
		yield;
		}
	Obj_Delete(cloud);
	}
}

function DiseaseCloudPlayer(obj){
let cloud = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(cloud);
Render(cloud, obj);
return(cloud);
	task Render(cloud, obj){
	let texture = GetCurrentScriptDirectory ~ "./img/Disease.png";
	ObjPrim_SetTexture(cloud, texture);
	Obj_SetRenderPriorityI(cloud, 40);
	ObjSprite2D_SetSourceRect(cloud,0,0,43,43);
	ObjSprite2D_SetDestCenter(cloud);	
	ObjRender_SetScaleXYZ(cloud,1,1,0);
	ObjRender_SetAngleXYZ(cloud,0,0,0);
	ObjRender_SetBlendType(cloud, BLEND_ADD_ARGB);
	ObjRender_SetColor(cloud, 255, 122, 255);
		while(!Obj_IsDeleted(obj)){
		ObjRender_SetAlpha(cloud,GetCommonData("Stacks", 0)/1.1);
		ObjRender_SetPosition(cloud, ObjMove_GetX(obj), ObjMove_GetY(obj), 0);
		yield;
		}
	Obj_Delete(cloud);
	}
}