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.ability;
22
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.Collection;
26
27 import net.sf.magicproject.action.MAction;
28 import net.sf.magicproject.clickable.targetable.card.MCard;
29 import net.sf.magicproject.event.CanICast;
30 import net.sf.magicproject.event.MEventListener;
31 import net.sf.magicproject.event.context.ContextEventListener;
32 import net.sf.magicproject.stack.StackManager;
33 import net.sf.magicproject.token.TrueFalseAuto;
34 import net.sf.magicproject.ui.i18n.LanguageManager;
35
36 /***
37 * An ability that can be manually played.
38 *
39 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
40 */
41 public class ActivatedAbility extends UserAbility {
42
43 /***
44 * Creates a new instance of ActivatedAbility <br>
45 * <ul>
46 * Structure of InputStream : Data[size]
47 * </ul>
48 *
49 * @param inputFile
50 * @param card
51 * @throws IOException
52 * if error occurred during the reading process from the specified
53 * input stream
54 */
55 public ActivatedAbility(InputStream inputFile, MCard card) throws IOException {
56 super(inputFile, card);
57 updateManaAbilityTag();
58 }
59
60 @Override
61 public Ability clone(MCard container) {
62 return new ActivatedAbility(getName(), actionList, effectList, optimizer,
63 priority, eventComing.clone(container), pictureName, linkedAbilities,
64 playAsSpell);
65 }
66
67 /***
68 * Create an instance of ActivatedAbility
69 *
70 * @param name
71 * Name of card used to display this ability in a stack
72 * @param actionList
73 * list of actions to do for activate this ability
74 * @param effectList
75 * list of effects of this ability
76 * @param optimizer
77 * the optimizer to use.
78 * @param priority
79 * the resolution type.
80 * @param eventComing
81 * event condition of this ability
82 * @param pictureName
83 * the picture name of this ability. If <code>null</code> the card
84 * picture will be used instead.
85 * @param linkedAbilities
86 * the linked abilities. May be null.
87 * @param playAsSpell
88 * play-as-spell.
89 */
90 protected ActivatedAbility(String name, MAction[] actionList,
91 MAction[] effectList, Optimization optimizer, Priority priority,
92 MEventListener eventComing, String pictureName,
93 Collection<Ability> linkedAbilities, TrueFalseAuto playAsSpell) {
94 super(name, actionList, effectList, optimizer, priority, eventComing,
95 pictureName, linkedAbilities, playAsSpell);
96 updateManaAbilityTag();
97 }
98
99 /***
100 * Iterate on actions of effect part looking for a 'give mana' action. If one
101 * or several are found, the <code>idCard</code> of canIcast event will be
102 * replaced by <code>IdTokens.MANA_ABILITY</code>
103 */
104 private void updateManaAbilityTag() {
105 if (eventComing instanceof CanICast) {
106 ((CanICast) eventComing).updateManaAbilityTag(effectList);
107 }
108 }
109
110 @Override
111 public void resolveStack() {
112 if (priority.isAutoResolve()) {
113 if (StackManager.actionManager.advancedMode) {
114
115
116
117
118
119 StackManager.actionManager.reactivate();
120 } else {
121
122
123
124
125
126
127 StackManager.activePlayer().waitTriggeredBufferChoice(true);
128 }
129 } else {
130 super.resolveStack();
131 }
132 }
133
134 @Override
135 public String getLog(ContextEventListener context) {
136 return toHtmlString(context) + "' of " + getCard();
137 }
138
139 @Override
140 public String getAbilityTitle() {
141 return LanguageManager.getString("activatedability")
142 + (getName() != null ? ": " + getName() : "") + super.getAbilityTitle();
143 }
144
145 }