/* * BAGSObject.bsh * * Copyright 2005 M. Aaron Wadley * * This file is part of BAGS (Beany Adventure Game System). * BAGS (Beany Adventure Game System) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * BAGS (Beany Adventure Game System) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with BAGS (Beany Adventure Game System); if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /** * Collection of all the objects defined in the game. */ GameObjects(customObjects) { allObjects = new HashMap(); log.info("Loading game objects"); // get methods (object definitions) from custom objects methods = customObjects.namespace.getMethods(); for ( m : methods) { Object o = new Object(); o = eval("customObjects." + m.getName() + "()"); // Set up default properties o.examined=false; if (o.taken == null || o.taken == void) { o.taken=false; } if (o.dropped == null || o.dropped == void) { o.dropped=false; } if (o.contents == null || o.contents == void) { o.contents = new String[0]; } else { parsed=o.contents.split(","); o.contents = parsed; } if (o.providesLight == null || o.providesLight == void) { o.providesLight=false; } // add the object w/id as key allObjects.put(o.id.toUpperCase(), o); // now add all synonyms if (o.synonyms != null && o.synonyms != void) { syns=o.synonyms.split(","); for ( synonym : syns) { allObjects.put(synonym.toUpperCase(), o); } } }// end for(m:methods) getObject(objectId) { log.trace("ENTER getObject()"); log.debug("Retrieving object " + objectId); o = allObjects.get(objectId.toUpperCase()); log.trace("EXIT getObject()"); return o; } /** * Get pipe-delimited string for regex */ getRegexString() { StringBuffer sb = new StringBuffer(); objectKeys = allObjects.keySet(); for (key : objectKeys) { sb.append(key + "|"); } return sb.toString(); } return this; }// end GameObjects()