Package games.stendhal.server.entity.npc.condition

Examples of games.stendhal.server.entity.npc.condition.QuestStateStartsWithCondition


    final SpeakerNPC npc = npcs.get("Ida");

    // player returns who has agreed to help fix machine and prompts ida
    npc.add(ConversationStates.ATTENDING,
        Arrays.asList("sewing", "machine", "sewing machine", "task", "quest"),
        new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "machine"),
        ConversationStates.QUEST_ITEM_QUESTION,
        "My sewing machine is still broken, did you bring anything to fix it?",
        null);

      // we stored the needed part name as part of the quest slot
View Full Code Here


      });

    // player needs eggshells
    npc.add(ConversationStates.ATTENDING,
      Arrays.asList("scissors", "magical", "magical scissors", "ida", "mithril", "cloak", "mithril cloak"),
      new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "need_eggshells"),
      ConversationStates.SERVICE_OFFERED,
      "So, did you bring the items I need for the magical scissors?", null);
                 
    // player asks about eggshells, hint to find terry
    npc.add(
      ConversationStates.ATTENDING,
      "eggshells",
      null,
      ConversationStates.ATTENDING,
      "They must be from dragon eggs. I guess you better find someone who dares to hatch dragons!",
      null);

    // player says yes they brought the items needed
    // we can't use the nice ChatActions here because the needed number is stored in the quest slot i.e. we need a fire
    npc.add(
      ConversationStates.SERVICE_OFFERED,
      ConversationPhrases.YES_MESSAGES,
      new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "need_eggshells"),
      ConversationStates.ATTENDING,
      null,
      new ChatAction() {
        public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
          final String[] questslot = player.getQuest(mithrilcloak.getQuestSlot()).split(";");
          final int neededEggshells = Integer.valueOf(questslot[1]);
          if (player.isEquipped("iron")
            && player.isEquipped("mithril bar")
            && player.isEquipped("magical eggshells", neededEggshells)) {
              player.drop("iron");
              player.drop("mithril bar");
              player.drop("magical eggshells", neededEggshells);
              npc.say("Good. It will take me some time to make these, come back in "
                     + REQUIRED_MINUTES_SCISSORS + " minutes to get your scissors.");
              player.addXP(100);
              player.setQuest(mithrilcloak.getQuestSlot(), "makingscissors;" + System.currentTimeMillis());
              player.notifyWorldAboutChanges();
            } else {
              npc.say("Liar, you don't have everything I need. Ask me about #scissors again when you have an iron bar, a mithril bar, and "
                  + questslot[1] + " magical eggshells. And don't be wasting my time!");
            }
        }
      });

    // player says they didn't bring the stuff yet
    npc.add(
      ConversationStates.SERVICE_OFFERED,
      ConversationPhrases.NO_MESSAGES,
      null,
      ConversationStates.ATTENDING,
      "What are you still here for then? Go get them!",
      null);

    // player returns while hogart is making scissors or has made them
    npc.add(ConversationStates.ATTENDING,
      Arrays.asList("scissors", "magical", "magical scissors", "ida", "mithril", "cloak", "mithril cloak"),
      new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "makingscissors;"),
      ConversationStates.ATTENDING, null, new ChatAction() {
        public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
          final String[] tokens = player.getQuest(mithrilcloak.getQuestSlot()).split(";");
          // minutes -> milliseconds
          final long delay = REQUIRED_MINUTES_SCISSORS * MathHelper.MILLISECONDS_IN_ONE_MINUTE;
 
View Full Code Here

    final SpeakerNPC npc = npcs.get("Terry");

    // offer eggshells when prompted
    npc.add(ConversationStates.ATTENDING,
        Arrays.asList("eggshells", "magical", "magical eggshells", "scissors", "hogart", "ida", "cloak", "mithril cloak", "specials"),
        new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "need_eggshells"),
        ConversationStates.QUEST_ITEM_QUESTION,
        "Sure, I sell eggshells. They're not worth much to me. I'll swap you one eggshell for every " + Integer.toString(REQUIRED_POISONS) + " disease poisons you bring me. I need it to kill the rats you see. Anyway, how many eggshells was you wanting?",
        null);

    // respond to question of how many eggshells are desired. terry expects a number or some kind
