package hud.inventory;

import interfaces.ItemIDs;
import player.Player;
import utils.Utils;
import world.DroppedItem;

/*  ------------- Nihilne ------------
    * Created by Mitch Weaver - 2016 *
      ~~~~ All Rights Reserved ~~~~ */

public final class InvenHelper implements ItemIDs{
	
		private static float tempWeight;
		public static final void calcWeight() {
			tempWeight = 0;
			for (final InventorySlot i : Player.inventorySlots) if (i.itemId != NULL_ITEM) computeWeightOfItemSlot(i);
			for (final InventorySlot i : Player.equipmentSlots) if (i.itemId != NULL_ITEM) computeWeightOfItemSlot(i);
			Player.weight = tempWeight;
		}
		
		private static final void computeWeightOfItemSlot(final InventorySlot i) {
			switch (i.itemId) {
				case PICKED_GRASS: 				    tempWeight += 0.1f * i.quantity;   break;
				case PICKED_FLOWERS: 			    tempWeight += 0.075f * i.quantity; break;
				case CRUDE_AXE:  					tempWeight += 1.35f * i.quantity;  break;
				case LOGS:  						tempWeight += 1.15f * i.quantity;  break;
				case CRUDE_PICKAXE: 			    tempWeight += 1.5f * i.quantity;   break;
				case ROCKS:  						tempWeight += 0.95f * i.quantity;  break;
				case STICKS:  						tempWeight += 0.3f * i.quantity;   break;
				case ASHES:  						tempWeight += 0.1f * i.quantity;   break;
				case TORCH: 						tempWeight += 1f * i.quantity;     break;
				case RABBIT_CARCASS:			    tempWeight += 1.8f * i.quantity;   break;
				case RABBIT_FOOT: 					tempWeight += 0f * i.quantity;     break;
				case ROT: 							tempWeight += 0.05f * i.quantity;  break;
				case BONES:							tempWeight += 0.5f * i.quantity;   break;
				case GOBLIN_SPEAR:					tempWeight += 2.1f * i.quantity;   break;
				
				default: System.out.println("YO YOU NEED TO COMPUTE WEIGHT OF YOUR NEW ITEM!"); System.exit(0);
			}
		}
		
	public final static boolean isStackable(final int itemId) {
		switch(itemId) {
			case PICKED_GRASS: 							return true;
			case PICKED_FLOWERS: 						return true;
			case LOGS: 									return true;
			case ROCKS:								    return true;
			case STICKS:							    return true;
			case ASHES: 								return true;
			case RABBIT_FOOT: 							return true;
			case ROT: 									return true;
			case BONES:									return true;
			
			default: 									return false;
		}
	}
	
	public final static boolean isEquippable(final int itemId) {
		switch(itemId){
			case CRUDE_AXE: 							 return true;
			case CRUDE_PICKAXE:  						 return true;
			case TORCH:									 return true;
			case GOBLIN_SPEAR:							 return true;
			
			default: 									 return false;
		}
	}
	
	public final static boolean hasWeapon() {
		switch(Player.equipmentSlots[HAND_SLOT].itemId) {
			case CRUDE_AXE: 							return true;
			case CRUDE_PICKAXE:						    return true;
			case GOBLIN_SPEAR:							return true;
			default: 									return false;
		}
	}
	
	public final static int calcEquipSlot(final int itemId) {
			switch(itemId){
				case CRUDE_AXE:  						return HAND_SLOT;
				case CRUDE_PICKAXE:  					return HAND_SLOT;
				case TORCH: 							return HAND_SLOT;
				case GOBLIN_SPEAR:						return HAND_SLOT;
				default: 								{ System.out.println("YO CALC EQUIP SLOT IS BROKEN"); return -1; }
			}
	}
	
	public static final int getStackableAmount(final int itemId) {
		switch(itemId) {
			case PICKED_GRASS: 			return 40;
			case PICKED_FLOWERS:		return 40;
			case LOGS:					return 20;
			case ROCKS:					return 30;
			case STICKS:				return 40;
			case ASHES:					return 40;
			case ROT:					return 40;
			case BONES:					return 40;
			
			default:					return Utils._2147483647;
		}
	}
	
	public final static boolean isAxe(final int itemId){
		switch(itemId){
			case CRUDE_AXE:				 return true;
			
			default: 					 return false;
		}
	}

	public final static boolean isPickaxe(final int itemId){
		switch(itemId){
			case CRUDE_PICKAXE:			return true;
			
			default: 					return false;
		}
	}
	
	
	public static synchronized final void DROP_ALL_INVENTORY() {
		for(final InventorySlot i : Player.inventorySlots) {
			if(i.itemId == NULL_ITEM) continue;
			DroppedItem.dropItemsWithOffsetAsStack(i.itemId, i.quantity, 100, Player.center.x, Player.center.y, i.durability);
			i.itemId = NULL_ITEM;
			i.quantity = 0;
			i.durability = 100;
			i.mouseClicked = false;
			i.equippable = false;
		}
	}
	
}
