1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.magicproject.clickable.ability;
24
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.util.Collection;
28
29 import net.sf.magicproject.action.MAction;
30 import net.sf.magicproject.clickable.targetable.card.MCard;
31 import net.sf.magicproject.event.MEventListener;
32 import net.sf.magicproject.event.context.ContextEventListener;
33 import net.sf.magicproject.stack.StackManager;
34 import net.sf.magicproject.token.TrueFalseAuto;
35
36 /***
37 * TODO is it important to keep cost ?
38 *
39 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
40 * @since 0.80
41 */
42 public class ReplacementAbility extends TriggeredAbility {
43
44 /***
45 * Creates a new instance of ReplacementAbility <br>
46 * <ul>
47 * Structure of InputStream : Data[size]
48 * <li>name name + '\0' [...]</li>
49 * <li>ability tags [1]</li>
50 * <li>event [...]</li>
51 * <li>nb of actions for effect part [1]</li>
52 * <li>pay action i [...]</li>
53 * </ul>
54 *
55 * @param inputFile
56 * @param card
57 * @throws IOException
58 * if error occurred during the reading process from the specified
59 * input stream
60 */
61 public ReplacementAbility(InputStream inputFile, MCard card)
62 throws IOException {
63 super(inputFile, card);
64 }
65
66 /***
67 * Create an instance of this class.
68 *
69 * @param name
70 * Name of card used to display this ability in a stack
71 * @param actionList
72 * list of actions to do for activate this ability
73 * @param effectList
74 * list of effects of this ability
75 * @param optimizer
76 * the optimizer to use.
77 * @param priority
78 * the resolution type.
79 * @param eventComing
80 * event condition of this ability
81 * @param linkedAbilities
82 * the linked abilities. May be null.
83 * @param playAsSpell
84 * play-as-spell.
85 */
86 private ReplacementAbility(String name, Optimization optimizer,
87 Priority priority, MEventListener eventComing, MAction[] actionList,
88 MAction[] effectList, Collection<Ability> linkedAbilities,
89 TrueFalseAuto playAsSpell) {
90 super(name, actionList, effectList, optimizer, priority, eventComing, null,
91 linkedAbilities, playAsSpell);
92 }
93
94 @Override
95 public boolean triggerIt(ContextEventListener context) {
96 throw new InternalError("Replacement ability cannot trigger");
97 }
98
99 @Override
100 public void resolveStack() {
101
102
103
104
105
106 if (optimizer == Optimization.action) {
107 StackManager.actionManager.setHop(1);
108 }
109 StackManager.resolveStack();
110 }
111
112 @Override
113 public Ability clone(MCard container) {
114 return new ReplacementAbility(getName(), optimizer, priority, eventComing
115 .clone(container), actionList, effectList, linkedAbilities, playAsSpell);
116 }
117
118 @Override
119 public boolean isMatching() {
120
121
122
123
124 return !StackManager.isPlaying(this);
125 }
126
127 @Override
128 public void removeFromManager() {
129 priority.removeFromManager(this);
130 if (delayedCard != null) {
131
132 StackManager.getSpellController().zoneManager.delayedBuffer
133 .remove(delayedCard);
134
135 delayedCard.removeFromManager();
136 delayedCard = null;
137 }
138 }
139
140 @Override
141 public final boolean isAutoResolve() {
142 return true;
143 }
144
145 @Override
146 public final boolean isHidden() {
147 return true;
148 }
149
150 @Override
151 public final boolean hasHighPriority() {
152 return true;
153 }
154
155 @Override
156 public void registerToManager() {
157 priority.registerToManager(this);
158 }
159 }