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

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


    quest.addToWorld();
    final Player pl = PlayerTestHelper.createPlayer("joe");
    assertFalse(quest.isStarted(pl));
    assertFalse(quest.isCompleted(pl));

    final Engine jynathEngine = jynath.getEngine();
    jynathEngine.step(pl, "Hi");
    assertTrue(jynath.isTalking());
    assertEquals("Greetings! How may I help you?", getReply(jynath));

    jynathEngine.step(pl, "book");
    assertTrue(jynath.isTalking());
    assertEquals(
        "Sssh! I'm concentrating on this potion recipe... it's a tricky one.",
        getReply(jynath));

    jynathEngine.step(pl, "bye");
    assertFalse(jynath.isTalking());
  }
View Full Code Here


 
    quest.addToWorld();
    final Player pl = PlayerTestHelper.createPlayer("joe");
    pl.setQuest(CERYL_BOOK, "jynath");

    final Engine cerylEngine = ceryl.getEngine();
    cerylEngine.step(pl, "Hi");
    assertTrue(ceryl.isTalking());
    assertEquals(
        "Haven't you got that #book back from #Jynath? Please go look for it, quickly!",
        getReply(ceryl));
View Full Code Here

 
    quest.addToWorld();
    final Player pl = PlayerTestHelper.createPlayer("player");
    assertFalse(quest.isStarted(pl));
    assertFalse(quest.isCompleted(pl));
    final Engine cerylEngine = ceryl.getEngine();
    cerylEngine.step(pl, "Hi");
    assertTrue(ceryl.isTalking());
    assertEquals("Greetings! How may I help you?", getReply(ceryl));
    cerylEngine.step(pl, ConversationPhrases.QUEST_MESSAGES.get(0));
    assertTrue(ceryl.isTalking());
    assertEquals("I am looking for a very special #book.",
        getReply(ceryl));
    cerylEngine.step(pl, "book");
    assertTrue(ceryl.isTalking());
    assertEquals(
        "Could you ask #Jynath to return her book? She's had it for months now, and people are looking for it.",
        getReply(ceryl));
    cerylEngine.step(pl, ConversationPhrases.YES_MESSAGES.get(0));
    assertTrue(ceryl.isTalking());
    assertEquals(
        "Great! Please get me it as quickly as possible... there's a huge waiting list!",
        getReply(ceryl));
    assertEquals("start", pl.getQuest(LookBookforCerylTest.CERYL_BOOK));
    cerylEngine.step(pl, "book");
    assertTrue(ceryl.isTalking());
    assertEquals("I really need that book now! Go to talk with #Jynath.",
        getReply(ceryl));
    cerylEngine.step(pl, ConversationPhrases.GOODBYE_MESSAGES.get(0));
    assertFalse(ceryl.isTalking());
    final Engine jynathEngine = jynath.getEngine();
    jynathEngine.step(pl, "Hi");
    assertTrue(jynath.isTalking());
    assertEquals(
        "Oh, Ceryl's looking for that book back? My goodness! I completely forgot about it... here you go!",
        getReply(jynath));
    assertTrue(pl.isEquipped("black book"));
    jynathEngine.step(pl, "bye");
    assertFalse(jynath.isTalking());

    jynathEngine.step(pl, "Hi");
    assertTrue(jynath.isTalking());
    assertEquals(
        "You'd better take that book back to #Ceryl quickly... he'll be waiting for you.",
        getReply(jynath));

    jynathEngine.step(pl, "bye");
    assertFalse(jynath.isTalking());

    cerylEngine.step(pl, "Hi");
    assertTrue(ceryl.isTalking());
    assertEquals("Oh, you got the book back! Phew, thanks!",
View Full Code Here

    SingletonRepository.getNPCList().add(new SpeakerNPC("Balduin"));
    final WeaponsCollector wc = new WeaponsCollector();
 
    wc.addToWorld();
    final SpeakerNPC npc = wc.getNPC();
    final Engine en = npc.getEngine();
    final Player pl = PlayerTestHelper.createPlayer("player");

    assertTrue(en.stepTest(pl, "hi"));
    assertEquals(wc.welcomeBeforeStartingQuest(), getReply(npc));

    assertTrue(en.stepTest(pl, "quest"));
    assertEquals(wc.respondToQuest(), getReply(npc));

    assertTrue(en.stepTest(pl, "no"));
    assertEquals(wc.respondToQuestRefusal(), getReply(npc));
  }
