package eu.smoser.dungeongenerator.dungeon;

import eu.smoser.dungeongenerator.util.Dice;

/**
 *
 * @author MrMcX
 */
public class Exit {

    /**
     * The room this exit leads to
     */
    public Room room;

    /**
     * The type of exit
     */
    public String type;

    /**
     * If the exit is start
     */
    boolean isStart;

    /**
     * If there is a trap in this exit
     */
    private boolean isTrap;

    /**
     * Type of trap
     */
    public String trap;
    
    /**
     * Constructs a random exit to a given room
     * @param room Room to lead to
     */
    public Exit(Room room){
        this(room, GetRandomType(), false);
    }
    
    /**
     * Constructs a exit of a give type to a room
     * @param room Room to lead to
     * @param type Type of exit
     */
    public Exit(Room room, String type){
        this(room, type, false);
    }
    
    private Exit(Room room, String type, boolean start){
        this.room = room;
        this.type = type;
        isStart = start;
        if(!isStart && type.contains("Falle")){
            isTrap = true;
            trap = GetRandomTrap();
        } else {
            isTrap = false;
        }
    }
    
    @Override
    public String toString(){
        return type;
    }
    
    /**
     * Gives this exits description
     * @return Description string
     */
    String toLongString(){
        String out = "- ";
        if(isStart){
            out += "Aus-/Eingang";
        } else if(room.number == 0){
            out += type + " zu einer Sackgasse";
        } else {
            out += type + " zu " + room.toShortString();
        }        
        if(isTrap){
            out += "; Falle: " + trap;
        }
        out += "\n";
        return out;
    }
    
    /**
     * Gives the entry
     * @return Entry of dungeon
     */
    static Exit Start(){
        return new Exit(null, null, true);
    }
    
    private static String GetRandomTrap(){
        switch(Dice.Roll(6, 1)){
            case 1: return "Giftnadel im Schloss; Gift ist zu alt, um Wirkung zu zeigen";
            case 2: return "Fallgrube öffnet sich direkt vor der Tür";
            case 3: return "Sensenklinge";
            case 4: return "Giftwolke (WdS 147)";
            case 5: return "Giftnadel im  Schloss (WdS 147)";
            case 6: return "herabstürzender Steinquader";
        }
        return "";
    }
    
    private static String GetRandomType(){
        switch(Dice.Roll(6, 2)){
            case 2:
            case 3:
            case 4: return "Freier Durchgang";
            case 5: return "Vorhang";
            case 6:
            case 7: return "Offene Tür";
            case 8: return "Geschlossene Tür";
            case 9: return "Geschlossene Tür mit Falle";
            case 10: return "Verschlossene Tür";
            case 11: return "Verschlossene Tür mit Falle";
            case 12: return "Geheimdurchgang";
        }
        return "";
    }
}
