Package games.stendhal.server.entity.npc

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


    addReply(Arrays.asList("Athor", "island"), "Athor Island is a fun place where many people spend their holidays.");
    add(ConversationStates.ATTENDING, "status",
        null,
        ConversationStates.ATTENDING,
        null,
        new ChatAction() {
          public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
            npc.say(ferrystate.toString());
          }
        });

    add(ConversationStates.ATTENDING,
        "board",
        null,
        ConversationStates.ATTENDING,
        null,
        new ChatAction() {
          public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
            if (ferrystate == Status.ANCHORED_AT_MAINLAND) {
              npc.say("In order to board the ferry, you have to pay " + AthorFerry.PRICE
            + " gold. Do you want to pay?");
              npc.setCurrentState(ConversationStates.SERVICE_OFFERED);
            } else {
              npc.say(ferrystate.toString()
                + " You can only board the ferry when it's anchored at the mainland.");
            }
          }
        });

    add(ConversationStates.SERVICE_OFFERED,
        ConversationPhrases.YES_MESSAGES,
        null,
        ConversationStates.ATTENDING, null,
        new ChatAction() {
          public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
            if (player.drop("money", AthorFerry.PRICE)) {
              player.teleport(getShipZone(), 27, 33, Direction.LEFT, null);

            } else {
View Full Code Here


        setPath(null);
      }

      @Override
      protected void createDialog() {
        addGreeting(null, new ChatAction() {
          public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
            String reply = "If you're going to the filthy rat city, don't come past me. ";
            if (player.getLevel() < 60) {
              reply += " In fact, just don't come this way at all, you wouldn't survive the mighty dark elves... ";
            } else {
              reply += " This passage east leads to the drow tunnels.";
            }
            raiser.say(reply);
          }
        });
        addJob("I'm keeping an eye on these rats. Us dark elves don't want the rat men interfering in our business.");
        addHelp("If you seek to kill some repulsive rat men, follow that wiggling path through to another huge cavern. Cross the cavern, go through the skull statues and you will find the rat city. Follow the pathetic corpses and you'll know you're on the right path.");
        addQuest("If you want #help ... just say.");
        addGoodbye("So long!");
      }
    };

    npc.addInitChatMessage(null, new ChatAction() {
      public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
        if (!player.hasQuest("WaerrynaFirstChat")) {
          player.setQuest("WaerrynaFirstChat", "done");
          player.addXP(300);
          ((SpeakerNPC) raiser.getEntity()).listenTo(player, "hi");
View Full Code Here

        });

    engine.add(ConversationStates.BUY_PRICE_OFFERED,
        ConversationPhrases.YES_MESSAGES, null,
        false, ConversationStates.ATTENDING,
        null, new ChatAction() {
          public void fire(final Player player, final Sentence sentence,
              final EventRaiser npc) {
            final String itemName = currentBehavRes.getChosenItemName();
            logger.debug("Selling a " + itemName + " to player " + player.getName());

            if (outfitBehaviour.transactAgreedDeal(currentBehavRes, npc, player)) {
              if (canReturn) {
                npc.say("Thanks, and please don't forget to #return it when you don't need it anymore!");
                // -1 is also the public static final int NEVER_WEARS_OFF = -1;
                // but it doesn't recognise it here ...
              } else if (outfitBehaviour.endurance != -1) {
                npc.say("Thanks! This will wear off in " +  TimeUtil.timeUntil((int) (outfitBehaviour.endurance * 0.3)) + ".");
              } else {
                npc.say("Thanks!");
              }
            }

            currentBehavRes = null;
          }
        });

    engine.add(ConversationStates.BUY_PRICE_OFFERED,
        ConversationPhrases.NO_MESSAGES, null,
        false, ConversationStates.ATTENDING,
        "Ok, how else may I help you?", null);

    if (canReturn) {
      engine.add(ConversationStates.ATTENDING, "return", null,
          false, ConversationStates.ATTENDING,
          null, new ChatAction() {
            public void fire(final Player player, final Sentence sentence,
                final EventRaiser npc) {
              if (outfitBehaviour.returnToOriginalOutfit(player)) {
                npc.say("Thank you!");
              } else {
View Full Code Here

   
    /* add to producer register */
    producerRegister.add(npcName, behaviour);   

        /* If the NPC is attending another player, say who they are attending */
    npc.addWaitMessage(null, new ChatAction() {
      public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
        raiser.say("Please wait! I am attending "
            + raiser.getAttending().getName() + ".");
      }
    });

        /* The Player greets the NPC.
        * The NPC is not currently producing for player (not started, is rejected, or is complete) */
    engine.add(ConversationStates.IDLE,
        ConversationPhrases.GREETING_MESSAGES,
        new AndCondition(new GreetingMatchesNameCondition(npcName),
            new QuestNotActiveCondition(QUEST_SLOT)),
        false, ConversationStates.ATTENDING, thisWelcomeMessage, null);

    engine.add(ConversationStates.ATTENDING,
        behaviour.getProductionActivity(),
        new SentenceHasErrorCondition(),
        false, ConversationStates.ATTENDING,
        null, new ComplainAboutSentenceErrorAction());

        /* In the behaviour a production activity is defined, e.g. 'cast' or 'mill'
        * and this is used as the trigger to start the production,
        * provided that the NPC is not currently producing for player (not started, is rejected, or is complete) */   
        engine.add(
        ConversationStates.ATTENDING,
        behaviour.getProductionActivity(),
        new AndCondition(
          new NotCondition(new SentenceHasErrorCondition()),
          new QuestNotActiveCondition(QUEST_SLOT)
        ),
                false,
                ConversationStates.ATTENDING, null,
        new ProducerBehaviourAction(behaviour) {
          @Override
          public void fireRequestOK(final ItemParserResult res, final Player player, final Sentence sentence, final EventRaiser npc) {
            // Find out how much items we shall produce.
            if (res.getAmount() > 1000) {
              logger.warn("Decreasing very large amount of "
                  + res.getAmount()
                  + " " + res.getChosenItemName()
                  + " to 1 for player "
                  + player.getName() + " talking to "
                  + npcName + " saying " + sentence);
              res.setAmount(1);
            }

            if (behaviour.askForResources(res, npc, player)) {
              currentBehavRes = res;
              npc.setCurrentState(ConversationStates.PRODUCTION_OFFERED);
            }
          }
        });

        /* Player agrees to the proposed production deal */
    engine.add(ConversationStates.PRODUCTION_OFFERED,
        ConversationPhrases.YES_MESSAGES, null,
        false, ConversationStates.ATTENDING,
        null, new ChatAction() {
          public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
            behaviour.transactAgreedDeal(currentBehavRes, npc, player);

            currentBehavRes = null;
          }
        });

        /* Player does not agree to the proposed production deal */
    engine.add(ConversationStates.PRODUCTION_OFFERED,
        ConversationPhrases.NO_MESSAGES, null,
        false, ConversationStates.ATTENDING, "OK, no problem.", null);

        /* Player says the production trigger word but the NPC is already producing items for that player */
    engine.add(
        ConversationStates.ATTENDING,
        behaviour.getProductionActivity(),
        new QuestActiveCondition(QUEST_SLOT),
                false, ConversationStates.ATTENDING,
        null, new ChatAction() {
          public void fire(final Player player, final Sentence sentence,
              final EventRaiser npc) {
                        // TODO: check - can the StateRemainingTimeAction be used here?
            npc.say("I still haven't finished your last order. Come back in "
                + behaviour.getApproximateRemainingTime(player)
                + "!");
          }
        });

        /* Player greets NPC and the NPC is already producing items for that player
         * There are two options: the NPC is still busy or he is finished
         * The method giveProduct(npc, player) used here takes care of both. */
    engine.add(
        ConversationStates.IDLE,
        ConversationPhrases.GREETING_MESSAGES,
        new AndCondition(new GreetingMatchesNameCondition(npcName),
            new QuestActiveCondition(QUEST_SLOT)),
        false, ConversationStates.ATTENDING,
        null, new ChatAction() {
          public void fire(final Player player, final Sentence sentence,
              final EventRaiser npc) {
            behaviour.giveProduct(npc, player);
          }
        });
View Full Code Here

    npc.add(ConversationStates.ATTENDING,
        ConversationPhrases.QUEST_MESSAGES,
        new AndCondition(new QuestCompletedCondition("weapons_collector"), new QuestNotStartedCondition(QUEST_SLOT)),
        ConversationStates.QUEST_2_OFFERED,
        null,
        new ChatAction() {
          public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
              if (player.isQuestCompleted(QUEST_SLOT)) {
                raiser.say("My collection is now complete! Thanks again.");
                raiser.setCurrentState(ConversationStates.ATTENDING);
              } else {
                raiser.say("Recent adventurers to these parts describe strange new creatures with weapons I have never seen. "
                    + "Would you fight these creatures and bring their weapons to me?");
              }
            }
        });

    // player is willing to help
    npc.add(ConversationStates.QUEST_2_OFFERED,
        ConversationPhrases.YES_MESSAGES,
        null,
        ConversationStates.ATTENDING,
        null,
        new ChatAction() {
          public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
            raiser.say("Wonderful. Now, the #list is small but the risk may be great. "
                + "If you return safely, I have another reward for you.");
            player.setQuest(QUEST_SLOT, "");
          }
        });

    // player is not willing to help
    npc.add(ConversationStates.QUEST_2_OFFERED,
        ConversationPhrases.NO_MESSAGES,
        null,
        ConversationStates.ATTENDING,
        "Well, maybe someone else will happen by and help me.",
        null);

    // player asks what exactly is missing
    npc.add(ConversationStates.ATTENDING,
        "list",
        new QuestActiveCondition(QUEST_SLOT),
        ConversationStates.QUESTION_2,
        null,
        new ChatAction() {
          public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
            final List<String> needed = missingWeapons(player, true);
            raiser.say("There "
                + Grammar.isare(needed.size())
                + " "
                + Grammar.quantityplnoun(needed.size(), "weapon", "a")
                + " still missing from my newest collection: "
                + Grammar.enumerateCollection(needed)
                + ". Do you have anything like that with you?");
          }
        });

    // player says he doesn't have required weapons with him
    npc.add(ConversationStates.QUESTION_2,
        ConversationPhrases.NO_MESSAGES,
        null,
        ConversationStates.IDLE,
        null,
        new ChatAction() {
          public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
            final List<String> missing = missingWeapons(player, false);
            raiser.say("Let me know as soon as you find "
                + Grammar.itthem(missing.size())
                + ". Farewell.");
          }
        });

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

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

            if (missing.contains(itemName)) {
              if (player.drop(itemName)) {
View Full Code Here

                  new LevelGreaterThanCondition(5),
                  new QuestCompletedCondition("pizza_delivery"),
                  new QuestNotActiveCondition(QUEST_SLOT)),
              ConversationStates.ATTENDING,
              null,
              new ChatAction() {
              public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
                final Item item =  SingletonRepository.getEntityManager().getItem(itemName);
                if (item == null) {
                  npc.say("Sorry, something went wrong. Could you say correctly the item, please?");
                } else {
                  player.equipOrPutOnGround(item);
                  player.setQuest(QUEST_SLOT, itemName);
                  npc.say("Here you are! Don't forget to #return it or you have to pay!");
                }
              }
            });
        }

        // additionally add "sugar" as trigger word
        add(ConversationStates.ATTENDING,
              "sugar",
              new AndCondition(
                  new LevelGreaterThanCondition(5),
                  new QuestCompletedCondition("pizza_delivery"),
                  new QuestNotActiveCondition(QUEST_SLOT)),
              ConversationStates.ATTENDING,
              null,
              new ChatAction() {
              public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
                npc.say("Sorry, I can't lend out sugar, only a #sugar #mill.");
              }
        });
