Package games.stendhal.server.entity.npc

Examples of games.stendhal.server.entity.npc.SpeakerNPC


  public InitialSteps(final MithrilCloakQuestInfo mithrilcloak) {
    this.mithrilcloak = mithrilcloak;
  }

  private void offerQuestStep() {
    final SpeakerNPC npc = npcs.get("Ida");
   

    // player asks about quest, they haven't started it yet
    npc.add(ConversationStates.ATTENDING,
        ConversationPhrases.QUEST_MESSAGES,
        new OrCondition(new QuestNotStartedCondition(mithrilcloak.getQuestSlot()), new QuestInStateCondition(mithrilcloak.getQuestSlot(), "rejected")),       
        ConversationStates.QUEST_OFFERED,
        "My sewing machine is broken, will you help me fix it?",
        null);
   
    final Map<String,Integer> items = new HashMap<String, Integer>();
    items.put("leather armor",1);
    items.put("oil",1);
    items.put("bobbin",1);

    // Player says yes they want to help
    npc.add(ConversationStates.QUEST_OFFERED,
      ConversationPhrases.YES_MESSAGES, null,
      ConversationStates.ATTENDING,
      null,     
      new MultipleActions(new SetQuestAndModifyKarmaAction(mithrilcloak.getQuestSlot(), "machine;", 15.0),
                new StartRecordingRandomItemCollectionAction(mithrilcloak.getQuestSlot(), 1, items, "Thank you! To fix it, it needs [#item]. I'm ever so grateful for your help.")));
   
    // player said no they didn't want to help
    npc.add(
      ConversationStates.QUEST_OFFERED,
      ConversationPhrases.NO_MESSAGES,
      null,
      ConversationStates.IDLE,
      "Oh dear, I don't know what I can do without a decent sewing machine. But don't worry I won't bother you any longer!",
      new SetQuestAndModifyKarmaAction(mithrilcloak.getQuestSlot(), "rejected", -5.0));


    // player asks for quest but they already did it 
    npc.add(ConversationStates.ATTENDING,
        ConversationPhrases.QUEST_MESSAGES,
        new QuestCompletedCondition(mithrilcloak.getQuestSlot()),
        ConversationStates.ATTENDING,
        "You've already completed the only quest that I have for you.",
        null);
   
    //player fixed the machine but hadn't got mithril shield.
    // they return and ask for quest but they still haven't got mithril shield
    npc.add(ConversationStates.ATTENDING,
        ConversationPhrases.QUEST_MESSAGES,
        new AndCondition(new NotCondition(new QuestCompletedCondition(mithrilcloak.getShieldQuestSlot())),
                 new OrCondition(new QuestInStateCondition(mithrilcloak.getQuestSlot(), "need_mithril_shield"),
                         new QuestInStateCondition(mithrilcloak.getQuestSlot(), "fixed_machine"))
                 ),
        ConversationStates.ATTENDING,
                 "I don't have anything for you until you have proved yourself worthy of carrying mithril items, by getting the mithril shield.",
        null);


    // player fixed the machine but hadn't got mithril shield at time or didn't ask to hear more about the cloak.
    // when they have got it and return to ask for quest she offers the cloak
    npc.add(ConversationStates.ATTENDING,
        ConversationPhrases.QUEST_MESSAGES,
        new AndCondition(
                 new QuestCompletedCondition(mithrilcloak.getShieldQuestSlot()),
                 new OrCondition(new QuestInStateCondition(mithrilcloak.getQuestSlot(), "need_mithril_shield"),
                         new QuestInStateCondition(mithrilcloak.getQuestSlot(), "fixed_machine"))
                 ),
        ConversationStates.QUEST_2_OFFERED,
        "Congratulations, you completed the quest for the mithril shield! Now, I have another quest for you, do you want to hear it?",
        null);

    npc.addReply(Arrays.asList("oil", "can of oil", "can"), "The only oil I have ever had is very fishy smelling. I expect a fisherman made it.");
    npc.addReply("bobbin", "Only dwarf smiths make bobbins, no-one else has nimble enough fingers. Try #Alrak.");
    npc.addReply("Alrak", "I thought you kids all knew Alrak, the only dwarf that kobolds have ever liked. Or maybe he's the only dwarf to ever like kobolds, I've never been sure which ...");
    npc.addReply(Arrays.asList("leather armor", "suit of leather armor", "suit"), "Yes, well, it needs a piece of leather for the mechanism, so I can cut a piece from that.");
  }
