1 /* $Id$ */ 2 /*************************************************************************** 3 * (C) Copyright 2003-2010 - 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 games.stendhal.server.maps.quests; 14 15 import static org.hamcrest.Matchers.greaterThan; 16 import static org.junit.Assert.assertEquals; 17 import static org.junit.Assert.assertNull; 18 import static org.junit.Assert.assertThat; 19 import static org.junit.Assert.assertTrue; 20 import static utilities.SpeakerNPCTestHelper.getReply; 21 22 import org.junit.After; 23 import org.junit.Before; 24 import org.junit.BeforeClass; 25 import org.junit.Test; 26 27 import games.stendhal.server.core.engine.SingletonRepository; 28 import games.stendhal.server.core.engine.StendhalRPZone; 29 import games.stendhal.server.entity.npc.SpeakerNPC; 30 import games.stendhal.server.entity.npc.fsm.Engine; 31 import games.stendhal.server.entity.player.Player; 32 import games.stendhal.server.maps.orril.dungeon.RatChild1NPC; 33 import games.stendhal.server.maps.orril.dungeon.RatChild2NPC; 34 import games.stendhal.server.maps.orril.dungeon.RatChildBoy1NPC; 35 import games.stendhal.server.maps.orril.dungeon.RatChildBoy2NPC; 36 import games.stendhal.server.maps.ratcity.house1.OldRatWomanNPC; 37 import utilities.PlayerTestHelper; 38 import utilities.QuestHelper; 39 40 public class FindRatChildrenTest { 41 42 private static final String QUEST_SLOT = "find_rat_kids"; 43 44 private Player player = null; 45 private SpeakerNPC npc = null; 46 private Engine en = null; 47 48 @BeforeClass setUpBeforeClass()49 public static void setUpBeforeClass() throws Exception { 50 QuestHelper.setUpBeforeClass(); 51 } 52 53 @Before setUp()54 public void setUp() { 55 56 final StendhalRPZone zone = new StendhalRPZone("admin_test"); 57 58 new OldRatWomanNPC().configureZone(zone, null); 59 new RatChildBoy1NPC().configureZone(zone, null); 60 new RatChildBoy2NPC().configureZone(zone, null); 61 new RatChild1NPC().configureZone(zone, null); 62 new RatChild2NPC().configureZone(zone, null); 63 64 AbstractQuest quest = new FindRatChildren(); 65 quest.addToWorld(); 66 67 player = PlayerTestHelper.createPlayer("bob"); 68 } 69 70 @After tearDown()71 public void tearDown() { 72 PlayerTestHelper.removeNPC("Agnus"); 73 PlayerTestHelper.removeNPC("Avalon"); 74 PlayerTestHelper.removeNPC("Cody"); 75 PlayerTestHelper.removeNPC("Mariel"); 76 PlayerTestHelper.removeNPC("Opal"); 77 } 78 79 @Test testMeetingKidBeforeQuestStarted()80 public void testMeetingKidBeforeQuestStarted() { 81 82 // haven't started quest yet 83 assertNull(player.getQuest(QUEST_SLOT)); 84 85 npc = SingletonRepository.getNPCList().get("Cody"); 86 en = npc.getEngine(); 87 88 en.step(player, "hi"); 89 assertEquals("Mother says I mustn't talk to strangers.", getReply(npc)); 90 en.step(player, "bye"); 91 } 92 // ----------------------------------------------- 93 94 @Test testStartQuest()95 public void testStartQuest() { 96 97 npc = SingletonRepository.getNPCList().get("Agnus"); 98 en = npc.getEngine(); 99 100 en.step(player, "hi"); 101 assertEquals("Hello there.", getReply(npc)); 102 en.step(player, "help"); 103 assertEquals("I have no help to offer you.", getReply(npc)); 104 en.step(player, "job"); 105 assertEquals("Leave it to my children to not check in once in a while.", getReply(npc)); 106 en.step(player, "task"); 107 assertEquals("I feel so worried. If I only knew my #children were safe I would feel better.", getReply(npc)); 108 en.step(player, "children"); 109 assertEquals("My children have gone to play in the sewers. They have been gone for a long time. Will you find them and see if they are ok?", getReply(npc)); 110 en.step(player, "no"); 111 assertEquals("Oh. Never mind. I'm sure someone else would be glad to help me.", getReply(npc)); 112 en.step(player, "bye"); 113 assertEquals("Bye", getReply(npc)); 114 115 // check quest slot 116 assertEquals(player.getQuest(QUEST_SLOT),"rejected"); 117 118 en.step(player, "hi"); 119 assertEquals("Hello there.", getReply(npc)); 120 en.step(player, "task"); 121 assertEquals("I feel so worried. If I only knew my #children were safe I would feel better.", getReply(npc)); 122 en.step(player, "children"); 123 assertEquals("My children have gone to play in the sewers. They have been gone for a long time. Will you find them and see if they are ok?", getReply(npc)); 124 en.step(player, "yes"); 125 assertEquals("That's so nice of you. Good luck searching for them.", getReply(npc)); 126 en.step(player, "task"); 127 assertEquals("Why must my children stay out so long? Please find them and tell me who is ok.", getReply(npc)); 128 en.step(player, "bye"); 129 assertEquals("Bye", getReply(npc)); 130 131 // check quest slot 132 assertEquals(player.getQuest(QUEST_SLOT),"looking:said"); 133 } 134 135 @Test testNamingKidsThatDontExistOrNotMet()136 public void testNamingKidsThatDontExistOrNotMet() { 137 138 npc = SingletonRepository.getNPCList().get("Agnus"); 139 en = npc.getEngine(); 140 141 // the state wasn't remembered across the new test method so we need to set it to what it was when we ended the last 142 player.setQuest(QUEST_SLOT, "looking:said"); 143 144 en.step(player, "hi"); 145 assertEquals("If you found any of my #children, please tell me their name.", getReply(npc)); 146 en.step(player, "children"); 147 assertEquals("I wish to know that my children are ok. Please tell me who is ok.", getReply(npc)); 148 en.step(player, "unknownchild"); 149 assertEquals("Sorry, I don't understand you. What name are you trying to say?", getReply(npc)); 150 en.step(player, "banana"); 151 assertEquals("Sorry, I don't understand you. What name are you trying to say?", getReply(npc)); 152 en.step(player, "Cody"); 153 assertEquals("I don't think you actually checked if they were ok. If you have seen any of my other children, please tell me who.", getReply(npc)); 154 en.step(player, "bye"); 155 assertEquals("No problem, come back later.", getReply(npc)); 156 157 // check quest slot 158 assertEquals(player.getQuest(QUEST_SLOT),"looking:said"); 159 } 160 161 @Test testMeetingCodyAfterQuestStarted()162 public void testMeetingCodyAfterQuestStarted() { 163 npc = SingletonRepository.getNPCList().get("Cody"); 164 en = npc.getEngine(); 165 166 // the state wasn't remembered across the new test method so we need to set it to what it was when we ended the last 167 player.setQuest(QUEST_SLOT, "looking:said"); 168 169 // remember the xp and karma, did it go up? 170 final int xp = player.getXP(); 171 172 en.step(player, "hi"); 173 assertEquals("Hello my name is Cody. Please tell mother that I am ok.", getReply(npc)); 174 // [11:49] kymara earns 500 experience points. 175 176 assertThat(player.getXP(), greaterThan(xp)); 177 // check quest slot 178 assertEquals(player.getQuest(QUEST_SLOT),"looking;cody:said"); 179 180 // return after having met in this quest run 181 en.step(player, "hi"); 182 assertEquals("Oh hello again.", getReply(npc)); 183 184 // check quest slot 185 assertEquals(player.getQuest(QUEST_SLOT),"looking;cody:said"); 186 } 187 188 @Test testNamingKidsMet()189 public void testNamingKidsMet() { 190 191 npc = SingletonRepository.getNPCList().get("Agnus"); 192 en = npc.getEngine(); 193 194 // the state wasn't remembered across the new test method so we need to set it to what it was when we ended the last 195 player.setQuest(QUEST_SLOT, "looking;cody:said"); 196 197 en.step(player, "hi"); 198 assertEquals("If you found any of my #children, please tell me their name.", getReply(npc)); 199 en.step(player, "children"); 200 assertEquals("I wish to know that my children are ok. Please tell me who is ok.", getReply(npc)); 201 en.step(player, "CODY"); 202 assertEquals("Thank you. If you have seen any of my other children, please tell me who.", getReply(npc)); 203 en.step(player, "mariel"); 204 assertEquals("I don't think you actually checked if they were ok. If you have seen any of my other children, please tell me who.", getReply(npc)); 205 en.step(player, "bye"); 206 assertEquals("No problem, come back later.", getReply(npc)); 207 208 // check quest slot 209 assertEquals(player.getQuest(QUEST_SLOT),"looking;cody:said;cody"); 210 } 211 212 @Test testMeetingRemainingKids()213 public void testMeetingRemainingKids() { 214 npc = SingletonRepository.getNPCList().get("Mariel"); 215 en = npc.getEngine(); 216 217 // the state wasn't remembered across the new test method so we need to set it to what it was when we ended the last 218 player.setQuest(QUEST_SLOT, "looking;cody:said;cody"); 219 220 en.step(player, "hi"); 221 assertEquals("Hello my name is Mariel. Please tell mother that I am ok.", getReply(npc)); 222 // [11:49] kymara earns 500 experience points. 223 224 // ----------------------------------------------- 225 226 npc = SingletonRepository.getNPCList().get("Opal"); 227 en = npc.getEngine(); 228 229 en.step(player, "hi"); 230 assertEquals("Hello my name is Opal. Please tell mother that I am ok.", getReply(npc)); 231 // [11:50] kymara earns 500 experience points. 232 233 // ----------------------------------------------- 234 npc = SingletonRepository.getNPCList().get("Avalon"); 235 en = npc.getEngine(); 236 237 en.step(player, "hi"); 238 assertEquals("Hello my name is Avalon. Please tell mother that I am ok.", getReply(npc)); 239 // [11:50] kymara earns 500 experience points. 240 241 // check quest slot 242 assertEquals(player.getQuest(QUEST_SLOT),"looking;cody;mariel;opal;avalon:said;cody"); 243 244 } 245 @Test testNamingRemainingKids()246 public void testNamingRemainingKids() { 247 248 npc = SingletonRepository.getNPCList().get("Agnus"); 249 en = npc.getEngine(); 250 251 // the state wasn't remembered across the new test method so we need to set it to what it was when we ended the last 252 player.setQuest(QUEST_SLOT, "looking;cody;mariel;opal;avalon:said;cody"); 253 254 en.step(player, "hi"); 255 assertEquals("If you found any of my #children, please tell me their name.", getReply(npc)); 256 en.step(player, "mariel"); 257 assertEquals("Thank you. If you have seen any of my other children, please tell me who.", getReply(npc)); 258 en.step(player, "bye"); 259 assertEquals("No problem, come back later.", getReply(npc)); 260 261 // check quest slot 262 assertEquals(player.getQuest(QUEST_SLOT),"looking;cody;mariel;opal;avalon:said;cody;mariel"); 263 264 // remember the xp and karma, did it go up? 265 final int xp = player.getXP(); 266 final double karma = player.getKarma(); 267 268 en.step(player, "hi"); 269 assertEquals("If you found any of my #children, please tell me their name.", getReply(npc)); 270 en.step(player, "avalon"); 271 assertEquals("Thank you. If you have seen any of my other children, please tell me who.", getReply(npc)); 272 // test saying a name we already had given 273 en.step(player, "Cody"); 274 assertEquals("Yes you told me that they were ok already, thanks. If you have seen any of my other children, please tell me who.", getReply(npc)); 275 en.step(player, "Opal"); 276 assertEquals("Thank you. Now that I know my kids are safe, I can set my mind at rest.", getReply(npc)); 277 // [11:50] kymara earns 5000 experience points. 278 en.step(player, "bye"); 279 assertEquals("Bye", getReply(npc)); 280 281 assertThat(player.getXP(), greaterThan(xp)); 282 assertThat(player.getKarma(), greaterThan(karma)); 283 284 // check quest slot 285 assertTrue(player.isQuestCompleted(QUEST_SLOT)); 286 } 287 288 @Test testReturningBeforeTimePassed()289 public void testReturningBeforeTimePassed() { 290 291 npc = SingletonRepository.getNPCList().get("Agnus"); 292 en = npc.getEngine(); 293 294 // the state wasn't remembered across the new test method so we need to set it to what it was when we ended the last 295 player.setQuest(QUEST_SLOT, "done;"+System.currentTimeMillis()); 296 297 en.step(player, "hi"); 298 assertEquals("Hello there.", getReply(npc)); 299 en.step(player, "task"); 300 assertEquals("Thank you! I feel better now knowing my kids are safe.", getReply(npc)); 301 en.step(player, "yes"); 302 en.step(player, "bye"); 303 assertEquals("Bye", getReply(npc)); 304 } 305 306 @Test testReturningAfterTimePassed()307 public void testReturningAfterTimePassed() { 308 309 // [11:51] Admin kymara changed your state of the quest 'find_rat_kids' from 'done;1270205441630' to 'done;1' 310 // [11:51] Changed the state of quest 'find_rat_kids' from 'done;1270205441630' to 'done;1' 311 312 // the state wasn't remembered across the new test method so we need to set it to what it was when we ended the last 313 player.setQuest(QUEST_SLOT, "done;1"); 314 315 npc = SingletonRepository.getNPCList().get("Agnus"); 316 en = npc.getEngine(); 317 318 en.step(player, "hi"); 319 assertEquals("Do you think you could find my children again?", getReply(npc)); 320 en.step(player, "yes"); 321 assertEquals("That's so nice of you. Good luck searching for them.", getReply(npc)); 322 en.step(player, "bye"); 323 assertEquals("Bye", getReply(npc)); 324 325 // ----------------------------------------------- 326 327 npc = SingletonRepository.getNPCList().get("Cody"); 328 en = npc.getEngine(); 329 330 en.step(player, "hi"); 331 assertEquals("Hello my name is Cody. Please tell mother that I am ok.", getReply(npc)); 332 // [11:51] kymara earns 500 experience points. 333 en.step(player, "bye"); 334 } 335 } 336