View Full Code Here

    npc.add(ConversationStates.INFORMATION_1,
        "revive",
        new QuestNotStartedCondition(QUEST_SLOT),
        ConversationStates.QUEST_OFFERED,
        null,
        new ChatAction() {
        public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
          if (player.hasQuest(QUEST_SLOT) && player.isQuestCompleted(QUEST_SLOT)) {
            // to be honest i don't understand when this
                // would be implemented. i put the text i
                // want down in stage 3 and it works fine.
            npc.say("I have everything for the recipe now.");
            npc.setCurrentState(ConversationStates.ATTENDING);
          } else {
            npc.say("My special soup has a magic touch. "
                + "I need you to bring me the #ingredients.");
          }
        }
      });

    // player asks what exactly is missing
    npc.add(ConversationStates.QUEST_OFFERED, "ingredients", null,
      ConversationStates.QUEST_OFFERED, 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 need "
              + Grammar.quantityplnoun(needed.size(),
                  "ingredient", "one")
View Full Code Here

    // 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(5.0);
                  player.addXP(20);
                  /*
                   * place soup after XP added otherwise
                   * the XP change MIGHT change level and
                   * player MIGHT gain health points which
                   * changes the base HP, which is desired
                   * to be accurate for the place soup
                   * stage
                   */
                  placeSoupFor(player);
                  player.healPoison();
                  npc.say("The soup's on the 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("Don't take me for a fool, traveller. 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);
      }
    });
