View Javadoc

1   /*
2    * Created on 27 févr. 2005
3    * 
4    *   Magic-Project is a turn based strategy simulator
5    *   Copyright (C) 2003-2007 Fabrice Daugan
6    *
7    *   This program is free software; you can redistribute it and/or modify it 
8    * under the terms of the GNU General Public License as published by the Free 
9    * Software Foundation; either version 2 of the License, or (at your option) any
10   * later version.
11   *
12   *   This program is distributed in the hope that it will be useful, but WITHOUT 
13   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
15   * details.
16   *
17   *   You should have received a copy of the GNU General Public License along  
18   * with this program; if not, write to the Free Software Foundation, Inc., 
19   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   */
21  package net.sf.magicproject.xml.tbs;
22  
23  import java.io.IOException;
24  import java.io.OutputStream;
25  import java.util.Iterator;
26  
27  import net.sf.magicproject.clickable.ability.AbilityType;
28  import net.sf.magicproject.xml.XmlEvent;
29  import net.sf.magicproject.xml.XmlParser;
30  import net.sf.magicproject.xml.XmlTbs;
31  import net.sf.magicproject.xml.XmlToMDB;
32  import net.sf.magicproject.xml.XmlTools;
33  
34  /***
35   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
36   * @since 0.82
37   */
38  public class Systemability implements XmlToMDB {
39  
40  	/***
41  	 * <ul>
42  	 * Structure of stream : Data[size]
43  	 * <li>ability [Ability]</li>
44  	 * <li>event [Event]</li>
45  	 * <li>cost [Action[]]</li>
46  	 * </ul>
47  	 * 
48  	 * @param node
49  	 *          the XML card structure
50  	 * @param out
51  	 *          outputstream where the card structure will be saved
52  	 * @return the amount of written action in the output.
53  	 * @throws IOException
54  	 *           error while writting.
55  	 * @see net.sf.magicproject.clickable.ability.Priority
56  	 */
57  	public final int buildMdb(XmlParser.Node node, OutputStream out)
58  			throws IOException {
59  
60  		Ability.buildAbility(AbilityType.SYSTEM_ABILITY, node, out);
61  
62  		// write the event
63  		node.addAttribute(new XmlParser.Attribute("zone", "play"));
64  		Iterator<?> it = node.iterator();
65  		XmlTools.defaultOnMeTag = false;
66  		while (it.hasNext()) {
67  			Object obj = it.next();
68  			if (obj instanceof XmlParser.Node) {
69  				XmlParser.Node child = (XmlParser.Node) obj;
70  				if ("text".equals(child.getTag())) {
71  					System.out.println("text element in ability is not yet implement");
72  				} else {
73  					XmlEvent.getEvent(child.getTag()).buildMdb(child, out);
74  					break;
75  				}
76  			}
77  		}
78  
79  		// write only the actions effects
80  		XmlTbs.currentInEffect = true;
81  		XmlTbs.writeActionList(node.get("effects"), out);
82  		return 0;
83  	}
84  
85  }