package com.hero.objects.powers;

import org.jdom.Element;

import com.hero.HeroDesigner;
import com.hero.objects.GenericObject;

/**
 * Copyright (c) 2000 - 2005, CompNet Design, Inc. All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, is prohibited unless the following conditions are met: 1.
 * Express written consent of CompNet Design, Inc. is obtained by the developer.
 * 2. Redistributions must retain this copyright notice. THIS SOFTWARE IS
 * PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 * EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * @author CompNet Design, Inc.
 * @version $Revision$
 */

public class MentalAwareness extends Sense {

	private static String xmlID = "MENTALAWARENESS";

	public MentalAwareness(Element root) {
		super(root, MentalAwareness.xmlID);
	}

	@Override
	public double getBaseCost() {
		if (HeroDesigner.getActiveHero() == null || HeroDesigner.getActiveTemplate().is6E()) {
			return super.getBaseCost();
		}
		for (GenericObject o : HeroDesigner.getActiveHero().getPowers()) {
			if (o.getTypes().contains("MENTAL")
					&& (GenericObject.findObjectByID(o.getAssignedModifiers(),
							"BASEDONCON") == null)
					&& (GenericObject.findObjectByID(o.getAssignedModifiers(),
							"DOESNOTPROVIDEMENTALAWARENESS") == null)
					&& (GenericObject.findObjectByID(o.getAssignedModifiers(),
							"BOECV") == null)) {
				return 0;
			} else if (o instanceof CompoundPower) {
				CompoundPower cp = (CompoundPower) o;
				for (GenericObject o2 : cp.getPowers()) {
					if (o2.getTypes().contains("MENTAL")
							&& (GenericObject.findObjectByID(o
									.getAssignedModifiers(), "BASEDONCON") == null)
							&& (GenericObject.findObjectByID(o
									.getAssignedModifiers(),
									"DOESNOTPROVIDEMENTALAWARENESS") == null)
							&& (GenericObject.findObjectByID(o
									.getAssignedModifiers(), "BOECV") == null)) {
						return 0;
					}
				}
			}
		}
		for (GenericObject o : HeroDesigner.getActiveHero().getEquipment()) {
			if (o.getTypes().contains("MENTAL")
					&& (GenericObject.findObjectByID(o.getAssignedModifiers(),
							"BASEDONCON") == null)
					&& (GenericObject.findObjectByID(o.getAssignedModifiers(),
							"DOESNOTPROVIDEMENTALAWARENESS") == null)
					&& (GenericObject.findObjectByID(o.getAssignedModifiers(),
							"BOECV") == null)) {
				return 0;
			} else if (o instanceof CompoundPower) {
				CompoundPower cp = (CompoundPower) o;
				for (GenericObject o2 : cp.getPowers()) {
					if (o2.getTypes().contains("MENTAL")
							&& (GenericObject.findObjectByID(o
									.getAssignedModifiers(), "BASEDONCON") == null)
							&& (GenericObject.findObjectByID(o
									.getAssignedModifiers(),
									"DOESNOTPROVIDEMENTALAWARENESS") == null)
							&& (GenericObject.findObjectByID(o
									.getAssignedModifiers(), "BOECV") == null)) {
						return 0;
					}
				}
			}
		}
		return super.getBaseCost();
	}

	@Override
	public String getDamageDisplay() {
		return "";
	}
}