View Full Code Here

        add(ConversationStates.ATTENDING,
            ConversationPhrases.QUEST_MESSAGES,
            null,
                ConversationStates.ATTENDING,
                null,
                new ChatAction() {
                  public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
                    if (Rand.throwCoin() == 1) {
                      npc.say("Ah, quests... just like the old days when I was young! I remember one quest that was about... Oh look, a bird! Hmm, what? Ah, quests... just like the old days when I was young!");
                    } else {
                      npc.say("You know that Sato over there buys sheep? Well, rumour has it that there's a creature deep in the dungeons who also buys sheep... and it pays much better than Sato, too!");
                    }
                  }
                });

        // A convenience function to make it easier for admins to test quests.
        add(ConversationStates.ATTENDING, "cleanme!", null, ConversationStates.ATTENDING, "What?",
                new ChatAction() {
                  public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
                    if (AdministrationAction.isPlayerAllowedToExecuteAdminCommand(player, "alter", false)) {
                      for (final String quest : player.getQuests()) {
                        player.removeQuest(quest);
                      }
View Full Code Here

          add(ConversationStates.IDLE,
            ConversationPhrases.GREETING_MESSAGES,
            new GreetingMatchesNameCondition(getName()), true,
            ConversationStates.IDLE,
            null,
            new ChatAction() {
              public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
                if (!player.hasQuest("find_ghosts")) {
                  player.setQuest("find_ghosts", "looking:said");
                }
                final String npcQuestText = player.getQuest("find_ghosts");
View Full Code Here

TOP

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

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.