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.stack;
21  
22  import java.io.IOException;
23  import java.io.InputStream;
24  
25  import net.sf.magicproject.action.ActionFactory;
26  import net.sf.magicproject.action.MAction;
27  import net.sf.magicproject.clickable.ability.Ability;
28  import net.sf.magicproject.clickable.action.ToStringHelper;
29  import net.sf.magicproject.event.context.ContextEventListener;
30  import net.sf.magicproject.test.Test;
31  import net.sf.magicproject.test.TestFactory;
32  
33  /***
34   * An additional cost definition : constraint and added actions.
35   * 
36   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
37   * @since 0.80
38   */
39  public class AdditionalCost {
40  
41  	/***
42  	 * The constraint to apply this additional cost
43  	 */
44  	public final Test constraint;
45  
46  	/***
47  	 * The additional cost
48  	 */
49  	public final MAction[] cost;
50  
51  	/***
52  	 * Creates a new instance of this class <br>
53  	 * 
54  	 * @param inputFile
55  	 *          is the file containing this definition.
56  	 * @throws IOException
57  	 *           if error occurred during the reading process from the specified
58  	 *           input stream
59  	 */
60  	public AdditionalCost(InputStream inputFile) throws IOException {
61  		this.constraint = TestFactory.readNextTest(inputFile);
62  		this.cost = ActionFactory.readActionList(inputFile, null);
63  	}
64  
65  	@Override
66  	public String toString() {
67  		return "{" + constraint + ":" + cost + "}";
68  	}
69  
70  	/***
71  	 * Return the HTML code representing this additionnal cost. If the given
72  	 * ability is named, it's name will be returned. If not, if existing, the
73  	 * picture associated to this ability is returned. Otherwise, toHtmlString is
74  	 * called for each owned actions.
75  	 * 
76  	 * @param ability
77  	 *          is the ability owning this test. The card component of this
78  	 *          ability should correspond to the card owning this test too.
79  	 * @param context
80  	 *          the context needed by event activated
81  	 * @return the HTML code representing this additionnal cost.
82  	 */
83  	public String toHtmlString(Ability ability, ContextEventListener context) {
84  		return ToStringHelper.toHtmlString(ability, cost, context);
85  	}
86  }