package xmpDynamicType;

import java.util.ArrayList;

public class Builder extends Character {
	
	private ArrayList<String> tools;
	static final String[] toolChest={"knife", "axe", "saw","hammer","ruler","adze",
			"plumbBob","pencil","abacus"};
	private int lastTool;

	/**
	 * @param name
	 */
	public Builder(String name) {
		super(name);
		tools = new ArrayList<String>();
	}
	
	public void addTool() {
		if (tools.size()<toolChest.length) {
			tools.add(toolChest[tools.size()]);
			addStrength(3);
		}
		
	}
	
	@Override
	public void age() {
		super.age();
		if (getAge()>lastTool+8) {
			lastTool=getAge();
			addTool();
		}
	}
	
	public String toolList() {
		return "Tools: " + String.join(",", tools);
	}
	
	public Builder mate(Builder lover) {
		Builder child=null;
		if (getStrength()>40 && getAge()>15) {
			if (lover.getStrength()>50 && lover.getAge()>20) {
				if (Character.randGen.nextInt(10)>4) {
					child = new Builder(getName()+"son");
					addStrength(-10);
					lover.addStrength(-5);
				}
			}
		}
		if (child != null) {
			System.out.println(getName() + " and " + lover.getName() + 
					" would like to announce the birth of " + child.getName() +
					". Welcome and build strongly!");
		}
		return child;
	}
	
	@Override
	public void eulogy() {
		super.eulogy();
		if (tools.size()==0) {
			System.out.println(getName() + "worked hard to build new buildings, using only his bare hands.");
		} else {
			System.out.print(getName() + " will be buried with trusty ");
			for(String tool : tools ) {
				System.out.print(tool + ", ");
			}
			System.out.println("and the gratitude of this tribe.");
		}
	}
	
	/* (non-Javadoc)
	 * @see lab09.Character#toString()
	 */
	@Override
	public String toString() {
		return "Builder " + super.toString() + " " + toolList();
	}

}
