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