Package games.stendhal.server.maps.quests

Source Code of games.stendhal.server.maps.quests.CleanStorageSpace

/* $Id: CleanStorageSpace.java,v 1.49 2011/02/10 19:28:11 kymara Exp $ */
/***************************************************************************
*                   (C) Copyright 2003-2011 - Stendhal                    *
***************************************************************************
***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/
package games.stendhal.server.maps.quests;

import games.stendhal.server.entity.npc.ChatAction;
import games.stendhal.server.entity.npc.ConversationPhrases;
import games.stendhal.server.entity.npc.ConversationStates;
import games.stendhal.server.entity.npc.SpeakerNPC;
import games.stendhal.server.entity.npc.action.IncreaseKarmaAction;
import games.stendhal.server.entity.npc.action.IncreaseXPAction;
import games.stendhal.server.entity.npc.action.MultipleActions;
import games.stendhal.server.entity.npc.action.SetQuestAction;
import games.stendhal.server.entity.npc.action.SetQuestAndModifyKarmaAction;
import games.stendhal.server.entity.npc.action.StartRecordingKillsAction;
import games.stendhal.server.entity.npc.condition.AndCondition;
import games.stendhal.server.entity.npc.condition.GreetingMatchesNameCondition;
import games.stendhal.server.entity.npc.condition.KilledForQuestCondition;
import games.stendhal.server.entity.npc.condition.NotCondition;
import games.stendhal.server.entity.npc.condition.QuestActiveCondition;
import games.stendhal.server.entity.npc.condition.QuestInStateCondition;
import games.stendhal.server.entity.npc.condition.QuestNotStartedCondition;
import games.stendhal.server.entity.player.Player;
import games.stendhal.server.maps.Region;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import marauroa.common.Pair;

/**
* QUEST: CleanStorageSpace
* <p>
* PARTICIPANTS:
* <li> Eonna
* <p>
* STEPS:
* <li> Eonna asks you to clean her storage space.
* <li> You go kill at least a rat, a cave rat and a cobra.
* <li> Eonna checks your kills and then thanks you.
* <p>
* REWARD:
* <li> 100 XP, karma
* <p>
* REPETITIONS:
* <li> None.
*/
public class CleanStorageSpace extends AbstractQuest {
  private static final String QUEST_SLOT = "clean_storage";

  @Override
  public String getSlotName() {
    return QUEST_SLOT;
  }
 
  @Override
  public List<String> getHistory(final Player player) {
    final List<String> res = new ArrayList<String>();
    if (!player.hasQuest(QUEST_SLOT)) {
      return res;
    }
    res.add("I have met Eonna at her house in Semos next to the bakery.");
    final String questState = player.getQuest(QUEST_SLOT, 0);
    if ("rejected".equals(questState)) {
      res.add("I do not want to clear her storage space of creatures.");
      return res;
    }
    res.add("I promised Eonna to kill the rats and snakes in her basement.");
    if (("start".equals(questState) && player.hasKilled("rat") && player.hasKilled("caverat") && player.hasKilled("snake")) || "done".equals(questState)) {
      res.add("I have cleaned out Eonna's storage space.");
    }
    if ("done".equals(questState)) {
      res.add("Wow, Eonna thinks I am her hero. *blush*");
    }
    return res;
  }
 
  private void step_1() {
    final SpeakerNPC npc = npcs.get("Eonna");

    npc.add(ConversationStates.ATTENDING,
        ConversationPhrases.QUEST_MESSAGES,
        new QuestNotStartedCondition(QUEST_SLOT),
        ConversationStates.QUEST_OFFERED,
        "My #basement is absolutely crawling with rats. Will you help me?",
        null);

    npc.add(ConversationStates.ATTENDING,
        ConversationPhrases.QUEST_MESSAGES,
        new QuestActiveCondition(QUEST_SLOT),
        ConversationStates.ATTENDING,
        "Thanks again! I think it's still clear down there.", null);

    final List<ChatAction> start = new LinkedList<ChatAction>();
   
    final HashMap<String, Pair<Integer, Integer>> toKill =
      new HashMap<String, Pair<Integer, Integer>>();
    // first number is required solo kills, second is required shared kills
    toKill.put("rat", new Pair<Integer, Integer>(0,1));
    toKill.put("caverat", new Pair<Integer, Integer>(0,1));
    toKill.put("snake", new Pair<Integer, Integer>(0,1));
   
    start.add(new IncreaseKarmaAction(2.0));
    start.add(new SetQuestAction(QUEST_SLOT, 0, "start"));   
    start.add(new StartRecordingKillsAction(QUEST_SLOT, 1, toKill));
   
    npc.add(
        ConversationStates.QUEST_OFFERED,
        ConversationPhrases.YES_MESSAGES,
        null,
        ConversationStates.ATTENDING,
        "Oh, thank you! I'll wait up here, and if any try to escape I'll hit them with the broom!",
        new MultipleActions(start));

    npc.add(ConversationStates.QUEST_OFFERED, ConversationPhrases.NO_MESSAGES, null,
        ConversationStates.ATTENDING,
        "*sigh* Oh well, maybe someone else will be my hero...",
        new SetQuestAndModifyKarmaAction(QUEST_SLOT, "rejected", -2.0));

    npc.add(
        ConversationStates.QUEST_OFFERED,
        Arrays.asList("basement", "storage space"),
        null,
        ConversationStates.QUEST_OFFERED,
        "Yes, it's just down the stairs, over there. A whole bunch of nasty-looking rats; I think I saw a snake as well! You should be careful... still want to help me?",
        null);
  }

  private void step_2() {
    // Go kill at least a rat, a cave rat and a snake.
  }

  private void step_3() {

    final SpeakerNPC npc = npcs.get("Eonna");
   
    final List<ChatAction> reward = new LinkedList<ChatAction>();
    reward.add(new IncreaseKarmaAction(5.0));
    reward.add(new IncreaseXPAction(100));
    reward.add(new SetQuestAction(QUEST_SLOT, "done"));

    // the player returns to Eonna after having started the quest.
    // Eonna checks if the player has killed one of each animal race.
    npc.add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES,
        new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
            new QuestInStateCondition(QUEST_SLOT, 0, "start"), new KilledForQuestCondition(QUEST_SLOT,1)),
        ConversationStates.ATTENDING, "A hero at last! Thank you!",
        new MultipleActions(reward));

    npc.add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES,
        new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
            new QuestInStateCondition(QUEST_SLOT, 0, "start"), new NotCondition(new KilledForQuestCondition(QUEST_SLOT, 1))),
        ConversationStates.QUEST_STARTED,
        "Don't you remember promising to clean out the rats from my #basement?",
        null);

    npc.add(
        ConversationStates.QUEST_STARTED,
        "basement",
        null,
        ConversationStates.ATTENDING,
        "Down the stairs, like I said. Please get rid of all those rats, and see if you can find the snake as well!",
        null);
  }

  @Override
  public void addToWorld() {
    super.addToWorld();
    fillQuestInfo(
        "Clean the Storage Space",
        "Eonna is too scared to go into her underground storage space, as it is filled with rats and snakes.",
        false);
    step_1();
    step_2();
    step_3();
  }

  @Override
  public String getName() {
    return "CleanStorageSpace";
  }
 
  @Override
  public int getMinLevel() {
    return 0;
  }
 
  @Override
  public String getRegion() {
    return Region.SEMOS_CITY;
  }
}
TOP

Related Classes of games.stendhal.server.maps.quests.CleanStorageSpace

TOP
Copyright © 2018 www.massapi.com. 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.