View Full Code Here


  }

 
  private void fixMachineStep() {

    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
      npc.add(ConversationStates.QUEST_ITEM_QUESTION,
          ConversationPhrases.YES_MESSAGES,
          new PlayerHasRecordedItemWithHimCondition(mithrilcloak.getQuestSlot(),1),
          ConversationStates.QUEST_2_OFFERED,
          "Thank you so much! Listen, I must repay the favour, and I have a wonderful idea. Do you want to hear more?",
          new MultipleActions(new DropRecordedItemAction(mithrilcloak.getQuestSlot(),1),
              new SetQuestAction(mithrilcloak.getQuestSlot(), "fixed_machine"),
              new IncreaseXPAction(100)));
     
      // we stored the needed part name as part of the quest slot
      npc.add(ConversationStates.QUEST_ITEM_QUESTION,
          ConversationPhrases.YES_MESSAGES,
          new NotCondition(new PlayerHasRecordedItemWithHimCondition(mithrilcloak.getQuestSlot(),1)),
          ConversationStates.ATTENDING,
          null,
          new SayRequiredItemAction(mithrilcloak.getQuestSlot(),1,"No, you don't have [the item] I need. What a shame."));
                 

      // player doesn't have the item to fix machine yet       
       npc.add(ConversationStates.QUEST_ITEM_QUESTION,
           ConversationPhrases.NO_MESSAGES,
           null,
           ConversationStates.ATTENDING,
           null,
           new SayRequiredItemAction(mithrilcloak.getQuestSlot(),1,"Ok, well if there's anything else I can help you with just say. Don't forget to bring [the item] next time though!"));

       //offer cloak
       npc.add(ConversationStates.QUEST_2_OFFERED,
           ConversationPhrases.YES_MESSAGES,
           new QuestCompletedCondition(mithrilcloak.getShieldQuestSlot()),
           ConversationStates.ATTENDING,      
           "I will make you the most amazing cloak of mithril. You just need to get me the fabric and any tools I need! First please bring me a couple yards of " + mithrilcloak.getFabricName() + ". The expert on fabrics is the wizard #Kampusch.",
           new SetQuestAndModifyKarmaAction(mithrilcloak.getQuestSlot(), "need_fabric", 10.0));
         

      // player asks for quest but they haven't completed mithril shield quest
      npc.add(ConversationStates.QUEST_2_OFFERED,
        ConversationPhrases.YES_MESSAGES,
        new AndCondition(
                 new NotCondition(new QuestCompletedCondition(mithrilcloak.getShieldQuestSlot())),
                 new QuestStartedCondition(mithrilcloak.getShieldQuestSlot())
                 ),
        ConversationStates.ATTENDING,
        "Oh, I see you are already on a quest to obtain a mithril shield. You see, I was going to offer you a mithril cloak. But you should finish that first. Come back when you've finished the mithril shield quest and we will speak again.",
        new SetQuestAction(mithrilcloak.getQuestSlot(), "need_mithril_shield"));
     
      // player asks for quest but they haven't completed mithril shield quest
      npc.add(ConversationStates.QUEST_2_OFFERED,
          ConversationPhrases.YES_MESSAGES,
          new QuestNotStartedCondition(mithrilcloak.getShieldQuestSlot()),
          ConversationStates.ATTENDING,
          "There are legends of a wizard called Baldemar, in the famous underground magic city, who will forge a mithril shield for those who bring him what it needs. You should meet him and do what he asks. Once you have completed that quest, come back here and speak with me again. I will have another quest for you.",
          new SetQuestAction(mithrilcloak.getQuestSlot(), "need_mithril_shield"));

      // player refused to hear more about another quest after fixing machine
      npc.add(ConversationStates.QUEST_2_OFFERED,
          ConversationPhrases.NO_MESSAGES,
          null,
          ConversationStates.ATTENDING,
          "Ok then obviously you don't need any mithril items! Forgive me for offering to help...!",
          null);

      // where to find wizard
      npc.addReply("Kampusch", "He is obsessed with antiques so look for him in an antiques shop or a museum.");
 
  }
View Full Code Here

  private void getScissorsStep() {

    // Careful not to overlap with any states from VampireSword quest

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

    // player asks about scissors. they will need a random number of eggshells plus the metal
    npc.add(ConversationStates.ATTENDING,
      Arrays.asList("scissors", "magical", "magical scissors", "ida", "mithril", "cloak", "mithril cloak"),
      new QuestInStateCondition(mithrilcloak.getQuestSlot(), "need_scissors"),
      ConversationStates.ATTENDING,
      null,
      new ChatAction() {
        public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
          final int neededEggshells = Rand.randUniform(2, 4);
          raiser.say("Ah yes, Ida sent me a message about some magical scissors. I need one each of an iron bar and a mithril bar, and also " + Integer.toString(neededEggshells) + " magical #eggshells. Ask me about #scissors again when you return with those items.");
          // store the number of needed eggshells in the quest slot so he remembers how many he asked for
          player.setQuest(mithrilcloak.getQuestSlot(), "need_eggshells;" + Integer.toString(neededEggshells));
        }
      });

    // 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;
          final long timeRemaining = (Long.parseLong(tokens[1]) + delay)
              - System.currentTimeMillis();
          if (timeRemaining > 0L) {
            npc.say("Pff you're impatient aren't you? I haven't finished making the scissors yet, come back in "
              + TimeUtil.approxTimeUntil((int) (timeRemaining / 1000L)) + ".");
            return;
          }
          npc.say("Ah, thanks for reminding me. Here, Ida's scissors are ready. You better take them to her next as I don't know what she wanted them for.");
          player.addXP(100);
          player.addKarma(15);
          final Item scissors = SingletonRepository.getEntityManager().getItem(
                  "magical scissors");
          scissors.setBoundTo(player.getName());
