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

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


    final BarMaidNPC barmaidConfigurator = new BarMaidNPC();
    final StendhalRPZone zone = new StendhalRPZone("testzone");
    barmaidConfigurator.configureZone(zone, null);
    final SpeakerNPC barMaid = (SpeakerNPC) zone.getNPCList().get(0);
    assertThat(barMaid.getName(), is("Siandra"));
    final Engine engine = barMaid.getEngine();
    engine.setCurrentState(ConversationStates.ATTENDING);

    Sentence sentence = new SentenceImplementation(new Expression("offer", ExpressionType.VERB));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.ATTENDING));
    assertThat("offer text", getReply(barMaid), equalTo("I buy pieces of cheese, pieces of meat, spinaches, pieces of ham, sacks of flour, and porcini."));

    final Expression sell = new Expression("sell", ExpressionType.VERB);

    sentence = new SentenceImplementation(sell);
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.ATTENDING));
    assertThat("offer text", getReply(barMaid), is("Please tell me what you want to sell."));

    sentence = new SentenceImplementation(sell, new Expression("cheese", ExpressionType.OBJECT));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("A piece of cheese is worth 5. Do you want to sell it?"));
    engine.setCurrentState(ConversationStates.ATTENDING);

    sentence = new SentenceImplementation(sell, new Expression("meat", ExpressionType.OBJECT));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("A piece of meat is worth 10. Do you want to sell it?"));

    engine.setCurrentState(ConversationStates.ATTENDING);
    sentence = new SentenceImplementation(sell, new Expression("spinach", ExpressionType.OBJECT));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("A spinach is worth 15. Do you want to sell it?"));

    engine.setCurrentState(ConversationStates.ATTENDING);
    sentence = new SentenceImplementation(sell, new Expression("ham", ExpressionType.OBJECT));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("A piece of ham is worth 20. Do you want to sell it?"));

    engine.setCurrentState(ConversationStates.ATTENDING);
    sentence = new SentenceImplementation(sell, new Expression("flour", ExpressionType.OBJECT));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("A sack of flour is worth 25. Do you want to sell it?"));

    engine.setCurrentState(ConversationStates.ATTENDING);
    sentence = new SentenceImplementation(sell, new Expression("porcini", ExpressionType.OBJECT));
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("A porcino is worth 30. Do you want to sell it?"));

    engine.setCurrentState(ConversationStates.ATTENDING);
    final Expression porcini = new Expression("porcini", ExpressionType.OBJECT);
    porcini.setAmount(2);
    sentence = new SentenceImplementation(sell, porcini);
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("2 porcini are worth 60. Do you want to sell them?"));

    engine.setCurrentState(ConversationStates.ATTENDING);
    final Expression flour = new Expression("flour", ExpressionType.OBJECT);
    flour.setAmount(2);
    sentence = new SentenceImplementation(sell, flour);
    engine.step(PlayerTestHelper.createPlayer("bob"), sentence);
    assertThat(engine.getCurrentState(), is(ConversationStates.SELL_PRICE_OFFERED));
    assertThat("offer text", getReply(barMaid), is("2 sacks of flour are worth 50. Do you want to sell them?"));
  }
View Full Code Here


    final StendhalRPZone zone = new StendhalRPZone("zone");
    final AdosDeathmatch adm = new AdosDeathmatch(zone, new Area(zone, 0, 0, 1, 1));
    adm.createNPC("th", 0, 0);
    final SpeakerNPC th = NPCList.get().get("th");
    assertNotNull(th);
    final Engine en = th.getEngine();
    final Player player = PlayerTestHelper.createPlayer("bob");
    en.setCurrentState(ConversationStates.ATTENDING);
    en.step(player, "bail");
    assertEquals("Coward, you haven't even #started!", getReply(th));
    th.put("text", "");
  }
