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.test;
23
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.util.List;
27
28 import net.sf.magicproject.clickable.ability.Ability;
29 import net.sf.magicproject.clickable.targetable.Targetable;
30 import net.sf.magicproject.clickable.targetable.card.MCard;
31 import net.sf.magicproject.event.MEventListener;
32 import net.sf.magicproject.event.phase.BeginningPhase;
33 import net.sf.magicproject.event.phase.EndOfPhase;
34 import net.sf.magicproject.event.phase.PhaseFilter;
35 import net.sf.magicproject.expression.Expression;
36 import net.sf.magicproject.expression.ExpressionFactory;
37 import net.sf.magicproject.token.IdZones;
38
39 /***
40 * Test the current phase
41 *
42 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
43 * @since 0.72
44 */
45 class PhaseIs extends Test {
46
47 /***
48 * Create an instance of PhaseIs by reading a file. Offset's file must
49 * pointing on the first byte of this test <br>
50 * <ul>
51 * Structure of InputStream : Data[size]
52 * <li>idTest [1]</li>
53 * <li>tested on (idTestedOn) [1]</li>
54 * <li>phase filter [1]</li>
55 * <li>phase index/id : Expression [...]</li>
56 * </ul>
57 *
58 * @param inputFile
59 * is the file containing this event
60 * @throws IOException
61 * if error occurred during the reading process from the specified
62 * input stream
63 */
64 PhaseIs(InputStream inputFile) throws IOException {
65 super(inputFile);
66 phaseFilter = PhaseFilter.valueOf(inputFile);
67 idPhase = ExpressionFactory.readNextExpression(inputFile);
68 }
69
70 @Override
71 public boolean test(Ability ability, Targetable tested) {
72 return phaseFilter.getPhaseFilter() == idPhase.getValue(ability, tested,
73 null);
74 }
75
76 @Override
77 public void extractTriggeredEvents(List<MEventListener> res, MCard source,
78 Test globalTest) {
79 res.add(new EndOfPhase(IdZones.PLAY, globalTest, source, idPhase,
80 phaseFilter));
81 res.add(new BeginningPhase(IdZones.PLAY, globalTest, source, idPhase,
82 phaseFilter));
83 }
84
85 /***
86 * Is the phase to match during each test
87 */
88 private Expression idPhase;
89
90 /***
91 * The phase filter to use.
92 */
93 protected PhaseFilter phaseFilter;
94
95 }