View Javadoc

1   /*
2    *   Magic-Project is a turn based strategy simulator
3    *   Copyright (C) 2003-2007 Fabrice Daugan
4    *
5    *   This program is free software; you can redistribute it and/or modify it 
6    * under the terms of the GNU General Public License as published by the Free 
7    * Software Foundation; either version 2 of the License, or (at your option) any
8    * later version.
9    *
10   *   This program is distributed in the hope that it will be useful, but WITHOUT 
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
13   * details.
14   *
15   *   You should have received a copy of the GNU General Public License along  
16   * with this program; if not, write to the Free Software Foundation, Inc., 
17   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 		// nothing to do
108 	}
109 
110 	public String toHtmlString(Ability ability, ContextEventListener context,
111 			ActionContextWrapper actionContext) {
112 		return toHtmlString(ability, context);
113 	}
114 }