/*
Tiamat - a role-playing game framework
Skill.java - represents a skill for a character, modifies an item
 
 Copyright  (C) 2004 Hugues Johnson
 
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package com.huguesjohnson.tiamat;

import java.lang.String;
import java.lang.StringBuffer;
import java.util.ArrayList;
import com.huguesjohnson.tiamat.NamedObject;
import com.huguesjohnson.tiamat.Target;

/** Skill - represents a skill for a character, modifies an a players attribute or ability to use an item.
 * @author Hugues Johnson
 */
public class Skill extends NamedObject{

/* begin public properties */
    //which items or attributes does this skill modify
    private ArrayList<Target> targets;
    /** 
     * Sets the Targets for this Skill.
     * @param targets The new Targets for this Skill.
     */
    public void setTargets(Target[] targets){
		int length=targets.length;
		this.targets=new ArrayList<Target>(length);
        for(int index=0;index<length;index++){
            this.targets.add(index,targets[index]);
        }
    }
    /** Returns the Targets for this Skill.
     * @return The Targets for this Skill.
     */
    public Target[] getTargets(){ return(this.targets.toArray(new Target[0])); }
    /**
     * Sets the Target at the specified index.
     * @param index The index to set.
     * @param target The Target to set.
     */
    public void setTarget(int index,Target target){ 
        if((index>=0)&&(index<this.targets.size())){ 
            this.targets.set(index,target); 
        } 
    }
    /**
     * Returns the Target at the specified index, null if index out of range.
     * @param index The index of the Target to retrieve.
     * @return The Target at the specified index, null if index out of range.
     */
    public Target getTarget(int index){
        if((index>=0)&&(index<this.targets.size())){
            return(this.targets.get(index)); 
        } 
        return(null); 
    }
/* end public properties */    
    
/* begin constructors */
    //blank skill with no targets
    /**
     * Creates a new Skill with no targets.
     * @param name The name of the Skill.
     * @param description The description of the Skill
     */
    public Skill(String name,String description){
        super(name,description);
        this.targets=new ArrayList<Target>();
    } 
    /**
     * Creates a new Skill.
     * @param name The name of the Skill.
     * @param description The description of the Skill
     * @param targets The Targets for this Skill.
     */
    public Skill(String name,String description,Target[] targets){
        super(name,description);
        this.setTargets(targets);
    }
/* end constructors */
    
/* begin public methods */
    /** 
     * Returns a string representation of the object.
     * @return A string representation of the object. 
     */
    public String toString(){
        StringBuffer tostring=new StringBuffer(this.getClass().getName());
        tostring.append("\n  name="+this.getName());
        tostring.append("\n  description="+this.getDescription());
        tostring.append("\n  targets=");
        int size=this.targets.size();
        tostring.append("\n    size="+size);
        for(int index=0;index<size;index++){
            tostring.append("\n    targets["+index+"]="+this.targets.get(index).toString());
        }        
        return(tostring.toString());
    }
    /** 
     * Returns the number of targets for this Skill. 
     * @return The number of targets for this Skill. 
     */
    public int getTargetCount(){ 
        return(this.targets.size()); 
    }
    /** 
     * Adds a Target to the collection of Targets.
     * @param target The Target to add.
     */
    public void addTarget(Target target){
        this.targets.add(target);
    }
/* end public methods */
}