Package games.stendhal.server.maps.quests.piedpiper

Source Code of games.stendhal.server.maps.quests.piedpiper.TPPQuest

/* $Id: TPPQuest.java,v 1.11 2011/01/07 22:46:57 nhnb 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.piedpiper;

import games.stendhal.common.NotificationType;
import games.stendhal.server.core.engine.GameEvent;
import games.stendhal.server.core.engine.SingletonRepository;
import games.stendhal.server.core.events.TurnListener;
import games.stendhal.server.core.events.TurnNotifier;
import games.stendhal.server.maps.quests.ThePiedPiper;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

public class TPPQuest implements ITPPQuest {
 
  protected static final Logger logger = Logger.getLogger(ThePiedPiper.class)
  protected Map<String, Integer> timings;
 
  public String getSwitchingToNextPhaseMessage() {
    return null;
  }
 
  public String getSwitchingToDefPhaseMessage() {
    return null;
  }
 
  public TPP_Phase getPhase() {
    return null;
  }
 
  public TPPQuest(Map<String, Integer> timings) {
    this.timings=timings;
  }
 
  /**
   * wrapper for shout to all function
   * @param msg
   */
  public void shoutMessage(final String msg) {
    if(msg!=null) {
      SingletonRepository.getRuleProcessor().tellAllPlayers(NotificationType.PRIVMSG, msg);
    }
  }

 
  /**
   * timer for npc's shouts to player.
   */
  class ShouterTimer implements TurnListener {
    private String shoutMsg;
    private int shoutTime;
   
    public void start() {
      shoutMessage(shoutMsg);
      TurnNotifier.get().dontNotify(this);
      TurnNotifier.get().notifyInSeconds(shoutTime, this);
    }
   
    public void stop() {
      TurnNotifier.get().dontNotify(this);
    }
   
    public void onTurnReached(int currentTurn) {     
      start();
    }
   
    public void setShouts(final String msg) {
      shoutMsg = msg;
    }
   
    public void setTime(int time) {
      shoutTime = time;
    }

    public ShouterTimer(final int time, final String msg) {
      setTime(time);
      setShouts(msg);
    }

  }
 
  private final ShouterTimer shouterTimer = new ShouterTimer(-1, null);
 
  protected void changeShouts(final int time, final String msg) {
    shouterTimer.setTime(time);
    shouterTimer.setShouts(msg);
  }
 
  protected void startShouts(int time, String msg) {
    shouterTimer.setTime(time);
    shouterTimer.setShouts(msg);
    shouterTimer.start();
  }
 
  protected void stopShouts() {
    shouterTimer.stop();
  }

 
  public void phaseToDefaultPhase(List<String> comments) {
    shoutMessage(getSwitchingToDefPhaseMessage());
    ThePiedPiper.setPhase(ThePiedPiper.getDefaultPhaseClass().getPhase());
    logger.info("ThePiedPiper quest: switch phase ("+
        ThePiedPiper.getPhase().name()+
        ") to ("+
        ThePiedPiper.getDefaultPhaseClass().getPhase().name());
    stopShouts();
    ThePiedPiper.setNewNotificationTime(
        ThePiedPiper.getDefaultPhaseClass().getMinTimeOut(),
        ThePiedPiper.getDefaultPhaseClass().getMaxTimeOut())
    ThePiedPiper.getDefaultPhaseClass().prepare();
    if(!comments.isEmpty()) {
      new GameEvent(null, "raid", comments.toString()).raise();
    }
  }

  public void phaseToNextPhase(ITPPQuest nextPhase, List<String> comments) {
    shoutMessage(getSwitchingToNextPhaseMessage());
    if(!comments.isEmpty()) {
      new GameEvent(null, "raid", comments.toString()).raise();
    }
    logger.info("ThePiedPiper quest: switch phase to ("+nextPhase.getPhase().name()+").");
    ThePiedPiper.setPhase(nextPhase.getPhase());
    stopShouts();
    ThePiedPiper.setNewNotificationTime(
        nextPhase.getMinTimeOut(),
        nextPhase.getMaxTimeOut());
    nextPhase.prepare();
  }
 
  public void prepare() {
   
  }
 
  public int getMaxTimeOut() {
    return 0;
  }

  public int getMinTimeOut() {
    return 0;
  }
 
}
TOP

Related Classes of games.stendhal.server.maps.quests.piedpiper.TPPQuest

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.