From: Katie <ky...@us...> - 2007-11-30 09:08:42
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/actions In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv5933/src/games/stendhal/server/actions Modified Files: BuddyAction.java ChatAction.java Log Message: add server side handling of grumpiness. the change to Player.java looks big, sorry, it's because i had to 'tabify' to correct my tabs in there which had been spaces. but really i'm just adding an attribute for grumpiness in that file Index: BuddyAction.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/actions/BuddyAction.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** BuddyAction.java 15 Aug 2007 08:30:31 -0000 1.15 --- BuddyAction.java 30 Nov 2007 09:08:41 -0000 1.16 *************** *** 22,25 **** --- 22,26 ---- BuddyAction buddy = new BuddyAction(); StendhalRPRuleProcessor.register("addbuddy", buddy); + StendhalRPRuleProcessor.register("grumpy", buddy); StendhalRPRuleProcessor.register("ignore", buddy); StendhalRPRuleProcessor.register("removebuddy", buddy); *************** *** 36,40 **** --- 37,44 ---- } else if (action.get("type").equals("unignore")) { onUnignore(player, action); + } else if (action.get("type").equals("grumpy")) { + onGrumpy(player, action); } + } *************** *** 106,108 **** --- 110,127 ---- } + + /** + * Handle a Grumpy action. + * + * @param player The player. + * @param action The action. + */ + protected void onGrumpy(Player player, RPAction action) { + if (action.has("reason")) { + player.setGrumpyMessage(action.get("reason")); + } else { + player.setGrumpyMessage(null); + } + player.notifyWorldAboutChanges(); + } } Index: ChatAction.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/actions/ChatAction.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** ChatAction.java 25 Oct 2007 10:13:49 -0000 1.40 --- ChatAction.java 30 Nov 2007 09:08:41 -0000 1.41 *************** *** 25,28 **** --- 25,29 ---- import marauroa.common.game.RPAction; + import marauroa.common.game.RPObject; /** *************** *** 98,101 **** --- 99,103 ---- String away; String reply; + String grumpy; // TODO: find a cleaner way to implement it *************** *** 169,172 **** --- 171,206 ---- } + // check grumpiness + grumpy = receiver.getGrumpyMessage(); + if (grumpy != null && receiver.getSlot("!buddy").size() > 0){ + RPObject buddies = receiver.getSlot("!buddy").iterator().next(); + boolean senderFound = false; + for (String buddyName : buddies) { + // TODO: as in Player.java, remove '_' prefix if ID is made completely virtual + if (buddyName.charAt(0) == '_') { + buddyName = buddyName.substring(1); + } + if (buddyName.equals(senderName)){ + senderFound = true; + break; + } + } + if(!senderFound){ + // sender is not a buddy + // HACK: do not notify postman + if (!senderName.equals("postman")) { + if (grumpy.length() == 0) { + player + .sendPrivateText(receiverName + + " has a closed mind, and is seeking solitude from all but close friends"); + } else { + player.sendPrivateText(receiverName + + " is seeking solitude from all but close friends: " + grumpy); + } + player.notifyWorldAboutChanges(); + } + return; + } + } // transmit the message receiver.sendPrivateText(message); |