package sso.event;

import sso.*;

/**
 *  This represents some action taken by a player, NPC, or the environment that
 *  generates some kind of message. These are simply called "action events" and
 *  will be interpreted based on the originator and flags. Typically, these
 *  will be things like movement, talking, attacking, etc.
 *
 *  These are generated by the GameObject, passed up to the immediate LOCATION,
 *  and from there they may propagate. ie--an attack originates with the
 *  attacker, includes the flag "attack" and the attack object, and gets passed
 *  to the attacker's location, a Tile. The Tile then passes the action event
 *  to it's neighbors, counting down the TTL (defined by the event type).
 *  Another example--a player speaks, includes the flag "talk" and the message
 *  String, and gets passed to the speaker's location and propagated from
 *  there. One final example--an alarm object in a bag generates a "talk" event
 *  and a message String, and passes it to the bag. The bag, if an
 *  ActionListener, will then decide to pass that to the holder or not.
 */
public class ActionEvent extends java.util.EventObject implements Cloneable
{
	int flag;
	int ttl;
	Object message;
	int id;

	// ACTION EVENT FLAGS
	public static final int	UNKNOWN		= 0;
	public static final int	TALK		= 1;
	public static final int	EMOTE		= 2;
	public static final int	ORDER		= 3;
	public static final int	SNEAK		= 4;
	public static final int	WALK		= 5;
	public static final int	RUN			= 6;
	public static final int	DIE			= 7;
	public static final int DESTROY		= 8;
	public static final int	CREATE		= 9;
	public static final int DISAPPEAR	= 10;
	public static final int	APPEAR		= 11;
	public static final int	ATTACK		= 12;
	public static final int	HURT		= 13;
	public static final int	HEAL		= 14;
	public static final int	CAST		= 15;
	public static final int	DODGE		= 16;
	public static final int	HIDE		= 17;
	public static final int	SLEEP		= 18;
	public static final int	LIE			= 19;
	public static final int	SEARCH		= 21;
	public static final int	GIVE		= 22;
	public static final int	STEAL		= 23;
	public static final int	PICKLOCK	= 24;
	public static final int	DISARM		= 25;
	public static final int	STAND		= 26;
	public static final int	SIT			= 27;
	public static final int	ORATE		= 28;
	public static final int	SHOUT		= 29;

	public ActionEvent(GameObject source, int flag, Object contents)
	{
		super(source);
		this.id = hashCode();
		this.flag = flag;
		message = contents;
		ttl = getTTL();
	}

	private int getTTL()
	{
		int t = 0;
	
		switch (flag)
		{
			case TALK:
				t = 5;
				break;
			case ORATE:
				t = 15;
				break;
			case SHOUT:
				t = 30;
				break;
			case SNEAK:
			case HURT:
			case HEAL:
			case DODGE:
			case SLEEP:
			case SEARCH:
			case GIVE:
			case STEAL:
			case PICKLOCK:
			case DISARM:
				t = 4;
				break;
			case RUN:
				t = 12;
				break;
			case ORDER:
			case WALK:
			case DIE:
			case DESTROY:
			case CREATE:
			case DISAPPEAR:
			case APPEAR:
			case ATTACK:
			case CAST:
			case HIDE:
			case LIE:
			case STAND:
			case SIT:
				t = 10;
				break;
			case EMOTE:
			default:
				t = 7;
		}

		return t;
		
	}

	public Object clone()
	{
		ActionEvent evt = new ActionEvent((GameObject)source, flag, message);
		evt.id = id;
		evt.ttl--;
		return (Object)evt;
	}

	public Integer getID()
	{
		return new Integer(id);
	} 

	public int getFlag()
	{
		return flag;
	}

	public void setTTL(int ttl)
	{
		this.ttl = ttl;
	}
}
		