View Full Code Here

    // remind about scissors
    npc.add(ConversationStates.ATTENDING,
        Arrays.asList("scissors", "magical", "magical scissors", "mithril", "cloak", "mithril cloak", "task", "quest"),
        new OrCondition(
                new QuestInStateCondition(mithrilcloak.getQuestSlot(), "need_scissors"),
                new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "need_eggshells;"),
                new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "makingscissors;"),
                new AndCondition(new QuestInStateCondition(mithrilcloak.getQuestSlot(), "got_scissors"),
                         new NotCondition(new PlayerHasItemWithHimCondition("magical scissors")))
                ),
        ConversationStates.ATTENDING,
        "Ask #Hogart about #scissors, I'm sure he will remember the messages I've sent him!",       
View Full Code Here

    final SpeakerNPC npc = npcs.get("Ritati Dragontracker");

    // ask for joke when prompted for needle
    npc.add(ConversationStates.ATTENDING,
        Arrays.asList("needle", "magical", "magical needle", "ida", "cloak", "mithril cloak", "specials"),
        new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "need_needle"),
        ConversationStates.ATTENDING,
        "Ok, but I have a little rule: never do important business with someone unless"
        + "they can make you laugh. So, come back to tell me a #joke and I will sell you a needle.",
        null);
   
    // ask for joke when player says joke
    npc.add(ConversationStates.ATTENDING,
        "joke",
        new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "need_needle"),
        ConversationStates.QUESTION_1,
        "Ok, lets hear your joke then. and I hope it's from the book in Nalwor Library, that's my favourite. What joke did you choose?",
        null);

    npc.add(ConversationStates.QUESTION_1, "", null,
        ConversationStates.QUEST_ITEM_QUESTION, null,
          new ChatAction() {
            public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
              for (int i = 1; i < 9; i++) {
                String joke = jokes.get(i);

                final Sentence answer = sentence.parseAsMatchingSource();
                final Sentence expected = ConversationParser.parse(joke, new SimilarExprMatcher());

                if (answer.matchesFull(expected)) {
                  final String[] questslot = player.getQuest(mithrilcloak.getQuestSlot()).split(";");
                  if (questslot.length > 2) {
                    // if the split worked, we had stored a needle number before and we need to store it again
                    int needles = Integer.parseInt(questslot[1]);
                    int saidjoke = Integer.parseInt(questslot[2]);
                    if (i == saidjoke) {
                      npc.say("You told me that joke last time, come back with a new one! Bye.");
                      npc.setCurrentState(ConversationStates.IDLE);
//                      // stop looking through the joke list
                      return;
                    } else {
                      player.setQuest(mithrilcloak.getQuestSlot(), "told_joke;" + Integer.toString(needles) + ";" + Integer.toString(i));
                    }
                  } else {
                    player.setQuest(mithrilcloak.getQuestSlot(), "told_joke;" + Integer.toString(i));
                  }
                  // this might have been his favourite joke, which is determined randomly
                  if (Rand.randUniform(1, 8) == i) {
                    npc.say("That's the funniest joke I ever heard! I think it's my favourite of the moment. Here, have your needle for free... and then get out of here, You've been here far too long already.");
                    new EquipItemAction("magical needle", 1, true).fire(player, sentence, npc);
                    npc.setCurrentState(ConversationStates.IDLE);
//                    // stop looking through the joke list
                    return;
                  } else {
                    npc.say("*guffaws* Alright, lets get on with business. A magical needle costs "
                      + Integer.toString(NEEDLE_COST) + " pieces of money. Do you want to buy one now?");
                    // stop looking through the joke list
                    npc.setCurrentState(ConversationStates.QUEST_ITEM_QUESTION);
                    return;
                   }
                }
              }
              if (ConversationPhrases.GOODBYE_MESSAGES.contains(sentence.getTriggerExpression().getNormalized())) {
                  npc.say("Ok, bye then.");
                  npc.setCurrentState(ConversationStates.IDLE);
              } else if (sentence.getTriggerExpression().getNormalized().equals("none")) {
                npc.say("Ok, bye.");
                npc.setCurrentState(ConversationStates.IDLE);
              } else {
                npc.say("Sorry, that joke just isn't funny. go back to Nalwor library and get another.");
                npc.setCurrentState(ConversationStates.IDLE);
              }
      }
    });
   
   
    // offer needle when prompted if they already told a joke
    npc.add(ConversationStates.ATTENDING,
        Arrays.asList("needle", "magical", "magical needle", "ida", "cloak", "mithril cloak", "specials"),
        new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "told_joke"),
        ConversationStates.QUEST_ITEM_QUESTION,
        "I have some magical needles but they cost a pretty penny, "
        + Integer.toString(NEEDLE_COST) + " pieces of money to be precise. Do you want to buy one?",
        null);

