
//ウェイトシステム

let m_weight = 250;

task once_system_TaskWeightMain(){

	once_system_TaskDrawWeightParam();

	loop{
//		OutputDebugString(0,"w", m_weight);
		let check = GetCommonDataDefaultEx("SPHERIA_ENEMY", "ENEMY_WEIGHT", []);
		
		while(length(check) != 0){
			let array = check[0];
			loop(array[2]){
				system_TaskWeightItem(array[0], array[1]);
			}
			check = erase(check, 0);
			system_SetScoreCombo(300);
			system_AddScoreComboCount();
			if(m_weight >= const_SphereWeightUnit[6]){
				system_AddScoreComboCount();
			}
			system_AddScoreRate( trunc(20/(system_GetSphereLevel()+1)) * trunc(system_GetChainLength()/60) * trunc(system_GetSpeedRate()*2 + 1));
		}
		SetCommonDataEx("SPHERIA_ENEMY", "ENEMY_WEIGHT", []);

		if(m_weight >= const_SphereWeightUnit[6]){
			m_weight = const_SphereWeightUnit[6];
		}

		loop(10){yield;}
	}

}//end task


task system_TaskWeightItem(let x, let y){

	let flag_intersect = false;
	let obj = REMY_CreateEffectObject(img_Sphere, 4, 4);
	let rect = system_GetGraphicRect("SPHERE_STONE");
	REMY_SetObjectVertexSquare(obj, rect, 0, 0, 255, 200, 200, 200);
	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj, rand(0,360));
	Obj_SetSpeed(obj, rand(1,4));

	Rotate();

	ascent(i in 0..30){
		Obj_SetSpeed(obj, Obj_GetSpeed(obj)-0.1);
		yield;
	}

	Obj_SetSpeed(obj, 0);
	loop(10){yield;}
	
	while(!flag_intersect){
		if(system_IsIntersectWithSphere(Obj_GetX(obj), Obj_GetY(obj), 20)){flag_intersect = true;}
		local{
	 		Obj_SetAngle(obj, system_GetAngleToSphere(Obj_GetX(obj), Obj_GetY(obj)));
		}
		Obj_SetSpeed(obj, REMY_GetNumMin(Obj_GetSpeed(obj)+0.2, 10));
		yield;
	}
	Obj_SetSpeed(obj, 0);
	system_AddWeight(1);
	//system_AddScoreRate(0);
	AddScore(trunc(2 * system_GetScoreRate() * (system_GetScoreComboCount()/20 + 1))*10);
	PlaySE(se_Item);

	ascent(j in 0..10){
		ObjEffect_SetScale(obj,1 + 3 * (j/10),1 + 3 * (j/10));
		ascent(i in 0..4){
			ObjEffect_SetVertexColor(obj, i, 150 *(1- j/10), 200, 200, 200);
		}
		yield;
	}
	Obj_Delete(obj);


	task Rotate(){
		let angle = rand(0, 180);
		ascent(i in 0..80){
			ObjEffect_SetAngle(obj,angle + i, angle+i, angle+i);
			yield;
		}
	}

}//end task


task system_TaskWeightItemLost(let x, let y, let angle){

	let obj = REMY_CreateEffectObject(img_Sphere, 4, 4);
	let rect = system_GetGraphicRect("SPHERE_STONE");
	REMY_SetObjectVertexSquare(obj, rect, 0, 0, 100, 200, 100, 100);

	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj, angle + rand(-80,80));
	Obj_SetSpeed(obj, rand(1,4));

	Rotate();

	ascent(i in 0..30){
		Obj_SetSpeed(obj, Obj_GetSpeed(obj)-0.1);
		yield;
	}

	ascent(j in 0..30){
		ObjEffect_SetScale(obj,1 - (j/30),1 - (j/30));
		ascent(i in 0..4){
			ObjEffect_SetVertexColor(obj, i, 100 *(1- j/30), 200, 100, 100);
		}
		yield;
	}
	Obj_Delete(obj);


	task Rotate(){
		let angle = rand(0, 180);
		ascent(i in 0..80){
			ObjEffect_SetAngle(obj,angle + i, angle+i, angle+i);
			yield;
		}
	}

}//end task


//アクセサ

function system_AddWeight(let val){m_weight = REMY_GetNumMax(m_weight + val, 0);}
function system_GetWeight(){return m_weight;}



//------------------------------------
//ライフアイテム
//------------------------------------



task once_system_TaskLifeItemMain(){


	loop{
//		OutputDebugString(0,"w", m_weight);
		let check = GetCommonDataDefaultEx("SPHERIA_ENEMY", "ENEMY_LIFEITEM", []);
		
		while(length(check) != 0){
			let array = check[0];
			loop(array[2]){
				system_TaskLifeItem(array[0], array[1]);
			}
			check = erase(check, 0);
		}
		SetCommonDataEx("SPHERIA_ENEMY", "ENEMY_LIFEITEM", []);

		loop(10){yield;}
	}

}//end task


task system_TaskLifeItem(let x, let y){

	let flag_intersect = false;
	let obj = REMY_CreateEffectObject(img_Sphere, 4, 4);
	let rect = system_GetGraphicRect("SPHERE_HEART");
	REMY_SetObjectVertexSquare(obj, rect, 0, 0, 255, 250, 60, 60);
	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj, rand(0,360));
	Obj_SetSpeed(obj, rand(1,4));
	ObjEffect_SetScale(obj, 0.6, 0.6);

	Rotate();

	ascent(i in 0..30){
		Obj_SetSpeed(obj, Obj_GetSpeed(obj)-0.1);
		yield;
	}

	Obj_SetSpeed(obj, 0);
	loop(10){yield;}
	
	while(!flag_intersect){
		if(REMY_IsIntersectWithPlayer(Obj_GetX(obj), Obj_GetY(obj), 20)){flag_intersect = true;}
		local{
	 		Obj_SetAngle(obj, REMY_GetAngleToPlayer(Obj_GetX(obj), Obj_GetY(obj)));
		}
		Obj_SetSpeed(obj, REMY_GetNumMin(Obj_GetSpeed(obj)+0.2, 10));
		yield;
	}
	Obj_SetSpeed(obj, 0);

	let chip = GetCommonDataDefaultEx("SPHERIA_PLAYER", "PLAYER_LIFE_CHIP", 0);
	SetCommonDataEx("SPHERIA_PLAYER", "PLAYER_LIFE_CHIP", chip+1);

	PlaySE(se_Item);

	ascent(j in 0..10){
		ObjEffect_SetScale(obj,0.6 + 3 * (j/10), 0.6 + 3 * (j/10));
		ascent(i in 0..4){
			ObjEffect_SetVertexColor(obj, i, 150 *(1- j/10), 250, 50, 50);
		}
		yield;
	}
	Obj_Delete(obj);


	task Rotate(){
		let angle = rand(0, 180);
		ascent(i in 0..80){
			ObjEffect_SetAngle(obj,angle + i, angle+i, angle+i);
			yield;
		}
	}

}//end task