View Full Code Here

  private void getEggshellsStep() {

    final int REQUIRED_POISONS = 6;

    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
    npc.addMatching(ConversationStates.QUEST_ITEM_QUESTION,
        // match for all numbers as trigger expression
        ExpressionType.NUMERAL, new JokerExprMatcher(),
        new TextHasNumberCondition(1, 5000),
        ConversationStates.ATTENDING, null,
        new ChatAction() {
          public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {

                        final int required = (sentence.getNumeral().getAmount());
            if (player.drop("disease poison", required * REQUIRED_POISONS)) {
              npc.say("Ok, here's your " + Integer.toString(required) + " eggshells. Enjoy!");
              new EquipItemAction("magical eggshells", required, true).fire(player, sentence, npc);
            } else {
              npc.say("Ok, ask me again when you have " + Integer.toString(required * REQUIRED_POISONS) + " disease poisons with you.");
            }           
          }
        });

    // didn't want eggshells yet
    npc.add(ConversationStates.QUEST_ITEM_QUESTION,
        Arrays.asList("no", "none", "nothing"),
        null,
        ConversationStates.ATTENDING,
        "No problem. Anything else I can help with, just say.",
        null);
View Full Code Here

   }

  private void giveScissorsStep() {

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

    // take scissors and ask for needle now
    npc.add(ConversationStates.ATTENDING,
        Arrays.asList("scissors", "magical", "magical scissors", "mithril", "cloak", "mithril cloak", "task", "quest"),
        new AndCondition(new QuestInStateCondition(mithrilcloak.getQuestSlot(), "got_scissors"), new PlayerHasItemWithHimCondition("magical scissors")),
        ConversationStates.ATTENDING,
        "You brought those magical scissors! Excellent! Now that I can cut the fabric I need a magical needle. You can buy one from a trader in the abandoned keep of Ados mountains, #Ritati Dragon something or other. Just go to him and ask for his 'specials'.",
        new MultipleActions(
                   new DropItemAction("magical scissors"),
                   new SetQuestAndModifyKarmaAction(mithrilcloak.getQuestSlot(), "need_needle;", 10.0),
                   new IncreaseXPAction(100)
                   )
        );

    // 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!",       
        null);

    npc.addReply("Ritati", "He's somewhere in the abandoned keep in the mountains north east from here.");
  }
View Full Code Here

      jokes.put(6, "Honk if you love peace and quiet.");
      jokes.put(7, "Always remember you're unique, just like everyone else.");
      jokes.put(8, "Half the people in the world are below average.");

   
    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);

    // agrees to buy 1 needle
    npc.add(ConversationStates.QUEST_ITEM_QUESTION,
        ConversationPhrases.YES_MESSAGES,
        new PlayerHasItemWithHimCondition("money", NEEDLE_COST),
        ConversationStates.IDLE,
        "Ok, here you are. Be careful with them, they break easy. Now, get lost, you have hung around here far too long already.",       
        new MultipleActions(
          new DropItemAction("money", NEEDLE_COST),
          new EquipItemAction("magical needle", 1, true)
          ));

    // said he had money but he didn't
    npc.add(ConversationStates.QUEST_ITEM_QUESTION,
        ConversationPhrases.YES_MESSAGES,
        new NotCondition(new PlayerHasItemWithHimCondition("money", NEEDLE_COST)),
        ConversationStates.ATTENDING,
        "What the ... you don't have enough money! Get outta here!",
        null);

    // doesn't want to buy needle
    npc.add(ConversationStates.QUEST_ITEM_QUESTION,
        ConversationPhrases.NO_MESSAGES,
        null,
        ConversationStates.ATTENDING,
        "Ok, no pressure, no pressure. Maybe you'll like some of my other #offers.",
        null);
   
    // specials response for if the queststate condition is not met
    npc.add(ConversationStates.ATTENDING,
        Arrays.asList("needle", "magical", "magical needle", "ida", "cloak", "mithril cloak", "specials"),
        null,
        ConversationStates.ATTENDING,
        "The time will come when you will need my specials, but that time is not now.",
        null);
