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.Test;
31
32 /***
33 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
34 */
35 public class ModifiedOwner extends TriggeredEvent {
36
37 /***
38 * Creates a new instance of MEventModifiedOwner <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 public ModifiedOwner(InputStream inputFile, MCard card) throws IOException {
54 super(inputFile, card);
55 }
56
57 /***
58 * Creates a new instance of MEventModifiedOwner <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 ModifiedOwner(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 ModifiedOwner(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 idPlayer
89 * the modified player
90 * @return true if the current event match with this event
91 */
92 public boolean isMatching(int idPlayer) {
93 return true;
94 }
95
96 /***
97 * Dispatch this event to all active event listeners able to understand this
98 * event. The listening events able to understand this event are <code>this
99 * </code>
100 * and other multiple event listeners. For each event listeners having
101 * responded they have been activated, the corresponding ability is added to
102 * the triggered buffer zone of player owning this ability
103 *
104 * @param idPlayer
105 * the new owner
106 * @see #isMatching(int)
107 */
108 public static void dispatchEvent(int idPlayer) {
109 for (Ability ability : TRIGGRED_ABILITIES.get(EVENT)) {
110 if (ability.isMatching()
111 && ((ModifiedOwner) ability.eventComing()).isMatching(idPlayer)) {
112 ability.triggerIt(new MContextCardCardIntInt(ability.getCard(),
113 idPlayer));
114 }
115 }
116 }
117
118 @Override
119 public final Event getIdEvent() {
120 return EVENT;
121 }
122
123 /***
124 * The event type.
125 */
126 public static final Event EVENT = Event.MODIFIED_OWNER;
127
128 }