1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package net.sf.magicproject.action;
23
24 import java.io.IOException;
25 import java.io.InputStream;
26
27 import net.sf.magicproject.action.handler.StandardAction;
28 import net.sf.magicproject.clickable.ability.Ability;
29 import net.sf.magicproject.clickable.targetable.player.Player;
30 import net.sf.magicproject.event.context.ContextEventListener;
31 import net.sf.magicproject.expression.Expression;
32 import net.sf.magicproject.expression.ExpressionFactory;
33 import net.sf.magicproject.stack.MPhase;
34 import net.sf.magicproject.stack.StackManager;
35
36 /***
37 * Skip a specified phase following it's identifiant. The specified phase name
38 * must have been previously defined in the source file or include. The target
39 * list is used to known the player(s) phase to skip.
40 *
41 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
42 * @since 0.1
43 */
44 class SkipPhase extends UserAction implements StandardAction {
45
46 /***
47 * Create an instance of SkipPhase by reading a file Offset's file must
48 * pointing on the first byte of this action <br>
49 * <ul>
50 * Structure of InputStream : Data[size]
51 * <li>phase [Expression]</li>
52 * </ul>
53 *
54 * @param inputFile
55 * file containing this action
56 * @throws IOException
57 * if error occurred during the reading process from the specified
58 * input stream
59 */
60 SkipPhase(InputStream inputFile) throws IOException {
61 super(inputFile);
62 phase = ExpressionFactory.readNextExpression(inputFile);
63 }
64
65 @Override
66 public final Actiontype getIdAction() {
67 return Actiontype.SKIP_PHASE;
68 }
69
70 public boolean play(ContextEventListener context, Ability ability) {
71 int idPhase = phase.getValue(ability, null, context);
72 for (int i = StackManager.getInstance().getTargetedList().size(); i-- > 0;) {
73 int idPlayer = ((Player) StackManager.getInstance().getTargetedList()
74 .get(i)).idPlayer;
75 for (int j = MPhase.phases[idPlayer].length; j-- > 0;) {
76 if (MPhase.phases[idPlayer][j].phaseType.id == idPhase) {
77 MPhase.phases[idPlayer][j].skipThisPhase = true;
78 }
79 }
80 }
81 return true;
82 }
83
84 @Override
85 public String toString(Ability ability) {
86 return "skip phase";
87 }
88
89 /***
90 * The phase index of the targeted player to skip
91 */
92 private Expression phase;
93
94 }