View Full Code Here

    final StendhalRPZone zone = new StendhalRPZone("zone");
    final AdosDeathmatch adm = new AdosDeathmatch(zone, new Area(zone, 0, 0, 1, 1));
    adm.createNPC("th", 0, 0);
    final SpeakerNPC th = NPCList.get().get("th");
    assertNotNull(th);
    final Engine en = th.getEngine();
    final Player player = PlayerTestHelper.createPlayer("bob");
    en.setCurrentState(ConversationStates.ATTENDING);
    player.setQuest("deathmatch", "done");
    en.step(player, "bail");
    assertEquals("Coward, we haven't even #started!", getReply(th));
    th.put("text", "");

  }
View Full Code Here

    final StendhalRPZone zone = new StendhalRPZone("zone");
    final AdosDeathmatch adm = new AdosDeathmatch(zone, new Area(zone, 0, 0, 1, 1));
    adm.createNPC("th", 0, 0);
    final SpeakerNPC th = NPCList.get().get("th");
    assertNotNull(th);
    final Engine en = th.getEngine();
    final Player player = PlayerTestHelper.createPlayer("bob");
    en.setCurrentState(ConversationStates.ATTENDING);
    player.setQuest("deathmatch", "start");
    en.step(player, "bail");
    assertEquals("Coward! You're not as experienced as you used to be.", getReply(th));
    th.put("text", "");
  }
View Full Code Here

    quest.setNpc(npc);
    final BringListOfItemsQuestLogic logic = new BringListOfItemsQuestLogic(quest);
    logic.addToWorld();

    final Player player = PlayerTestHelper.createPlayer("player");
    final Engine en = npc.getEngine();
    en.step(player, "hi");
    assertTrue(npc.isTalking());
    assertEquals("first hi", quest.welcomeBeforeStartingQuest(), getReply(npc));
    npc.put("text", "");

    en.step(player, ConversationPhrases.QUEST_MESSAGES.get(0));
    assertEquals("answer to quest", quest.respondToQuest(), getReply(npc));

    en.step(player, "no");
    assertEquals("answer to quests accepted", quest.respondToQuestRefusal(), getReply(npc));
  }
View Full Code Here

  @Test
  public void testRingIsboundAfterfix() {
    RingMaker rm = new RingMaker();
    SpeakerNPC testNpc = new SpeakerNPC("jack");
    rm.fixRingStep(testNpc);
    Engine engine = testNpc.getEngine();
    engine.setCurrentState(ConversationStates.ATTENDING);
    Player bob = PlayerTestHelper.createPlayer("bob");
    bob.setQuest(QUEST_SLOT, "forging;0");
    assertTrue(engine.step(bob, "life"));
    assertTrue(bob.isEquipped("emerald ring"));
    assertTrue(bob.getFirstEquipped("emerald ring").isBound());
  }
View Full Code Here

  @Test
  public void testRingIsUnboundAfterfix() {
    RingMaker rm = new RingMaker();
    SpeakerNPC testNpc = new SpeakerNPC("jack");
    rm.fixRingStep(testNpc);
    Engine engine = testNpc.getEngine();
    engine.setCurrentState(ConversationStates.ATTENDING);
    Player bob = PlayerTestHelper.createPlayer("bob");
    bob.setQuest(QUEST_SLOT, "forgingunbound;0");
    assertTrue(engine.step(bob, "life"));
    assertTrue(bob.isEquipped("emerald ring"));
    assertFalse(bob.getFirstEquipped("emerald ring").isBound());
  }
View Full Code Here

    RingMaker rm = new RingMaker();
    SpeakerNPC testNpc = new SpeakerNPC("jack");
    Player hasnoRingPlayer = PlayerTestHelper.createPlayer("hasnoRingPlayer");
   
    rm.fixRingStep(testNpc);
    Engine engine = testNpc.getEngine();
    engine.setCurrentState(ConversationStates.ATTENDING);
      //queststate may not start with forging
    hasnoRingPlayer.setQuest(QUEST_SLOT, "doesnotstartwithforging");
    assertTrue(engine.step(hasnoRingPlayer, "life"));
    assertThat(getReply(testNpc), is("It is difficult to get the ring of life. Do a favour for a powerful elf in Nal'wor and you may receive one as a reward."));
    assertThat(engine.getCurrentState(), is(ConversationStates.ATTENDING));

    assertFalse(hasnoRingPlayer.isEquipped("emerald ring"));
   
  }
