1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.token;
20
21 import net.sf.magicproject.clickable.targetable.player.Player;
22 import net.sf.magicproject.stack.StackManager;
23
24 /***
25 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
26 * @since 0.90
27 */
28 public enum Visibility {
29
30 /***
31 *
32 */
33 PUBLIC,
34
35 /***
36 *
37 */
38 PRIVATE,
39
40 /***
41 *
42 */
43 HIDDEN;
44
45 /***
46 * Is the card is visible for the specified player.
47 *
48 * @param player
49 * the player looking this card.
50 * @return true if the card is visible for the specified player.
51 */
52 public final boolean isVisibleFor(Player player) {
53 if (player.isYou()) {
54 return isVisibleForYou();
55 }
56 return isVisibleForOpponent();
57 }
58
59 /***
60 * Is the card is visible for the specified player.
61 *
62 * @return true if the card is visible for you.
63 */
64 public boolean isVisibleForYou() {
65 switch (this) {
66 case PUBLIC:
67 return true;
68 case PRIVATE:
69 return true;
70 case HIDDEN:
71 default:
72 return false;
73 }
74 }
75
76 /***
77 * Is the card is visible for the specified player.
78 *
79 * @return true if the card is visible for you.
80 */
81 public boolean isVisibleForOpponent() {
82 switch (this) {
83 case PUBLIC:
84 return true;
85 case PRIVATE:
86 return false;
87 case HIDDEN:
88 default:
89 return false;
90 }
91 }
92
93 /***
94 * Return the increased visibility for this player
95 *
96 * @param player
97 * is the player whom the visibility is granted.
98 * @return the increased visibility for this player
99 */
100 public Visibility increaseFor(Player player) {
101 switch (this) {
102 case PUBLIC:
103 return PUBLIC;
104 case PRIVATE:
105 if (player.isYou()) {
106 return PRIVATE;
107 }
108 return PUBLIC;
109 case HIDDEN:
110 default:
111 if (player.isYou()) {
112 return PRIVATE;
113 }
114 return HIDDEN;
115 }
116 }
117
118 /***
119 * Return the increased visibility for this player
120 *
121 * @param controller
122 * The controller of component to modify.
123 * @param visibilityChange
124 * The visibility change.
125 * @return the increased visibility for this player
126 */
127 public Visibility increaseFor(Player controller,
128 VisibilityChange visibilityChange) {
129 switch (this) {
130 case PUBLIC:
131 return PUBLIC;
132 case PRIVATE:
133 case HIDDEN:
134 default:
135 switch (visibilityChange) {
136 case controller:
137 return PRIVATE;
138 case everyone:
139 return PUBLIC;
140 case opponent:
141
142 return PUBLIC;
143 case you:
144 default:
145 if (StackManager.getSpellController() == controller)
146 return PRIVATE;
147
148 return PUBLIC;
149 }
150 }
151 }
152
153 /***
154 * Return the decreased visibility for this player
155 *
156 * @param player
157 * is the player whom the visibility is removed.
158 * @return the decreased visibility for this player
159 */
160 public Visibility decreaseFor(Player player) {
161 switch (this) {
162 case PUBLIC:
163 if (player.isYou()) {
164 return PRIVATE;
165 }
166 return PUBLIC;
167 case PRIVATE:
168 if (player.isYou()) {
169 return HIDDEN;
170 }
171 return PRIVATE;
172 case HIDDEN:
173 default:
174 return HIDDEN;
175 }
176 }
177
178 /***
179 * Return the increased visibility for this player
180 *
181 * @param controller
182 * The controller of component to modify.
183 * @param visibilityChange
184 * The visibility change.
185 * @return the increased visibility for this player
186 */
187 public Visibility decreaseFor(Player controller,
188 VisibilityChange visibilityChange) {
189 switch (this) {
190 case PUBLIC:
191 switch (visibilityChange) {
192 case controller:
193
194 return HIDDEN;
195 case everyone:
196 return HIDDEN;
197 case opponent:
198 return PRIVATE;
199 case you:
200 default:
201 if (StackManager.getSpellController() == controller)
202
203 return HIDDEN;
204 return PRIVATE;
205 }
206 case PRIVATE:
207 switch (visibilityChange) {
208 case controller:
209 case everyone:
210 return HIDDEN;
211 case opponent:
212 return PRIVATE;
213 case you:
214 default:
215 if (StackManager.getSpellController() == controller)
216 return HIDDEN;
217
218 return PRIVATE;
219 }
220 case HIDDEN:
221 default:
222 return HIDDEN;
223 }
224 }
225
226 }