View Full Code Here

  }

  private void giveNeedleStep() {

    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"))
View Full Code Here

        null);
  }

  private void sewingStep() {

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

    // 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;
              final long timeRemaining = (Long.parseLong(tokens[1]) + delay)
                - System.currentTimeMillis();
              if (timeRemaining > 0L) {
                npc.say("I'm still sewing your cloak, come back in "
                    + TimeUtil.approxTimeUntil((int) (timeRemaining / 1000L)) + " - and don't rush me, or I'm more likely to break the needle.");
                return;
              }
              // ida breaks needles, but if it is the last one,
              // she pricks her finger on that needle
              if (Integer.valueOf(tokens[2]) == 1) {
                npc.say("Ouch! I pricked my finger on that needle! I feel woozy ...");
                player.setQuest(mithrilcloak.getQuestSlot(), "twilight_zone");
              } else {
                npc.say("These magical needles are so fragile, I'm sorry but you're going to have to get me another, the last one broke. Hopefully Ritati still has plenty.");
                final int needles = Integer.parseInt(tokens[2]) - 1;
                int saidjoke = Integer.parseInt(tokens[3]);
                player.setQuest(mithrilcloak.getQuestSlot(), "need_needle;" + needles + ";" + saidjoke);
              }             
        }
View Full Code Here

  public String getSlotName() {
    return QUEST_SLOT;
  }
 
  private void step_1() {
    final SpeakerNPC npc = npcs.get("Baldemar");

    npc.add(ConversationStates.ATTENDING,
      ConversationPhrases.QUEST_MESSAGES, null,
      ConversationStates.QUEST_OFFERED, null,
      new ChatAction() {
        public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
          if (!player.hasQuest(QUEST_SLOT) || "rejected".equals(player.getQuest(QUEST_SLOT))) {
            raiser.say("I can forge a shield made from mithril along with several other items. Would you like me to do that?");
          } else if (player.isQuestCompleted(QUEST_SLOT)) {
            raiser.say("I would prefer you left me to my entertainment.");
            raiser.setCurrentState(ConversationStates.ATTENDING);
          } else {
            raiser.say("Why are you bothering me when you haven't completed your quest yet?");
            raiser.setCurrentState(ConversationStates.ATTENDING);
          }
        }
      });

    npc.add(ConversationStates.QUEST_OFFERED,
      ConversationPhrases.YES_MESSAGES, null,
      ConversationStates.ATTENDING, null,
      new ChatAction() {
        public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
          raiser.say(I_WILL_NEED_MANY_THINGS);
          player.setQuest(QUEST_SLOT, "start;0;0;0;0;0;0;0;0;0;0;0;0;0;0");
          player.addKarma(10);

        }
      });

    npc.add(
      ConversationStates.QUEST_OFFERED,
      ConversationPhrases.NO_MESSAGES,
      null,
      ConversationStates.IDLE,
      "I can't believe you are going to pass up this opportunity! You must be daft!!!",
      new SetQuestAndModifyKarmaAction(QUEST_SLOT, "rejected", -10.0));

    npc.addReply("exact",
      "As I have listed them here, you must provide them in that order.");
  }
View Full Code Here

  private void step_2() {
    /* Get the stuff. */
  }

  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(";");
         
          final long delay = REQUIRED_MINUTES * MathHelper.MILLISECONDS_IN_ONE_MINUTE;
          final long timeRemaining = (Long.parseLong(tokens[1]) + delay)
              - System.currentTimeMillis();

          if (timeRemaining > 0L) {
            raiser.say("I haven't finished forging your shield. Please check back in "
              + TimeUtil.approxTimeUntil((int) (timeRemaining / 1000L))
              + ".");
            return;
          }

          raiser.say("I have finished forging your new mithril shield. Enjoy. Now I will see what Trillium has stored behind the counter for me. ;)");
          player.addXP(95000);
          player.addKarma(25);
          final Item mithrilshield = SingletonRepository.getEntityManager().getItem("mithril shield");
          mithrilshield.setBoundTo(player.getName());
          player.equipOrPutOnGround(mithrilshield);
          player.notifyWorldAboutChanges();
          player.setQuest(QUEST_SLOT, "done");
        }
      });

    npc.add(ConversationStates.ATTENDING,
      Arrays.asList("forge", "missing"),
      new QuestStartedCondition(QUEST_SLOT),
      ConversationStates.ATTENDING,
      null,
      new ChatAction() {
View Full Code Here

TOP

Related Classes of games.stendhal.server.entity.npc.SpeakerNPC

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.