/*
 *  Initiative - A role playing utility to track turns
 *  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
 *
 * Spell.java
 *
 * Created on January 16, 2002, 12:27 PM
 */

package org.evilsoft.gaming.Init;

import org.evilsoft.gaming.System.SystemInitiative;
import java.util.Vector;

/**
 *
 * @author  devon
 * @version 
 */
public class Spell implements InitHolder {

    public SystemInitiative init;

    private String holderType = "Spell";
    private int duration;
    private String name;
    private String player;
    private String status = "Active";
    
    
    /** Creates new Spell */
    public Spell(String name, String player, int duration, int init) {
        this.name = name;
        this.player = player;
        this.duration = duration;
        this.init = new SystemInitiative(0);
        this.init.setCurrentInitiative(init);
    }
    
    public String getName() {
        return name;
    }

    public String getPlayer() {
        return player;
    }

    public String getStatus() {
        return status;
    }

    public int getDuration() {
        return duration;
    }

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

    public void setPlayer(String player) {
        this.player = player;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }
    
    public int decDuration() {
        duration--;
        return duration;
    }

    public SystemInitiative getInitiative() {
      return init;
    }
    
    public String getHolderType() {
      return holderType;
    }
    
    public Vector getRowVector(Vector columnOrder) {
        Vector rowVector = new Vector();
        int columns = columnOrder.size();
        for(int j = 0; j < columns; j++) {
            String columnName = (String)columnOrder.get(j);
            if(columnName.equals("Name")) {
                rowVector.add(getName());
            }
            else if(columnName.equals("Player")) {
                rowVector.add(getPlayer());
            }
            else if(columnName.equals("Status")) {
                rowVector.add(getStatus());
            }
            else if(columnName.equals("+")) {
                rowVector.add("");
            }
            else if(columnName.equals("Init")) {
                rowVector.add("" + init.getCurrentInitiative());
            }
            else if(columnName.equals("Dur")) {
                rowVector.add("" + getDuration());
            }
            else if(columnName.equals("#")) {
                rowVector.add("");
            }
            else if(columnName.equals("HP")) {
                rowVector.add("");
            }
            else if(columnName.equals("HP Max")) {
                rowVector.add("");
            }
        }
        return rowVector;
    }
    
    public void editRow(Vector columnOrder, int colNumber, Object data) {
        Vector rowVector = new Vector();
        String columnName = (String)columnOrder.elementAt(colNumber);
        String strData = String.valueOf(data);
        if(columnName.equals("Name")) {
            setName(strData);
        }
        else if(columnName.equals("Player")) {
            setPlayer(strData);
        }
        else if(columnName.equals("Status")) {
            setStatus(strData);
        }
        else if(columnName.equals("Init")) {
          Integer intData = new Integer(strData);
          init.setCurrentInitiative(intData.intValue());
        }
        else if(columnName.equals("Dur")) {
          Integer intData = new Integer(strData);
          setDuration(intData.intValue());
        }
    }
}
