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

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


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

    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 neededIron = REQUIRED_IRON
              - Integer.parseInt(tokens[1]);
          int neededWoodLogs = REQUIRED_WOOD
              - Integer.parseInt(tokens[2]);
          int neededGoldBars = REQUIRED_GOLD_BAR
              - Integer.parseInt(tokens[3]);
          int neededGiantHearts = REQUIRED_GIANT_HEART
              - Integer.parseInt(tokens[4]);
          boolean missingSomething = false;

          if (!missingSomething && (neededIron > 0)) {
            if (player.isEquipped("iron", neededIron)) {
              player.drop("iron", neededIron);
              neededIron = 0;
            } else {
              final int amount = player.getNumberOfEquipped("iron");
              if (amount > 0) {
                player.drop("iron", amount);
                neededIron -= amount;
              }

              raiser.say("I cannot #forge it without the missing "
                + Grammar.quantityplnoun(
                    neededIron, "iron", "a")
                + ".");
              missingSomething = true;
            }
          }

          if (!missingSomething && (neededWoodLogs > 0)) {
            if (player.isEquipped("wood", neededWoodLogs)) {
              player.drop("wood", neededWoodLogs);
              neededWoodLogs = 0;
            } else {
              final int amount = player.getNumberOfEquipped("wood");
              if (amount > 0) {
                player.drop("wood", amount);
                neededWoodLogs -= amount;
              }

              raiser.say("How do you expect me to #forge it without missing "
                + Grammar.quantityplnoun(neededWoodLogs, "wood log", "a")
                + " for the fire?");
              missingSomething = true;
            }
          }

          if (!missingSomething && (neededGoldBars > 0)) {
            if (player.isEquipped("gold bar", neededGoldBars)) {
              player.drop("gold bar", neededGoldBars);
              neededGoldBars = 0;
            } else {
              final int amount = player.getNumberOfEquipped("gold bar");
              if (amount > 0) {
                player.drop("gold bar", amount);
                neededGoldBars -= amount;
              }
              raiser.say("I must pay a bill to spirits in order to cast the enchantment over the sword. I need "
                  + Grammar.quantityplnoun(neededGoldBars, "gold bar", "one") + " more.");
              missingSomething = true;
            }
          }

          if (!missingSomething && (neededGiantHearts > 0)) {
            if (player.isEquipped("giant heart", neededGiantHearts)) {
              player.drop("giant heart", neededGiantHearts);
              neededGiantHearts = 0;
            } else {
              final int amount = player.getNumberOfEquipped("giant heart");
              if (amount > 0) {
                player.drop("giant heart", amount);
                neededGiantHearts -= amount;
              }
              raiser.say("It is the base element of the enchantment. I need "
                + Grammar.quantityplnoun(neededGiantHearts, "giant heart", "one") + " still.");
              missingSomething = true;
            }
          }

          if (player.hasKilled("giant") && !missingSomething) {
            raiser.say("You've brought everything I need to make the immortal sword, and what is more, you are strong enough to handle it. Come back in "
              + REQUIRED_MINUTES
              + " minutes and it will be ready.");
            player.setQuest(QUEST_SLOT, "forging;" + System.currentTimeMillis());
          } else {
            if (!player.hasKilled("giant") && !missingSomething) {
              raiser.say("Did you really get those giant hearts yourself? I don't think so! This powerful sword can only be given to those that are strong enough to kill a #giant.");
            }

            player.setQuest(QUEST_SLOT,
              "start;"
              + (REQUIRED_IRON - neededIron)
              + ";"
              + (REQUIRED_WOOD - neededWoodLogs)
              + ";"
              + (REQUIRED_GOLD_BAR - neededGoldBars)
              + ";"
              + (REQUIRED_GIANT_HEART - neededGiantHearts));
          }
        }
      });

    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


    npc.add(
      ConversationStates.IDLE,
      ConversationPhrases.GREETING_MESSAGES,
      new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
          new QuestStartedCondition(QUEST_SLOT),
          new NotCondition(new QuestStateStartsWithCondition(QUEST_SLOT, "done"))),
      ConversationStates.QUESTION_1,
      "Welcome back! I hope you collected some #ingredients for the fish soup, or #everything.",
      null);

    // player asks what exactly is missing
    npc.add(ConversationStates.QUESTION_1, "ingredients",
      new AndCondition(new QuestStartedCondition(QUEST_SLOT), new NotCondition(new QuestStateStartsWithCondition(QUEST_SLOT, "done"))),
      ConversationStates.QUESTION_1, null,
      new ChatAction() {
        public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
          final List<String> needed = missingFood(player, true);
          npc.say("I still need "
              + Grammar.quantityplnoun(needed.size(),
                  "ingredient", "one") + ": "
              + Grammar.enumerateCollection(needed)
              + ". Did you bring anything I need?");
        }
      });

    // player says he has a required ingredient with him
    npc.add(ConversationStates.QUESTION_1,
        ConversationPhrases.YES_MESSAGES, null,
        ConversationStates.QUESTION_1, "What did you bring?", null);

    for(final String itemName : NEEDED_FOOD) {
      npc.add(ConversationStates.QUESTION_1, itemName, null,
        ConversationStates.QUESTION_1, null,
        new ChatAction() {
          public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
            List<String> missing = missingFood(player, false);

            if (missing.contains(itemName)) {
              if (player.drop(itemName)) {
                // register ingredient as done
                final String doneText = player.getQuest(QUEST_SLOT);
                player.setQuest(QUEST_SLOT, doneText + ";" + itemName);

                // check if the player has brought all Food
                missing = missingFood(player, true);

                if (!missing.isEmpty()) {
                  npc.say("Thank you very much! What else did you bring?");
                } else {
                  player.addKarma(10.0);
                  player.addXP(50);
                  placeSoupFor(player);
                  player.healPoison();
                  npc.say("The soup's on the market table for you. It will heal you. "
                      + "My magical method in making the soup has given you a little karma too.");
                  player.setQuest(QUEST_SLOT, "done;"
                      + System.currentTimeMillis());
                  player.notifyWorldAboutChanges();
                  npc.setCurrentState(ConversationStates.ATTENDING);
                }
              } else {
                npc.say("Oh come on, I don't have time for jokes! You don't have "
                  + Grammar.a_noun(itemName)
                  + " with you.");
              }
            } else {
              npc.say("You brought me that ingredient already.");
            }
          }
        });
    }
   
    // Perhaps player wants to give all the ingredients at once
    npc.add(ConversationStates.QUESTION_1, "everything",
        null,
        ConversationStates.QUESTION_1,
        null,
        new ChatAction() {
          public void fire(final Player player, final Sentence sentence,
             final EventRaiser npc) {
            checkForAllIngredients(player, npc);
      }
    });

    // player says something which isn't in the needed food list.
    npc.add(ConversationStates.QUESTION_1, "",
      new NotCondition(new TriggerInListCondition(NEEDED_FOOD)),
      ConversationStates.QUESTION_1,
      "I won't put that in your fish soup.", null);

    // allow to say goodbye while Florence is listening for food names
    npc.add(ConversationStates.QUESTION_1, ConversationPhrases.GOODBYE_MESSAGES, null,
        ConversationStates.IDLE, "Bye.", null);

    npc.add(ConversationStates.ATTENDING, ConversationPhrases.NO_MESSAGES,
      new AndCondition(new QuestStartedCondition(QUEST_SLOT), new NotCondition(new QuestStateStartsWithCondition(QUEST_SLOT, "done"))),
      ConversationStates.ATTENDING,
      "I'm not sure what you want from me, then.", null);

    // player says he didn't bring any Food to different question
    npc.add(ConversationStates.QUESTION_1, ConversationPhrases.NO_MESSAGES,
      new AndCondition(new QuestStartedCondition(QUEST_SLOT), new NotCondition(new QuestStateStartsWithCondition(QUEST_SLOT, "done"))),
      ConversationStates.ATTENDING, "Okay then. Come back later.",
      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.