View Javadoc

1   /*
2    * MEventDuringPhase.java 
3    * Created on 27 janv. 2004
4    * 
5    *   Magic-Project is a turn based strategy simulator
6    *   Copyright (C) 2003-2007 Fabrice Daugan
7    *
8    *   This program is free software; you can redistribute it and/or modify it 
9    * under the terms of the GNU General Public License as published by the Free 
10   * Software Foundation; either version 2 of the License, or (at your option) any
11   * later version.
12   *
13   *   This program is distributed in the hope that it will be useful, but WITHOUT 
14   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
16   * details.
17   *
18   *   You should have received a copy of the GNU General Public License along  
19   * with this program; if not, write to the Free Software Foundation, Inc., 
20   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21   * 
22   */
23  package net.sf.magicproject.event.phase;
24  
25  import java.io.IOException;
26  import java.io.InputStream;
27  
28  import net.sf.magicproject.clickable.ability.Ability;
29  import net.sf.magicproject.clickable.targetable.card.MCard;
30  import net.sf.magicproject.event.Event;
31  import net.sf.magicproject.event.MEventListener;
32  import net.sf.magicproject.event.context.ContextEventListener;
33  import net.sf.magicproject.expression.Expression;
34  import net.sf.magicproject.stack.EventManager;
35  import net.sf.magicproject.test.Or;
36  import net.sf.magicproject.test.Test;
37  import net.sf.magicproject.ui.i18n.LanguageManagerMDB;
38  
39  /***
40   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
41   * @since 0.54
42   */
43  public class BeginningPhase extends PhaseEvent {
44  
45  	/***
46  	 * Create an instance of MEventBeginningPhase by reading a file Offset's file
47  	 * must pointing on the first byte of this event <br>
48  	 * <ul>
49  	 * Structure of InputStream : Data[size]
50  	 * <li>idZone [1]</li>
51  	 * <li>test [...]</li>
52  	 * <li>idPhase(phase identifiant) [2]</li>
53  	 * </ul>
54  	 * 
55  	 * @param inputFile
56  	 *          is the file containing this event
57  	 * @param card
58  	 *          is the card owning this event
59  	 * @throws IOException
60  	 *           if error occurred during the reading process from the specified
61  	 *           input stream
62  	 */
63  	public BeginningPhase(InputStream inputFile, MCard card) throws IOException {
64  		super(inputFile, card);
65  	}
66  
67  	/***
68  	 * Creates a new instance of MEventBeginningPhase specifying all attributes of
69  	 * this class. All parameters are copied, not cloned. So this new object
70  	 * shares the card and the specified codes
71  	 * 
72  	 * @param idZone
73  	 *          the place constraint to activate this event
74  	 * @param test
75  	 *          the additional test
76  	 * @param card
77  	 *          is the card owning this card
78  	 * @param idPhase
79  	 *          the looked for phase identifiant
80  	 * @param phaseFilter
81  	 *          the filter.
82  	 */
83  	public BeginningPhase(int idZone, Test test, MCard card, Expression idPhase,
84  			PhaseFilter phaseFilter) {
85  		super(idZone, test, card, idPhase, phaseFilter);
86  	}
87  
88  	@Override
89  	public final Event getIdEvent() {
90  		return EVENT;
91  	}
92  
93  	/***
94  	 * The event type.
95  	 */
96  	public static final Event EVENT = Event.BEGINNING_PHASE;
97  
98  	/***
99  	 * Dispatch this event to all active event listeners able to understand this
100 	 * event. The listening events able to understand this event are <code>this
101 	 * </code>
102 	 * and other multiple event listeners. For each event listeners having
103 	 * responded they have been activated, the corresponding ability is added to
104 	 * the triggered buffer zone of player owning this ability. <br>
105 	 */
106 	public static void dispatchEvent() {
107 		dispatchEvent(EVENT);
108 	}
109 
110 	/***
111 	 * Return a copy of this with the specified owner
112 	 * 
113 	 * @param card
114 	 *          is the card of the ability of this event
115 	 * @return copy of this event
116 	 */
117 	@Override
118 	public MEventListener clone(MCard card) {
119 		return new BeginningPhase(idZone, test, card, idPhase, phaseFilter);
120 	}
121 
122 	@Override
123 	public String toHtmlString(Ability ability, ContextEventListener context) {
124 		return LanguageManagerMDB.getString("event-bop", LanguageManagerMDB
125 				.getString(EventManager.turnStructure[idPhase.getValue(ability, null,
126 						context)].phaseName));
127 	}
128 
129 	@Override
130 	public MEventListener appendOr(MEventListener other) {
131 		if (((PhaseEvent) other).idPhase == idPhase) {
132 			return new BeginningPhase(idZone, Or.append(this.test, other.test), card,
133 					idPhase, phaseFilter);
134 		}
135 		return null;
136 	}
137 }