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.test.Or;
31 import net.sf.magicproject.test.Test;
32
33 /***
34 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
35 * @since 0.54
36 */
37 public class BecomeTapped extends TriggeredEvent {
38
39 /***
40 * Create an instance of MEventBecomeTapped by reading a file Offset's file
41 * must pointing on the first byte of this event <br>
42 * <ul>
43 * Structure of InputStream : Data[size]
44 * <li>idZone [1]</li>
45 * <li>test [...]</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 BecomeTapped(InputStream inputFile, MCard card) throws IOException {
57 super(inputFile, card);
58 }
59
60 /***
61 * Creates a new instance of MEventBecomeTapped specifying all attributes of
62 * this class. All parameters are copied, not cloned. So this new object
63 * shares the card and the specified codes
64 *
65 * @param idZone
66 * the place constraint to activate this event
67 * @param test
68 * the test of this event
69 * @param card
70 * is the card owning this card
71 */
72 public BecomeTapped(int idZone, Test test, MCard card) {
73 super(idZone, test, card);
74 }
75
76 @Override
77 public MEventListener clone(MCard card) {
78 return new BecomeTapped(idZone, test, card);
79 }
80
81 /***
82 * Tell if the current event matches with this event. If there is an
83 * additional code to check, it'would be checked if the main event matches
84 * with the main event
85 *
86 * @param tappedCard
87 * the became taped/untapped
88 * @param ability
89 * is the ability owning this test. The card component of this
90 * ability should correspond to the card owning this test too.
91 * @return true if the current event match with this event
92 */
93 public boolean isMatching(Ability ability, MCard tappedCard) {
94 return test(ability, tappedCard);
95 }
96
97 /***
98 * Dispatch this event to all active event listeners able to understand this
99 * event. The listening events able to understand this event are <code>this
100 * </code>
101 * and other multiple event listeners. For each event listeners having
102 * responded they have been activated, the corresponding ability is added to
103 * the triggered buffer zone of player owning this ability
104 *
105 * @param tappedCard
106 * the became taped/untapped
107 * @see #isMatching(Ability, MCard)
108 */
109 public static void dispatchEvent(MCard tappedCard) {
110 for (Ability ability : TRIGGRED_ABILITIES.get(EVENT)) {
111 if (ability.isMatching()
112 && ((BecomeTapped) ability.eventComing()).isMatching(ability,
113 tappedCard)) {
114 ability.triggerIt(new MContextCardCardIntInt(tappedCard));
115 }
116 }
117 }
118
119 @Override
120 public final Event getIdEvent() {
121 return EVENT;
122 }
123
124 /***
125 * The event type.
126 */
127 public static final Event EVENT = Event.BECOMING_TAPPED;
128
129 @Override
130 public MEventListener appendOr(MEventListener other) {
131 return new BecomeTapped(idZone, Or.append(this.test, other.test), card);
132 }
133
134 }