View Javadoc

1   /*
2    * Created on Nov 1, 2004 
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   */
22  package net.sf.magicproject.action;
23  
24  import net.sf.magicproject.action.handler.StandardAction;
25  import net.sf.magicproject.clickable.ability.Ability;
26  import net.sf.magicproject.clickable.targetable.card.MCard;
27  import net.sf.magicproject.event.context.ContextEventListener;
28  import net.sf.magicproject.event.context.MContextMtargetable;
29  import net.sf.magicproject.modifier.ModifierModel;
30  
31  /***
32   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
33   */
34  public class AddModifierFromStaticModifier extends MAction implements
35  		StandardAction {
36  
37  	/***
38  	 * Creates a new instance of AddModifierFromStaticModifier <br>
39  	 * 
40  	 * @param modifiers
41  	 */
42  	public AddModifierFromStaticModifier(ModifierModel... modifiers) {
43  		this.modifiers = modifiers;
44  	}
45  
46  	/***
47  	 * Return the index of this action. As default, this is a zero id
48  	 * 
49  	 * @return the index of this action.
50  	 * @see Actiontype
51  	 */
52  	@Override
53  	public final Actiontype getIdAction() {
54  		return Actiontype.REFRESH_STATIC_MODIFIER;
55  	}
56  
57  	public boolean play(ContextEventListener context, Ability ability) {
58  		/*
59  		 * this action can only be played with a triggered ability actived with the
60  		 * 'movedcard' event
61  		 */
62  		final MContextMtargetable context2 = (MContextMtargetable) context;
63  		for (ModifierModel modifierModel : modifiers) {
64  			modifierModel.addModifierFromModel(ability, context2.getOriginalCard());
65  		}
66  		return true;
67  	}
68  
69  	/***
70  	 * return the string representation of this action
71  	 * 
72  	 * @param ability
73  	 *          is the ability owning this test. The card component of this
74  	 *          ability should correspond to the card owning this test too.
75  	 * @return the string representation of this action
76  	 * @see Object#toString()
77  	 */
78  	@Override
79  	public String toString(Ability ability) {
80  		return "refresh static modifier : " + trigger;
81  	}
82  
83  	/***
84  	 * List of static modifiers to add
85  	 */
86  	private ModifierModel[] modifiers;
87  
88  	/***
89  	 * The card controlling the modifier
90  	 */
91  	private MCard trigger;
92  
93  }