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.event;
23
24 import java.io.IOException;
25 import java.io.InputStream;
26
27 import net.sf.magicproject.clickable.ability.Ability;
28 import net.sf.magicproject.clickable.targetable.Targetable;
29 import net.sf.magicproject.clickable.targetable.card.MCard;
30 import net.sf.magicproject.expression.Expression;
31 import net.sf.magicproject.expression.ExpressionFactory;
32 import net.sf.magicproject.operation.Any;
33 import net.sf.magicproject.operation.Operation;
34 import net.sf.magicproject.test.Test;
35 import net.sf.magicproject.token.Register;
36
37 /***
38 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
39 * @since 0.86
40 */
41 public class ModifiedRegisterRange extends ModifiedRegister {
42
43 /***
44 * Create an instance of MEventModifiedRegisterRange by reading a file
45 * Offset's file must pointing on the first byte of this event <br>
46 * <ul>
47 * Structure of InputStream : Data[size]
48 * <li>[super]</li>
49 * <li>sup [Expression]</li>
50 * </ul>
51 *
52 * @param inputFile
53 * is the file containing this event
54 * @param card
55 * is the card owning this event
56 * @throws IOException
57 * if error occurred during the reading process from the specified
58 * input stream
59 */
60 ModifiedRegisterRange(InputStream inputFile, MCard card) throws IOException {
61 super(inputFile, card);
62 sup = ExpressionFactory.readNextExpression(inputFile);
63 }
64
65 /***
66 * Creates a new instance of MEventModifiedRegisterRange specifying all
67 * attributes of this class. All parameters are copied, not cloned. So this
68 * new object shares the card and the specified codes
69 *
70 * @param idZone
71 * the place constraint to activate this event
72 * @param sourceTest
73 * the test applied on card modifying the card.
74 * @param testModified
75 * the test applied on the modified component.
76 * @param card
77 * is the card owning this card
78 * @param op
79 * the looked for operation. Any or specific operation instance.
80 * @param register
81 * the modified register
82 * @param inf
83 * the inferior range looked for this event
84 * @param sup
85 * the superior range looked for this event
86 */
87 public ModifiedRegisterRange(int idZone, Test sourceTest, Test testModified,
88 MCard card, Operation op, Register register, Expression inf,
89 Expression sup) {
90 super(idZone, sourceTest, testModified, card, op, register, inf);
91 this.sup = sup;
92 }
93
94 @Override
95 public MEventListener clone(MCard card) {
96 return new ModifiedRegisterRange(idZone, test, testModified, card, op,
97 register, index, sup);
98 }
99
100 @Override
101 public boolean isMatching(Ability ability, Targetable modified, MCard source,
102 Operation op, int register, int index) {
103 final int indexValue = this.index.getValue(ability, modified, null);
104 return this.register.ordinal() == register && indexValue <= index
105 && indexValue >= index
106 && (this.op == op || this.op == Any.getInstance())
107 && testModified.test(ability, modified) && test(ability, source);
108 }
109
110 /***
111 * The superior range looked for this event
112 */
113 protected Expression sup;
114
115 }