1 /* $Id$ */ 2 /*************************************************************************** 3 * (C) Copyright 2003-2011 - Stendhal * 4 *************************************************************************** 5 *************************************************************************** 6 * * 7 * This program is free software; you can redistribute it and/or modify * 8 * it under the terms of the GNU General Public License as published by * 9 * the Free Software Foundation; either version 2 of the License, or * 10 * (at your option) any later version. * 11 * * 12 ***************************************************************************/ 13 package utilities; 14 15 import java.util.ArrayList; 16 import java.util.List; 17 18 import games.stendhal.common.constants.Events; 19 import games.stendhal.server.entity.npc.SpeakerNPC; 20 import marauroa.common.game.RPEvent; 21 22 /** 23 * Provides convenience methods for SpeakerNPC creation. the Created NPC extends 24 * <p> 25 * SpeakerNPC and overrides <code>registerTheNewNameInTheConversationParserWordList</code> to 26 * avoid database access 27 * 28 */ 29 public abstract class SpeakerNPCTestHelper { 30 createSpeakerNPC()31 public static SpeakerNPC createSpeakerNPC() { 32 return createSpeakerNPC("bob"); 33 } 34 createSpeakerNPC(final String name)35 public static SpeakerNPC createSpeakerNPC(final String name) { 36 PlayerTestHelper.generateNPCRPClasses(); 37 return new SpeakerNPC(name); 38 } 39 40 /** 41 * Query the events for public visible text messages. 42 * 43 * @param npc 44 * The entity who's events should be checked. 45 * @return 46 * Most recent text message. 47 */ getReply(final SpeakerNPC npc)48 public static String getReply(final SpeakerNPC npc) { 49 String reply = null; 50 51 for (RPEvent event : npc.events()) { 52 if (event.getName().equals(Events.PUBLIC_TEXT)) { 53 reply = event.get("text"); 54 } 55 } 56 57 npc.clearEvents(); 58 59 return reply; 60 } 61 62 /** 63 * Query the events for public visible text messages. 64 * 65 * @param npc 66 * The entity who's events should be checked. 67 * @return 68 * List of text messages. 69 */ getReplies(final SpeakerNPC npc)70 public static List<String> getReplies(final SpeakerNPC npc) { 71 final List<String> replies = new ArrayList<>(); 72 73 for (final RPEvent event : npc.events()) { 74 if (event.getName().equals(Events.PUBLIC_TEXT)) { 75 replies.add(event.get("text")); 76 } 77 } 78 79 npc.clearEvents(); 80 81 return replies; 82 } 83 } 84