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.card.MCard;
29 import net.sf.magicproject.event.context.MContextCardCardIntInt;
30 import net.sf.magicproject.expression.Expression;
31 import net.sf.magicproject.expression.ExpressionFactory;
32 import net.sf.magicproject.test.Test;
33
34 /***
35 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
36 */
37 public class ModifiedIdColor extends TriggeredEvent {
38
39 /***
40 * Creates a new instance of MEventModifiedIdColor <br>
41 * <ul>
42 * Structure of InputStream : Data[size]
43 * <li>[super]</li>
44 * <li>test [Test]</li>
45 * <li>color [Expression]</li>
46 * </ul>
47 *
48 * @param inputFile
49 * is the file containing this event
50 * @param card
51 * is the card owning this event
52 * @throws IOException
53 * if error occurred during the reading process from the specified
54 * input stream
55 */
56 ModifiedIdColor(InputStream inputFile, MCard card) throws IOException {
57 super(inputFile, card);
58 idColor = ExpressionFactory.readNextExpression(inputFile);
59 }
60
61 /***
62 * Creates a new instance of MEventModifiedIdColor <br>
63 *
64 * @param idZone
65 * the place constraint to activate this event
66 * @param test
67 * the test of this event
68 * @param card
69 * is the card owning this card
70 * @param idColor
71 * the modified color.
72 */
73 public ModifiedIdColor(int idZone, Test test, MCard card, Expression idColor) {
74 super(idZone, test, card);
75 this.idColor = idColor;
76 }
77
78 /***
79 * Return a copy of this with the specified owner
80 *
81 * @param card
82 * is the card of the ability of this event
83 * @return copy of this event
84 */
85 @Override
86 public MEventListener clone(MCard card) {
87 return new ModifiedIdColor(idZone, test, card, idColor);
88 }
89
90 /***
91 * Tell if the current event matches with this event. If there is an
92 * additional code to check, it'would be checked if the main event matches
93 * with the main event
94 *
95 * @param ability
96 * is the ability owning this test. The card component of this
97 * ability should correspond to the card owning this test too.
98 * @param modifiedCard
99 * is the modified card.
100 * @param idColor
101 * the modified color
102 * @return true if the current event match with this event
103 */
104 public boolean isMatching(Ability ability, MCard modifiedCard, int idColor) {
105 return (this.idColor.getValue(ability, modifiedCard, null) & idColor) != 0
106 && test(ability, modifiedCard);
107 }
108
109 /***
110 * Dispatch this event to all active event listeners able to understand this
111 * event. The listening events able to understand this event are <code>this
112 * </code>
113 * and other multiple event listeners. For each event listeners having
114 * responded they have been activated, the corresponding ability is added to
115 * the triggered buffer zone of player owning this ability
116 *
117 * @param modifiedCard
118 * is the targetable owning the modified color
119 * @param color
120 * the modified color
121 * @see #isMatching(Ability, MCard, int)
122 */
123 public static void dispatchEvent(MCard modifiedCard, int color) {
124 for (Ability ability : TRIGGRED_ABILITIES.get(EVENT)) {
125 if (ability.isMatching()
126 && ((ModifiedIdColor) ability.eventComing()).isMatching(ability,
127 modifiedCard, color)) {
128 ability.triggerIt(new MContextCardCardIntInt(modifiedCard, color));
129 }
130 }
131 }
132
133 @Override
134 public final Event getIdEvent() {
135 return EVENT;
136 }
137
138 /***
139 * The event type.
140 */
141 public static final Event EVENT = Event.MODIFIED_IDCOLOR;
142
143 /***
144 * The tested color identifier
145 */
146 private Expression idColor;
147
148 }