View Full Code Here

    SingletonRepository.getNPCList().add(new SpeakerNPC("Balduin"));
    final WeaponsCollector wc = new WeaponsCollector();

    wc.addToWorld();
    final SpeakerNPC npc = wc.getNPC();
    final Engine en = npc.getEngine();
    final Player pl = PlayerTestHelper.createPlayer("pl");

    assertTrue(en.stepTest(pl, "hello"));
    assertEquals(wc.welcomeBeforeStartingQuest(), getReply(npc));

    assertTrue(en.stepTest(pl, "quest"));
    assertEquals(wc.respondToQuest(), getReply(npc));

    assertTrue(en.stepTest(pl, "collection"));
    assertEquals(wc.firstAskForMissingItems(wc.getNeededItems()), getReply(npc));

    assertTrue(en.stepTest(pl, "yes"));
    assertEquals(wc.respondToQuestAcception(), getReply(npc));

    //npc has stopped conversation

    assertTrue("the quest was accepted, so it should be started", wc.isStarted(pl));
    assertFalse(wc.isCompleted(pl));

    assertTrue(en.stepTest(pl, ConversationPhrases.GREETING_MESSAGES.get(0)));
    assertEquals(wc.welcomeDuringActiveQuest(), getReply(npc));
    npc.remove("text");
    en.stepTest(pl, ConversationPhrases.YES_MESSAGES.get(0));
    assertEquals(wc.askForItemsAfterPlayerSaidHeHasItems(), getReply(npc));

    en.stepTest(pl, "bardiche");
    assertEquals(wc.respondToOfferOfNotExistingItem("bardiche"), getReply(npc));

        Item cloak = new Item("bardiche", "", "", null);
    pl.getSlot("bag").add(cloak);

    assertTrue(en.stepTest(pl, "bardiche"));
    assertEquals(wc.respondToItemBrought(), getReply(npc));

    assertTrue(en.stepTest(pl, "bardiche"));
    assertEquals(wc.respondToOfferOfNotMissingItem(), getReply(npc));

    cloak = new Item("stone cloak", "", "", null);
    pl.getSlot("bag").add(cloak);

    for (final String cloakName : wc.getNeededItems()) {
      cloak = new Item(cloakName, "", "", null);
      pl.getSlot("bag").add(cloak);
      assertTrue(en.step(pl, cloakName));
    }

    assertEquals(wc.respondToLastItemBrought(), getReply(npc));
    assertTrue(wc.isCompleted(pl));
    assertTrue(npc.isTalking());
