package common.entity.npc;

import java.util.List;

import common.attributes.Attributes;
import common.collect.Lists;
import common.rng.Random;
import common.util.Identifyable;
import common.world.World;

public class EntityPrimarch extends EntityMobNPC {
	public static enum Founding implements Identifyable {
		OTHER("other", "", 0, 0x000000, 0x000000),
		DARK_ANGELS("darkangel", "Dark Angels", 1, 0xaf0000, 0x400000, "Lion El'Jonson:lion_el_jonson", 2.65f, 850, Alignment.GOOD),
		UNKNOWN_A("unkna", "[Legion 2]", 2, 0xaf0000, 0x400000),
		EMPERORS_CHILDREN("emperorchild", "Emperors Children", 3, 0xaf0000, 0x400000, "Fulgrim", 2.65f, 1250, Alignment.NEUTRAL),
		IRON_WARRIORS("ironwarrior", "Iron Warriors", 4, 0xaf0000, 0x400000, "Perturabo", 2.65f, 450, Alignment.NEUTRAL),
		WHITE_SCARS("whitescar", "White Scars", 5, 0xaf0000, 0x400000, "Jaghatai Khan", 2.65f, 850, Alignment.NEUTRAL),
		SPACE_WOLVES("spacewolf", "Space Wolves", 6, 0xaf0000, 0x400000, "Leman Russ", 2.65f, 850, Alignment.NEUTRAL),
		IMPERIAL_FISTS("imperialfist", "Imperial Fists", 7, 0xaf0000, 0x400000, "Rogal Dorn", 2.65f, 850, Alignment.NEUTRAL),
		NIGHT_LORDS("nightlord", "Night Lords", 8, 0xaf0000, 0x400000, "Konrad Curze", 2.65f, 850, Alignment.NEUTRAL),
		BLOOD_ANGELS("bloodangel", "Blood Angels", 9, 0xaf0000, 0x400000, "Sanguinius", 2.65f, 850, Alignment.CHAOTIC_GOOD),
		IRON_HANDS("ironhand", "Iron Hands", 10, 0xaf0000, 0x400000, "Ferrus Manus", 2.65f, 850, Alignment.NEUTRAL),
		UNKNOWN_B("unknb", "[Legion 11]", 11, 0xaf0000, 0x400000),
		WORLD_EATERS("worldeater", "World Eaters", 12, 0xaf0000, 0x400000, "Angron", 2.65f, 850, Alignment.NEUTRAL),
		ULTRAMARINES("ultramarine", "Ultramarines", 13, 0xaf0000, 0x400000, "Roboute Guilliman", 2.65f, 850, Alignment.NEUTRAL),
		DEATH_GUARD("deathguard", "Death Guard", 14, 0xaf0000, 0x400000, "Mortarion", 2.65f, 850, Alignment.NEUTRAL),
		THOUSAND_SONS("thousandson", "Thousand Sons", 15, 0xaf0000, 0x400000, "Magnus the Red", 2.65f, 850, Alignment.NEUTRAL),
		LUNA_WOLVES("lunawolf", "Luna Wolves", 16, 0xaf0000, 0x400000, "Horus Lupercal", 2.65f, 850, Alignment.NEUTRAL),
		WORD_BEARERS("wordbearer", "Word Bearers", 17, 0xaf0000, 0x400000, "Lorgar Aurelian", 2.65f, 850, Alignment.NEUTRAL),
		SALAMANDERS("salamander", "Salamanders", 18, 0xaf0000, 0x400000, "Vulkan", 2.65f, 850, Alignment.NEUTRAL),
		RAVEN_GUARD("ravenguard", "Raven Guard", 19, 0xaf0000, 0x400000, "Corvus Corax", 2.65f, 850, Alignment.NEUTRAL),
		ALPHA_LEGION("alphalegion", "Alpha Legion", 20, 0xaf0000, 0x400000, "Alpharius Omegon", 2.65f, 850, Alignment.NEUTRAL);
		
		public static final Object[] PRIMARCHS;

		private final String name;
		private final String display;
		public final int numeral;
		public final int color1;
		public final int color2;
		public final float size;
		public final int health;
		public final Alignment align;
		public final String primarch;
		
		static {
			List<Object> primarchs = Lists.newArrayList();
			for(Founding founding : values()) {
				if(founding.primarch != null) {
					primarchs.add(founding);
					primarchs.add(founding.primarch);
					primarchs.add(founding.color1);
					primarchs.add(founding.color2);
				}
			}
			PRIMARCHS = primarchs.toArray(new Object[primarchs.size()]);
			primarchs.clear();
		}

		private Founding(String name, String display, int num, int color1, int color2) {
			this(name, display, num, color1, color2, null, 2.65f, 850, Alignment.NEUTRAL);
		}
		
		private Founding(String name, String display, int num, int color1, int color2, String primarch, float psize, int phealth, 
				Alignment palign) {
			this.name = name;
			this.display = display;
			this.numeral = num;
			this.color1 = color1;
			this.color2 = color2;
			this.primarch = primarch;
			this.size = psize;
			this.health = phealth;
			this.align = palign;
		}
		
		public String getName() {
			return this.name;
		}
		
		public String toString() {
			return this.display;
		}
	}
	
	public EntityPrimarch(World worldIn) {
		super(worldIn);
	}

//	public boolean isAggressive() {
//		return false;
//	}
//
//	public boolean isPeaceful() {
//		return false;
//	}

//	public boolean isAggressive(Class<? extends EntityNPC> clazz) {
//		return false;
//	}
//
//	public boolean isPeaceful(Class<? extends EntityNPC> clazz) {
//		return false;
//	}

//	public boolean canInfight(Alignment align) {
//		return false;
//	}
//
//	public boolean canMurder(Alignment align) {
//		return false;
//	}

	public boolean canUseMagic() {
		return true;
	}

	public int getBaseHealth(Random rand) {
		return this.getFounding().health; // rand.range(450, 1250);
	}

//	public int getBaseEnergy(Random rand) {
//		return 0;
//	}
    
    public float getSpeciesBaseSize() {
    	return 2.65f;
    }
    
    public float getEntityBaseSize() {
    	return this.getFounding().size;
    }
    
//    public float getHeightDeviation(Random rand) {
//    	return 0.0f; // rand.frange(0.0f, 0.5f);
//    }

	public Alignment getNaturalAlign() {
		return this.getFounding().align;
	}

	public boolean isImmuneToFire() {
		return true;
	}
    
	public int getColor() {
		return 0xff9494;
	}
    
//    public boolean canAmbush(EntityLiving entity) {
//    	return true;
//    }

    protected void applyEntityAttributes() {
        super.applyEntityAttributes();
        this.getEntityAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(20.0D);
    }
    
//    public TextComponent getPrefix() {
//    	return null;
//    }
	
	public Founding getFounding() {
		Enum legion = this.getNpcClass();
		return legion == null ? Founding.OTHER : (Founding)legion;
	}
    
    public Object onInitialSpawn(Object livingdata) {
        livingdata = super.onInitialSpawn(livingdata);
        this.setMaxHealth(this.getFounding().health);
        this.setHealth(this.getMaxHealth());
        return livingdata;
    }
    
    public boolean isMagnetic() {
    	return true;
    }
}
