/**
 * Copyright © 2010, Res Interactive, LLC. All Rights Reserved.
 */
package com.tootsville.items;

import org.starhope.appius.except.NotFoundException;
import org.starhope.appius.game.AppiusClaudiusCaecus;
import org.starhope.appius.game.DamageArea;
import org.starhope.appius.game.DamageTypeRanks;
import org.starhope.appius.game.inventory.InventoryItem;
import org.starhope.appius.game.inventory.effects.SimpleRangedWeapon;
import org.starhope.appius.game.npc.DamageHitHandler;
import org.starhope.appius.game.npc.DamageMissHandler;
import org.starhope.appius.game.npc.Projectile;
import org.starhope.appius.user.AbstractUser;
import org.starhope.appius.user.AvatarClass;
import org.starhope.appius.user.Nomenclator;

/**
 * Zap shoots magic fireballs that do tiny levels of Wish damage.
 * 
 * @author brpocock@star-hope.org
 */
public class ZapWishBolt extends SimpleRangedWeapon implements
DamageHitHandler, DamageMissHandler {

	/**
	 * Java serialization unique ID
	 */
	private static final long serialVersionUID = 7862547989517966462L;

	/**
	 * @param theItem the item from which to shoot fireballs
	 */
	public ZapWishBolt (final InventoryItem theItem) {
		super (theItem);
		setLimitedAmmunition (false);
		setMaxAmmunition (99);
		setAmmunition (theItem.getHealth ().intValueExact ());
		setAvatarUseAction (null);
		try {
			setProjectileAvatar (Nomenclator.getDataRecord (
					AvatarClass.class, "Fire.Shot"));
		} catch (final NotFoundException e) {
			throw AppiusClaudiusCaecus.fatalBug (
					"Can't get the bullet avatar ", e);
		}
		setHitHandler (this);
		setHitAvatar (null);
		setMissAvatar (null);
		setMissHandler (this);
		setRepeatRateMillis (500);
		setShotDelayMillis (250);
		setTravelRate (175);
		attackDamage = new DamageTypeRanks ();
		try {
			attackDamage.add (Nomenclator.getDataRecord (
					DamageArea.class, "Wish"), 1);
		} catch (final NotFoundException e) {
			throw AppiusClaudiusCaecus.fatalBug (e);
		}
		travelsToEdgeOfScreen = true;
	}

	/**
	 * @see org.starhope.appius.game.npc.DamageMissHandler#damageMiss(org.starhope.appius.game.npc.Projectile)
	 */
	@Override
	public void damageMiss (final Projectile projectile) {
		// TODO Auto-generated method stub

	}

	/**
	 * @see org.starhope.appius.game.npc.DamageHitHandler#hitForDamage(org.starhope.appius.game.npc.Projectile,
	 *      org.starhope.appius.user.AbstractUser)
	 */
	@Override
	public void hitForDamage (final Projectile projectile, final AbstractUser victim) {
		final DamageTypeRanks attack = new DamageTypeRanks ();
		try {
			attack.add (Nomenclator.getDataRecord (DamageArea.class, "Wish"), 1);
		} catch (final NotFoundException e) {
			AppiusClaudiusCaecus.reportBug ("Caught a NotFoundException in ZapWishBolt.hitForDamage ", e);
		}
		victim.takeAttack (attack);
	}
}
