/*
 *  RPGeneration - A role playing utility generate interesting things
 *  Copyright (C) 2002 Devon D Jones
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  The author of this program grants you the ability to use this code
 *  in conjunction with code that is covered under the Open Gaming License
 *
 * Information.java
 *
 * Created on October 28, 2002, 11:52 AM
 */

package org.evilsoft.gaming.RPGeneration;

import org.jdom.*;
import java.util.ArrayList;
import java.util.Random;
/**
 *
 * @author  devon
 */
public class Information {
    private String type = "";
    private String data = "";
    private Roll roll;
    private VariableHashMap allVars;
    /** Creates a new instance of DetailBooleanEffect */
    public Information(Element informationElement, VariableHashMap allVars) {
        this.allVars = allVars;
        try {
            if(informationElement.getAttribute("Type") != null) {
                type = informationElement.getAttribute("Type").getValue();
            }
            if(informationElement.getAttribute("Data") != null) {
                data = informationElement.getAttribute("Data").getValue();
            }
            Element roll = informationElement.getChild("Roll");
            if(roll != null) {
                this.roll = new Roll(roll, type, allVars);
            }
        }
        catch(Exception e) {
            System.out.println("XML ERROR");
            e.printStackTrace();
        }
    }

    public Information(String type, String data, VariableHashMap allVars) {
        this.type = type;
        this.data = data;
        this.allVars = allVars;
    }

    public String getType() {
        return allVars.parse(type);
    }

    public String getData() {
        String modData = data;
        if(roll != null) {
            int rollTotal = roll.getRoll(allVars.getRandom());
            modData = modData.replaceAll("#", rollTotal + "");
        }
        return allVars.parse(modData);
    }
}
