package org.studiorailgun.sim.character;

import org.studiorailgun.Globals;
import org.studiorailgun.sim.character.emotion.EmotionData;
import org.studiorailgun.sim.character.needs.NeedsHierarchy;
import org.studiorailgun.sim.character.vis.CharacterAppearance;
import org.studiorailgun.sim.space.Location;

/**
 * A reasoning entity being simulated in the game world
 */
public class Character {

    /**
     * An unassigned location
     */
    public static final int LOCATION_UNASSIGNED = -1;

    /**
     * The id of the character
     */
    int id;

    /**
     * The name of the character
     */
    String name;
    
    /**
     * The physical appearance of the character
     */
    CharacterAppearance appearance;

    /**
     * The emotional data for the character
     */
    EmotionData emotions;

    /**
     * The needs hierarchy for the character
     */
    NeedsHierarchy needs;

    /**
     * The id of the location of this character is in
     */
    int locationId;

    /**
     * Simulates this character
     */
    public void simulate(){
    }

    /**
     * Moves this character to the destination
     * @param destination The destination location
     */
    public void move(Location destination){
        //remove from old pos
        Location oldLoc = Globals.world.getLocation(locationId);
        if(oldLoc != null){
            oldLoc.removeCharacter(this);
        }
        //add to new pos
        destination.addCharacter(this);
        locationId = destination.getId();
    }

    /**
     * Gets the appearance of the character
     * @return The appearance of the character
     */
    public CharacterAppearance getAppearance() {
        return appearance;
    }

    /**
     * Sets the appearance of the character
     * @param appearance The appearance of the character
     */
    public void setAppearance(CharacterAppearance appearance) {
        this.appearance = appearance;
    }

    /**
     * Gets the emotions of the character
     * @return The emotions of the character
     */
    public EmotionData getEmotions() {
        return emotions;
    }

    /**
     * Sets the emotions of the character
     * @param emotions The emotions of the character
     */
    public void setEmotions(EmotionData emotions) {
        this.emotions = emotions;
    }

    /**
     * Gets the id of the location this character is at
     * @return The id of the location this character is at
     */
    public int getLocationId() {
        return locationId;
    }

    /**
     * Sets the id of the location this character is at
     * @param locationId The id of the location this character is at
     */
    public void setLocationId(int locationId) {
        this.locationId = locationId;
    }

    /**
     * Gets the location this character is in
     * @return The location
     */
    public Location getLocation(){
        return Globals.world.getLocation(this.locationId);
    }

    public NeedsHierarchy getNeeds() {
        return needs;
    }

    public void setNeeds(NeedsHierarchy needs) {
        this.needs = needs;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * Describes the character
     */
    public void describe(){
        System.out.println("A " + this.getAppearance().getRace() + ".");
    }

    
    

}