View Full Code Here

  }

  @Test
  public void testQuest() { 
    SpeakerNPC henry = SingletonRepository.getNPCList().get("Henry");
    Engine en1 = henry.getEngine();

    SpeakerNPC james = SingletonRepository.getNPCList().get("Sergeant James");
    Engine en2 = james.getEngine();

    // talk with Henry
    en1.step(player, "hi");
    assertEquals("Ssshh! Silence or you will attract more #dwarves.", getReply(henry));
    en1.step(player, "dwarves");
    assertEquals("They are everywhere! Their #kingdom must be close.", getReply(henry));
    en1.step(player, "kingdom");
    assertEquals("Kanmararn, the legendary city of the #dwarves.", getReply(henry));
    en1.step(player, "dwarves");
    assertEquals("They are everywhere! Their #kingdom must be close.", getReply(henry));
    en1.step(player, "kingdom");
    assertEquals("Kanmararn, the legendary city of the #dwarves.", getReply(henry));
    en1.step(player, "job");
    assertEquals("I'm a soldier in the army.", getReply(henry));
    en1.step(player, "offer");
    en1.step(player, "help");
    assertEquals("I need help myself. I got separated from my #group. Now I'm all alone.", getReply(henry));
    en1.step(player, "group");
    assertEquals("The General sent five of us to explore this area in search for #treasure.", getReply(henry));
    en1.step(player, "treasure");
    assertEquals("A big treasure is rumored to be #somewhere in this dungeon.", getReply(henry));
    en1.step(player, "somewhere");
    assertEquals("If you #help me I might give you a clue.", getReply(henry));
    en1.step(player, "help");
    assertEquals("I need help myself. I got separated from my #group. Now I'm all alone.", getReply(henry));
    en1.step(player, "group");
    assertEquals("The General sent five of us to explore this area in search for #treasure.", getReply(henry));
    en1.step(player, "task");
    assertEquals("Find my #group, Peter, Tom, and Charles, prove it and I will reward you. Will you do it?", getReply(henry));
    en1.step(player, "group");
    assertEquals("The General sent five of us to explore this area in search for #treasure. So, will you help me find them?", getReply(henry));
    en1.step(player, "no");
    assertEquals("OK. I understand. I'm scared of the #dwarves myself.", getReply(henry));
    en1.step(player, "task");
    assertEquals("Find my #group, Peter, Tom, and Charles, prove it and I will reward you. Will you do it?", getReply(henry));
    en1.step(player, "group");
    assertEquals("The General sent five of us to explore this area in search for #treasure. So, will you help me find them?", getReply(henry));
    en1.step(player, "yes");
    assertEquals("Thank you! I'll be waiting for your return.", getReply(henry));
    en1.step(player, "task");
    assertEquals("Find my #group, Peter, Tom, and Charles, prove it and I will reward you. Will you do it?", getReply(henry));
    en1.step(player, "yes");
    assertEquals("Thank you! I'll be waiting for your return.", getReply(henry));
    en1.step(player, "map");
    assertEquals("If you find my friends, I will give you the map.", getReply(henry));
    en1.step(player, "treasure");
    assertEquals("A big treasure is rumored to be #somewhere in this dungeon.", getReply(henry));
    en1.step(player, "dwarves");
    assertEquals("They are everywhere! Their #kingdom must be close.", getReply(henry));
    en1.step(player, "kingodom");
    assertEquals("Kanmararn, the legendary city of the #dwarves.", getReply(henry));
    en1.step(player, "bye");
    assertEquals("Bye and be careful with all those dwarves around!", getReply(henry));

    en1.step(player, "hi");
    assertEquals("You didn't prove that you have found them all!", getReply(henry));
    en1.step(player, "bye");
    assertEquals("Bye and be careful with all those dwarves around!", getReply(henry));

    // You see the cold corpse of Peter. You can inspect it to see its contents.
    // You see a slightly rusty scale armor. It is heavily deformed by several strong hammer blows. Stats are (DEF: 7).
    // take scale armor with me
    PlayerTestHelper.equipWithItem(player, "scale armor", "peter");
   
    // You see the rotten corpse of Tom. You can inspect it to see its contents.
    // take leather legs with me
    // You see torn leather legs that are heavily covered with blood. Stats are (DEF: 1).
    PlayerTestHelper.equipWithItem(player, "leather legs", "tom");


    // now talk with James
    en2.step(player, "hi");
    assertEquals("Good day, adventurer!", getReply(james));
    en2.step(player, "map");
    assertEquals("The #treasure map that leads into the heart of the #dwarven #kingdom.", getReply(james));
    en2.step(player, "treasure");
    assertEquals("A big treasure is rumored to be somewhere in this dungeon.", getReply(james));
    en2.step(player, "dwarven kingdom");
    assertEquals("They are strong enemies! We're in their #kingdom.", getReply(james));
    en2.step(player, "kingdom");
    assertEquals("Kanmararn, the legendary kingdom of the #dwarves.", getReply(james));
    en2.step(player, "dwarves");
    assertEquals("They are strong enemies! We're in their #kingdom.", getReply(james));
    en2.step(player, "dwarven kingdom");
    assertEquals("They are strong enemies! We're in their #kingdom.", getReply(james));
    en2.step(player, "bye");
    assertEquals("Good luck and better watch your back with all those dwarves around!", getReply(james));

    en2.step(player, "hi");
    assertEquals("Good day, adventurer!", getReply(james));
    en2.step(player, "task");
    assertEquals("Find my fugitive soldier and bring him to me ... or at least the #map he's carrying.", getReply(james));
    en2.step(player, "bye");
    assertEquals("Good luck and better watch your back with all those dwarves around!", getReply(james));
    // You see the slightly rotten corpse of Charles. You can inspect it to see its contents.
    // You read: "IOU 250 money. (signed) McPegleg"
    // take IOU with me
    PlayerTestHelper.equipWithItem(player, "note", "charles");
    en2.step(player, "hi");

    // drop leather legs for testing
    player.drop("leather legs");

    en1.step(player, "hi");
    assertEquals("You didn't prove that you have found them all!", getReply(henry));
    en1.step(player, "bye");
    assertEquals("Bye and be careful with all those dwarves around!", getReply(henry));

    // take legs up again
    PlayerTestHelper.equipWithItem(player, "leather legs", "tom");

    assertFalse(player.isEquipped("map"));
    assertEquals(0, player.getXP());

    // back to Henry
    en1.step(player, "hi");
    assertEquals("Oh my! Peter, Tom, and Charles are all dead? *cries*. Anyway, here is your reward. And keep the IOU.", getReply(henry));
    // player earns 2500 experience points.
    assertEquals(2500, player.getXP());
    // You see a hand drawn map, but no matter how you look at it, nothing on it looks familiar.
    assertTrue(player.isEquipped("map"));
    assertEquals("map", player.getQuest(questSlot, 0));
    en1.step(player, "bye");
    assertEquals("Bye and be careful with all those dwarves around!", getReply(henry));

    // back to James
    en2.step(player, "hi");
    assertEquals("Good day, adventurer!", getReply(james));
    en2.step(player, "map");
    assertEquals("The map! Wonderful! Thank you. And here is your reward.", getReply(james));
    // player earns 5000 experience points.
    assertEquals(7500, player.getXP());
    // You see a pair of steel boots, fit for any soldier. It is a special quest reward for player, and cannot be used by others. Stats are (DEF: 6).
    assertTrue(player.isEquipped("steel boots"));
    en2.step(player, "bye");
    assertEquals("Good luck and better watch your back with all those dwarves around!", getReply(james));

    // back to Henry
    en1.step(player, "hi");
    assertEquals("Ssshh! Silence or you will attract more #dwarves.", getReply(henry));
View Full Code Here

  public final void missingPreviousQuest() {   
    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");
   
    /*
     * Josephine should have nothing to say to us, unless we have completed
     * cloaks_collector quest. Those people would be getting the answer from
     *  that quest.
     */
    en.stepTest(player, ConversationPhrases.GREETING_MESSAGES.get(0));
    assertEquals("Josephines answer to non cloak1 people", null, getReply(npc));   
  }
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.