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.action.target;
21  
22  import java.io.IOException;
23  import java.io.InputStream;
24  
25  import net.sf.magicproject.action.context.ActionContextWrapper;
26  import net.sf.magicproject.action.handler.InitAction;
27  import net.sf.magicproject.clickable.ability.Ability;
28  import net.sf.magicproject.clickable.targetable.Targetable;
29  import net.sf.magicproject.event.context.ContextEventListener;
30  import net.sf.magicproject.stack.StackManager;
31  
32  /***
33   * Add to the target list card(s) or player(s) following the specified mode and
34   * the specified type. If mode is 'choose' or 'opponentchoose', then a
35   * 'targeted' event is raised when the choice is made. In case of 'all',
36   * 'random', 'myself' or any target known with acces register, no event is
37   * generated. The friendly test, and the type are required only for the modes
38   * 'random', 'all', 'choose' and 'opponentchoose' to list the valids targets.
39   * The target list is used by the most actions. <br>
40   * For example, if the next action 'damage', all cards/player from the target
41   * list would be damaged. When a new ability is added to the stack, a new list
42   * is created and attached to it. Actions may modify, acceess it until the
43   * ability is completely resolved.
44   * 
45   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
46   * @since 0.86
47   */
48  public final class RealTarget extends ChoosenTarget implements InitAction {
49  
50  	/***
51  	 * Create an instance by reading a file Offset's file must pointing on the
52  	 * first byte of this action <br>
53  	 * <ul>
54  	 * Structure of InputStream : Data[size]
55  	 * <li>[super]</li>
56  	 * </ul>
57  	 * For the available options, see interface IdTargets
58  	 * 
59  	 * @param type
60  	 *          the concerned target's type previously read by the factory
61  	 * @param options
62  	 *          the options previously read by the factory
63  	 * @param inputFile
64  	 *          file containing this action
65  	 * @throws IOException
66  	 *           If some other I/O error occurs
67  	 */
68  	RealTarget(int type, int options, InputStream inputFile) throws IOException {
69  		super(type, options, inputFile);
70  	}
71  
72  	@Override
73  	protected boolean succeedClickOn(Targetable targetable) {
74  		if (StackManager.actionManager.advancedMode) {
75  			StackManager.getInstance().getTargetedList().addTarget(options & 0x30,
76  					targetable, test, false);
77  		}
78  		return super.succeedClickOn(targetable);
79  	}
80  
81  	@Override
82  	public String toString(Ability ability) {
83  		return "Target" + super.toString(ability);
84  	}
85  
86  	@Override
87  	public boolean choose(ActionContextWrapper actionContext,
88  			ContextEventListener context, Ability ability) {
89  		return replay(actionContext, context, ability);
90  	}
91  
92  	@Override
93  	public boolean isTargeting() {
94  		return true;
95  	}
96  
97  }