View Javadoc

1   /*
2    *   Magic-Project is a turn based strategy simulator
3    *   Copyright (C) 2003-2007 Fabrice Daugan
4    *
5    *   This program is free software; you can redistribute it and/or modify it 
6    * under the terms of the GNU General Public License as published by the Free 
7    * Software Foundation; either version 2 of the License, or (at your option) any
8    * later version.
9    *
10   *   This program is distributed in the hope that it will be useful, but WITHOUT 
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
13   * details.
14   *
15   *   You should have received a copy of the GNU General Public License along  
16   * with this program; if not, write to the Free Software Foundation, Inc., 
17   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   * 
19   * MEventBecomeUnTapped.java
20   * Created on 29 janv. 2004
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 become untapped
35   * 
36   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
37   * @since 0.54
38   */
39  public class BecomeUnTapped extends TriggeredEvent {
40  
41  	/***
42  	 * Create an instance of MEventBecomeUnTapped by reading a file Offset's file
43  	 * must pointing 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  	BecomeUnTapped(InputStream inputFile, MCard card) throws IOException {
59  		super(inputFile, card);
60  	}
61  
62  	/***
63  	 * Creates a new instance of MEventBecomeUnTapped specifying all attributes of
64  	 * this class. All parameters are copied, not cloned. So this new object
65  	 * shares the card 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 BecomeUnTapped(int idZone, Test test, MCard card) {
75  		super(idZone, test, card);
76  	}
77  
78  	@Override
79  	public MEventListener clone(MCard card) {
80  		return new BecomeUnTapped(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 tappedCard
92  	 *          the became taped/untapped
93  	 * @return true if the current event match with this event
94  	 */
95  	public boolean isMatching(Ability ability, MCard tappedCard) {
96  		return test(ability, tappedCard);
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 tappedCard
108 	 *          the became taped/untapped
109 	 * @see #isMatching(Ability, MCard)
110 	 */
111 	public static void dispatchEvent(MCard tappedCard) {
112 		for (Ability ability : TRIGGRED_ABILITIES.get(EVENT)) {
113 			if (ability.isMatching()
114 					&& ((BecomeUnTapped) ability.eventComing()).isMatching(ability,
115 							tappedCard)) {
116 				ability.triggerIt(new MContextCardCardIntInt(tappedCard));
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.BECOMING_UNTAPPED;
130 
131 	@Override
132 	public MEventListener appendOr(MEventListener other) {
133 		return new BecomeUnTapped(idZone, Or.append(this.test, other.test), card);
134 	}
135 
136 }