1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.magicproject.action;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24
25 import net.sf.magicproject.action.context.ActionContextWrapper;
26 import net.sf.magicproject.action.context.ObjectArray;
27 import net.sf.magicproject.action.handler.ChoosenAction;
28 import net.sf.magicproject.action.handler.InitAction;
29 import net.sf.magicproject.clickable.ability.Ability;
30 import net.sf.magicproject.event.context.ContextEventListener;
31 import net.sf.magicproject.stack.StackManager;
32 import net.sf.magicproject.token.IdCardColors;
33
34 /***
35 * This action is used to modifiy the amount of required mana.
36 *
37 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
38 * @since 0.71
39 */
40 class ModifyRequiredMana extends ModifyRegister implements InitAction,
41 ChoosenAction {
42
43 /***
44 * Create an instance of ModifyRegister by reading a file Offset's file must
45 * pointing on the first byte of this action <br>
46 * <ul>
47 * Structure of InputStream : Data[size]
48 * <li>[super]</li>
49 * </ul>
50 *
51 * @param inputFile
52 * file containing this action
53 * @throws IOException
54 * if error occurred during the reading process from the specified
55 * input stream
56 */
57 ModifyRequiredMana(InputStream inputFile) throws IOException {
58 super(inputFile);
59 }
60
61 @Override
62 public final Actiontype getIdAction() {
63 return Actiontype.MODIFY_REQUIRED_MANA;
64 }
65
66 public boolean init(ActionContextWrapper actionContext,
67 ContextEventListener context, Ability ability) {
68 final ObjectArray<Integer> actionCxt;
69 if (actionContext.actionContext == null) {
70 actionCxt = new ObjectArray<Integer>(IdCardColors.CARD_COLOR.length);
71 actionContext.actionContext = actionCxt;
72 } else {
73 actionCxt = (ObjectArray<Integer>) actionContext.actionContext;
74 }
75 int index = this.index.getValue(ability, null, context);
76 int value = valueExpr.getValue(ability, ability.getCard(), context);
77 StackManager.actionManager.updateRequiredMana(op, index, value);
78 return true;
79 }
80
81 public boolean choose(ActionContextWrapper actionContext,
82 ContextEventListener context, Ability ability) {
83 return true;
84 }
85
86 public boolean replay(ActionContextWrapper actionContext,
87 ContextEventListener context, Ability ability) {
88 return true;
89 }
90
91 @Override
92 public boolean play(ContextEventListener context, Ability ability) {
93 final int reg = index.getValue(ability, null, context);
94 StackManager.actionManager.updateRequiredMana(op, reg, getValue(ability, ability.getCard(),
95 context));
96 return true;
97 }
98
99
100 @Override
101 public String toString(Ability ability) {
102 return "modify-required-mana";
103 }
104
105 public void disactivate(ActionContextWrapper actionContext,
106 ContextEventListener context, Ability ability) {
107
108 }
109
110 public String toHtmlString(Ability ability, ContextEventListener context,
111 ActionContextWrapper actionContext) {
112 return toHtmlString(ability, context);
113 }
114 }