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.HashSet;
24 import java.util.Set;
25
26 import net.sf.magicproject.clickable.targetable.player.Player;
27
28 /***
29 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
30 * @since 0.83
31 */
32 public final class LastKnownCardInfoImpl implements LastKnownCardInfo {
33
34 @SuppressWarnings("unchecked")
35 LastKnownCardInfoImpl(MCard originalCard, int timestampReferences,
36 int destinationZone) {
37 assert timestampReferences > 0;
38 this.originalCard = originalCard;
39 this.destinationZone = destinationZone;
40 this.idColor = originalCard.getIdColor();
41 this.idCard = originalCard.getIdCard();
42 this.tapped = originalCard.tapped;
43 this.cachedRegisters = originalCard.cachedRegisters.clone();
44 this.cachedProperties = (Set<Integer>) ((HashSet<Integer>) originalCard.cachedProperties)
45 .clone();
46
47 this.controller = originalCard.controller;
48 this.owner = originalCard.owner;
49 this.timestamp = originalCard.getTimestamp();
50 this.timestampReferences = timestampReferences;
51 }
52
53 /***
54 * Create and return a LastKnownCard object build with the last known
55 * informations.
56 *
57 * @return a LastKnownCard object build with the last known informations.
58 */
59 public LastKnownCard createLastKnownCard() {
60 return new LastKnownCard(originalCard, destinationZone, idColor, idCard,
61 tapped, cachedRegisters, controller, owner, cachedProperties,
62 timestamp, timestampReferences);
63 }
64
65 /***
66 * Remove a reference to the given timestamp of card.
67 *
68 * @param timestamp
69 * the timestamp reference
70 * @return true if the given timestamp is no more referenced.
71 */
72 public boolean removeTimestamp(int timestamp) {
73 return --timestampReferences <= 0;
74 }
75
76 /***
77 * The last known colors.
78 */
79 private int idColor;
80
81 /***
82 * The last known card identifiant.
83 */
84 private int idCard;
85
86 /***
87 * The last known registers.
88 */
89 private int[] cachedRegisters;
90
91 /***
92 * The last known controller.
93 */
94 private Player controller;
95
96 /***
97 * The last known owner.
98 */
99 private Player owner;
100
101 /***
102 * The last known properties.
103 */
104 private Set<Integer> cachedProperties;
105
106 /***
107 * The last known information on tap state.
108 */
109 private boolean tapped;
110
111 /***
112 * The original card.
113 */
114 private MCard originalCard;
115
116 /***
117 * The timestamp of card when it has been saved.
118 */
119 private int timestamp;
120
121 /***
122 * The amount of references to the original card with the specific timestamp.
123 */
124 private int timestampReferences;
125
126 /***
127 * The destination zone of this card before it moved.
128 */
129 private int destinationZone;
130 }