package org.studiorailgun.sim.eval.command;

import org.studiorailgun.Globals;
import org.studiorailgun.sim.character.Character;
import org.studiorailgun.sim.space.Location;

/**
 * Handler for look command
 */
public class LookCommand {
    
    /**
     * Handles a look command
     */
    public static void handle(String input){
        Location playerLoc = Globals.playerCharacter.getLocation();
        if(LookCommand.scanForNames(input, playerLoc) != null){
            Character character = LookCommand.scanForNames(input, playerLoc);
            character.describe();
        } else {
            playerLoc.describe();
        }
    }

    /**
     * Scans the input for character names and returns the character that is found.
     * @param input The input string
     * @param loc The location to scan within
     * @return The character if one is found, false otherwise
     */
    private static Character scanForNames(String input, Location loc){
        for(Character character : loc.getChars()){
            if(input.contains(character.getName())){
                return character;
            }
        }
        return null;
    }

}