View Full Code Here

    final SpeakerNPC npc = npcs.get("Ida");

    // player brings needle for first or subsequent time
    npc.add(ConversationStates.ATTENDING,
        Arrays.asList("needle", "magical needle", "magical", "mithril", "cloak", "mithril cloak", "task", "quest"),
        new AndCondition(new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "told_joke"), new PlayerHasItemWithHimCondition("magical needle")),
        ConversationStates.ATTENDING,
        null,
        new MultipleActions(
          new ChatAction() {
            public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
              final String[] questslot = player.getQuest(mithrilcloak.getQuestSlot()).split(";");   
              int needles = 1;
              int saidjoke = 1;
              if (questslot.length > 2) {
                // if the split works, we had stored a needle number before
                needles = Integer.parseInt(questslot[1]);
                saidjoke = Integer.parseInt(questslot[2]);
                npc.say("I'm really sorry about the previous needle breaking. I'll start work again on your cloak,"
                    + " please return in another " + REQUIRED_HOURS_SEWING + " hours.");
               } else if (questslot.length > 1) {
                // it wasn't split with a needle number, only joke
                // so this is the first time we brought a needle
                saidjoke = Integer.parseInt(questslot[1]);
                npc.say("Looks like you found Ritatty then, good. I'll start on the cloak now!"
                    + " A seamstress needs to take her time, so return in " + REQUIRED_HOURS_SEWING + " hours.");
                // ida breaks needles - she will need 1 - 3
                needles = Rand.randUniform(1, 3);
              }
              player.setQuest(mithrilcloak.getQuestSlot(), "sewing;" + System.currentTimeMillis() + ";" + needles + ";" + saidjoke);
            }
          },
          new DropItemAction("magical needle")
          )
        );

    // remind about needle
    npc.add(ConversationStates.ATTENDING,
        Arrays.asList("needle", "magical needle", "magical", "mithril", "cloak", "mithril cloak", "task", "quest"),
        new OrCondition(new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "need_needle"),
                new AndCondition(
                  new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "told_joke"),
                  new NotCondition(new PlayerHasItemWithHimCondition("magical needle"))
                )
            ),
        ConversationStates.ATTENDING,
        "Please ask Ritati thingummy for his 'specials', or just ask about a #needle.",       
