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 * Event generated when a card is faced down.
35 *
36 * @author <a href="mailto:hoani.cross@gmail.com">Hoani CROSS</a>
37 * @since 0.90
38 */
39 public class FacedDown extends TriggeredEvent {
40
41 /***
42 * Create an instance of FacedUp by reading a file Offset's file must pointing
43 * on the first byte of this event <br>
44 * <ul>
45 * Structure of InputStream : Data[size]
46 * <li>idZone [1]</li>
47 * <li>test [...]</li>
48 * </ul>
49 *
50 * @param inputFile
51 * is the file containing this event
52 * @param card
53 * is the card owning this event
54 * @throws IOException
55 * if error occurred during the reading process from the specified
56 * input stream
57 */
58 FacedDown(InputStream inputFile, MCard card) throws IOException {
59 super(inputFile, card);
60 }
61
62 /***
63 * Creates a new instance of FacedUp specifying all attributes of this class.
64 * All parameters are copied, not cloned. So this new object shares the card
65 * and the specified codes
66 *
67 * @param idZone
68 * the place constraint to activate this event
69 * @param test
70 * the test of this event
71 * @param card
72 * is the card owning this card
73 */
74 public FacedDown(int idZone, Test test, MCard card) {
75 super(idZone, test, card);
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 FacedDown(idZone, test, card);
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 facedDownCard
96 * the became taped/untapped
97 * @param ability
98 * is the ability owning this test. The card component of this
99 * ability should correspond to the card owning this test too.
100 * @return true if the current event match with this event
101 */
102 public boolean isMatching(Ability ability, MCard facedDownCard) {
103 return test(ability, facedDownCard);
104 }
105
106 /***
107 * Dispatch this event to all active event listeners able to understand this
108 * event. The listening events able to understand this event are <code>this
109 * </code>
110 * and other multiple event listeners. For each event listeners having
111 * responded they have been activated, the corresponding ability is added to
112 * the triggered buffer zone of player owning this ability
113 *
114 * @param facedDownCard
115 * the became taped/untapped
116 * @see #isMatching(Ability, MCard)
117 */
118 public static void dispatchEvent(MCard facedDownCard) {
119 for (Ability ability : TRIGGRED_ABILITIES.get(EVENT)) {
120 if (ability.isMatching()
121 && ((FacedDown) ability.eventComing()).isMatching(ability,
122 facedDownCard)) {
123 ability.triggerIt(new MContextCardCardIntInt(facedDownCard));
124 }
125 }
126 }
127
128 @Override
129 public final Event getIdEvent() {
130 return EVENT;
131 }
132
133 /***
134 * The event type.
135 */
136 public static final Event EVENT = Event.FACED_DOWN;
137
138 /***
139 * Create and returns an union of this event and the specified one. Both event
140 * must have the same type. Test(s) and events attributes may be groupped
141 * depending instance of this event. If no possible append is possible
142 * <code>null</code> is returned.
143 *
144 * @param other
145 * the event to append with 'or' operator.
146 * @return a new event reprensenting 'this' or 'other'
147 */
148 @Override
149 public MEventListener appendOr(MEventListener other) {
150 return new FacedDown(idZone, Or.append(this.test, other.test), card);
151 }
152 }