package util;

import java.util.*;
import java.math.*;

public class EntityPlayer extends Entity {
	protected double armor,speed,speedX,level;
	protected int heldItemIndex;
	protected Inventory inventory;
	protected Abilities abilities;
	
	public EntityPlayer() {
		super();
		this.armor = 0.1;
		this.speed = 0.35;
		this.speedX = 1;
		this.inventory = new Inventory(3);
		this.abilities = new NormalAbilities(this);
		
	}
	
	
	public EntityPlayer(double armor, double health, double speed, double damage){
		super(health, damage);
		this.armor = armor;
		this.speed = speed;
		this.maxHealth = health;
		this.inventory = new Inventory(3);
		this.level = 1;
		this.speedX = 1;
	}
	/*
	 * returns damage + the addedDamage combined
	 */
	public double getDamage(){
		if(inventory.getItem(1) != null) return damage + ((Sword)inventory.getItem(1)).getDamage();
		else return damage + (level * 5);
	}
	
	public double getArmor() {
		if(inventory.getItem(0) != null) return armor + ((Armor)inventory.getItem(0)).getArmor();
		else return armor + (level/100);
	}
	
	/*
	 * applies input damage from object creature to player
	 * 
	 * takes into account armor
	 */
	public void damagePlayer(EntityCreature creature){
		health = health - ( creature.getDamage() - (creature.getDamage() * (getArmor())));
	}
	
	/*
	 * adds health to player, then returns
	 * 
	 * takes into account error in going over full health, no worries
	 */
	public double healPlayer(double item){
		if (item + health >= health)
			{
				health = maxHealth;
				return health;
			}
		else return health + item;
		
	}
	
	/*
	 * returns speed times the multiplier
	 */
	public double getSpeed(){
		return speed * speedX;
	}
	
	public Item getCurrentHeldItem() {
		return this.inventory.getItem(this.heldItemIndex);
	}
	
	public void setHeldItem(Item item) {
		if(this.inventory.getSlot(item) > -1) this.heldItemIndex = this.inventory.getSlot(item);
	}
	
	/*
	 * adds item based on type
	 * 
	 * works off of instanceof , error will occur if one of the following items aren't used "Armor, Potion, Sword, Boot"
	 */
	public void addItem(Item item){
		for (int i = 0; i < inventory.size(); i++){
			if(inventory.getItem(i) == item) {
				setHeldItem(item);
				removeItem(heldItemIndex);	
				break;
			}	
		}
		if(item instanceof Armor)
			{
				inventory.setSlot(0,item);
			}
		else if (item instanceof Potion)
			{
				this.health = (healPlayer(((Potion)item).getHeal())); 
			}
		else if (item instanceof Sword)
			{
				inventory.setSlot(1,item);
			}
		else if (item instanceof Boots)
			{
				this.speedX = ((Boots)item).getSpeed();
				inventory.setSlot(2,item);
			}
	}
	public double getAbilities(int abilityNum){
		switch(abilityNum){
		case 1: return abilities.damageAbility();
		case 2: return abilities.defenceAbility();
		case 3: return abilities.utilAbility();
		case 4: return abilities.ultiAbility();
		}
		return 0;
		
	}
		
	/*
	 * this is used to elimate item values
	 * MUST BE USED AFTER THE METHOD "setHeldItem(Item)"
	 */
	
	public void removeItem(int itemIndex) {
			inventory.setSlot(itemIndex,null);
		
	}
	

	public void leveling(EntityCreature creature){
		level = level + ((level * Math.sqrt(creature.getXP()))/100);
		this.health = this.health + ((getLevel() * health)/7);
		this.damage = this.damage + ((getLevel() * damage)/4);
		
	}
	public double getLevel(){
		return level;
	}
	
	

}

@@ -2893,16 +2893,302 @@
 ;%0A%09%09%0A%09%7D%0A
+%09%0A%09public String getAbilitiesDesc(int abilityNum)%7B%0A%09%09switch(abilityNum)%7B%0A%09%09case 1: return abilities.damageAbilityDesc();%0A%09%09case 2: return abilities.defenceAbilityDec();%0A%09%09case 3: return abilities.utilAbilityDesc();%0A%09%09case 4: return abilities.ultiAbilityDesc();%0A%09%09%7D%0A%09%09return null;%0A%09%09%0A%09%7D%0A
 %09%09%0A%09/*%0A%09

return stringdesk