Package games.stendhal.server.maps.quests

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

/* $Id: KillGnomes.java,v 1.15 2010/12/29 17:58:36 kymara Exp $ */
/***************************************************************************
*                   (C) Copyright 2003-2010 - 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.common.MathHelper;
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.EquipItemAction;
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.SetQuestToTimeStampAction;
import games.stendhal.server.entity.npc.action.StartRecordingKillsAction;
import games.stendhal.server.entity.npc.condition.AndCondition;
import games.stendhal.server.entity.npc.condition.KilledForQuestCondition;
import games.stendhal.server.entity.npc.condition.NotCondition;
import games.stendhal.server.entity.npc.condition.QuestInStateCondition;
import games.stendhal.server.entity.npc.condition.QuestNotStartedCondition;
import games.stendhal.server.entity.npc.condition.QuestStateStartsWithCondition;
import games.stendhal.server.entity.npc.condition.TimePassedCondition;
import games.stendhal.server.entity.player.Player;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import marauroa.common.Pair;

/**
* QUEST: Kill Gnomes
* <p>
* PARTICIPANTS:
* <ul>
* <li> Jenny, by the mill in Semos Plains
* </ul>
*
* STEPS:
* <ul>
* <li> Gnomes have been stealing carrots so Jenny asks you to kill some.
* <li> You go kill the Gnomes in the gnome village and you get the reward from Jenny
* </ul>
* <p>
* REWARD:
* <ul>
* <li> 3 potions
* <li> 100 XP
* <li> No karma (deliberately. Killing gnomes is mean!)
* </ul>
*
* REPETITIONS:
* <ul>
* <li> after 7 days.
* </ul>
*/

public class KillGnomes extends AbstractQuest {

  private static final String QUEST_SLOT = "kill_gnomes";
  private static final int WEEK_IN_MINUTES = MathHelper.MINUTES_IN_ONE_HOUR * 24 * 7;
  @Override
  public String getSlotName() {
    return QUEST_SLOT;
  }
 
  private void step_1() {
    final SpeakerNPC npc = npcs.get("Jenny");

    npc.add(ConversationStates.ATTENDING,
        ConversationPhrases.QUEST_MESSAGES,
        new QuestNotStartedCondition(QUEST_SLOT),
        ConversationStates.QUEST_OFFERED,
        "Some gnomes have been stealing carrots from the farms North of Semos. "
        + "They need to be taught a lesson, will you help?",
        null);

    npc.add(ConversationStates.ATTENDING,
        ConversationPhrases.QUEST_MESSAGES,
        new AndCondition(new QuestStateStartsWithCondition(QUEST_SLOT,"killed"),
             new TimePassedCondition(QUEST_SLOT, 1, WEEK_IN_MINUTES)),
        ConversationStates.QUEST_OFFERED,
        "Those pesky gnomes are stealing carrots again. I think they need another lesson. Will you help?",
        null);

    npc.add(ConversationStates.ATTENDING,
        ConversationPhrases.QUEST_MESSAGES,
        new AndCondition(new QuestStateStartsWithCondition(QUEST_SLOT,"killed"),
             new NotCondition(new TimePassedCondition(QUEST_SLOT, 1, WEEK_IN_MINUTES))),
        ConversationStates.ATTENDING,
        "The gnomes haven't made any trouble since you last taught them a lesson.",
        null);

    final Map<String, Pair<Integer, Integer>> toKill = new TreeMap<String, Pair<Integer, Integer>>();
    toKill.put("gnome", new Pair<Integer, Integer>(0,1));
    toKill.put("infantry gnome", new Pair<Integer, Integer>(0,1));
    toKill.put("cavalryman gnome",new Pair<Integer, Integer>(0,1));

    final List<ChatAction> actions = new LinkedList<ChatAction>();
    actions.add(new SetQuestAction(QUEST_SLOT, "start"));
    actions.add(new StartRecordingKillsAction(QUEST_SLOT, 1, toKill));
   
    npc.add(ConversationStates.QUEST_OFFERED,
        ConversationPhrases.YES_MESSAGES,
        null,
        ConversationStates.ATTENDING,
        "Excellent. You'll find the gnomes camped out, north west of Semos. Make sure you kill some of the ringleaders.",
        new MultipleActions(actions));

    npc.add(ConversationStates.QUEST_OFFERED,
        ConversationPhrases.NO_MESSAGES,
        null,
        ConversationStates.ATTENDING,
        "You're right, perhaps it is cruel to slaughter gnomes who only stole a carrot or so. "
        + "Maybe the farms should just increase their security. ",
        new SetQuestAction(QUEST_SLOT, "rejected"));
  }

  private void step_2() {
    /* Player has to kill the creatures*/
  }

  private void step_3() {

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


    final List<ChatAction> actions = new LinkedList<ChatAction>();
      actions.add(new EquipItemAction("potion", 3));
    actions.add(new IncreaseXPAction(100));
    actions.add(new SetQuestAction(QUEST_SLOT, "killed;1"));
    actions.add(new SetQuestToTimeStampAction(QUEST_SLOT, 1));
   
    LinkedList<String> triggers = new LinkedList<String>();
    triggers.addAll(ConversationPhrases.FINISH_MESSAGES);
    triggers.addAll(ConversationPhrases.QUEST_MESSAGES);   
    npc.add(ConversationStates.ATTENDING,
        triggers,
        new AndCondition(
            new QuestInStateCondition(QUEST_SLOT, 0, "start"),
            new KilledForQuestCondition(QUEST_SLOT, 1)),
        ConversationStates.ATTENDING,
        "I see you have killed the gnomes as I asked. I hope they will stay away from the carrots for a while! "
        + "Please take these potions as a reward.",
        new MultipleActions(actions));

    npc.add(ConversationStates.ATTENDING,
        triggers,
        new AndCondition(
            new QuestInStateCondition(QUEST_SLOT, 0, "start"),
            new NotCondition(new KilledForQuestCondition(QUEST_SLOT, 1))),
        ConversationStates.ATTENDING,
        "You need to teach those pesky gnomes a lesson, by killing some as an example! "
        + "Make sure you get the leaders, too, at least one infantryman and one cavalryman.",
        null);
  }

  @Override
  public void addToWorld() {
    super.addToWorld();
    fillQuestInfo(
        "Kill Gnomes",
        "Jenny isn't happy that gnomes keep stealing her carrots.",
        false);
    step_1();
    step_2();
    step_3();
  }
 
  @Override
  public List<String> getHistory(final Player player) {
      final List<String> res = new ArrayList<String>();
      if (!player.hasQuest(QUEST_SLOT)) {
        return res;
      }
      if (!isCompleted(player)) {
        res.add("I must kill some gnomes, especially the leader ones, to teach them all a lesson!");
      } else if(isRepeatable(player)){
        res.add("Those pesky gnomes have forgotten the lesson I taught them and are stealing again! Jenny needs my help.");
      } else {
        res.add("The gnomes are now staying away from Jenny's carrots. Yeah!");
      }
      return res;
  }


  @Override
  public String getName() {
    return "KillGnomes";
  }
 
  @Override
  public int getMinLevel() {
    return 10;
  }
 
  @Override
  public boolean isRepeatable(final Player player) {
    return new AndCondition(new QuestStateStartsWithCondition(QUEST_SLOT,"killed"),
         new TimePassedCondition(QUEST_SLOT, 1, WEEK_IN_MINUTES)).fire(player,null, null);
  }
 
  @Override
  public boolean isCompleted(final Player player) {
    return new QuestStateStartsWithCondition(QUEST_SLOT,"killed").fire(player, null, null);
  }
}
TOP

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

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.