1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
144 originalCard.registerAbilities(newIdPlace);
145 originalCard.moveCard(newIdPlace, newController, newIsTapped, idPosition);
146 }
147
148
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 }