Scriptable.java

com/planet_ink/coffee_mud/Behaviors/Scriptable.java · 283.9 KB

From the archive CoffeeMud.zip

Download the archive   « Back to the archive contents

package com.planet_ink.coffee_mud.Behaviors;
import com.planet_ink.coffee_mud.core.interfaces.*;
import com.planet_ink.coffee_mud.core.*;
import com.planet_ink.coffee_mud.Abilities.interfaces.*;
import com.planet_ink.coffee_mud.Areas.interfaces.*;
import com.planet_ink.coffee_mud.Behaviors.interfaces.*;
import com.planet_ink.coffee_mud.CharClasses.interfaces.*;
import com.planet_ink.coffee_mud.Commands.interfaces.*;
import com.planet_ink.coffee_mud.Common.interfaces.*;
import com.planet_ink.coffee_mud.Exits.interfaces.*;
import com.planet_ink.coffee_mud.Items.interfaces.*;
import com.planet_ink.coffee_mud.Locales.interfaces.*;
import com.planet_ink.coffee_mud.MOBS.interfaces.*;
import com.planet_ink.coffee_mud.Races.interfaces.*;


import org.mozilla.javascript.*;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.planet_ink.coffee_mud.Libraries.interfaces.*;

/* 
   Copyright 2000-2006 Bo Zimmerman

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
public class Scriptable extends StdBehavior implements ScriptingEngine
{
	public String ID(){return "Scriptable";}
	protected int canImproveCode(){return Behavior.CAN_MOBS|Behavior.CAN_ITEMS|Behavior.CAN_ROOMS;}
	protected MOB lastToHurtMe=null;
	protected Room lastKnownLocation=null;
	protected Tickable altStatusTickable=null;
	protected Vector que=new Vector();
	protected static final Hashtable funcH=new Hashtable();
	protected static final Hashtable methH=new Hashtable();
	protected static final Hashtable progH=new Hashtable();
    private static Hashtable patterns=new Hashtable();
	protected Vector oncesDone=new Vector();
	protected Hashtable delayTargetTimes=new Hashtable();
	protected Hashtable delayProgCounters=new Hashtable();
	protected Hashtable lastTimeProgsDone=new Hashtable();
	protected Hashtable lastDayProgsDone=new Hashtable();
    private HashSet registeredSpecialEvents=new HashSet();
    private Hashtable noTrigger=new Hashtable();
	protected long tickStatus=Tickable.STATUS_NOT;
	private Quest defaultQuest=null;

	public long getTickStatus()
	{
	    Tickable T=altStatusTickable;
	    if(T!=null) return T.getTickStatus();
	    return tickStatus;
	}

    public void registerDefaultQuest(Quest Q){
    	defaultQuest=Q;
    }
    public boolean endQuest(Environmental hostObj, MOB mob, String quest)
    {
        if(mob!=null)
        {
            Vector scripts=getScripts();
            if(!mob.amDead()) lastKnownLocation=mob.location();
            for(int v=0;v<scripts.size();v++)
            {
                Vector script=(Vector)scripts.elementAt(v);
                String trigger="";
                if(script.size()>0)
                    trigger=((String)script.elementAt(0)).toUpperCase().trim();
                if((getTriggerCode(trigger)==13) //questtimeprog
                &&(!oncesDone.contains(script))
                &&(CMParms.getCleanBit(trigger,1).equalsIgnoreCase(quest)||(quest.equalsIgnoreCase("*")))
                &&(CMath.s_int(CMParms.getCleanBit(trigger,2).trim())<0))
                {
                    oncesDone.addElement(script);
                    execute(hostObj,mob,mob,mob,null,null,script,null,new Object[10]);
                    return true;
                }
            }
        }
        return false;
    }

	public Vector externalFiles()
	{
	    Vector xmlfiles=new Vector();
	    parseParmFilenames(getParms(),xmlfiles,0);
		return xmlfiles;
	}
	
    public String getVarHost(Environmental E, 
    						 String rawHost, 
    						 MOB source, 
    						 Environmental target,
                             MOB monster, 
                             Item primaryItem, 
                             Item secondaryItem, 
                             String msg,
                             Object[] tmp)
    {
        if(!rawHost.equals("*"))
        {
            if(E==null)
                rawHost=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,rawHost);
            else
            if(E instanceof Room)
                rawHost=CMLib.map().getExtendedRoomID((Room)E);
            else
                rawHost=E.Name();
        }
        return rawHost;
    }
    
    public String getVar(Environmental E, String rawHost, String var, MOB source, Environmental target,
                         MOB monster, Item primaryItem, Item secondaryItem, String msg, Object[] tmp)
    { return getVar(getVarHost(E,rawHost,source,target,monster,primaryItem,secondaryItem,msg,tmp),var); }
             
    public static String getVar(String host, String var)
    {
        Hashtable H=(Hashtable)Resources.getResource("SCRIPTVAR-"+host);
        String val="";
        if(H!=null)
        {
            val=(String)H.get(var.toUpperCase());
            if(val==null) val="";
        }
        return val;
    }

    protected static class JScriptEvent extends ScriptableObject
    {
        public String getClassName(){ return "JScriptEvent";}
        static final long serialVersionUID=43;
        Environmental h=null;
        MOB s=null;
        Environmental t=null;
        MOB m=null;
        Item pi=null;
        Item si=null;
        Vector scr;
        String message=null;
        public Environmental host(){return h;}
        public MOB source(){return s;}
        public Environmental target(){return t;}
        public MOB monster(){return m;}
        public Item item(){return pi;}
        public Item item2(){return si;}
        public String message(){return message;}
        public void setVar(String host, String var, String value)
        {
            Scriptable.mpsetvar(host.toString(),var.toString().toUpperCase(),value.toString());
        }
        public String getVar(String host, String var)
        { return Scriptable.getVar(host,var);}
        public String toJavaString(Object O){return Context.toString(O);}
        
        public JScriptEvent(Environmental host,
                            MOB source,
                            Environmental target,
                            MOB monster,
                            Item primaryItem,
                            Item secondaryItem,
                            String msg)
        {
            h=host;
            s=source;
            t=target;
            m=monster;
            pi=primaryItem;
            si=secondaryItem;
            message=msg;
        }
    }
    
    
	public void setParms(String newParms)
	{
		newParms=CMStrings.replaceAll(newParms,"'","`");
		if(newParms.startsWith("+"))
		{
			String superParms=super.getParms();
			if(superParms.length()>100)
				Resources.removeResource("PARSEDPRG: "+superParms.substring(0,100)+superParms.length()+superParms.hashCode());
			else
				Resources.removeResource("PARSEDPRG: "+superParms);
			newParms=super.getParms()+";"+newParms.substring(1);
		}
        que=new Vector();
        oncesDone=new Vector();
        delayTargetTimes=new Hashtable();
        delayProgCounters=new Hashtable();
        lastTimeProgsDone=new Hashtable();
        lastDayProgsDone=new Hashtable();
        registeredSpecialEvents=new HashSet();
        noTrigger=new Hashtable();
		super.setParms(newParms);
		if(oncesDone.size()>0) 
			oncesDone.clear();
	}

	protected void parseParmFilenames(String parse, Vector filenames, int depth)
	{
		if(depth>10) return;  // no including off to infinity
		while(parse.length()>0)
		{
			int y=parse.toUpperCase().indexOf("LOAD=");
			if(y>=0)
			{
				int z=parse.indexOf("~",y);
				while((z>0)&&(parse.charAt(z-1)=='\\'))
				    z=parse.indexOf("~",z+1);
				if(z>0)
				{
					String filename=parse.substring(y+5,z).trim();
					parse=parse.substring(z+1);
					filenames.addElement(filename);
                    parseParmFilenames(new CMFile("resources/"+filename,null,true).text().toString(),filenames,depth+1);
				}
				else
				{
					String filename=parse.substring(y+5).trim();
					filenames.addElement(filename);
					parseParmFilenames(new CMFile("resources/"+filename,null,true).text().toString(),filenames,depth+1);
					break;
				}
			}
			else
				break;
		}
	}
	
	protected String parseLoads(String text, int depth)
	{
		StringBuffer results=new StringBuffer("");
		String parse=text;
		if(depth>10) return "";  // no including off to infinity
		while(parse.length()>0)
		{
			int y=parse.toUpperCase().indexOf("LOAD=");
			if(y>=0)
			{
				results.append(parse.substring(0,y).trim()+"\n");
				int z=parse.indexOf("~",y);
				while((z>0)&&(parse.charAt(z-1)=='\\'))
				    z=parse.indexOf("~",z+1);
				if(z>0)
				{
					String filename=parse.substring(y+5,z).trim();
					parse=parse.substring(z+1);
					results.append(parseLoads(new CMFile("resources/"+filename,null,true).text().toString(),depth+1));
				}
				else
				{
					String filename=parse.substring(y+5).trim();
					results.append(parseLoads(new CMFile("resources/"+filename,null,true).text().toString(),depth+1));
					break;
				}
			}
			else
			{
				results.append(parse);
				break;
			}
		}
		return results.toString();
	}

	protected Vector parseScripts(String text)
	{
		synchronized(funcH)
		{
			if(funcH.size()==0)
			{
				for(int i=0;i<funcs.length;i++)
					funcH.put(funcs[i],new Integer(i+1));
				for(int i=0;i<methods.length;i++)
					methH.put(methods[i],new Integer(i+1));
				for(int i=0;i<progs.length;i++)
					progH.put(progs[i],new Integer(i+1));
			}
		}
		Vector V=new Vector();
		text=parseLoads(text,0);
		int y=0;
		while((text!=null)&&(text.length()>0))
		{
			y=text.indexOf("~");
			while((y>0)&&(text.charAt(y-1)=='\\'))
			    y=text.indexOf("~",y+1);
			String script="";
			if(y<0)
			{
				script=text.trim();
				text="";
			}
			else
			{
				script=text.substring(0,y).trim();
				text=text.substring(y+1).trim();
			}
			if(script.length()>0)
				V.addElement(script);
		}
		for(int v=0;v<V.size();v++)
		{
			String s=(String)V.elementAt(v);
			Vector script=new Vector();
			while(s.length()>0)
			{
				y=-1;
				int yy=0;
				while(yy<s.length())
					if((s.charAt(yy)==';')&&((yy<=0)||(s.charAt(yy-1)!='\\'))) {y=yy;break;}
					else
					if(s.charAt(yy)=='\n'){y=yy;break;}
					else
					if(s.charAt(yy)=='\r'){y=yy;break;}
					else yy++;
				String cmd="";
				if(y<0)
				{
					cmd=s.trim();
					s="";
				}
				else
				{
					cmd=s.substring(0,y).trim();
					s=s.substring(y+1).trim();
				}
				if((cmd.length()>0)&&(!cmd.startsWith("#")))
				{
				    cmd=CMStrings.replaceAll(cmd,"\\~","~");
				    cmd=CMStrings.replaceAll(cmd,"\\=","=");
					script.addElement(CMStrings.replaceAll(cmd,"\\;",";"));
				}
			}
			V.setElementAt(script,v);
		}
		V.trimToSize();
		return V;
	}

	protected Room getRoom(String thisName, Room imHere)
	{
		if(thisName.length()==0) return null;
		Room room=CMLib.map().getRoom(thisName);
		if((room!=null)&&(room.roomID().equalsIgnoreCase(thisName)))
			return room;
		Room inAreaRoom=null;
		try
		{
            for(Enumeration p=CMLib.map().players();p.hasMoreElements();)
            {
                MOB M=(MOB)p.nextElement();
                if((M.Name().equalsIgnoreCase(thisName))
                &&(M.location()!=null)
                &&(CMLib.flags().isInTheGame(M,true)))
                    inAreaRoom=M.location();
            }
            if(inAreaRoom==null)
            for(Enumeration p=CMLib.map().players();p.hasMoreElements();)
            {
                MOB M=(MOB)p.nextElement();
                if((M.name().equalsIgnoreCase(thisName))
                &&(M.location()!=null)
                &&(CMLib.flags().isInTheGame(M,true)))
                    inAreaRoom=M.location();
            }
            if(inAreaRoom==null)
			for(Enumeration r=CMLib.map().rooms();r.hasMoreElements();)
			{
				Room R=(Room)r.nextElement();
				if((R.roomID().endsWith("#"+thisName))
				||(R.roomID().endsWith(thisName)))
				{
					if((imHere!=null)&&(imHere.getArea().Name().equals(R.getArea().Name())))
						inAreaRoom=R;
					else
						room=R;
				}
			}
	    }catch(NoSuchElementException nse){}
		if(inAreaRoom!=null) return inAreaRoom;
		if(room!=null) return room;
		try
		{
			for(Enumeration r=CMLib.map().rooms();r.hasMoreElements();)
			{
				Room R=(Room)r.nextElement();
				if(CMLib.english().containsString(R.displayText(),thisName))
				{
					if((imHere!=null)&&(imHere.getArea().Name().equals(R.getArea().Name())))
						inAreaRoom=R;
					else
						room=R;
				}
			}
	    }catch(NoSuchElementException nse){}
		if(inAreaRoom!=null) return inAreaRoom;
		if(room!=null) return room;
		try
		{
			for(Enumeration r=CMLib.map().rooms();r.hasMoreElements();)
			{
				Room R=(Room)r.nextElement();
				if(CMLib.english().containsString(R.description(),thisName))
				{
					if((imHere!=null)&&(imHere.getArea().Name().equals(R.getArea().Name())))
						inAreaRoom=R;
					else
						room=R;
				}
			}
	    }catch(NoSuchElementException nse){}
		if(inAreaRoom!=null) return inAreaRoom;
		if(room!=null) return room;
		try
		{
			for(Enumeration r=CMLib.map().rooms();r.hasMoreElements();)
			{
				Room R=(Room)r.nextElement();
				if((R.fetchInhabitant(thisName)!=null)
				||(R.fetchItem(null,thisName)!=null))
				{
					if((imHere!=null)&&(imHere.getArea().Name().equals(R.getArea().Name())))
						inAreaRoom=R;
					else
						room=R;
				}
			}
	    }catch(NoSuchElementException nse){}
		if(inAreaRoom!=null) return inAreaRoom;
		return room;
	}


	protected void scriptableError(Environmental scripted, String cmdName, String errType, String errMsg)
	{
		if(scripted!=null)
		{
			Room R=CMLib.map().roomLocation(scripted);
			Log.errOut("Scriptable",scripted.name()+"/"+CMLib.map().getExtendedRoomID(R)+"/"+ cmdName+"/"+errType+"/"+errMsg);
			if(R!=null) R.showHappens(CMMsg.MSG_OK_VISUAL,"Scriptable Error: "+scripted.name()+"/"+CMLib.map().getExtendedRoomID(R)+"/"+CMParms.toStringList(externalFiles())+"/"+ cmdName+"/"+errType+"/"+errMsg);
		}
		else
			Log.errOut("Scriptable","*/*/"+CMParms.toStringList(externalFiles())+"/"+cmdName+"/"+errType+"/"+errMsg);

	}

	protected boolean simpleEvalStr(Environmental scripted,
									String arg1,
									String arg2,
									String cmp,
									String cmdName)
	{
		int x=arg1.compareToIgnoreCase(arg2);
		if(cmp.equalsIgnoreCase("==")) return (x==0);
		else if(cmp.equalsIgnoreCase(">=")) return (x==0)||(x>0);
		else if(cmp.equalsIgnoreCase("<=")) return (x==0)||(x<0);
		else if(cmp.equalsIgnoreCase(">"))  return (x>0); 
        else if(cmp.equalsIgnoreCase("<"))  return (x<0);
		else if(cmp.equalsIgnoreCase("!=")) return (x!=0);
		else
		{
			scriptableError(scripted,cmdName,"Syntax",arg1+" "+cmp+" "+arg2);
			return false;
		}
	}


	protected boolean simpleEval(Environmental scripted, String arg1, String arg2, String cmp, String cmdName)
	{
		long val1=CMath.s_long(arg1.trim());
		long val2=CMath.s_long(arg2.trim());
		if(cmp.equalsIgnoreCase("=="))      return (val1==val2);
		else if(cmp.equalsIgnoreCase(">=")) return val1>=val2;
		else if(cmp.equalsIgnoreCase("<=")) return val1<=val2;
		else if(cmp.equalsIgnoreCase(">"))  return (val1>val2); 
        else if(cmp.equalsIgnoreCase("<"))  return (val1<val2);
		else if(cmp.equalsIgnoreCase("!=")) return (val1!=val2);
		else
		{
			scriptableError(scripted,cmdName,"Syntax",val1+" "+cmp+" "+val2);
			return false;
		}
	}

    protected boolean simpleExpressionEval(Environmental scripted, String arg1, String arg2, String cmp, String cmdName)
    {
        double val1=CMath.s_parseMathExpression(arg1.trim());
        double val2=CMath.s_parseMathExpression(arg2.trim());
        if(cmp.equalsIgnoreCase("=="))      return (val1==val2);
        else if(cmp.equalsIgnoreCase(">=")) return val1>=val2;
        else if(cmp.equalsIgnoreCase("<=")) return val1<=val2;
        else if(cmp.equalsIgnoreCase(">"))  return (val1>val2); 
        else if(cmp.equalsIgnoreCase("<"))  return (val1<val2);
        else if(cmp.equalsIgnoreCase("!=")) return (val1!=val2);
        else
        {
            scriptableError(scripted,cmdName,"Syntax",val1+" "+cmp+" "+val2);
            return false;
        }
    }
	protected Vector loadMobsFromFile(Environmental scripted, String filename)
	{
		filename=filename.trim();
		Vector monsters=(Vector)Resources.getResource("RANDOMMONSTERS-"+filename);
		if(monsters!=null) return monsters;
		StringBuffer buf=new CMFile(filename,null,true).text();
		String thangName="null";
		Room R=CMLib.map().roomLocation(scripted);
		if(R!=null)
		    thangName=scripted.name()+" at "+CMLib.map().getExtendedRoomID((Room)scripted);
		else
		if(scripted!=null)
		    thangName=scripted.name();
		if((buf==null)||((buf!=null)&&(buf.length()<20)))
		{
			scriptableError(scripted,"XMLLOAD","?","Unknown XML file: '"+filename+"' in "+thangName);
			return null;
		}
		if(buf.substring(0,20).indexOf("<MOBS>")<0)
		{
			scriptableError(scripted,"XMLLOAD","?","Invalid XML file: '"+filename+"' in "+thangName);
			return null;
		}
		monsters=new Vector();
		String error=CMLib.coffeeMaker().addMOBsFromXML(buf.toString(),monsters,null);
		if(error.length()>0)
		{
			scriptableError(scripted,"XMLLOAD","?","Error in XML file: '"+filename+"'");
			return null;
		}
		if(monsters.size()<=0)
		{
			scriptableError(scripted,"XMLLOAD","?","Empty XML file: '"+filename+"'");
			return null;
		}
		Resources.submitResource("RANDOMMONSTERS-"+filename,monsters);
		return monsters;
	}

	protected Vector loadItemsFromFile(Environmental scripted, String filename)
	{
		filename=filename.trim();
		Vector items=(Vector)Resources.getResource("RANDOMITEMS-"+filename);
		if(items!=null) return items;
		StringBuffer buf=new CMFile(filename,null,true).text();
		String thangName="null";
		Room R=CMLib.map().roomLocation(scripted);
		if(R!=null)
		    thangName=scripted.name()+" at "+CMLib.map().getExtendedRoomID((Room)scripted);
		else
		if(scripted!=null)
		    thangName=scripted.name();
		if((buf==null)||((buf!=null)&&(buf.length()<20)))
		{
			scriptableError(scripted,"XMLLOAD","?","Unknown XML file: '"+filename+"' in "+thangName);
			return null;
		}
		if(buf.substring(0,20).indexOf("<ITEMS>")<0)
		{
			scriptableError(scripted,"XMLLOAD","?","Invalid XML file: '"+filename+"' in "+thangName);
			return null;
		}
		items=new Vector();
		String error=CMLib.coffeeMaker().addItemsFromXML(buf.toString(),items,null);
		if(error.length()>0)
		{
			scriptableError(scripted,"XMLLOAD","?","Error in XML file: '"+filename+"'");
			return null;
		}
		if(items.size()<=0)
		{
			scriptableError(scripted,"XMLLOAD","?","Empty XML file: '"+filename+"'");
			return null;
		}
		Resources.submitResource("RANDOMITEMS-"+filename,items);
		return items;
	}

	protected Environmental findSomethingCalledThis(String thisName, MOB meMOB, Room imHere, Vector OBJS, boolean mob)
	{
		if(thisName.length()==0) return null;
		Environmental thing=null;
		Environmental areaThing=null;
        ShopKeeper SK=null;
		if(thisName.toUpperCase().trim().startsWith("FROMFILE "))
		{
			try{
				Vector V=null;
				if(mob)
					V=loadMobsFromFile(null,CMParms.getCleanBit(thisName,1));
				else
					V=loadItemsFromFile(null,CMParms.getCleanBit(thisName,1));
				if(V!=null)
				{
					String name=CMParms.getPastBit(thisName,1);
					if(name.equalsIgnoreCase("ALL"))
						OBJS=V;
					else
					if(name.equalsIgnoreCase("ANY"))
					{
						if(V.size()>0)
							areaThing=(Environmental)V.elementAt(CMLib.dice().roll(1,V.size(),-1));
					}
					else
					{
						areaThing=CMLib.english().fetchEnvironmental(V,name,true);
						if(areaThing==null)
							areaThing=CMLib.english().fetchEnvironmental(V,name,false);
					}
				}
			}
			catch(Exception e){}
		}
		else
		{
	    	if(!mob) areaThing=meMOB.fetchInventory(thisName); 
		    try
		    {
		    	if(areaThing==null)
				for(Enumeration r=CMLib.map().rooms();r.hasMoreElements();)
				{
					Room R=(Room)r.nextElement();
					Environmental E=null;
					if(mob)
						E=R.fetchInhabitant(thisName);
					else
					{
						E=R.fetchItem(null,thisName);
						if(E==null)
						for(int i=0;i<R.numInhabitants();i++)
						{
							MOB M=R.fetchInhabitant(i);
							if(M!=null)
							{
								E=M.fetchInventory(thisName);
                                SK=CMLib.coffeeShops().getShopKeeper(M);
								if((SK!=null)&&(E==null))
									E=SK.getShop().getStock(thisName,null,SK.whatIsSold(),M.getStartRoom());
							}
						}
					}
					if(E!=null)
					{
						if((imHere!=null)&&(imHere.getArea().Name().equals(R.getArea().Name())))
							areaThing=E;
						else
							thing=E;
					}
				}
		    }catch(NoSuchElementException nse){}
		}
		if(areaThing!=null)
			OBJS.addElement(areaThing);
		else
		if(thing!=null)
			OBJS.addElement(thing);
		if(OBJS.size()>0)
			return (Environmental)OBJS.firstElement();
		return null;
	}

	public Environmental getArgumentMOB(String str, 
										MOB source, 
										MOB monster, 
										Environmental target, 
										Item primaryItem, 
										Item secondaryItem, 
										String msg,
										Object[] tmp)
	{
        return getArgumentItem(str,source,monster,monster,target,primaryItem,secondaryItem,msg,tmp);
	}
	
	public Environmental getArgumentItem(String str, 
										 MOB source, 
										 MOB monster, 
										 Environmental scripted, 
										 Environmental target, 
										 Item primaryItem, 
										 Item secondaryItem, 
										 String msg,
										 Object[] tmp)
	{
		if(str.length()<2) return null;
		if(str.charAt(0)=='$')
		{
			if(Character.isDigit(str.charAt(1)))
			{
				Object O=tmp[CMath.s_int(Character.toString(str.charAt(1)))];
				if(O instanceof Environmental) 
					return (Environmental)O;
				else
				if((O instanceof Vector)&&(str.length()>3)&&(str.charAt(2)=='.'))
				{
					Vector V=(Vector)O;
					String back=str.substring(2);
	                if(back.charAt(1)=='$')
	                    back=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,back);
	    			if((back.length()>1)&&Character.isDigit(back.charAt(1)))
	    			{
	    				int x=1;
	    				while((x<back.length())&&(Character.isDigit(back.charAt(x)))) x++;
	    				int y=CMath.s_int(back.substring(1,x).trim());
	    				if((V.size()>0)&&(y>=0))
	    				{
	    					if(y>=V.size()) return null;
	    					O=V.elementAt(y);
	    					if(O instanceof Environmental) return (Environmental)O;
	    				}
						str=O.toString(); // will fall through
	    			}
				}
				else
				if(O!=null)
					str=O.toString(); // will fall through
				else
					return null;
			}
			else
			switch(str.charAt(1))
			{
			case 'a': return (lastKnownLocation!=null)?lastKnownLocation.getArea():null;
			case 'N':
			case 'n': return source;
			case 'I':
			case 'i': return scripted;
			case 'T':
			case 't': return target;
			case 'O':
			case 'o': return primaryItem;
			case 'P':
			case 'p': return secondaryItem;
			case 'd': 
			case 'D': return lastKnownLocation;
			case 'F':
			case 'f': if((monster!=null)&&(monster.amFollowing()!=null))
						return monster.amFollowing();
					  return null;
			case 'r':
			case 'R': return getFirstPC(monster,null,lastKnownLocation);
			case 'c':
			case 'C': return getFirstAnyone(monster,null,lastKnownLocation);
			case 'w': return primaryItem!=null?primaryItem.owner():null;
			case 'W': return secondaryItem!=null?secondaryItem.owner():null;
			case 'x':
			case 'X':
				if(lastKnownLocation!=null)
				{
					if((str.length()>2)&&(Directions.getGoodDirectionCode(""+str.charAt(2))>=0))
						return lastKnownLocation.getExitInDir(Directions.getGoodDirectionCode(""+str.charAt(2)));
					int i=0;
					Exit E=null;
					while(((++i)<100)||(E!=null))
						E=lastKnownLocation.getExitInDir(CMLib.dice().roll(1,Directions.NUM_DIRECTIONS,-1));
					return E;
				}
				return null;
			}
		}
		if(lastKnownLocation!=null)
		{
			str=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,str);
			Environmental E=lastKnownLocation.fetchFromRoomFavorMOBs(null,str,Item.WORNREQ_ANY);
			if(E==null) E=lastKnownLocation.fetchFromMOBRoomFavorsItems(monster,null,str,Item.WORNREQ_ANY);
			return E;
		}
		return null;
	}

	private String makeNamedString(Object O)
	{
		if(O instanceof Vector)
			return makeParsableString((Vector)O);
		else
		if(O instanceof Room) 
			return ((Room)O).roomTitle();
		else
		if(O instanceof Environmental) 
			return ((Environmental)O).Name();
		else
		if(O!=null) 
			return O.toString();
		return "";
	}
	
	private String makeParsableString(Vector V)
	{
		if((V==null)||(V.size()==0)) return "";
		if(V.firstElement() instanceof String) return CMParms.combineWithQuotes(V,0);
		StringBuffer ret=new StringBuffer("");
		String S=null;
		for(int v=0;v<V.size();v++)
		{
			S=makeNamedString(V.elementAt(v)).trim();
			if(S.length()==0)
				ret.append("? ");
			else
			if(S.indexOf(" ")>=0)
				ret.append("\""+S+"\" ");
			else
				ret.append(S+" ");
		}
		return ret.toString();
	}
	
	public String varify(MOB source, 
						 Environmental target, 
						 MOB monster, 
						 Item primaryItem, 
						 Item secondaryItem, 
						 String msg,
						 Object[] tmp,
						 String varifyable)
	{
		int t=varifyable.indexOf("$");
		if((monster!=null)&&(monster.location()!=null))
			lastKnownLocation=monster.location();
        if(lastKnownLocation==null) lastKnownLocation=source.location();
		MOB randMOB=null;
		while((t>=0)&&(t<varifyable.length()-1))
		{
			char c=varifyable.charAt(t+1);
			String middle="";
			String front=varifyable.substring(0,t);
			String back=varifyable.substring(t+2);
			if(Character.isDigit(c))
				middle=makeNamedString(tmp[CMath.s_int(Character.toString(c))]);
			else
			switch(c)
			{
			case 'a':
				if(lastKnownLocation!=null)
					middle=lastKnownLocation.getArea().name();
				break;
			case 'c':
			case 'C':
				randMOB=getFirstAnyone(monster,randMOB,lastKnownLocation);
				if(randMOB!=null)
					middle=randMOB.name();
				break;
			case 'i':
				if(monster!=null)
					middle=monster.name();
				break;
			case 'I':
				if(monster!=null)
					middle=monster.displayText();
				break;
			case 'n':
			case 'N':
				if(source!=null)
					middle=source.name();
				break;
			case 't':
			case 'T':
				if(target!=null)
					middle=target.name();
				break;
            case 'y':
                if(source!=null)
                    middle=source.charStats().sirmadam();
                break;
            case 'Y':
                if((target!=null)&&(target instanceof MOB))
                    middle=((MOB)target).charStats().sirmadam();
                break;
			case 'r':
			case 'R':
				randMOB=getFirstPC(monster,randMOB,lastKnownLocation);
				if(randMOB!=null)
					middle=randMOB.name();
				break;
			case 'j':
				if(monster!=null)
					middle=monster.charStats().heshe();
				break;
			case 'f':
				if((monster!=null)&&(monster.amFollowing()!=null))
					middle=monster.amFollowing().name();
				break;
			case 'F':
				if((monster!=null)&&(monster.amFollowing()!=null))
					middle=monster.amFollowing().charStats().heshe();
				break;
			case 'e':
				if(source!=null)
					middle=source.charStats().heshe();
				break;
			case 'E':
				if((target!=null)&&(target instanceof MOB))
					middle=((MOB)target).charStats().heshe();
				break;
			case 'J':
				randMOB=getFirstPC(monster,randMOB,lastKnownLocation);
				if(randMOB!=null)
					middle=randMOB.charStats().heshe();
				break;
			case 'k':
				if(monster!=null)
					middle=monster.charStats().hisher();
				break;
			case 'm':
				if(source!=null)
					middle=source.charStats().hisher();
				break;
			case 'M':
				if((target!=null)&&(target instanceof MOB))
					middle=((MOB)target).charStats().hisher();
				break;
			case 'K':
				randMOB=getFirstPC(monster,randMOB,lastKnownLocation);
				if(randMOB!=null)
					middle=randMOB.charStats().hisher();
				break;
			case 'o':
			case 'O':
				if(primaryItem!=null)
					middle=primaryItem.name();
				break;
			case 'g': middle=((msg==null)?"":msg.toLowerCase()); break;
			case 'G': middle=((msg==null)?"":msg); break;
			case 'd': middle=(lastKnownLocation!=null)?lastKnownLocation.roomTitle():""; break;
			case 'D': middle=(lastKnownLocation!=null)?lastKnownLocation.roomDescription():""; break;
			case 'p':
			case 'P':
				if(secondaryItem!=null)
					middle=secondaryItem.name();
				break;
			case 'w': 
			    middle=primaryItem!=null?primaryItem.owner().Name():middle;
			    break;
			case 'W': 
			    middle=secondaryItem!=null?secondaryItem.owner().Name():middle;
			    break;
			case 'l':
				if(lastKnownLocation!=null)
				{
					StringBuffer str=new StringBuffer("");
					for(int i=0;i<lastKnownLocation.numInhabitants();i++)
					{
						MOB M=lastKnownLocation.fetchInhabitant(i);
						if((M!=null)&&(M!=monster)&&(CMLib.flags().canBeSeenBy(M,monster)))
						   str.append("\""+M.name()+"\" ");
					}
					middle=str.toString();
					break;
				}
			case 'L':
				if(lastKnownLocation!=null)
				{
					StringBuffer str=new StringBuffer("");
					for(int i=0;i<lastKnownLocation.numItems();i++)
					{
						Item I=lastKnownLocation.fetchItem(i);
						if((I!=null)&&(I.container()==null)&&(CMLib.flags().canBeSeenBy(I,monster)))
						   str.append("\""+I.name()+"\" ");
					}
					middle=str.toString();
					break;
				}
			case '<':
				{
					int x=back.indexOf(">");
					if(x>=0)
					{
						String mid=back.substring(0,x);
						int y=mid.indexOf(" ");
						Environmental E=null;
                        String arg1="";
						if(y>=0)
						{
                            arg1=mid.substring(0,y).trim();
							E=getArgumentItem(arg1,source,monster,monster,target,primaryItem,secondaryItem,msg,tmp);
							mid=mid.substring(y+1).trim();
						}
                        if(arg1.length()>0)
                            middle=getVar(E,arg1,mid,source,target,monster,primaryItem,secondaryItem,msg,tmp);
                        back=back.substring(x+1);
					}
				}
				break;
			case '[':
				{
					middle="";
					int x=back.indexOf("]");
					if(x>=0)
					{
						String mid=back.substring(0,x);
						int y=mid.indexOf(" ");
						if(y>0)
						{
							int num=CMath.s_int(mid.substring(0,y).trim());
							mid=mid.substring(y+1).trim();
							Quest Q=mid.equals("*")?defaultQuest:CMLib.quests().fetchQuest(mid);
							if(Q!=null)	middle=Q.getQuestItemName(num);
						}
						back=back.substring(x+1);
					}
				}
				break;
			case '{':
				{
					middle="";
					int x=back.indexOf("}");
					if(x>=0)
					{
						String mid=back.substring(0,x).trim();
						int y=mid.indexOf(" ");
						if(y>0)
						{
							int num=CMath.s_int(mid.substring(0,y).trim());
							mid=mid.substring(y+1).trim();
							Quest Q=mid.equals("*")?defaultQuest:CMLib.quests().fetchQuest(mid);
							if(Q!=null)	middle=Q.getQuestMobName(num);
						}
						back=back.substring(x+1);
					}
				}
				break;
			case '%':
				{
					middle="";
					int x=back.indexOf("%");
					if(x>=0)
					{
						middle=functify(monster,source,target,monster,primaryItem,secondaryItem,msg,tmp,back.substring(0,x).trim());
						back=back.substring(x+1);
					}
				}
				break;
			//case 'a':
			case 'A':
				// unnecessary, since, in coffeemud, this is part of the name
				break;
			case 'x':
			case 'X':
				if(lastKnownLocation!=null)
				{
					middle="";
					Exit E=null;
					int dir=-1;
					if((t<varifyable.length()-2)&&(Directions.getGoodDirectionCode(""+varifyable.charAt(t+2))>=0))
					{
						dir=Directions.getGoodDirectionCode(""+varifyable.charAt(t+2));
						E=lastKnownLocation.getExitInDir(dir);
					}
					else
					{
						int i=0;
						while(((++i)<100)||(E!=null))
						{
							dir=CMLib.dice().roll(1,Directions.NUM_DIRECTIONS,-1);
							E=lastKnownLocation.getExitInDir(dir);
						}
					}
					if((dir>=0)&&(E!=null))
					{
						if(c=='x')
							middle=Directions.getDirectionName(dir);
						else
							middle=E.name();
					}
				}
				break;
			}
            if((middle.length()>0)
            &&(back.startsWith("."))
            &&(back.length()>1))
            {
                if(back.charAt(1)=='$')
                    back=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,back);
    			if((back.length()>1)&&Character.isDigit(back.charAt(1)))
    			{
    				int x=1;
    				while((x<back.length())
    				&&(Character.isDigit(back.charAt(x))))
    					x++;
    				int y=CMath.s_int(back.substring(1,x).trim());
    				back=back.substring(x);
    				boolean rest=back.startsWith("..");
    				if(rest) back=back.substring(2);
    				Vector V=CMParms.parse(middle);
    				if((V.size()>0)&&(y>=0))
    				{
    					if(y>=V.size())
    						middle="";
    					else
    					if(rest)
    					    middle=CMParms.combine(V,y);
    					else
    						middle=(String)V.elementAt(y);
    				}
    			}
            }
			varifyable=front+middle+back;
			t=varifyable.indexOf("$");
		}
		return varifyable;
	}

	public static DVector getScriptVarSet(String mobname, String varname)
	{
		DVector set=new DVector(2);
		if(mobname.equals("*"))
		{
			Vector V=Resources.findResourceKeys("SCRIPTVAR-");
			for(int v=0;v<V.size();v++)
			{
				String key=(String)V.elementAt(v);
				if(key.startsWith("SCRIPTVAR-"))
				{
					Hashtable H=(Hashtable)Resources.getResource(key);
					if(varname.equals("*"))
					{
						for(Enumeration e=H.keys();e.hasMoreElements();)
						{
							String vn=(String)e.nextElement();
							set.addElement(key.substring(10),vn);
						}
					}
					else
						set.addElement(key.substring(10),varname);
				}
			}
		}
		else
		{
			Hashtable H=(Hashtable)Resources.getResource("SCRIPTVAR-"+mobname);
			if(varname.equals("*"))
			{
				for(Enumeration e=H.keys();e.hasMoreElements();)
				{
					String vn=(String)e.nextElement();
					set.addElement(mobname,vn);
				}
			}
			else
				set.addElement(mobname,varname);
		}
		return set;
	}
    
    public String getStatValue(Environmental E, String arg2)
    {
        boolean found=false;
        String val="";
        for(int i=0;i<E.getStatCodes().length;i++)
        {
            if(E.getStatCodes()[i].equalsIgnoreCase(arg2))
            {
                val=E.getStat(arg2);
                found=true;
                break;
            }
        }
        if((!found)&&(E instanceof MOB))
        {
            MOB M=(MOB)E;
            for(int i=0;i<CharStats.STAT_DESCS.length;i++)
                if(CharStats.STAT_DESCS[i].equalsIgnoreCase(arg2))
                {
                    val=""+M.charStats().getStat(CharStats.STAT_DESCS[i]);
                    found=true;
                    break;
                }
            if(!found)
            for(int i=0;i<M.curState().getStatCodes().length;i++)
                if(M.curState().getStatCodes()[i].equalsIgnoreCase(arg2))
                {
                    val=M.curState().getStat(M.curState().getStatCodes()[i]);
                    found=true;
                    break;
                }
            if(!found)
            for(int i=0;i<M.envStats().getCodes().length;i++)
                if(M.envStats().getCodes()[i].equalsIgnoreCase(arg2))
                {
                    val=M.envStats().getStat(M.envStats().getCodes()[i]);
                    found=true;
                    break;
                }
			if((!found)&&(M.playerStats()!=null))
				for(int i=0;i<M.playerStats().getStatCodes().length;i++)
					if(M.playerStats().getStatCodes()[i].equalsIgnoreCase(arg2))
					{
						val=M.playerStats().getStat(M.playerStats().getStatCodes()[i]);
						found=true;
						break;
					}
            if((!found)&&(arg2.toUpperCase().startsWith("BASE")))
                for(int i=0;i<M.baseState().getStatCodes().length;i++)
                    if(M.baseState().getStatCodes()[i].equalsIgnoreCase(arg2.substring(4)))
                    {
                        val=M.baseState().getStat(M.baseState().getStatCodes()[i]);
                        found=true;
                        break;
                    }
        }
        if(!found)return null;
        return val;
    }
    public String getGStatValue(Environmental E, String arg2)
    {
        if(E==null) return null;
        boolean found=false;
        String val="";
        for(int i=0;i<E.getStatCodes().length;i++)
        {
            if(E.getStatCodes()[i].equalsIgnoreCase(arg2))
            {
                val=E.getStat(arg2);
                found=true; break;
            }
        }
        if(!found)
        if(E instanceof MOB)
        {
            for(int i=0;i<CMObjectBuilder.GENMOBCODES.length;i++)
            {
                if(CMObjectBuilder.GENMOBCODES[i].equalsIgnoreCase(arg2))
                {
                    val=CMLib.coffeeMaker().getGenMobStat((MOB)E,CMObjectBuilder.GENMOBCODES[i]);
                    found=true; break;
                }
            }
            if(!found)
            {
                MOB M=(MOB)E;
                for(int i=0;i<CharStats.STAT_DESCS.length;i++)
                    if(CharStats.STAT_DESCS[i].equalsIgnoreCase(arg2))
                    {
                        val=""+M.charStats().getStat(CharStats.STAT_DESCS[i]);
                        found=true;
                        break;
                    }
                if(!found)
                for(int i=0;i<M.curState().getStatCodes().length;i++)
                    if(M.curState().getStatCodes()[i].equalsIgnoreCase(arg2))
                    {
                        val=M.curState().getStat(M.curState().getStatCodes()[i]);
                        found=true;
                        break;
                    }
                if(!found)
                for(int i=0;i<M.envStats().getCodes().length;i++)
                    if(M.envStats().getCodes()[i].equalsIgnoreCase(arg2))
                    {
                        val=M.envStats().getStat(M.envStats().getCodes()[i]);
                        found=true;
                        break;
                    }
    			if((!found)&&(M.playerStats()!=null))
				for(int i=0;i<M.playerStats().getStatCodes().length;i++)
					if(M.playerStats().getStatCodes()[i].equalsIgnoreCase(arg2))
					{
						val=M.playerStats().getStat(M.playerStats().getStatCodes()[i]);
						found=true;
						break;
					}
                if((!found)&&(arg2.toUpperCase().startsWith("BASE")))
                    for(int i=0;i<M.baseState().getStatCodes().length;i++)
                        if(M.baseState().getStatCodes()[i].equalsIgnoreCase(arg2.substring(4)))
                        {
                            val=M.baseState().getStat(M.baseState().getStatCodes()[i]);
                            found=true;
                            break;
                        }
            }
        }
        else
        if(E instanceof Item)
        {
            for(int i=0;i<CMObjectBuilder.GENITEMCODES.length;i++)
            {
                if(CMObjectBuilder.GENITEMCODES[i].equalsIgnoreCase(arg2))
                {
                    val=CMLib.coffeeMaker().getGenItemStat((Item)E,CMObjectBuilder.GENITEMCODES[i]);
                    found=true; break;
                }
            }
        }
        if(found) return val;
        return null;
    }
    

	public static void mpsetvar(String name, String key, String val)
	{
		DVector V=getScriptVarSet(name,key);
		for(int v=0;v<V.size();v++)
		{
			name=(String)V.elementAt(v,1);
			key=((String)V.elementAt(v,2)).toUpperCase();
			Hashtable H=(Hashtable)Resources.getResource("SCRIPTVAR-"+name);
			if(H==null)
			{
				if(val.length()==0)
					continue;

				H=new Hashtable();
				Resources.submitResource("SCRIPTVAR-"+name,H);
			}
			if(val.equals("++"))
			{
				String num=(String)H.get(key);
				if(num==null) num="0";
				val=new Integer(CMath.s_int(num.trim())+1).toString();
			}
			else
			if(val.equals("--"))
			{
				String num=(String)H.get(key);
				if(num==null) num="0";
				val=new Integer(CMath.s_int(num.trim())-1).toString();
			}
			else
			if(val.startsWith("+"))
			{
				// add via +number form
				val=val.substring(1);
				int amount=CMath.s_int(val.trim());
				String num=(String)H.get(key);
				val=new Integer(CMath.s_int(num.trim())+amount).toString();
			}
			else
			if(val.startsWith("-"))
			{
				// subtract -number form
				val=val.substring(1);
				int amount=CMath.s_int(val.trim());
				String num=(String)H.get(key);
				val=new Integer(CMath.s_int(num.trim())-amount).toString();
			}
			else
			if(val.startsWith("*"))
			{
				// multiply via *number form
				val=val.substring(1);
				int amount=CMath.s_int(val.trim());
				String num=(String)H.get(key);
				val=new Integer(CMath.s_int(num.trim())*amount).toString();
			}
			else
			if(val.startsWith("/"))
			{
				// divide /number form
				val=val.substring(1);
				int amount=CMath.s_int(val.trim());
				String num=(String)H.get(key);
				val=new Integer(CMath.s_int(num.trim())/amount).toString();
			}
			if(H.containsKey(key))
				H.remove(key);
			if(val.trim().length()>0)
				H.put(key,val);
			if(H.size()==0)
				Resources.removeResource("SCRIPTVAR-"+name);
		}
	}


	public boolean eval(Environmental scripted,
						MOB source,
						Environmental target,
						MOB monster,
						Item primaryItem,
						Item secondaryItem,
						String msg,
						Object[] tmp,
						String evaluable)
	{
		Vector formatCheck=CMParms.parse(evaluable);
		for(int i=1;i<(formatCheck.size()-1);i++)
			if((" == >= > < <= => =< != ".indexOf(" "+((String)formatCheck.elementAt(i))+" ")>=0)
			&&(((String)formatCheck.elementAt(i-1)).endsWith(")")))
			{
				String ps=(String)formatCheck.elementAt(i-1);
				ps=ps.substring(0,ps.length()-1);
				if(ps.length()==0) ps=" ";
				formatCheck.setElementAt(ps,i-1);

				String os=null;
				if((((String)formatCheck.elementAt(i+1)).startsWith("'")
				   ||((String)formatCheck.elementAt(i+1)).startsWith("`")))
				{
					os="";
					while((i<(formatCheck.size()-1))
					&&((!((String)formatCheck.elementAt(i+1)).endsWith("'"))
					&&(!((String)formatCheck.elementAt(i+1)).endsWith("`"))))
					{
						os+=((String)formatCheck.elementAt(i+1))+" ";
						formatCheck.removeElementAt(i+1);
					}
					os=(os+((String)formatCheck.elementAt(i+1))).trim();
				}
				else
				if((i==(formatCheck.size()-3))
				&&(((String)formatCheck.lastElement()).indexOf("(")<0))
				{
					os=((String)formatCheck.elementAt(i+1))
					+" "+((String)formatCheck.elementAt(i+2));
					formatCheck.removeElementAt(i+2);
				}
				else
					os=(String)formatCheck.elementAt(i+1);
				os=os+")";
				formatCheck.setElementAt(os,i+1);
				i+=2;
			}
		evaluable=CMParms.combine(formatCheck,0);
		String uevaluable=evaluable.toUpperCase().trim();
		boolean returnable=false;
		boolean lastreturnable=true;
		int joined=0;
		while(evaluable.length()>0)
		{
			int y=evaluable.indexOf("(");
			int z=y+1;
			int numy=1;
			while((y>=0)&&(numy>0)&&(z<evaluable.length()))
			{
				if(evaluable.charAt(z)=='(')
					numy++;
				else
				if(evaluable.charAt(z)==')')
					numy--;
				z++;
			}
			if((y<0)||(numy>0)||(z<=y))
			{
				scriptableError(scripted,"EVAL","Format",evaluable);
				return false;
			}
			z--;
			String preFab=uevaluable.substring(0,y).trim();
			Integer funcCode=(Integer)funcH.get(preFab);
			if(funcCode==null)
			    funcCode=new Integer(0);
			if(y==0)
			{
				int depth=0;
				int i=0;
				while((++i)<evaluable.length())
				{
					char c=evaluable.charAt(i);
					if((c==')')&&(depth==0))
					{
						String expr=evaluable.substring(1,i);
						evaluable=evaluable.substring(i+1).trim();
						uevaluable=uevaluable.substring(i+1).trim();
						returnable=eval(scripted,source,target,monster,primaryItem,secondaryItem,msg,tmp,expr);
						switch(joined)
						{
						case 1: returnable=lastreturnable&&returnable; break;
						case 2: returnable=lastreturnable||returnable; break;
						case 4: returnable=!returnable; break;
						case 5: returnable=lastreturnable&&(!returnable); break;
						case 6: returnable=lastreturnable||(!returnable); break;
						default: break;
						}
						joined=0;
						break;
					}
					else
					if(c=='(') depth++;
					else
					if(c==')') depth--;
				}
				z=evaluable.indexOf(")");
			}
			else
			if(evaluable.startsWith("!"))
			{
			    joined=joined|4;
				evaluable=evaluable.substring(1).trim();
				uevaluable=uevaluable.substring(1).trim();
			}
			else
			if(uevaluable.startsWith("AND "))
			{
			    joined=1;
			    lastreturnable=returnable;
				evaluable=evaluable.substring(4).trim();
				uevaluable=uevaluable.substring(4).trim();
			}
			else
			if(uevaluable.startsWith("OR "))
			{
			    joined=2;
			    lastreturnable=returnable;
				evaluable=evaluable.substring(3).trim();
				uevaluable=uevaluable.substring(3).trim();
			}
			else
			if((y<0)||(z<y))
			{
				scriptableError(scripted,"()","Syntax",evaluable);
				break;
			}
			else
			{
		    tickStatus=Tickable.STATUS_MISC+funcCode.intValue();
			switch(funcCode.intValue())
			{
			case 1: // rand
			{
				int arg=CMath.s_int(evaluable.substring(y+1,z).trim());
				if(CMLib.dice().rollPercentage()<arg)
					returnable=true;
				else
					returnable=false;
				break;
			}
			case 2: // has
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if(arg2.length()==0)
				{
					scriptableError(scripted,"HAS","Syntax",evaluable);
					return returnable;
				}
				Environmental E2=getArgumentItem(arg2,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if(E==null)
					returnable=false;
				else
				if(E instanceof MOB)
				{
				    if(E2!=null)
						returnable=((MOB)E).isMine(E2);
			        else
						returnable=(((MOB)E).fetchInventory(arg2)!=null);
				}
				else
				if(E instanceof Item)
					returnable=CMLib.english().containsString(E.name(),arg2);
				else
				if(E instanceof Room)
				{
				    if(E2 instanceof Item)
						returnable=((Room)E).isContent((Item)E2);
			        else
			            returnable=(((Room)E).fetchItem(null,arg2)!=null);
				}
				else
					returnable=false;
				break;
			}
            case 74: // hasnum
            {
                String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
                String item=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),1));
                String cmp=CMParms.getCleanBit(evaluable.substring(y+1,z),2);
                String value=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),2));
                Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
                if((value.length()==0)||(item.length()==0)||(cmp.length()==0))
                {
                    scriptableError(scripted,"HASNUM","Syntax",evaluable);
                    return returnable;
                }
                Item I=null;
                int num=0;
                if(E==null)
                    returnable=false;
                else
                if(E instanceof MOB)
                {
                    MOB M=(MOB)E;
                    for(int i=0;i<M.inventorySize();i++)
                    {
                        I=M.fetchInventory(i);
                        if(I==null) break;
                        if((item.equalsIgnoreCase("all"))
                        ||(CMLib.english().containsString(I.Name(),item)))
                            num++;
                    }
                    returnable=simpleEval(scripted,""+num,value,cmp,"HASNUM");
                }
                else
                if(E instanceof Item)
                {
                    num=CMLib.english().containsString(E.name(),item)?1:0;
                    returnable=simpleEval(scripted,""+num,value,cmp,"HASNUM");
                }
                else
                if(E instanceof Room)
                {
                    Room R=(Room)E;
                    for(int i=0;i<R.numItems();i++)
                    {
                        I=R.fetchItem(i);
                        if(I==null) break;
                        if((item.equalsIgnoreCase("all"))
                        ||(CMLib.english().containsString(I.Name(),item)))
                            num++;
                    }
                    returnable=simpleEval(scripted,""+num,value,cmp,"HASNUM");
                }
                else
                    returnable=false;
                break;
            }
			case 67: // hastitle
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if(arg2.length()==0)
				{
					scriptableError(scripted,"HASTITLE","Syntax",evaluable);
					return returnable;
				}
				if(E instanceof MOB)
				{
				    MOB M=(MOB)E;
				    returnable=(M.playerStats()!=null)&&(M.playerStats().getTitles().contains(arg2));
				}
				else
				    returnable=false;
				break;
			}
			case 3: // worn
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if(arg2.length()==0)
				{
					scriptableError(scripted,"WORN","Syntax",evaluable);
					return returnable;
				}
				if(E==null)
					returnable=false;
				else
				if(E instanceof MOB)
					returnable=(((MOB)E).fetchWornItem(arg2)!=null);
				else
				if(E instanceof Item)
					returnable=(CMLib.english().containsString(E.name(),arg2)&&(!((Item)E).amWearingAt(Item.IN_INVENTORY)));
				else
					returnable=false;
				break;
			}
			case 4: // isnpc
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
					returnable=((MOB)E).isMonster();
				break;
			}
			case 5: // ispc
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
					returnable=!((MOB)E).isMonster();
				break;
			}
			case 6: // isgood
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
					returnable=CMLib.flags().isGood(E);
				break;
			}
			case 8: // isevil
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
					returnable=CMLib.flags().isEvil(E);
				break;
			}
			case 9: // isneutral
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
					returnable=CMLib.flags().isNeutral(E);
				break;
			}
			case 54: // isalive
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((E!=null)&&((E instanceof MOB))&&(!((MOB)E).amDead()))
					returnable=true;
				else
					returnable=false;
				break;
			}
			case 58: // isable
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getPastBitClean(evaluable.substring(y+1,z),0);
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((E!=null)&&((E instanceof MOB))&&(!((MOB)E).amDead()))
				{
					ExpertiseLibrary X=(ExpertiseLibrary)CMLib.expertises().findDefinition(arg2,true);
					if(X!=null)
						returnable=((MOB)E).fetchExpertise(X.ID())!=null;
					else
						returnable=((MOB)E).findAbility(arg2)!=null;
				}
				else
					returnable=false;
				break;
			}
			case 59: // isopen
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				int dir=Directions.getGoodDirectionCode(arg1);
				returnable=false;
				if(dir<0)
				{
					Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
					if((E!=null)&&(E instanceof Container))
						returnable=((Container)E).isOpen();
					else
					if((E!=null)&&(E instanceof Exit))
					    returnable=((Exit)E).isOpen();
				}
				else
				if(lastKnownLocation!=null)
				{
					Exit E=lastKnownLocation.getExitInDir(dir);
					if(E!=null) returnable= E.isOpen();
				}
				break;
			}
			case 60: // islocked
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				int dir=Directions.getGoodDirectionCode(arg1);
				returnable=false;
				if(dir<0)
				{
					Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
					if((E!=null)&&(E instanceof Container))
						returnable=((Container)E).isLocked();
					else
					if((E!=null)&&(E instanceof Exit))
					    returnable=((Exit)E).isLocked();
				}
				else
				if(lastKnownLocation!=null)
				{
					Exit E=lastKnownLocation.getExitInDir(dir);
					if(E!=null) returnable= E.isLocked();
				}
				break;
			}
			case 10: // isfight
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
					returnable=((MOB)E).isInCombat();
				break;
			}
			case 11: // isimmort
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
					returnable=CMSecurity.isAllowed(((MOB)E),lastKnownLocation,"IMMORT");
				break;
			}
			case 12: // ischarmed
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
					returnable=CMLib.flags().flaggedAffects(E,Ability.FLAG_CHARMING).size()>0;
				break;
			}
			case 15: // isfollow
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
				if(((MOB)E).amFollowing()==null)
					returnable=false;
				else
				if(((MOB)E).amFollowing().location()!=lastKnownLocation)
					returnable=false;
				else
					returnable=true;
				break;
			}
            case 73: // isservant
            {
                String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
                Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
                if((E==null)||(!(E instanceof MOB))||(lastKnownLocation==null))
                    returnable=false;
                else
                if((((MOB)E).getLiegeID()==null)||(((MOB)E).getLiegeID().length()==0))
                    returnable=false;
                else
                if(lastKnownLocation.fetchInhabitant("$"+((MOB)E).getLiegeID()+"$")==null)
                    returnable=false;
                else
                    returnable=true;
                break;
            }
			case 55: // ispkill
			{
				String arg1=CMParms.cleanBit(evaluable.substring(y+1,z));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
				if(CMath.bset(((MOB)E).getBitmap(),MOB.ATT_PLAYERKILL))
					returnable=true;
				else
					returnable=false;
				break;
			}
			case 7: // isname
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if(E==null)
					returnable=false;
				else
					returnable=CMLib.english().containsString(E.name(),arg2);
				break;
			}
			case 56: // name
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBit(evaluable.substring(y+1,z),1));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if(E==null)
					returnable=false;
				else
					returnable=simpleEvalStr(scripted,E.Name(),arg3,arg2,"NAME");
				break;
			}
            case 75: // currency
            {
                String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
                String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
                String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBit(evaluable.substring(y+1,z),1));
                Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
                if(E==null)
                    returnable=false;
                else
                    returnable=simpleEvalStr(scripted,CMLib.beanCounter().getCurrency(E),arg3,arg2,"CURRENCY");
                break;
            }
			case 61: // strin
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				Vector V=CMParms.parse(arg1.toUpperCase());
				returnable=V.contains(arg2.toUpperCase());
				break;
			}
			case 62: // callfunc
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				String found=null;
				boolean validFunc=false;
				Vector scripts=getScripts();
				for(int v=0;v<scripts.size();v++)
				{
					Vector script2=(Vector)scripts.elementAt(v);
					if(script2.size()<1) continue;
					String trigger=((String)script2.elementAt(0)).toUpperCase().trim();
					if(getTriggerCode(trigger)==17)
					{
						String fnamed=CMParms.getCleanBit(trigger,1);
						if(fnamed.equalsIgnoreCase(arg1))
						{
							validFunc=true;
							found=
							execute(scripted,
									source,
									target,
									monster,
									primaryItem,
									secondaryItem,
									script2,
									varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,arg2),
									tmp);
							if(found==null) found="";
							break;
						}
					}
				}
				if(!validFunc)
					scriptableError(scripted,"CALLFUNC","Unknown","Function: "+arg1);
				else
					returnable=!(found.trim().length()==0);
				break;
			}
			case 14: // affected
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if(E==null)
					returnable=false;
				else
					returnable=(E.fetchEffect(arg2)!=null);
				break;
			}
			case 69: // isbehave
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if(E==null)
					returnable=false;
				else
					returnable=(E.fetchBehavior(arg2)!=null);
				break;
			}
            case 70: // ipaddress
            {
                String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
                String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
                String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBit(evaluable.substring(y+1,z),1));
                Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
                if((E==null)||(!(E instanceof MOB))||(((MOB)E).isMonster()))
                    returnable=false;
                else
                    returnable=simpleEvalStr(scripted,((MOB)E).session().getAddress(),arg3,arg2,"ADDRESS");
                break;
            }
			case 28: // questwinner
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=CMParms.getPastBitClean(evaluable.substring(y+1,z),0);
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				Quest Q=arg2.equals("*")?defaultQuest:CMLib.quests().fetchQuest(arg2);
				if(Q==null)
					returnable=false;
				else
				{
					if(E!=null) arg1=E.Name();
					returnable=Q.wasWinner(arg1);
				}
				break;
			}
			case 29: // questmob
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=CMParms.getPastBitClean(evaluable.substring(y+1,z),0);
				Quest Q=arg2.equals("*")?defaultQuest:CMLib.quests().fetchQuest(arg2);
				if(Q==null)
					returnable=false;
				else
					returnable=(Q.wasQuestMob(arg1)>=0);
				break;
			}
			case 31: // isquestmobalive
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=CMParms.getPastBitClean(evaluable.substring(y+1,z),0);
				Quest Q=arg2.equals("*")?defaultQuest:CMLib.quests().fetchQuest(arg2);
				if(Q==null)
					returnable=false;
				else
				{
					MOB M=null;
					if(CMath.s_int(arg1.trim())>0)
						M=Q.getQuestMob(CMath.s_int(arg1.trim()));
					else
						M=Q.getQuestMob(Q.wasQuestMob(arg1));
					if(M==null) returnable=false;
					else returnable=!M.amDead();
				}
				break;
			}
			case 32: // nummobsinarea
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0)).toUpperCase();
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				int num=0;
                Vector MASK=null;
                if((arg3.toUpperCase().startsWith("MASK")&&(arg3.substring(4).trim().startsWith("="))))
                { 
                    arg3=arg3.substring(4).trim(); 
                    arg3=arg3.substring(1).trim();
                    MASK=CMLib.masking().maskCompile(arg3);
                }
				for(Enumeration e=lastKnownLocation.getArea().getProperMap();e.hasMoreElements();)
				{
					Room R=(Room)e.nextElement();
					for(int m=0;m<R.numInhabitants();m++)
					{
						MOB M=R.fetchInhabitant(m);
                        if(M==null) continue;
                        if(MASK!=null)
                        {
                            if(CMLib.masking().maskCheck(MASK,M))
                                num++;
                        }
                        else
                        if(CMLib.english().containsString(M.name(),arg1))
                            num++;
					}
				}
				returnable=simpleEval(scripted,""+num,arg3,arg2,"NUMMOBSINAREA");
				break;
			}
			case 33: // nummobs
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0)).toUpperCase();
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				int num=0;
                Vector MASK=null;
                if((arg3.toUpperCase().startsWith("MASK")&&(arg3.substring(4).trim().startsWith("="))))
                { 
                    arg3=arg3.substring(4).trim(); 
                    arg3=arg3.substring(1).trim();
                    MASK=CMLib.masking().maskCompile(arg3);
                }
				try
				{
					for(Enumeration e=CMLib.map().rooms();e.hasMoreElements();)
					{
						Room R=(Room)e.nextElement();
						for(int m=0;m<R.numInhabitants();m++)
						{
							MOB M=R.fetchInhabitant(m);
                            if(M==null) continue;
                            if(MASK!=null)
                            {
                                if(CMLib.masking().maskCheck(MASK,M))
                                    num++;
                            }
                            else
                            if(CMLib.english().containsString(M.name(),arg1))
								num++;
						}
					}
			    }catch(NoSuchElementException nse){}
				returnable=simpleEval(scripted,""+num,arg3,arg2,"NUMMOBS");
				break;
			}
			case 34: // numracesinarea
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0)).toUpperCase();
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				int num=0;
				Room R=null;
				MOB M=null;
				for(Enumeration e=lastKnownLocation.getArea().getProperMap();e.hasMoreElements();)
				{
					R=(Room)e.nextElement();
					for(int m=0;m<R.numInhabitants();m++)
					{
						M=R.fetchInhabitant(m);
						if((M!=null)&&(M.charStats().raceName().equalsIgnoreCase(arg1)))
							num++;
					}
				}
				returnable=simpleEval(scripted,""+num,arg3,arg2,"NUMRACESINAREA");
				break;
			}
			case 35: // numraces
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0)).toUpperCase();
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				int num=0;
				try
				{
					for(Enumeration e=CMLib.map().rooms();e.hasMoreElements();)
					{
						Room R=(Room)e.nextElement();
						for(int m=0;m<R.numInhabitants();m++)
						{
							MOB M=R.fetchInhabitant(m);
							if((M!=null)&&(M.charStats().raceName().equalsIgnoreCase(arg1)))
								num++;
						}
					}
			    }catch(NoSuchElementException nse){}
				returnable=simpleEval(scripted,""+num,arg3,arg2,"NUMRACES");
				break;
			}
			case 30: // questobj
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=CMParms.getPastBitClean(evaluable.substring(y+1,z),0);
				Quest Q=arg2.equals("*")?defaultQuest:CMLib.quests().fetchQuest(arg2);
				if(Q==null)
					returnable=false;
				else
					returnable=(Q.wasQuestItem(arg1)>=0);
				break;
			}
			case 16: // hitprcnt
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((arg2.length()==0)||(arg3.length()==0))
				{
					scriptableError(scripted,"HITPRCNT","Syntax",evaluable);
					return returnable;
				}
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
				{
					double hitPctD=CMath.div(((MOB)E).curState().getHitPoints(),((MOB)E).maxState().getHitPoints());
					int val1=(int)Math.round(hitPctD*100.0);
					returnable=simpleEval(scripted,""+val1,arg3,arg2,"HITPRCNT");
				}
				break;
			}
			case 50: // isseason
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.cleanBit(evaluable.substring(y+1,z)));
				returnable=false;
				if(monster.location()!=null)
				for(int a=0;a<TimeClock.SEASON_DESCS.length;a++)
					if((TimeClock.SEASON_DESCS[a]).startsWith(arg1.toUpperCase())
					&&(monster.location().getArea().getTimeObj().getSeasonCode()==a))
					{returnable=true; break;}
				break;
			}
			case 51: // isweather
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.cleanBit(evaluable.substring(y+1,z)));
				returnable=false;
				if(monster.location()!=null)
				for(int a=0;a<Climate.WEATHER_DESCS.length;a++)
					if((Climate.WEATHER_DESCS[a]).startsWith(arg1.toUpperCase())
					&&(monster.location().getArea().getClimateObj().weatherType(monster.location())==a))
					{returnable=true; break;}
				break;
			}
			case 57: // ismoon
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.cleanBit(evaluable.substring(y+1,z)));
				returnable=false;
				if(monster.location()!=null)
				{
					if(arg1.length()==0)
						returnable=monster.location().getArea().getClimateObj().canSeeTheStars(monster.location());
					else
					for(int a=0;a<TimeClock.PHASE_DESC.length;a++)
						if((TimeClock.PHASE_DESC[a]).startsWith(arg1.toUpperCase())
						&&(monster.location().getArea().getTimeObj().getMoonPhase()==a))
						{
							returnable=true;
							break;
						}
				}
				break;
			}
			case 38: // istime
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.cleanBit(evaluable.substring(y+1,z)));
				if(monster.location()==null)
					returnable=false;
				else
				if(("daytime").startsWith(arg1.toLowerCase())
				&&(monster.location().getArea().getTimeObj().getTODCode()==TimeClock.TIME_DAY))
					returnable=true;
				else
				if(("dawn").startsWith(arg1.toLowerCase())
				&&(monster.location().getArea().getTimeObj().getTODCode()==TimeClock.TIME_DAWN))
					returnable=true;
				else
				if(("dusk").startsWith(arg1.toLowerCase())
				&&(monster.location().getArea().getTimeObj().getTODCode()==TimeClock.TIME_DUSK))
					returnable=true;
				else
				if(("nighttime").startsWith(arg1.toLowerCase())
				&&(monster.location().getArea().getTimeObj().getTODCode()==TimeClock.TIME_NIGHT))
					returnable=true;
				else
				if((monster.location().getArea().getTimeObj().getTODCode()==CMath.s_int(arg1.trim())))
					returnable=true;
				else
					returnable=false;
				break;
			}
			case 39: // isday
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.cleanBit(evaluable.substring(y+1,z)));
				if((monster.location()!=null)&&(monster.location().getArea().getTimeObj().getDayOfMonth()==CMath.s_int(arg1.trim())))
					returnable=true;
				else
					returnable=false;
				break;
			}
			case 45: // nummobsroom
			{
                int num=0;
                int startbit=0;
                if(lastKnownLocation!=null) 
                {
                    num=lastKnownLocation.numInhabitants();
                    if((CMParms.numBits(evaluable.substring(y+1,z))>2)
                    &&(!CMath.isInteger(CMParms.getCleanBit(evaluable.substring(y+1,z),1).trim())))
                    {
                        String name=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
                        startbit++;
                        if(!name.equalsIgnoreCase("*"))
                        {
                            num=0;
                            Vector MASK=null;
                            if((name.toUpperCase().startsWith("MASK")&&(name.substring(4).trim().startsWith("="))))
                            { 
                                name=name.substring(4).trim(); 
                                name=name.substring(1).trim();
                                MASK=CMLib.masking().maskCompile(name);
                            }
                            for(int i=0;i<lastKnownLocation.numInhabitants();i++)
                            {
                                MOB M=lastKnownLocation.fetchInhabitant(i);
                                if(M==null) continue;
                                if(MASK!=null)
                                {
                                    if(CMLib.masking().maskCheck(MASK,M))
                                        num++;
                                }
                                else
                                if(CMLib.english().containsString(M.Name(),name)
                                ||CMLib.english().containsString(M.displayText(),name))
                                    num++;
                            }
                        }
                    }
                }
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),startbit));
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),startbit));
				if(lastKnownLocation!=null)
					returnable=simpleEval(scripted,""+num,arg2,arg1,"NUMMOBSROOM");
				break;
			}
			case 63: // numpcsroom
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				if(lastKnownLocation!=null)
					returnable=simpleEval(scripted,""+lastKnownLocation.numPCInhabitants(),arg2,arg1,"NUMPCSROOM");
				break;
			}
			case 79: // numpcsarea
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				if(lastKnownLocation!=null)
				{
					int num=0;
					for(int s=0;s<CMLib.sessions().size();s++)
					{
						Session S=CMLib.sessions().elementAt(s);
						if((S!=null)&&(S.mob()!=null)&&(S.mob().location()!=null)&&(S.mob().location().getArea()==lastKnownLocation.getArea()))
							num++;
					}
					returnable=simpleEval(scripted,""+num,arg2,arg1,"NUMPCSAREA");
				}
				break;
			}
            case 77: // explored
            {
                String whom=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
                String where=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),1));
                String cmp=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),2));
                String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),2));
                Environmental E=getArgumentItem(whom,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
                if((E==null)||(!(E instanceof MOB)))
                {
                    scriptableError(scripted,"EXPLORED","Unknown Code",whom);
                    return returnable;
                }
                Area A=null;
                if(!where.equalsIgnoreCase("world"))
                {
                    Environmental E2=getArgumentItem(where,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
                    if(E2 instanceof Area)
                        A=(Area)E2;
                    else
                        A=CMLib.map().getArea(where);
                    if(A==null)
                    {
                        scriptableError(scripted,"EXPLORED","Unknown Area",where);
                        return returnable;
                    }
                }
                if(lastKnownLocation!=null)
                {
                    int pct=0;
                    MOB M=(MOB)E;
                    if(M.playerStats()!=null)
                        pct=M.playerStats().percentVisited(M,A);
                    returnable=simpleEval(scripted,""+pct,arg2,cmp,"EXPLORED");
                }
                break;
            }
            case 72: // faction
            {
                String whom=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
                String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),1));
                String cmp=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),2));
                String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),3));
                Environmental E=getArgumentItem(whom,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
                Faction F=CMLib.factions().getFaction(arg1);
                if((E==null)||(!(E instanceof MOB)))
                {
                    scriptableError(scripted,"FACTION","Unknown Code",whom);
                    return returnable;
                }
                if(F==null)
                {
                    scriptableError(scripted,"FACTION","Unknown Faction",arg1);
                    return returnable;
                }
                MOB M=(MOB)E;
                String value=null;
                if(!M.hasFaction(F.factionID()))
                    value="";
                else
                {
                    int myfac=M.fetchFaction(F.factionID());
                    if(CMath.isNumber(arg2.trim()))
                        value=new Integer(myfac).toString();
                    else
                    {
                        Faction.FactionRange FR=CMLib.factions().getRange(F.factionID(),myfac);
                        if(FR==null) 
                            value="";
                        else 
                            value=FR.name();
                    }
                }
                if(lastKnownLocation!=null)
                    returnable=simpleEval(scripted,value,arg2,cmp,"FACTION");
                break;
            }
			case 46: // numitemsroom
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				int ct=0;
				if(lastKnownLocation!=null)
				for(int i=0;i<lastKnownLocation.numItems();i++)
				{
					Item I=lastKnownLocation.fetchItem(i);
					if((I!=null)&&(I.container()==null))
						ct++;
				}
				returnable=simpleEval(scripted,""+ct,arg2,arg1,"NUMITEMSROOM");
				break;
			}
			case 47: //mobitem
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),1));
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				MOB M=null;
				if(lastKnownLocation!=null)
					M=lastKnownLocation.fetchInhabitant(CMath.s_int(arg1.trim())-1);
				Item which=null;
				int ct=1;
				if(M!=null)
				for(int i=0;i<M.inventorySize();i++)
				{
					Item I=M.fetchInventory(i);
					if((I!=null)&&(I.container()==null))
					{
						if(ct==CMath.s_int(arg2.trim()))
						{ which=I; break;}
						ct++;
					}
				}
				if(which==null)
					returnable=false;
				else
					returnable=(CMLib.english().containsString(which.name(),arg3)
								||CMLib.english().containsString(which.Name(),arg3)
								||CMLib.english().containsString(which.displayText(),arg3));
				break;
			}
			case 49: // hastattoo
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getPastBitClean(evaluable.substring(y+1,z),0);
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if(arg2.length()==0)
				{
					scriptableError(scripted,"HASTATTOO","Syntax",evaluable);
					break;
				}
				else
				if((E!=null)&&(E instanceof MOB))
					returnable=(((MOB)E).fetchTattoo(arg2)!=null);
				else
					returnable=false;
				break;
			}
			case 48: // numitemsmob
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),1));
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				MOB which=null;
				if(lastKnownLocation!=null)
					which=lastKnownLocation.fetchInhabitant(CMath.s_int(arg1.trim())-1);
				int ct=1;
				if(which!=null)
				for(int i=0;i<which.inventorySize();i++)
				{
					Item I=which.fetchInventory(i);
					if((I!=null)&&(I.container()==null))
						ct++;
				}
				returnable=simpleEval(scripted,""+ct,arg3,arg2,"NUMITEMSMOB");
				break;
			}
			case 43: // roommob
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				Environmental which=null;
				if(lastKnownLocation!=null)
					which=lastKnownLocation.fetchInhabitant(CMath.s_int(arg1.trim())-1);
				if(which==null)
					returnable=false;
				else
					returnable=(CMLib.english().containsString(which.name(),arg2)
								||CMLib.english().containsString(which.Name(),arg2)
								||CMLib.english().containsString(which.displayText(),arg2));
				break;
			}
			case 44: // roomitem
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),0));
				Environmental which=null;
				int ct=1;
				if(lastKnownLocation!=null)
				for(int i=0;i<lastKnownLocation.numItems();i++)
				{
					Item I=lastKnownLocation.fetchItem(i);
					if((I!=null)&&(I.container()==null))
					{
						if(ct==CMath.s_int(arg1.trim()))
						{ which=I; break;}
						ct++;
					}
				}
				if(which==null)
					returnable=false;
				else
					returnable=(CMLib.english().containsString(which.name(),arg2)
								||CMLib.english().containsString(which.Name(),arg2)
								||CMLib.english().containsString(which.displayText(),arg2));
				break;
			}
			case 36: // ishere
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.cleanBit(evaluable.substring(y+1,z)));
				if(lastKnownLocation!=null)
					returnable=((lastKnownLocation.fetchAnyItem(arg1)!=null)||(lastKnownLocation.fetchInhabitant(arg1)!=null));
				else
					returnable=false;
				break;
			}
			case 17: // inroom
			{
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
				String comp="==";
				Environmental E=monster;
				if((" == >= > < <= => =< != ".indexOf(" "+CMParms.getCleanBit(evaluable.substring(y+1,z),1)+" ")>=0))
				{
					E=getArgumentItem(CMParms.getCleanBit(evaluable.substring(y+1,z),0),source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
					comp=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
					arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				}
				else
				{
					scriptableError(scripted,"INROOM","Syntax",evaluable);
					return returnable;
				}
				Room R=null;
				if(arg2.startsWith("$"))
					R=CMLib.map().roomLocation(this.getArgumentItem(arg2,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp));
				if(R==null)
					R=getRoom(arg2,lastKnownLocation);
				if(E==null)
					returnable=false;
				else
				{
					Room R2=CMLib.map().roomLocation(E);
					if((R==null)&&((arg2.length()==0)||(R2==null)))
						returnable=true;
					else
					if((R==null)||(R2==null))
						returnable=false;
					else
						returnable=simpleEvalStr(scripted,CMLib.map().getExtendedRoomID(R2),CMLib.map().getExtendedRoomID(R),comp,"INROOM");
				}
				break;
			}
			case 37: // inlocale
			{
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.cleanBit(evaluable.substring(y+1,z)));
				Environmental E=monster;
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
				if(arg2.length()==0)
					returnable=true;
				else
				if(CMClass.className(((MOB)E).location()).toUpperCase().indexOf(arg2.toUpperCase())>=0)
					returnable=true;
				else
					returnable=false;
				break;
			}
			case 18: // sex
			{
				String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0).toUpperCase());
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=CMParms.getPastBitClean(evaluable.substring(y+1,z),1).toUpperCase();
				if(CMath.isNumber(arg3.trim()))
					switch(CMath.s_int(arg3.trim()))
					{
					case 0: arg3="NEUTER"; break;
					case 1: arg3="MALE"; break;
					case 2: arg3="FEMALE"; break;
					}
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((arg2.length()==0)||(arg3.length()==0))
				{
					scriptableError(scripted,"SEX","Syntax",evaluable);
					return returnable;
				}
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
				{
					String sex=(""+((char)((MOB)E).charStats().getStat(CharStats.STAT_GENDER))).toUpperCase();
					if(arg2.equals("=="))
						returnable=arg3.startsWith(sex);
					else
					if(arg2.equals("!="))
						returnable=!arg3.startsWith(sex);
					else
					{
						scriptableError(scripted,"SEX","Syntax",evaluable);
						return returnable;
					}
				}
				break;
			}
			case 13: // stat
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=CMParms.getCleanBit(evaluable.substring(y+1,z),2);
				String arg4=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBit(evaluable.substring(y+1,z),2));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((arg2.length()==0)||(arg3.length()==0))
				{
					scriptableError(scripted,"STAT","Syntax",evaluable);
					break;
				}
				if(E==null)
					returnable=false;
				else
				{
					String val=getStatValue(E,arg2);
                    if(val==null)
					{
						scriptableError(scripted,"STAT","Syntax","Unknown stat: "+arg2+" for "+E.name());
						break;
					}

					if(arg3.equals("=="))
						returnable=val.equalsIgnoreCase(arg4);
					else
					if(arg3.equals("!="))
						returnable=!val.equalsIgnoreCase(arg4);
					else
						returnable=simpleEval(scripted,val,arg4,arg3,"STAT");
				}
				break;
			}
			case 52: // gstat
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=CMParms.getCleanBit(evaluable.substring(y+1,z),2);
				String arg4=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBit(evaluable.substring(y+1,z),2));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((arg2.length()==0)||(arg3.length()==0))
				{
					scriptableError(scripted,"GSTAT","Syntax",evaluable);
					break;
				}
				if(E==null)
					returnable=false;
				else
				{
					String val=getGStatValue(E,arg2);
					if(val==null)
					{
						scriptableError(scripted,"GSTAT","Syntax","Unknown stat: "+arg2+" for "+E.name());
						break;
					}

					if(arg3.equals("=="))
						returnable=val.equalsIgnoreCase(arg4);
					else
					if(arg3.equals("!="))
						returnable=!val.equalsIgnoreCase(arg4);
					else
						returnable=simpleEval(scripted,val,arg4,arg3,"GSTAT");
				}
				break;
			}
			case 19: // position
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=CMParms.getPastBitClean(evaluable.substring(y+1,z),1).toUpperCase();
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((arg2.length()==0)||(arg3.length()==0))
				{
					scriptableError(scripted,"POSITION","Syntax",evaluable);
					return returnable;
				}
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
				{
					String sex="STANDING";
					if(CMLib.flags().isSleeping(E))
						sex="SLEEPING";
					else
					if(CMLib.flags().isSitting(E))
						sex="SITTING";
					if(arg2.equals("=="))
						returnable=sex.startsWith(arg3);
					else
					if(arg2.equals("!="))
						returnable=!sex.startsWith(arg3);
					else
					{
						scriptableError(scripted,"POSITION","Syntax",evaluable);
						return returnable;
					}
				}
				break;
			}
			case 20: // level
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((arg2.length()==0)||(arg3.length()==0))
				{
					scriptableError(scripted,"LEVEL","Syntax",evaluable);
					return returnable;
				}
				if(E==null)
					returnable=false;
				else
				{
					int val1=E.envStats().level();
					returnable=simpleEval(scripted,""+val1,arg3,arg2,"LEVEL");
				}
				break;
			}
			case 80: // questpoints
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((arg2.length()==0)||(arg3.length()==0))
				{
					scriptableError(scripted,"QUESTPOINTS","Syntax",evaluable);
					return returnable;
				}
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
				{
					int val1=((MOB)E).getQuestPoint();
					returnable=simpleEval(scripted,""+val1,arg3,arg2,"QUESTPOINTS");
				}
				break;
			}
			case 83: // qvar
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),1));
				String arg3=CMParms.getCleanBit(evaluable.substring(y+1,z),2);
				String arg4=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),2));
				Quest Q=arg1.equals("*")?defaultQuest:CMLib.quests().fetchQuest(arg1);
				if((arg2.length()==0)||(arg3.length()==0))
				{
					scriptableError(scripted,"QUESTPOINTS","Syntax",evaluable);
					return returnable;
				}
				if(Q==null)
					returnable=false;
				else
					returnable=simpleEvalStr(scripted,Q.getStat(arg2),arg4,arg3,"QVAR");
				break;
			}
            case 84: // math
            {
                String arg1=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getCleanBit(evaluable.substring(y+1,z),0));
                String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
                String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
                if(!CMath.isMathExpression(arg1))
                {
                    scriptableError(scripted,"MATH","Syntax",evaluable);
                    return returnable;
                }
                if(!CMath.isMathExpression(arg3))
                {
                    scriptableError(scripted,"MATH","Syntax",evaluable);
                    return returnable;
                }
                returnable=simpleExpressionEval(scripted,arg1,arg3,arg2,"MATH");
                break;
            }
			case 81: // trains
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((arg2.length()==0)||(arg3.length()==0))
				{
					scriptableError(scripted,"TRAINS","Syntax",evaluable);
					return returnable;
				}
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
				{
					int val1=((MOB)E).getTrains();
					returnable=simpleEval(scripted,""+val1,arg3,arg2,"TRAINS");
				}
				break;
			}
			case 82: // pracs
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((arg2.length()==0)||(arg3.length()==0))
				{
					scriptableError(scripted,"PRACS","Syntax",evaluable);
					return returnable;
				}
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
				{
					int val1=((MOB)E).getPractices();
					returnable=simpleEval(scripted,""+val1,arg3,arg2,"PRACS");
				}
				break;
			}
			case 66: // clanrank
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1));
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((arg2.length()==0)||(arg3.length()==0))
				{
					scriptableError(scripted,"CLANRANK","Syntax",evaluable);
					return returnable;
				}
				if(E==null)
					returnable=false;
				else
				{
					int val1=(E instanceof MOB)?((MOB)E).getClanRole():-1;
					returnable=simpleEval(scripted,""+val1,arg3,arg2,"CLANRANK");
				}
				break;
			}
			case 64: // deity 
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),1).toUpperCase());
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if(arg2.length()==0)
				{
					scriptableError(scripted,"DEITY","Syntax",evaluable);
					return returnable;
				}
				if((E==null)||(!(E instanceof MOB)))
					returnable=false;
				else
				{
					String sex=((MOB)E).getWorshipCharID();
					if(arg2.equals("=="))
						returnable=sex.equalsIgnoreCase(arg3);
					else
					if(arg2.equals("!="))
						returnable=!sex.equalsIgnoreCase(arg3);
					else
					{
						scriptableError(scripted,"DEITY","Syntax",evaluable);
						return returnable;
					}
				}
				break;
			}
			case 68: // clandata
			{
				String arg1=CMParms.getCleanBit(evaluable.substring(y+1,z),0);
				String arg2=CMParms.getCleanBit(evaluable.substring(y+1,z),1);
				String arg3=CMParms.getCleanBit(evaluable.substring(y+1,z),2);
				String arg4=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,CMParms.getPastBitClean(evaluable.substring(y+1,z),2).toUpperCase());
				Environmental E=getArgumentItem(arg1,source,monster,scripted,target,primaryItem,secondaryItem,msg,tmp);
				if((arg2.length()==0)||(arg3.length()==0))
				{
					scriptableError(scripted,"CLANDATA","Syntax",evaluable);
					return returnable;
				}
				String clanID=null;
				if((E!=null)&&(E instanceof MOB))
				    clanID=((MOB)E).getClanID();
				else
					clanID=varify(source,target,monster,primaryItem,secondaryItem,msg,tmp,arg1);
				Clan C=CMLib.clans().findClan(clanID);
				if(C!=null)
				{
				    int whichVar=-1;
				    for(int i=0;i<clanVars.length;i++)
				        if(arg2.equalsIgnoreCase(clanVars[i]))
				        { whichVar=i; break;}
				    String whichVal="";
				    switch(whichVar)
				    {
				    case 0: whichVal=C.getAcceptanceSettings(); break;
				    case 1: whichVal=C.getDetail(monster); break;
				    case 2: whichVal=C.getDonation(); break;
				    case 3: whichVal=""+C.getExp(); break;
				    case 4: whichVal=Clan.GVT_DESCS[C.getGovernment()]; break;
				    case 5: whichVal=C.getMorgue(); break;
				    case 6: whichVal=C.getPolitics(); break;
				    case 7: whichVal=C.getPremise(); break;
				    case 8: whichVal=C.getRecall(); break;
				    case 9: whichVal=""+C.getSize(); break; // size
				    case 10: whichVal=Clan.CLANSTATUS_DESC[C.getStatus()]; break;
				    case 11: whichVal=""+C.getTaxes(); break;
				    case 12: whichVal=""+C.getTrophies(); break;
				    case 13: whichVal=""+C.getType(); break; // type
				    case 14: {
			        	 Vector areas=C.getControlledAreas();
			        	 StringBuffer list=new StringBuffer("");
			        	 for(int i=0;i<areas.size();i++)
			        	     list.append("\""+((Environmental)areas.elementAt(i)).name()+"\" ");
			        	 whichVal=list.toString().trim();
			  

Showing the first 100 KB of 283.9 KB. Download the archive for the full file.

Site Stats

Snippets: 1791
Codebases: 571