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.test;
22
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.List;
26 import java.util.Map;
27
28 import net.sf.magicproject.clickable.ability.Ability;
29 import net.sf.magicproject.clickable.ability.Priority;
30 import net.sf.magicproject.clickable.ability.ReplacementAbility;
31 import net.sf.magicproject.clickable.targetable.card.MCard;
32 import net.sf.magicproject.event.MEventListener;
33 import net.sf.magicproject.tools.MToolKit;
34
35 /***
36 * Is the tested card owns an ability
37 *
38 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
39 * @since 0.82
40 */
41 class HasAbility extends TestCard {
42
43 /***
44 * Create an instance of HasAbility by reading a file. Offset's file must
45 * pointing on the first byte of this test <br>
46 * <ul>
47 * Structure of InputStream : Data[size]
48 * <li>ability name [...]</li>
49 * </ul>
50 *
51 * @param inputFile
52 * is the file containing this event
53 * @throws IOException
54 * if error occurred during the reading process from the specified
55 * input stream
56 */
57 HasAbility(InputStream inputFile) throws IOException {
58 super(inputFile);
59 abilityName = MToolKit.readString(inputFile).intern();
60 }
61
62 @Override
63 protected boolean testCard(Ability ability, MCard tested) {
64 MCard card = on.getCard(ability, tested);
65 for (List<Ability> abilities : MEventListener.CAN_I_CAST_ABILITIES) {
66 for (Ability tAbility : abilities) {
67 if (card == tAbility.getCard()
68 && abilityName.equals(tAbility.getName())) {
69 return true;
70 }
71 }
72 }
73 for (List<Ability> abilities : MEventListener.TRIGGRED_ABILITIES.values()) {
74 for (Ability tAbility : abilities) {
75 if (card == tAbility.getCard()
76 && abilityName.equals(tAbility.getName())) {
77 return true;
78 }
79 }
80 }
81 for (Map<Priority, List<ReplacementAbility>> triggeredList : MEventListener.REPLACEMENT_ABILITIES
82 .values()) {
83 for (List<ReplacementAbility> abilities : triggeredList.values()) {
84 for (Ability tAbility : abilities) {
85 if (card == tAbility.getCard()
86 && abilityName.equals(tAbility.getName())) {
87 return true;
88 }
89 }
90 }
91 }
92 return false;
93 }
94
95 /***
96 * The ability name to match during each test
97 */
98 private final String abilityName;
99
100 }