1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.magicproject.xml.action;
22
23 import java.io.IOException;
24 import java.io.OutputStream;
25
26 import net.sf.magicproject.action.Actiontype;
27 import net.sf.magicproject.operation.IdOperations;
28 import net.sf.magicproject.test.TestOn;
29 import net.sf.magicproject.token.IdCommonToken;
30 import net.sf.magicproject.token.IdTokens;
31 import net.sf.magicproject.tools.MToolKit;
32 import net.sf.magicproject.xml.XmlAction;
33 import net.sf.magicproject.xml.XmlConfiguration;
34 import net.sf.magicproject.xml.XmlParser;
35 import net.sf.magicproject.xml.XmlToMDB;
36 import net.sf.magicproject.xml.XmlTools;
37
38 /***
39 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
40 * @since 0.82
41 */
42 public class Paymana implements XmlToMDB {
43
44 /***
45 * <ul>
46 * Structure of stream : Data[size]
47 * <li>idAction [1]</li>
48 * <li>the player paying this mana [TestOn]</li>
49 * <li>idNumber COLORLESS or IdTokens#REGISTERS[2]</li>
50 * <li>idNumber BLACK [2]</li>
51 * <li>idNumber BLUE [2]</li>
52 * <li>idNumber GREEN [2]</li>
53 * <li>idNumber RED [2]</li>
54 * <li>idNumber WHITE [2]</li>
55 * <li>colors of X = 2^ID__Color1+2^ID__Color2...[2]</li>
56 * </ul>
57 *
58 * @param node
59 * the XML action structure
60 * @param out
61 * outputstream where the card structure will be saved.
62 * @return the amount of written action in the output.
63 * @throws IOException
64 */
65 public final int buildMdb(XmlParser.Node node, OutputStream out)
66 throws IOException {
67 XmlAction.buildMdb(Actiontype.PAY_MANA, node, out);
68
69 String controllerAttr = node.getAttribute("controller");
70 if (controllerAttr == null) {
71 TestOn.CONTROLLER.serialize(out);
72 } else {
73 TestOn.serialize(out, controllerAttr);
74 }
75
76 if (XmlConfiguration.noPayMana) {
77
78 MToolKit.writeInt16(out, 0);
79 for (int i = 0; i < IdCommonToken.COLOR_NAMES.length; i++) {
80 out.write(IdOperations.INT_VALUE);
81 MToolKit.writeInt16(out, 0);
82 }
83 } else {
84 String braAttr = node.getAttribute("value");
85 if (braAttr != null) {
86 MToolKit.writeInt16(out, IdTokens.MANA_POOL);
87 XmlTools.writeTestOn(out, node.getAttribute("card"));
88 } else {
89 MToolKit.writeInt16(out, 0);
90 for (int i = 0; i < IdCommonToken.COLOR_NAMES.length; i++) {
91 if (node.getAttribute(IdCommonToken.COLOR_NAMES[i]) == null
92 && node.get(IdCommonToken.COLOR_NAMES[i]) == null) {
93
94 out.write(IdOperations.INT_VALUE);
95 MToolKit.writeInt16(out, 0);
96 } else {
97 XmlTools.writeAttrOptions(node, IdCommonToken.COLOR_NAMES[i], out);
98 }
99 }
100 }
101 }
102 return 1;
103 }
104
105 }