import { Player, system } from "@minecraft/server";
import { replaceEquipment, setItemInInventory } from "./function";
import { getScoreUtility, setScoreUtility } from "./scoreboard";


/**
 * @param {Player} player
 */
export function pressedSneak(player){
	const mainhandItemStack = player.getComponent("equippable").getEquipment("Mainhand");
	const offhandItemStack = player.getComponent("equippable").getEquipment("Offhand");
	if(mainhandItemStack!=undefined){
		const itemId = mainhandItemStack.typeId;
		if(!itemId.includes("hxc:")) return;
		const id = itemId.split("hxc:")[1];
		if(mainhandItemStack.hasTag("hxc:skill")){
			skill(player,id);
		}
	}
}
/**
 * @param {Player} player
 */
export function releasedSneak(player){
	return;
}
/**
 * 剣術入れ替え
 * @param {Player} player 
 * @param {String} id 
 */
function skill(player,id){
	if(id == "combat_punch"){
		replaceEquipment(player,"Mainhand","hxc:combat_kick",1,true,"inventory");
	}
	else if(id == "combat_kick"){
		replaceEquipment(player,"Mainhand","hxc:combat_punch2",1,true,"inventory");
	}
	else if(id == "combat_punch2"){
		replaceEquipment(player,"Mainhand","hxc:combat_punch",1,true,"inventory");
	}
	else if(id == "nobunaga_katana"){
		replaceEquipment(player,"Mainhand","hxc:nobunaga_katana2",1,false,"none");
	}
	else if(id == "nobunaga_katana2"){
		replaceEquipment(player,"Mainhand","hxc:nobunaga_katana3",1,false,"none");
	}
	else if(id == "nobunaga_katana3"){
		replaceEquipment(player,"Mainhand","hxc:nobunaga_katana4",1,false,"none");
	}
	else if(id == "nobunaga_katana4"){
		replaceEquipment(player,"Mainhand","hxc:nobunaga_katana",1,false,"none");
	}
	else if(id == "feitan_sword"){
		replaceEquipment(player,"Mainhand","hxc:feitan_sword2",1,false,"none");
	}
	else if(id == "feitan_sword2"){
		replaceEquipment(player,"Mainhand","hxc:feitan_sword3",1,false,"none");
	}
	else if(id == "feitan_sword3"){
		replaceEquipment(player,"Mainhand","hxc:feitan_sword4",1,false,"none");
	}
	else if(id == "feitan_sword4"){
		replaceEquipment(player,"Mainhand","hxc:feitan_sword",1,false,"none");
	}
	else if(id == "god_trident"){
		replaceEquipment(player,"Mainhand","hxc:god_trident2",1,false,"none");
	}
	else if(id == "god_trident2"){
		replaceEquipment(player,"Mainhand","hxc:god_trident3",1,false,"none");
	}
	else if(id == "god_trident3"){
		replaceEquipment(player,"Mainhand","hxc:god_trident4",1,false,"none");
	}
	else if(id == "god_trident4"){
		replaceEquipment(player,"Mainhand","hxc:god_trident5",1,false,"none");
	}
	else if(id == "god_trident5"){
		replaceEquipment(player,"Mainhand","hxc:god_trident",1,false,"none");
	}
}