View Full Code Here

  @Test
  public void quest() {
 
    final Player player = PlayerTestHelper.createPlayer("player");

    final Engine en = hayunn.getEngine();
    en.step(player, "hi");
    // we assume the player has already completed the meet hayunn quest
    // so that we know which of the greetings he will use
    player.setQuest("meet_hayunn", "done");
    assertTrue(player.isQuestCompleted("meet_hayunn"));
    assertTrue(hayunn.isTalking());
    assertEquals(
        "Hi. I bet you've been sent here to learn about adventuring from me. First, lets see what you're made of. Go and kill a rat outside, you should be able to find one easily. Do you want to learn how to attack it, before you go?",
        getReply(hayunn));
    en.step(player, "quest");
    assertEquals(
        "My mouth is dry, but I can't be seen to abandon this teaching room! Could you bring me some #beer from the #tavern?",
        getReply(hayunn));
    en.step(player, "yes");
    assertTrue(player.hasQuest("beer_hayunn"));
    en.step(player, "bye");
    assertFalse(hayunn.isTalking());
    assertEquals("start", player.getQuest("beer_hayunn"));
    final StackableItem beer = new StackableItem("beer", "", "", null);
    beer.setQuantity(1);
    beer.setID(new ID(2, "testzone"));
    player.getSlot("bag").add(beer);
    assertEquals(1, player.getNumberOfEquipped("beer"));
    en.step(player, "hi");
    en.step(player, "yes");
    assertEquals("done", player.getQuest("beer_hayunn"));
    en.step(player, "bye");
    // reject
    final Player player2 = PlayerTestHelper.createPlayer("player");

    en.step(player2, "hi");
    player2.setQuest("meet_hayunn", "done");
    assertTrue(player2.isQuestCompleted("meet_hayunn"));
    assertTrue(hayunn.isTalking());
    assertEquals(
      "Hi. I bet you've been sent here to learn about adventuring from me. First, lets see what you're made of. Go and kill a rat outside, you should be able to find one easily. Do you want to learn how to attack it, before you go?",
        getReply(hayunn));
    en.step(player2, "quest");
    assertEquals(
        "My mouth is dry, but I can't be seen to abandon this teaching room! Could you bring me some #beer from the #tavern?",
        getReply(hayunn));
    en.step(player2, "no");
    assertTrue(player2.hasQuest("beer_hayunn"));
    assertEquals("rejected", player2.getQuest("beer_hayunn"));
    en.step(player2, "bye");
  }
