View Javadoc

1   /*
2    * Created on 21 mars 2005
3    * 
4    *   Magic-Project is a turn based strategy simulator
5    *   Copyright (C) 2003-2007 Fabrice Daugan
6    *
7    *   This program is free software; you can redistribute it and/or modify it 
8    * under the terms of the GNU General Public License as published by the Free 
9    * Software Foundation; either version 2 of the License, or (at your option) any
10   * later version.
11   *
12   *   This program is distributed in the hope that it will be useful, but WITHOUT 
13   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
15   * details.
16   *
17   *   You should have received a copy of the GNU General Public License along  
18   * with this program; if not, write to the Free Software Foundation, Inc., 
19   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   */
21  package net.sf.magicproject.clickable.targetable.card;
22  
23  import java.util.Set;
24  
25  import net.sf.magicproject.clickable.targetable.Targetable;
26  import net.sf.magicproject.clickable.targetable.player.Player;
27  import net.sf.magicproject.modifier.ColorModifier;
28  import net.sf.magicproject.modifier.ControllerModifier;
29  import net.sf.magicproject.modifier.IdCardModifier;
30  import net.sf.magicproject.modifier.PlayableZoneModifier;
31  import net.sf.magicproject.modifier.PropertyModifier;
32  import net.sf.magicproject.modifier.RegisterIndirection;
33  import net.sf.magicproject.modifier.RegisterModifier;
34  import net.sf.magicproject.operation.Operation;
35  import net.sf.magicproject.token.IdTokens;
36  
37  /***
38   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
39   * @since 0.83
40   */
41  public class LastKnownCard extends MCard implements LastKnownCardInfo {
42  
43  	/***
44  	 * @param originalCard
45  	 *          the original card reference.
46  	 * @param destinationZone
47  	 *          destination id zone.
48  	 * @param idColor
49  	 *          the original color id.
50  	 * @param idCard
51  	 *          the original card type.
52  	 * @param tapped
53  	 *          the original tapped position.
54  	 * @param registers
55  	 *          the original registers.
56  	 * @param controller
57  	 *          the original controller.
58  	 * @param owner
59  	 *          the original owner.
60  	 * @param properties
61  	 *          the original properties.
62  	 * @param timestamp
63  	 *          the snapshot timestamp.
64  	 * @param timestampReferences
65  	 *          the references to the cards.
66  	 */
67  	public LastKnownCard(MCard originalCard, int destinationZone, int idColor,
68  			int idCard, boolean tapped, int[] registers, Player controller,
69  			Player owner, Set<Integer> properties, int timestamp,
70  			int timestampReferences) {
71  		// the current zone of the referenced card and not the last known zone.
72  		super();
73  		if (originalCard != null) {
74  			this.database = originalCard.database;
75  		}
76  		this.idZone = destinationZone;
77  		this.cachedIdColor = idColor;
78  		this.cachedIdCard = idCard;
79  		this.cachedRegisters = registers;
80  		this.cachedProperties = properties;
81  		this.tapped = tapped;
82  		this.controller = controller;
83  		this.owner = owner;
84  		this.originalCard = originalCard;
85  		this.timeStamp = timestamp;
86  		this.timestampReferences = timestampReferences;
87  	}
88  
89  	@Override
90  	public void addTimestampReference() {
91  		originalCard.addTimestampReference();
92  	}
93  
94  	@Override
95  	public void reverse(boolean reversed) {
96  		originalCard.reverse(reversed);
97  	}
98  
99  	public LastKnownCard createLastKnownCard() {
100 		return this;
101 	}
102 
103 	@Override
104 	public Targetable getOriginalTargetable() {
105 		return originalCard;
106 	}
107 
108 	/***
109 	 * Remove a reference to the given timestamp of card.
110 	 * 
111 	 * @param timestamp
112 	 *          the timestamp reference
113 	 * @return true if the given timestamp is no more referenced.
114 	 */
115 	public boolean removeTimestamp(int timestamp) {
116 		return --timestampReferences <= 0;
117 	}
118 
119 	@Override
120 	public boolean isSameState(int zoneConstaint) {
121 		return originalCard.isSameState(zoneConstaint);
122 	}
123 
124 	@Override
125 	public boolean isSameIdZone(int idZone) {
126 		return originalCard.isSameIdZone(idZone);
127 	}
128 
129 	@Override
130 	public int getIdZone() {
131 		return originalCard.getIdZone();
132 	}
133 
134 	@Override
135 	public void tap(boolean tapped) {
136 		originalCard.tap(tapped);
137 	}
138 
139 	@Override
140 	public void moveCard(int newIdPlace, Player newController,
141 			boolean newIsTapped, int idPosition) {
142 
143 		// restore available abilities
144 		originalCard.registerAbilities(newIdPlace);
145 		originalCard.moveCard(newIdPlace, newController, newIsTapped, idPosition);
146 	}
147 
148 	// TODO making the difference between 'register indirection' and 'register
149 	@Override
150 	public int getValue(int index) {
151 		if (index == IdTokens.MANA_POOL) {
152 			int res = 0;
153 			for (int i = 6; i-- > 0;) {
154 				res += cachedRegisters[i];
155 			}
156 			return res;
157 		}
158 		return cachedRegisters[index];
159 	}
160 
161 	@Override
162 	public void addModifier(ColorModifier modifier) {
163 		originalCard.addModifier(modifier);
164 	}
165 
166 	@Override
167 	public void addModifier(IdCardModifier modifier) {
168 		originalCard.addModifier(modifier);
169 	}
170 
171 	@Override
172 	public void addModifier(PropertyModifier modifier) {
173 		originalCard.addModifier(modifier);
174 	}
175 
176 	@Override
177 	public void addModifier(ControllerModifier modifier) {
178 		originalCard.addModifier(modifier);
179 	}
180 
181 	@Override
182 	public void addModifier(PlayableZoneModifier modifier) {
183 		originalCard.addModifier(modifier);
184 	}
185 
186 	@Override
187 	public void addModifier(RegisterModifier modifier, int index) {
188 		originalCard.addModifier(modifier, index);
189 	}
190 
191 	@Override
192 	public void addModifier(RegisterIndirection modifier, int index) {
193 		originalCard.addModifier(modifier, index);
194 	}
195 
196 	@Override
197 	public void removeModifier(RegisterModifier modifier, int index) {
198 		originalCard.removeModifier(modifier, index);
199 	}
200 
201 	@Override
202 	public void removeModifier(RegisterIndirection indirection, int index) {
203 		originalCard.removeModifier(indirection, index);
204 	}
205 
206 	@Override
207 	public void removeModifier(IdCardModifier modifier) {
208 		originalCard.removeModifier(modifier);
209 	}
210 
211 	@Override
212 	public void removeModifier(ControllerModifier modifier) {
213 		originalCard.removeModifier(modifier);
214 	}
215 
216 	@Override
217 	public void removeModifier(PropertyModifier modifier) {
218 		originalCard.removeModifier(modifier);
219 	}
220 
221 	@Override
222 	public void removeModifier(PlayableZoneModifier modifier) {
223 		originalCard.removeModifier(modifier);
224 	}
225 
226 	@Override
227 	public void removeModifier(ColorModifier modifier) {
228 		originalCard.removeModifier(modifier);
229 	}
230 
231 	@Override
232 	public boolean playableZone(int supposedZone, int idZone) {
233 		return originalCard.playableZone(supposedZone, idZone);
234 	}
235 
236 	@Override
237 	public void setValue(int index, Operation operation, int rightValue) {
238 		originalCard.setValue(index, operation, rightValue);
239 	}
240 
241 	@Override
242 	public boolean isSamePosition(int position) {
243 		return originalCard.isSamePosition(position);
244 	}
245 
246 	/***
247 	 * The referenced card.
248 	 */
249 	private MCard originalCard;
250 
251 }