1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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 }