View Full Code Here

   * Tests for athorNPC.
   */
  @Test
  public void testAthorNPC() {
    final SpeakerNPC npc = getNPC("Cyk");
    final Engine en = npc.getEngine();
    player.setAge(3700000);
   
    en.step(player, "hi");
    assertEquals("Hello, player.", getReply(npc));
    en.step(player, "cost");
    assertEquals("What do you want with an apartment on Athor when you're not even a good #fisherman? We are trying to attract owners who will spend time on the island. Come back when you have proved yourself a better fisherman.", getReply(npc));
    en.step(player, "fisherman");
    assertEquals("A fishing license from Santiago in Ados is the sign of a good fisherman, he sets two exams. Once you have passed both parts you are a good fisherman.", getReply(npc));
    // [14:06] Admin player changed your state of the quest 'fishermans_license2' from 'null' to 'done'
    // [14:06] Changed the state of quest 'fishermans_license2' from 'null' to 'done'
    player.setQuest("fishermans_license2", "done");
    en.step(player, "bye");
    assertEquals("Goodbye.", getReply(npc));

    // -----------------------------------------------
    final StackableItem money = (StackableItem)SingletonRepository.getEntityManager().getItem("money");
    money.setQuantity(100000);
    player.equipToInventoryOnly(money);

    en.step(player, "hi");
    assertEquals("Hello, player.", getReply(npc));
    en.step(player, "buy");
    assertEquals("The cost of a new apartment is 100000 money.  Also, you must pay a monthly tax of 1000 money. If you have an apartment in mind, please tell me the number now. I will check availability. Athor Apartments are numbered 101 to 108.", getReply(npc));
   
//     add a portal to the maps so that there's something to check and sell
    Portal destination = new Portal();
    destination.setIdentifier("dest");
    SingletonRepository.getRPWorld().getRPZone(ZONE_NAME).add(destination);
    chest = new StoredChest();
    SingletonRepository.getRPWorld().getRPZone(ZONE_NAME).add(chest);

    for (String zone : CITY_ZONES) {
      assertNotNull(zone);
      HousePortal portal = new HousePortal("athor apartment 101");
      portals.add(portal);
      portal.setDestination(ZONE_NAME, "dest");
      portal.setIdentifier("keep rpzone happy");
      SingletonRepository.getRPWorld().getRPZone(zone).add(portal);
    }

    en.step(player, "101");
    assertEquals("Congratulations, here is your key to athor apartment 101! Make sure you change the locks if you ever lose it. Do you want to buy a spare key, at a price of 1000 money?", getReply(npc));
    en.step(player, "yes");

    assertTrue(player.isEquipped("player's house key"));
   
    Item item = player.getFirstEquipped("player's house key");
    assertNotNull(item);
    assertEquals("athor apartment 101;0;player", item.get("infostring"));
    assertFalse(item.isBound());
   
    player.equip(SingletonRepository.getEntityManager().getItem("money"), 1000);
    assertEquals("Before we go on, I must warn you that anyone with a key to your house can enter it, and access the items in the chest in your house. Do you still wish to buy a spare key?", getReply(npc));
    en.step(player, "yes");

    assertEquals("Here you go, a spare key to your house. Please remember, only give spare keys to people you #really, #really, trust! Anyone with a spare key can access your chest, and tell anyone that you give a key to, to let you know if they lose it. If that happens, you should #change your locks.", getReply(npc));
    // [14:07] You see a key to player's property, athor apartment 101.
    en.step(player, "change");
    assertEquals("If you are at all worried about the security of your house or, don't trust anyone you gave a spare key to, it is wise to change your locks. Do you want me to change your house lock and give you a new key now?", getReply(npc));
    en.step(player, "no");
    assertEquals("OK, if you're really sure. Please let me know if I can help with anything else.", getReply(npc));
    en.step(player, "change");
    assertEquals("If you are at all worried about the security of your house or, don't trust anyone you gave a spare key to, it is wise to change your locks. Do you want me to change your house lock and give you a new key now?", getReply(npc));
    en.step(player, "yes");
    assertEquals("The locks have been changed for athor apartment 101, here is your new key. Do you want to buy a spare key, at a price of 1000 money?", getReply(npc));
    en.step(player, "no");
    assertEquals("No problem! Just so you know, if you need to #change your locks, I can do that, and you can also #resell your house to me if you want to.", getReply(npc));
    en.step(player, "bye");
    assertEquals("Goodbye.", getReply(npc));

    // -----------------------------------------------

    en.step(player, "hi");
    assertEquals("Hello, player. At the cost of 1000 money you can purchase a spare key for your house. Do you want to buy one now?", getReply(npc));
    en.step(player, "no");
    assertEquals("No problem! Just so you know, if you need to #change your locks, I can do that, and you can also #resell your house to me if you want to.", getReply(npc));
    en.step(player, "available");
    assertTrue(getReply(npc).startsWith("According to my records, athor apartment 101, athor apartment 101, athor apartment 101, athor apartment 101, athor apartment 101"));
    en.step(player, "purchase");
    assertEquals("As you already know, the cost of a new house is 100000 money. But you cannot own more than one house, the market is too demanding for that! You cannot own another house until you #resell the one you already own.", getReply(npc));

    en.step(player, "resell");
    assertEquals("The state will pay you 40 percent of the price you paid for your house, minus any taxes you owe. You should remember to collect any belongings from your house before you sell it. Do you really want to sell your house to the state?", getReply(npc));
    en.step(player, "no");
    assertEquals("Well, I'm glad you changed your mind.", getReply(npc));
    en.step(player, "resell");
    assertEquals("The state will pay you 40 percent of the price you paid for your house, minus any taxes you owe. You should remember to collect any belongings from your house before you sell it. Do you really want to sell your house to the state?", getReply(npc));
    en.step(player, "yes");
    assertEquals("Thanks, here is your 40000 money owed, from the house value, minus any owed taxes. Now that you don't own a house you would be free to buy another if you want to.", getReply(npc));
    // one extra athor apartment 101 available :D
    en.step(player, "available");
    assertTrue(getReply(npc).startsWith("According to my records, athor apartment 101, athor apartment 101, athor apartment 101, athor apartment 101, athor apartment 101"));
    en.step(player, "bye");
    assertEquals("Goodbye.", getReply(npc));
  }
