Package games.stendhal.server.entity.npc.fsm

Examples of games.stendhal.server.entity.npc.fsm.Engine


  public final void rejectQuest() {
    SingletonRepository.getNPCList().add(new SpeakerNPC(NPC));
    final CloakCollector2 cc = new CloakCollector2();
    cc.addToWorld();
    final SpeakerNPC npc = cc.npcs.get(NPC);
    final Engine en = npc.getEngine();
    final Player player = PlayerTestHelper.createPlayer("player");
    final double karma = player.getKarma();
   
    // CloakCollector needs to be done to start this quest
    player.setQuest(OLD_QUEST, "done");
    en.stepTest(player, ConversationPhrases.GREETING_MESSAGES.get(0));
    assertEquals("Josephines first greeting""Hi again! I hear there's some new cloaks out, and I'm regretting not asking you about the ones I didn't like before. It feels like my #collection isn't complete...", getReply(npc));
   
    en.stepTest(player, "no");
    assertEquals("Answer to refusal", "Oh ... you're not very friendly. Please say yes?", getReply(npc));
    assertEquals("Karma penalty at refusal", karma - 5.0, player.getKarma(), 0.01);
  }
View Full Code Here


  public final void doQuest() {
    SingletonRepository.getNPCList().add(new SpeakerNPC(NPC));
    final CloakCollector2 cc = new CloakCollector2();
    cc.addToWorld();
    final SpeakerNPC npc = cc.npcs.get(NPC);
    final Engine en = npc.getEngine();
    final Player player = PlayerTestHelper.createPlayer("player");
    final double karma = player.getKarma();
   
    player.setQuest(OLD_QUEST, "done");

    en.stepTest(player, ConversationPhrases.GREETING_MESSAGES.get(0));
    assertEquals("Hi again! I hear there's some new cloaks out, and I'm regretting not asking you about the ones I didn't like before. It feels like my #collection isn't complete...", getReply(npc));
   
    en.stepTest(player, "collection");
    assertEquals("Answer to 'collection'",
        initiallyWantedMessage(player), getReply(npc));
   
    for (final String item : CLOAKS) {
      en.stepTest(player, item);
      final String expected = "You haven't seen one before? Well, it's a "
        + item
        + ". Sorry if that's not much help, it's all I know! So, will you find them all?";
      assertEquals(expected, getReply(npc));
    }

    // does not exist
    en.stepTest(player, "pink cloak");
    assertEquals("I don't know pink cloak. Can you name me another cloak please?", getReply(npc));

    en.stepTest(player, ConversationPhrases.YES_MESSAGES.get(0));
    assertEquals("Brilliant! I'm all excited again! Bye!", getReply(npc));
    assertEquals(karma + 5.0, player.getKarma(), 0.01);
   
    en.stepTest(player, ConversationPhrases.GREETING_MESSAGES.get(0));
    assertEquals("Welcome back! Have you brought any #cloaks with you?", getReply(npc));
   
    en.stepTest(player, "cloaks");
    assertEquals(stillWantedMessage(player), getReply(npc));
   
    en.stepTest(player, "no");
    assertEquals("Okay then. Come back later.", getReply(npc));
   
    // This is weird, but it's how the quest works at the moment
    en.stepTest(player, "no");
    assertEquals("Ok. If you want help, just say.", getReply(npc));
   
    /* Josephine does not know what to do with "bye" without CloakCollector,
       so do it manually. Jump over the greeting as it was already tested above */
    en.setCurrentState(ConversationStates.QUESTION_2);
   
    en.stepTest(player, "yes");
    assertEquals("Woo! What #cloaks did you bring?", getReply(npc));
   
    // Give her all but the last - Thrice to test the possible answers 
    for (final String itemName : CLOAKS.subList(1, CLOAKS.size())) {
      en.stepTest(player, itemName);
      assertEquals("Oh, I'm disappointed. You don't really have "
          + Grammar.a_noun(itemName) + " with you.", getReply(npc));
     
      final Item cloak = new Item(itemName, "", "", null);
      player.getSlot("bag").add(cloak);
      en.stepTest(player, itemName);
      assertEquals("Wow, thank you! What else did you bring?", getReply(npc));
     
      en.stepTest(player, itemName);
      assertEquals("You're terribly forgetful, you already brought that one to me.", getReply(npc));
    }
   
    // check the message again now that it has changed
    en.stepTest(player, "cloaks");
    assertEquals(stillWantedMessage(player), getReply(npc));
   
    // Give the last one too. Try lying first again just to be sure
    final String lastCloak = CLOAKS.get(0);
    en.stepTest(player, lastCloak);
    assertEquals("Oh, I'm disappointed. You don't really have "
        + Grammar.a_noun(lastCloak) + " with you.", getReply(npc));
    final Item cloak = new Item(lastCloak, "", "", null);
    player.getSlot("bag").add(cloak);
    en.stepTest(player, lastCloak);
    assertEquals("Answer to last brought cloak", "Oh, yay! You're so kind, I bet you'll have great Karma now! Here, take these killer boots. I think they're gorgeous but they don't fit me!", getReply(npc));
   
    // check the rewards
    assertEquals(karma + 5.0 + 100.0, player.getKarma(), 0.01);
    assertEquals(100000, player.getXP());
View Full Code Here

  public final void compatibility() {
    SingletonRepository.getNPCList().add(new SpeakerNPC(NPC));
    final CloakCollector2 cc = new CloakCollector2();
    cc.addToWorld();
    final SpeakerNPC npc = cc.npcs.get(NPC);
    final Engine en = npc.getEngine();
    final Player player = PlayerTestHelper.createPlayer("player");
   
    player.setQuest(OLD_QUEST, "done");
    player.setQuest(QUEST_NAME, "done");
   
    en.stepTest(player, ConversationPhrases.GREETING_MESSAGES.get(0));
    assertEquals("Message for the compatibility hack""Oh! I didn't reward you for helping me again! Here, take these boots. I think they're gorgeous but they don't fit me :(", getReply(npc));
    assertEquals("done;rewarded", player.getQuest(QUEST_NAME));
    assertTrue("The player got the boots", player.isEquipped("killer boots"));
   
    final Item boots = player.getFirstEquipped("killer boots");
View Full Code Here

   */
  @Test
  public void testHiAndBye() {
    final SpeakerNPC npc = getNPC("Granny Graham");
    assertNotNull(npc);
    final Engine en = npc.getEngine();

    assertTrue(en.step(player, "hello"));
    assertEquals("Hello, dear.", getReply(npc));

    assertTrue(en.step(player, "bye"));
    assertEquals("Bye now.", getReply(npc));
  }
View Full Code Here

   * Tests for MakeTea.
   */
  @Test
  public void testMakeTea() {
    final SpeakerNPC npc = getNPC("Granny Graham");
    final Engine en = npc.getEngine();

    assertTrue(en.step(player, "hi"));
    assertEquals("Hello, dear.", getReply(npc));

    assertTrue(en.step(player, "job"));
    assertEquals("I'm the housekeeper here. I can #brew you a nice cup of #tea, if you like.", getReply(npc));

    assertTrue(en.step(player, "offer"));
    assertEquals("I will #brew you a hot cup of #tea, if you like.", getReply(npc));

    assertTrue(en.step(player, "quest"));
    assertEquals("I have such a headache and little Annie shrieking every time she goes down the slide doesn't help. Maybe you could give her something to keep her occupied? ... like a gag ...", getReply(npc));

    assertTrue(en.step(player, "tea"));
    assertEquals("It's the very best drink of all. I sweeten mine with #honey. Just ask if you'd like a #brew.", getReply(npc));

    assertTrue(en.step(player, "brew"));
    assertEquals("I can only brew a cup of tea if you bring me a #'bottle of milk' and a #'jar of honey'.", getReply(npc));

    assertTrue(en.step(player, "milk"));
    assertEquals("Well my dear, I expect you can get milk from a farm.", getReply(npc));

    assertTrue(en.step(player, "bottle of milk"));
    assertEquals("Well my dear, I expect you can get milk from a farm.", getReply(npc));

    assertTrue(en.step(player, "honey"));
    assertEquals("Don't you know the beekeeper of Fado Forest?", getReply(npc));

    assertTrue(en.step(player, "jar of honey"));
    assertEquals("Don't you know the beekeeper of Fado Forest?", getReply(npc));

    assertFalse(player.isEquipped("tea"));

    PlayerTestHelper.equipWithItem(player, "milk");
    PlayerTestHelper.equipWithItem(player, "honey");

    assertTrue(en.step(player, "brew"));
    assertEquals("I need you to fetch me a #'bottle of milk' and a #'jar of honey' for this job. Do you have it?", getReply(npc));

    assertTrue(en.step(player, "no"));
    assertEquals("OK, no problem.", getReply(npc));

    assertTrue(en.step(player, "brew"));
    assertEquals("I need you to fetch me a #'bottle of milk' and a #'jar of honey' for this job. Do you have it?", getReply(npc));

    assertTrue(en.step(player, "yes"));
    assertEquals("OK, I will brew a cup of tea for you, but that will take some time. Please come back in 3 minutes.", getReply(npc));
    assertFalse(player.isEquipped("tea"));

    assertTrue(en.step(player, "bye"));
    assertEquals("Bye now.", getReply(npc));

    // wait one minute
    setPastTime(player, QUEST_SLOT, 2, 1*60);

    assertTrue(en.step(player, "hi"));
    assertEquals("Welcome back! I'm still busy with your order to brew a cup of tea for you. Come back in 2 minutes to get it.", getReply(npc));

    assertTrue(en.step(player, "bye"));
    assertEquals("Bye now.", getReply(npc));

    // wait three minutes
    setPastTime(player, QUEST_SLOT, 3, 4*60);

    assertTrue(en.step(player, "hi"));
    assertEquals("Welcome back! I'm done with your order. Here you have the cup of tea.", getReply(npc));

    assertTrue(player.isEquipped("tea", 1));

    assertTrue(en.step(player, "bye"));
    assertEquals("Bye now.", getReply(npc));
  }
View Full Code Here

   */
  @Test
  public void testHiAndBye() {
    final SpeakerNPC npc = getNPC("Sam");
    assertNotNull(npc);
    final Engine en = npc.getEngine();

    assertTrue(en.step(player, "hello"));
    assertEquals("Hi. Can I #offer you an ice cream?", getReply(npc));

    assertTrue(en.step(player, "bye"));
    assertEquals("Bye, enjoy your day!", getReply(npc));
  }
View Full Code Here

   * Tests for buyIceCream.
   */
  @Test
  public void testBuyIceCream() {
    final SpeakerNPC npc = getNPC("Sam");
    final Engine en = npc.getEngine();

    assertTrue(en.step(player, "hi"));
    assertEquals("Hi. Can I #offer you an ice cream?", getReply(npc));

    assertTrue(en.step(player, "job"));
    assertEquals("I sell delicious ice creams.", getReply(npc));

    assertTrue(en.step(player, "offer"));
    assertEquals("I sell ice cream.", getReply(npc));

    assertTrue(en.step(player, "quest"));
    assertEquals("Mine's a simple life, I don't need a lot.", getReply(npc));

    assertTrue(en.step(player, "buy"));
    assertEquals("An ice cream will cost 30. Do you want to buy it?", getReply(npc));
    assertTrue(en.step(player, "no"));
    assertEquals("Ok, how else may I help you?", getReply(npc));

    assertTrue(en.step(player, "buy dog"));
    assertEquals("Sorry, I don't sell dogs.", getReply(npc));

    assertTrue(en.step(player, "buy house"));
    assertEquals("Sorry, I don't sell houses.", getReply(npc));

    assertTrue(en.step(player, "buy someunknownthing"));
    assertEquals("Sorry, I don't sell someunknownthings.", getReply(npc));

    assertTrue(en.step(player, "buy a bunch of socks"));
    assertEquals("Sorry, I don't sell bunches of socks.", getReply(npc));

    assertTrue(en.step(player, "buy 0 ice creams"));
    assertEquals("Sorry, how many ice creams do you want to buy?!", getReply(npc));

    assertTrue(en.step(player, "buy ice cream"));
    assertEquals("An ice cream will cost 30. Do you want to buy it?", getReply(npc));

    assertTrue(en.step(player, "no"));
    assertEquals("Ok, how else may I help you?", getReply(npc));

    assertTrue(en.step(player, "buy ice cream"));
    assertEquals("An ice cream will cost 30. Do you want to buy it?", getReply(npc));

    assertTrue(en.step(player, "yes"));
    assertEquals("Sorry, you don't have enough money!", getReply(npc));

    // equip with enough money to buy two ice creams
    assertTrue(equipWithMoney(player, 60));

    assertTrue(en.step(player, "buy three icecreams"));
    assertEquals("3 ice creams will cost 90. Do you want to buy them?", getReply(npc));

    assertTrue(en.step(player, "yes"));
    assertEquals("Sorry, you don't have enough money!", getReply(npc));

    assertTrue(en.step(player, "buy ice cream"));
    assertEquals("An ice cream will cost 30. Do you want to buy it?", getReply(npc));

    assertFalse(player.isEquipped("ice cream"));

    assertTrue(en.step(player, "yes"));
    assertEquals("Congratulations! Here is your ice cream!", getReply(npc));
    assertTrue(player.isEquipped("icecream", 1));

    assertTrue(en.step(player, "buy icecream"));
    assertEquals("An ice cream will cost 30. Do you want to buy it?", getReply(npc));

    assertTrue(en.step(player, "yes"));
    assertEquals("Congratulations! Here is your ice cream!", getReply(npc));
    assertTrue(player.isEquipped("icecream", 2));

    assertTrue(en.step(player, "buy 0 ice creams"));
    assertEquals("Sorry, how many ice creams do you want to buy?!", getReply(npc));

    // buying one ice cream by answering "yes" to npc's greeting
    assertTrue(equipWithMoney(player, 30));   
    assertTrue(en.step(player, "bye"));
    assertEquals("Bye, enjoy your day!", getReply(npc));
    assertTrue(en.step(player, "hi"));
    assertEquals("Hi. Can I #offer you an ice cream?", getReply(npc));   
    assertTrue(en.step(player, "yes"));
    assertEquals("An ice cream will cost 30. Do you want to buy it?", getReply(npc));
    assertTrue(en.step(player, "yes"));
    assertEquals("Congratulations! Here is your ice cream!", getReply(npc));
    assertTrue(player.isEquipped("icecream", 3));   
  }
View Full Code Here

   * Tests for buying.
   */
  @Test
  public void testBuy() {
    final SpeakerNPC npc = getNPC("Granny Graham");
    final Engine en = npc.getEngine();

    assertTrue(en.step(player, "hi Granny Graham"));
    assertEquals("Hello, dear.", getReply(npc));

    // Currently there are no response to buy sentences for Granny Graham.
    assertFalse(en.step(player, "buy"));

    assertTrue(en.step(player, "bye"));
    assertEquals("Bye now.", getReply(npc));
  }
View Full Code Here

   * Tests for selling.
   */
  @Test
  public void testSell() {
    final SpeakerNPC npc = getNPC("Granny Graham");
    final Engine en = npc.getEngine();

    assertTrue(en.step(player, "hi Granny Graham"));
    assertEquals("Hello, dear.", getReply(npc));

    // Currently there are no response to sell sentences for Granny Graham.
    assertFalse(en.step(player, "sell"));

    assertTrue(en.step(player, "bye"));
    assertEquals("Bye now.", getReply(npc));
  }
View Full Code Here

   * Tests for sellIceCream.
   */
  @Test
  public void testSellIceCream() {
    final SpeakerNPC npc = getNPC("Sam");
    final Engine en = npc.getEngine();

    assertTrue(en.step(player, "hi Sam"));
    assertEquals("Hi. Can I #offer you an ice cream?", getReply(npc));

    // Currently there are no response to sell sentences for Sam.
    assertFalse(en.step(player, "sell"));
  }
View Full Code Here

TOP

Related Classes of games.stendhal.server.entity.npc.fsm.Engine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.