package mobs;

import java.util.Random;

import interfaces.ItemIDs;
import interfaces.Mob.MOB_ID;
import utils.Point2f;
import utils.Utils;
import world.DroppedItem;

/**  ------------- Nihilne ------------
    *** @author Mitch Weaver - 2016 ***
      ~~~~ All Rights Reserved ~~~~ */

public final class DROP_TABLES implements ItemIDs {
	
	public static synchronized final void dropItem (final MOB_ID id, final Point2f center) {
		CENTER = center;
		
		switch(id) {
			case RABBIT: {
				roll(1000, RABBIT_FOOT); 
				roll(300, PICKED_GRASS); 
				drop(RABBIT_CARCASS); break;
			}
			case GOBLIN: {
				roll(1000, ASHES);
				roll(300, PICKED_GRASS);
				roll(200, STICKS);
				roll(100, ROCKS);
				roll(50, ROT, 3);
				roll(15, ROT);
				if(chance(10)) new DroppedItem(CENTER, GOBLIN_SPEAR, 1, (Utils.rand.nextInt(200) + 1)*0.5f); // drop spear with random durability
				drop(BONES); break;
			}
			
			default: System.out.println("YO YOU NEED TO CONFIG THIS MOBS DROPS!!!!!"); System.exit(1);
		}
		
	}
	
/********************************************************************************************************************************/
		private static Point2f CENTER = new Point2f(0,0);
		private static final synchronized void roll(int CHANCE, int itemId) { if(chance(CHANCE)) drop(itemId); }
		private static final synchronized void roll(int CHANCE, int itemId, int quantity) { if(chance(CHANCE)) drop(itemId, quantity); }
		private static final synchronized void drop(int itemId) { new DroppedItem(CENTER, itemId); }
		private static final synchronized void drop(int itemId, int quantity) { new DroppedItem(CENTER, itemId, quantity); }
		private static final synchronized boolean chance(final int bound) { return new Random().nextInt(bound) == 0; }
		
}