View Full Code Here

  public final void rejectQuest() {
    SingletonRepository.getNPCList().add(new SpeakerNPC(NPC));
    final ClubOfThorns quest = new ClubOfThorns();
    quest.addToWorld();
    final SpeakerNPC npc = quest.npcs.get(NPC);
    final Engine en = npc.getEngine();
    final Player player = PlayerTestHelper.createPlayer("player");
    final double karma = player.getKarma();
   
    // Greetings missing. Jump straight to attending
    en.setCurrentState(ConversationStates.ATTENDING);
   
    en.stepTest(player, ConversationPhrases.QUEST_MESSAGES.get(0));
    assertEquals("Make revenge! Kill de Mountain Orc Chief! unnerstand? ok?", getReply(npc));
   
    en.stepTest(player, "no");
    assertEquals("Answer to refusal", "Ugg! i want hooman make #task, kill!", getReply(npc));
    assertEquals("Karma penalty", karma - 6.0, player.getKarma(), 0.01);
  }
View Full Code Here

  public final void doQuest() {
    SingletonRepository.getNPCList().add(new SpeakerNPC(NPC));
    final ClubOfThorns quest = new ClubOfThorns();
    quest.addToWorld();
    final SpeakerNPC npc = quest.npcs.get(NPC);
    final Engine en = npc.getEngine();
    final Player player = PlayerTestHelper.createPlayer("player");
    double karma = player.getKarma();
   
    // Kill a mountain orc chief to to allow checking the slot gets cleaned
    player.setSoloKill(VICTIM);
    // Greetings missing. Jump straight to attending
    en.setCurrentState(ConversationStates.ATTENDING);
   
    en.stepTest(player, ConversationPhrases.QUEST_MESSAGES.get(0));
    assertEquals("Make revenge! Kill de Mountain Orc Chief! unnerstand? ok?", getReply(npc));
   
    // test the stuff that should be done at the quest start
    en.stepTest(player, ConversationPhrases.YES_MESSAGES.get(0));
    assertEquals("Take dat key. he in jail. Kill! Denn, say me #kill! Say me #kill!", getReply(npc));
    assertTrue(player.isEquipped(KEY_NAME));
    assertEquals("player", player.getFirstEquipped(KEY_NAME).getBoundTo());
    assertEquals("Karma bonus for accepting the quest",
      karma + 6.0, player.getKarma(), 0.01);
    assertEquals("start", player.getQuest(QUEST_NAME, 0));
    //assertFalse("Cleaning kill slot", player.hasKilled(VICTIM));
    final String[] questTokens = player.getQuest(QUEST_NAME, 1).split(",");
    assertEquals(questTokens[0],"mountain orc chief");
    assertEquals(questTokens[1],"0");
    assertEquals(questTokens[2],"1");
    assertEquals(Arrays.asList(questTokens).size(), 5);
   
    en.stepTest(player, ConversationPhrases.QUEST_MESSAGES.get(0));
    assertEquals("Make revenge! #Kill Mountain Orc Chief!", getReply(npc));
   
    en.stepTest(player, "kill");
    assertEquals("kill Mountain Orc Chief! Kotoch orcs nid revenge!", getReply(npc));
   
    // Kill a mountain orc chief
    player.setSoloKill("mountain orc chief");
    // Try restarting the task in the middle
    en.stepTest(player, ConversationPhrases.QUEST_MESSAGES.get(0));
    assertEquals("Make revenge! #Kill Mountain Orc Chief!", getReply(npc));
    assertTrue("Keeping the kill slot, while the quest is active", player.hasKilled(VICTIM));
   
    // completion and rewards
    karma = player.getKarma();
    en.stepTest(player, "kill");
    assertEquals("Revenge! Good! Take club of hooman blud.", getReply(npc));
    assertTrue(player.isEquipped("club of thorns"));
    assertEquals("The club is bound", "player", player.getFirstEquipped("club of thorns").getBoundTo());
    assertEquals("Final karma bonus", karma + 10.0, player.getKarma(), 0.01);
    assertEquals("XP", 1000, player.getXP());
    assertEquals("done", player.getQuest(QUEST_NAME));
   
    // don't allow restarting
    en.stepTest(player, ConversationPhrases.QUEST_MESSAGES.get(0));
    assertEquals("Saman has revenged! dis Good!", getReply(npc));
    assertEquals("done", player.getQuest(QUEST_NAME));
  }