View Full Code Here

    // the quest slot that starts with sewing is the form "sewing;number;number" where the first number is the time she started sewing
    // the second number is the number of needles that she's still going to use - player doesn't know number

    npc.add(ConversationStates.ATTENDING,
        Arrays.asList("magical", "mithril", "cloak", "mithril cloak", "task", "quest"),
        new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "sewing;"),
        ConversationStates.ATTENDING, null, new ChatAction() {
            public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
              final String[] tokens = player.getQuest(mithrilcloak.getQuestSlot()).split(";");
              // hours -> milliseconds
              final long delay = REQUIRED_HOURS_SEWING * MathHelper.MILLISECONDS_IN_ONE_HOUR;
 
View Full Code Here

  private void step_3() {
    final SpeakerNPC npc = npcs.get("Baldemar");

    npc.add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES,
      new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
          new QuestStateStartsWithCondition(QUEST_SLOT, "start")),
      ConversationStates.ATTENDING, null,
      new ChatAction() {
        public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
          final String[] tokens = player.getQuest(QUEST_SLOT).split(";");
         
          int idx1 = 1;
          for (ItemData itemdata : neededItems.values()) {
              itemdata.resetAmount();
              itemdata.subAmount(tokens[idx1]);
              idx1++;
          }

          boolean missingSomething = false;

          int size = neededItems.size();
          for (int idx = 1; !missingSomething && idx <= size; idx++) {
            ItemData itemData = neededItems.get(idx);
            missingSomething = proceedItem(player, raiser,
                itemData);
          }
         
          if (player.hasKilledSolo("black giant") && !missingSomething) {
            raiser.say("You've brought everything I need to forge the shield. Come back in "
              + REQUIRED_MINUTES
              + " minutes and it will be ready.");
            player.setQuest(QUEST_SLOT, "forging;" + System.currentTimeMillis());
          } else {
            if (!player.hasKilledSolo("black giant") && !missingSomething) {
              raiser.say("This shield can only be given to those who have killed a black giant, and without the help of others.");
            }

            StringBuilder sb = new StringBuilder(30);
            sb.append("start");
            for (ItemData id : neededItems.values()) {
              sb.append(";");
              sb.append(id.getAlreadyBrought());
            }
            player.setQuest(QUEST_SLOT, sb.toString());
             
          }
        }

 
        private boolean proceedItem(final Player player,
            final EventRaiser engine, final ItemData itemData) {
          if (itemData.getStillNeeded() > 0) {
           
            if (player.isEquipped(itemData.getName(), itemData.getStillNeeded())) {
              player.drop(itemData.getName(), itemData.getStillNeeded());
              itemData.setAmount(0);
            } else {
              final int amount = player.getNumberOfEquipped(itemData.getName());
              if (amount > 0) {
                player.drop(itemData.getName(), amount);
                itemData.subAmount(amount);
              }

              engine.say(itemData.getAnswer());
              return true;
            }
          }
          return false;
        }
      });

    npc.add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES,
        new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
            new QuestStateStartsWithCondition(QUEST_SLOT, "forging;")),
        ConversationStates.IDLE, null, new ChatAction() {
        public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {

          final String[] tokens = player.getQuest(QUEST_SLOT).split(";");
         
View Full Code Here

    "I'm drunken now thank you!",
    null);

npc.add(ConversationStates.ATTENDING,
    ConversationPhrases.QUEST_MESSAGES,
    new AndCondition(new TimePassedCondition(QUEST_SLOT, 1, REQUIRED_MINUTES), new QuestStateStartsWithCondition(QUEST_SLOT, "drinking;")),
    ConversationStates.QUEST_OFFERED,
    "The last cocktail you brought me was so lovely. Will you bring me another?",
    null);

npc.add(ConversationStates.ATTENDING,
    ConversationPhrases.QUEST_MESSAGES,
    new AndCondition(new NotCondition(new TimePassedCondition(QUEST_SLOT, 1, REQUIRED_MINUTES)), new QuestStateStartsWithCondition(QUEST_SLOT, "drinking;")),
    ConversationStates.ATTENDING,
    null,
    new SayTimeRemainingAction(QUEST_SLOT, 1, REQUIRED_MINUTES, "I'm sure I'll be too drunk to have another for at least "));
   
    npc.add(ConversationStates.ATTENDING,
View Full Code Here

    return 70;
  }
 
  @Override
  public boolean isRepeatable(final Player player) {
    return new AndCondition(new QuestStateStartsWithCondition(QUEST_SLOT,"drinking;"),
         new TimePassedCondition(QUEST_SLOT, 1, REQUIRED_MINUTES)).fire(player,null, null);
  }
View Full Code Here

TOP

Related Classes of games.stendhal.server.entity.npc.condition.QuestStateStartsWithCondition

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.