From: Daniel H. <wik...@us...> - 2006-05-22 19:53:15
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/npc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6838/src/games/stendhal/server/entity/npc Modified Files: Behaviours.java Log Message: fixed grammar bug where sellers say things like "I sell sheep," created nicer enumerations, e.g. "I sell beer, wine, flask, cheese, apple, carrot, meat, and ham." or "I sell wooden_bow and wooden_arrow." Index: Behaviours.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/npc/Behaviours.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** Behaviours.java 22 May 2006 18:19:25 -0000 1.37 --- Behaviours.java 22 May 2006 19:52:59 -0000 1.38 *************** *** 1,4 **** --- 1,5 ---- package games.stendhal.server.entity.npc; + import java.util.Collection; import java.util.Map; import java.util.HashMap; *************** *** 36,39 **** --- 37,65 ---- public static final String[] GOODBYE_MESSAGES = {"bye", "farewell", "cya", "adios"}; + /** + * Helper function to nicely formulate an enumeration of a collection. + * For example, for a collection containing the 3 elements x, y, z, + * returns the string "x, y, and z". + * @param collection The collection whose elements should be enumerated + * @return A nice String representation of the collection + */ + private static String enumerateCollection(Collection<String> collection) { + String[] elements = collection.toArray(new String[collection.size()]); + if (elements.length == 0) { + return ""; + } else if (elements.length == 1) { + return elements[0]; + } else if (elements.length == 2) { + return elements[0] + " and " + elements[1]; + } else { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < elements.length - 1; i++) { + sb.append(elements[i] + ", "); + } + sb.append("and " + elements[elements.length - 1]); + return sb.toString(); + } + } + public static void initialize(RPServerManager rpman, StendhalRPRuleProcessor rules, RPWorld world) { // Behaviours.rpman = rpman; *************** *** 312,320 **** npc.setBehaviourData("seller", items); - StringBuffer st = new StringBuffer(); - for (String item : items.getItems()) { - st.append(item + ", "); - } - if (offer) { npc.add(ConversationStates.ATTENDING, --- 338,341 ---- *************** *** 322,326 **** null, ConversationStates.ATTENDING, ! "I sell " + st.toString(), null); } --- 343,347 ---- null, ConversationStates.ATTENDING, ! "I sell " + enumerateCollection(items.getItems()) + ".", null); } *************** *** 548,556 **** npc.setBehaviourData("buyer", items); - StringBuffer st = new StringBuffer(); - for (String item : items.getItems()) { - st.append(item + ", "); - } - if (offer) { npc.add(ConversationStates.ATTENDING, --- 569,572 ---- *************** *** 558,562 **** null, ConversationStates.ATTENDING, ! "I buy " + st.toString(), null); } --- 574,578 ---- null, ConversationStates.ATTENDING, ! "I buy " + enumerateCollection(items.getItems()) + ".", null); } |