View Full Code Here

    final SpeakerNPC recruiter = SingletonRepository.getNPCList().get("Thonatus");
    assertNotNull(recruiter);
    assertNotNull(zone);
    assertNotNull(ados_wall_n);
    final Player dmPlayer = PlayerTestHelper.createPlayer("dmPlayer");
    final Engine en = recruiter.getEngine();
    assertEquals(ConversationStates.IDLE, en.getCurrentState());
    en.step(dmPlayer, "hi");
    assertEquals(ConversationStates.ATTENDING, en.getCurrentState());
    assertEquals("Hey there. You look like a reasonable fighter.", getReply(recruiter));
   
    en.step(dmPlayer, "job");
    assertEquals(ConversationStates.ATTENDING, en.getCurrentState());
    assertEquals("I'm recruiter for the Ados #deathmatch.", getReply(recruiter));
   
    en.step(dmPlayer, "deathmatch");
    assertEquals(ConversationStates.ATTENDING, en.getCurrentState());
    assertEquals("Many dangerous creatures will attack you in the deathmatch arena. It is only for strong #heroes.", getReply(recruiter));
   
   
     dmPlayer.setLevel(19);
     en.step(dmPlayer, "challenge");
     assertEquals(ConversationStates.ATTENDING, en.getCurrentState());
     assertEquals("Sorry, you are too weak for the #deathmatch now, come back when you have at least level 20.", getReply(recruiter));
     recruiter.remove("text");
   
    en.step(dmPlayer, "bye");
    assertEquals(ConversationStates.IDLE, en.getCurrentState());
    assertEquals("I hope you will enjoy the Ados Deathmatch!", getReply(recruiter));
   

   
    dmPlayer.setLevel(20);
    //assertNotNull(dmPlayer.getZone());
    en.step(dmPlayer, "hi");
    assertEquals(ConversationStates.ATTENDING, en.getCurrentState());
    assertEquals("Hey there. You look like a reasonable fighter.", getReply(recruiter));
    recruiter.remove("text");
    en.step(dmPlayer, "challenge");
   
    assertEquals(ConversationStates.IDLE, en.getCurrentState());
    assertEquals(null, getReply(recruiter));
    assertNotNull(dmPlayer.getZone());
    // no players already in zone, send straight in
    assertEquals(ados_wall_n, dmPlayer.getZone());
    assertEquals(100, dmPlayer.getX());
   
    en.setCurrentState(ConversationStates.IDLE);
   
    final Player joiner = PlayerTestHelper.createPlayer("dmPlayer");
    joiner.setLevel(19);
    en.step(joiner, "hi");
    recruiter.remove("text");
    en.step(joiner, "challenge");
    recruiter.remove("text");
    assertEquals(null, joiner.getZone());
    joiner.setLevel(20);
   
    en.step(joiner, "challenge");
    assertEquals("There are heroes battling right now in the deathmatch, so it may be dangerous there. Do you want to join dmPlayer?", getReply(recruiter));
    en.step(joiner, "yes");
    assertEquals(ados_wall_n, joiner.getZone());
   
  }
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.