View Javadoc

1   /*
2    * Created on Nov 9, 2004 
3    * Original filename was NextPhase.java
4    * 
5    *   Magic-Project is a turn based strategy simulator
6    *   Copyright (C) 2003-2007 Fabrice Daugan
7    *
8    *   This program is free software; you can redistribute it and/or modify it 
9    * under the terms of the GNU General Public License as published by the Free 
10   * Software Foundation; either version 2 of the License, or (at your option) any
11   * later version.
12   *
13   *   This program is distributed in the hope that it will be useful, but WITHOUT 
14   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
16   * details.
17   *
18   *   You should have received a copy of the GNU General Public License along  
19   * with this program; if not, write to the Free Software Foundation, Inc., 
20   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21   * 
22   */
23  package net.sf.magicproject.action;
24  
25  import java.io.IOException;
26  import java.io.InputStream;
27  
28  import net.sf.magicproject.action.handler.StandardAction;
29  import net.sf.magicproject.clickable.ability.Ability;
30  import net.sf.magicproject.event.context.ContextEventListener;
31  import net.sf.magicproject.event.phase.PhaseFilter;
32  import net.sf.magicproject.expression.Expression;
33  import net.sf.magicproject.expression.ExpressionFactory;
34  
35  /***
36   * Set the next phase name.
37   * 
38   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
39   * @since 0.80
40   */
41  class NextPhase extends UserAction implements StandardAction {
42  
43  	/***
44  	 * Create an instance of NextPhase by reading a file Offset's file must
45  	 * pointing on the first byte of this action
46  	 * <ul>
47  	 * Structure of InputStream : Data[size]
48  	 * <li>idAction [1]</li>
49  	 * <li>phase filter [1]</li>
50  	 * <li>phase index/id : Expression [...]</li>
51  	 * </ul>
52  	 * 
53  	 * @param inputFile
54  	 *          file containing this action
55  	 * @throws IOException
56  	 *           if error occurred during the reading process from the specified
57  	 *           input stream
58  	 */
59  	NextPhase(InputStream inputFile) throws IOException {
60  		super(inputFile);
61  		phaseFilter = PhaseFilter.valueOf(inputFile);
62  		idPhase = ExpressionFactory.readNextExpression(inputFile);
63  	}
64  
65  	@Override
66  	public final Actiontype getIdAction() {
67  		return Actiontype.NEXT_PHASE;
68  	}
69  
70  	public boolean play(ContextEventListener context, Ability ability) {
71  		phaseFilter.setNextPhase(idPhase.getValue(ability, ability.getCard(),
72  				context));
73  		return true;
74  	}
75  
76  	@Override
77  	public String toString(Ability ability) {
78  		return "next phase";
79  	}
80  
81  	/***
82  	 * The next phase identifiant to set. The complex expression to use for the
83  	 * right value. Is null if the IdToken number is not a complex expression.
84  	 */
85  	private Expression idPhase = null;
86  
87  	/***
88  	 * The phase filter to use.
89  	 */
90  	protected PhaseFilter phaseFilter;
91  
92  }