1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }