import { world, Entity } from "@minecraft/server";
const scoreboardList = [
	{ id:"nen",score:0 },
	{ id:"nen_max",score:0 },
	{ id:"charge",score:0 },
	{ id:"charge_max",score:20 },
	{ id:"score_test",score:0 },
	{ id:"pain_score",score:0 },
	{ id:"guard_time",score:110 }
]
/**
 * @param {String} objId
 */
function addScoreboard(objId){
	if(world.scoreboard.getObjective(objId)==null){
		world.scoreboard.addObjective(objId,"");
	}
};
/**
 * @param {Entity} entity
 * @param {String} objId
 */
function getScore0(entity,objId){
	const score = world.scoreboard.getObjective(objId).getScore(entity);
	if(score!=undefined){
		return score;
	}else{
		if(objId == "charge_max"){
			world.scoreboard.getObjective(objId).setScore(entity,20);
			return 20;
		}
		else if(true){
			world.scoreboard.getObjective(objId).setScore(entity,0);
			return 0;
		}
	}
};
/**
 * @param {Entity} entity
 * @param {String} objId
 */
function getScoreUtility(entity,objId){
	addScoreboard(objId);
	return getScore0(entity,objId);
};
/**
 * @param {Entity} entity
 * @param {String} objId
 * @param {Number} score
 */
function setScoreUtility(entity,objId,score){
	addScoreboard(objId);
	world.scoreboard.getObjective(objId).setScore(entity,score);
};
/**
 * @param {Entity} entity
 * @param {String} objId
 * @param {Number} score
 */
function operationScoreUtility(entity,objId,score){
	addScoreboard(objId);
	world.scoreboard.getObjective(objId).setScore(entity,getScore0(entity,objId)+score);
};

export { getScoreUtility, setScoreUtility, operationScoreUtility, scoreboardList };