package common.entity.npc;

import java.util.List;

import common.attributes.Attributes;
import common.collect.Lists;
import common.init.Items;
import common.init.SpeciesRegistry;
import common.item.ItemStack;
import common.rng.Random;
import common.util.Identifyable;
import common.world.World;

public class EntityChaosMarine extends EntityNPC {
	public static enum Legion implements Identifyable {
		OTHER("other", null, 0x000000, 0x000000, 2.15f, 200),
		EMPERORS_CHILDREN("emperorchild", "Emperors Children", 0xa224cc, 0xccb963, 2.43f, 300, "emperors_child");
		
		public static final Object[] MARINES;

		private final String name;
		private final String display;
		public final int color1;
		public final int color2;
		public final float size;
		public final int health;
		public final String[] classes;
		
		static {
			List<Object> marines = Lists.newArrayList();
			for(Legion legion : values()) {
				if(legion.classes.length > 0)
					marines.add(legion);
				for(String type : legion.classes) {
					marines.add(":marine_" + type);
					marines.add(legion.color1);
					marines.add(legion.color2);
				}
			}
			MARINES = marines.toArray(new Object[marines.size()]);
			marines.clear();
		}
		
		private Legion(String name, String display, int color1, int color2, float size, int health, String ... classes) {
			this.name = name;
			this.display = display == null ? "" : display + " Einheit";
			this.color1 = color1;
			this.color2 = color2;
			this.size = size;
			this.health = health;
			this.classes = classes;
		}
		
		public String getName() {
			return this.name;
		}
		
		public String toString() {
			return this.display;
		}
	}
	
	public EntityChaosMarine(World worldIn) {
		super(worldIn);
	}
	
	public Legion getLegion() {
		Enum legion = this.getNpcClass();
		return legion == null ? Legion.OTHER : (Legion)legion;
	}
    
    public boolean isAggressive(Class<? extends EntityNPC> clazz) {
    	return "terra".equals(SpeciesRegistry.CLASSES.get(clazz).origin);
    }
    
    public int getBaseHealth(Random rand) {
    	return this.getLegion().health;
    }
    
    public float getSpeciesBaseSize() {
    	return 2.15f;
    }
    
    public float getEntityBaseSize() {
    	return this.getLegion().size;
    }
    
    public Alignment getNaturalAlign() {
    	return rand.chance(Alignment.CHAOTIC_EVIL, Alignment.EVIL, 6);
    }
    
    public Object onInitialSpawn(Object livingdata) {
        livingdata = super.onInitialSpawn(livingdata);
        this.setMaxHealth(this.getLegion().health);
        this.setHealth(this.getMaxHealth());
        return livingdata;
    }
    
    public boolean isMagnetic() {
    	return true;
    }
	
    public boolean isSneakingVisually() {
        return false;
    }

	public int getTotalArmorValue() {
		return 20;
	}
    
    protected int getAttackSpeed() {
    	return 5;
    }
    
//    public boolean canAmbush(EntityLiving entity) {
//    	return true;
//    }

    protected void applyEntityAttributes() {
        super.applyEntityAttributes();
        this.getEntityAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(12.0D);
    }

	protected ItemStack pickItem() {
		return this.rand.chance(new ItemStack(Items.boltgun), null, 3);
	}
}
