1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.firemox.xml.tbs;
22
23 import java.io.IOException;
24 import java.io.OutputStream;
25 import java.util.Iterator;
26
27 import net.sf.firemox.clickable.ability.AbilityType;
28 import net.sf.firemox.clickable.ability.Optimization;
29 import net.sf.firemox.clickable.ability.Priority;
30 import net.sf.firemox.token.TrueFalseAuto;
31 import net.sf.firemox.tools.MToolKit;
32 import net.sf.firemox.xml.XmlEvent;
33 import net.sf.firemox.xml.XmlParser;
34 import net.sf.firemox.xml.XmlTbs;
35 import net.sf.firemox.xml.XmlToMDB;
36 import net.sf.firemox.xml.XmlTools;
37
38 /***
39 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
40 * @since 0.82
41 */
42 public class Replacementability implements XmlToMDB {
43
44 /***
45 * <ul>
46 * Structure of stream : Data[size]
47 * <li>ability type [1]</li>
48 * <li>name [String]</li>
49 * <li>ability tags = hidden+unique [1]</li>
50 * <li>event [MEventListener]</li>
51 * <li>pay actions[Action[]]</li>
52 * </ul>
53 *
54 * @param node
55 * the XML ability structure
56 * @param out
57 * output stream where the card structure will be saved
58 * @return the amount of written action in the output.
59 * @see net.sf.firemox.clickable.ability.TriggeredAbility
60 * @see net.sf.firemox.clickable.ability.ReplacementAbility
61 * @throws IOException
62 * error while writing.
63 */
64 public final int buildMdb(XmlParser.Node node, OutputStream out)
65 throws IOException {
66
67 AbilityType.REPLACEMENT_ABILITY.write(out);
68
69
70 MToolKit.writeString(out, node.getAttribute("name"));
71
72
73 String layer = node.getAttribute("layer");
74 if (layer == null) {
75 Priority.high.write(out);
76 } else {
77 Priority.values()[Integer.parseInt(layer)].write(out);
78 }
79
80 if (Optimization.action.name().equals(node.getAttribute("optimize"))) {
81 Optimization.action.write(out);
82 } else {
83 Optimization.first.write(out);
84 }
85 TrueFalseAuto.valueOfXsd(node.getAttribute("play-as-spell")).serialize(out);
86
87
88 Iterator<?> it = node.iterator();
89 XmlTools.defaultOnMeTag = false;
90 while (it.hasNext()) {
91 Object obj = it.next();
92 if (obj instanceof XmlParser.Node) {
93 XmlParser.Node child = (XmlParser.Node) obj;
94 if ("text".equals(child.getTag())) {
95 System.out.println("text element in ability is not yet implement");
96 } else {
97 XmlEvent.getEvent(child.getTag()).buildMdb(child, out);
98 break;
99 }
100 }
101 }
102
103
104 out.write(0);
105
106 XmlTbs.currentInEffect = true;
107 XmlTbs.writeActionList(node.get("effects"), out);
108 return 0;
109 }
110
111 }