package de.rico.adventure.entity.character;

import de.rico.adventure.entity.item.Item;
import de.rico.adventure.inventory.AbstractInventory;
import de.rico.adventure.structure.Room;
import de.rico.engine.geometry.AbstractMesh;

/**
 * Class for playable characters.
 *
 * @author Frank Bruns
 */
public class PlayableCharacter extends AbstractCharacter
{
	private AbstractInventory inventory = null;
	private Room previousRoom = null;

	/**
	 * Creates a new playable character that uses the specified mesh as a model
	 * and the specified inventory system for its items.
	 *
	 * @param mesh mesh to use as a model
	 * @param inventory inventory system for the character
	 */
	public PlayableCharacter(AbstractMesh mesh, AbstractInventory inventory)
	{
		super(mesh);
		this.inventory = inventory;
	}

	/**
	 * Returns the room the player previously visited. This information can
	 * be important in MAP mode.
	 * @return previously by the player visited room
	 */
	public Room getPreviousRoom()
	{
		return this.previousRoom;
	}

	/**
	 * Sets the room that was previously visited by the player.
	 * @param room room that was previously visited by the player
	 */
	public void setPreviousRoom(Room room)
	{
		this.previousRoom = room;
	}

	/**
	 * Sets the inventory system of the character.
	 *
	 * @param inventory inventory system for the character
	 */
	public void setInventory(AbstractInventory inventory)
	{
		this.inventory = inventory;
	}

	/**
	 * Returns the inventory of the character.
	 *
	 * @return inventory of the character
	 */
	public AbstractInventory getInventory()
	{
		return this.inventory;
	}

	/**
	 * This method picks up an item and adds it to the playable character's
	 * inventory.
	 *
	 * @param item item to pick up and add to the inventory
	 */
	public void pickUp(Item item)
	{
		// leave, if can't be picked up
		if (item.canBePickedUp() == false) return;

		// else pick up
		this.inventory.add(item);
		this.getRoom().removeItem(item);
	}

	/**
	 * Determines whether or not the specified item is equal to the
	 * one that is currently selected from the inventory.
	 * @param item item to checked for being currently used.
	 * @return is item equal to currently used inventor item?
	 * --> true=yes, false=no
	 */
	public boolean uses(Item item)
	{
		if(item.equals(this.getInventory().getSelectedInventoryItem()))
			return true;
		else return false;
	}
}
