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 games.stendhal.server.maps.quests;
14 
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertTrue;
17 import static utilities.SpeakerNPCTestHelper.getReply;
18 
19 import org.junit.Before;
20 import org.junit.BeforeClass;
21 import org.junit.Test;
22 
23 import games.stendhal.server.actions.move.MoveToAction;
24 import games.stendhal.server.core.engine.SingletonRepository;
25 import games.stendhal.server.entity.mapstuff.portal.Portal;
26 import games.stendhal.server.entity.npc.SpeakerNPC;
27 import games.stendhal.server.entity.npc.fsm.Engine;
28 import games.stendhal.server.maps.ados.magician_house.WizardNPC;
29 import utilities.PlayerTestHelper;
30 import utilities.QuestHelper;
31 import utilities.ZonePlayerAndNPCTestImpl;
32 
33 /**
34  * JUnit test for the Maze quest.
35  * @author bluelads, M. Fuchs
36  */
37 public class MazeTest extends ZonePlayerAndNPCTestImpl {
38 
39 	private SpeakerNPC npc = null;
40 	private Engine en = null;
41 
42 	private String questSlot;
43 	private static final String ZONE_NAME = "int_ados_magician_house";
44 
45 	@BeforeClass
setUpBeforeClass()46 	public static void setUpBeforeClass() throws Exception {
47 		QuestHelper.setUpBeforeClass();
48 		setupZone(ZONE_NAME);
49 	}
50 
MazeTest()51 	public MazeTest() {
52 		super(ZONE_NAME, "Haizen");
53 	}
54 
55 	@Override
56 	@Before
setUp()57 	public void setUp() throws Exception {
58 		super.setUp();
59 
60 		new WizardNPC().configureZone(zone, null);
61 
62 		quest = new Maze();
63 		quest.addToWorld();
64 
65 		questSlot = quest.getSlotName();
66 	}
67 
68 	@Test
testQuest()69 	public void testQuest() {
70 		npc = SingletonRepository.getNPCList().get("Haizen");
71 		en = npc.getEngine();
72 
73 		en.step(player, "hi");
74 		assertEquals("Greetings! How may I help you?", getReply(npc));
75 		en.step(player, "task");
76 		assertEquals("I can send you to a #maze you need to find your way out. I keep the a list of the fast and frequent maze solvers in that blue book on the table.", getReply(npc));
77 		en.step(player, "maze");
78 		assertEquals("There will be a portal out in the opposite corner of the maze. I'll also add scrolls to the two other corners you can try to get if you are fast enough. Do you want to try?", getReply(npc));
79 		en.step(player, "no");
80 		assertEquals("OK. You look like you'd only get lost anyway.", getReply(npc));
81 		en.step(player, "task");
82 		assertEquals("I can send you to a #maze you need to find your way out. I keep the a list of the fast and frequent maze solvers in that blue book on the table.", getReply(npc));
83 		en.step(player, "maze");
84 		assertEquals("There will be a portal out in the opposite corner of the maze. I'll also add scrolls to the two other corners you can try to get if you are fast enough. Do you want to try?", getReply(npc));
85 		en.step(player, "yes");
86 		String questStarted = player.getQuest(questSlot);
87 		assertTrue(questStarted.startsWith("start;"));
88 
89 		// tried to double-click
90 		new MoveToAction().onAction(player, null);
91 		assertEquals("Mouse movement is not possible here. Use your keyboard.", PlayerTestHelper.getPrivateReply(player));
92 
93 		// didn't solve the maze
94 		en.step(player, "hi");
95 		assertEquals("Greetings! How may I help you?", getReply(npc));
96 		en.step(player, "task");
97 		assertEquals("I can send you to a #maze you need to find your way out. I keep the a list of the fast and frequent maze solvers in that blue book on the table.", getReply(npc));
98 		en.step(player, "maze");
99 		assertTrue(getReply(npc).matches("I can send you to the maze only once in a day. You can go there again in .*\\."));
100 		en.step(player, "bye");
101 		assertEquals("Bye.", getReply(npc));
102 
103 		// jump back to the quest start state
104 		player.setQuest(questSlot, questStarted);
105 		// solve the maze
106 		Portal portal = ((Maze) quest).getPortal();
107 		player.setPosition(portal.getX(), portal.getY());
108 		portal.onUsed(player);
109 		assertTrue(PlayerTestHelper.getPrivateReply(player).matches("You used 0 seconds to solve the maze. That was worth [0-9]+ points."));
110 		assertEquals("done", player.getQuest(questSlot, 0));
111 	}
112 }
113