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.modifier;
21  
22  import java.util.List;
23  
24  import net.sf.magicproject.action.AddModifierFromStaticModifier;
25  import net.sf.magicproject.clickable.ability.Ability;
26  import net.sf.magicproject.clickable.ability.TriggeredStaticModifierAbility;
27  import net.sf.magicproject.clickable.targetable.card.MCard;
28  import net.sf.magicproject.event.MEventListener;
29  import net.sf.magicproject.event.MovedCard;
30  import net.sf.magicproject.test.InZone;
31  import net.sf.magicproject.test.Test;
32  import net.sf.magicproject.test.True;
33  import net.sf.magicproject.test.TestOn;
34  import net.sf.magicproject.token.IdZones;
35  
36  /***
37   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
38   * @since 0.86 Any event interferring with the filter-test make this
39   *        static-modifier to be re-evaluated for the concerned card.
40   */
41  public class StaticModifier extends Modifier {
42  
43  	/***
44  	 * Creates a new instance of StaticModifier <br>
45  	 * 
46  	 * @param name
47  	 *          the modifier name
48  	 * @param to
49  	 *          the component to be attached to
50  	 * @param ability
51  	 *          is the ability owning this test. The card component of this
52  	 *          ability should correspond to the card owning this test too.
53  	 * @param whileCondition
54  	 *          the test conditionning the activation of this modifier.
55  	 * @param linkedEvents
56  	 *          the events to be registered. This events would cause this modifier
57  	 *          to be updated.
58  	 * @param until
59  	 *          this modifier exists while this test is true.
60  	 * @param linked
61  	 *          is the creator is linked to this modifier.
62  	 * @param modifiers
63  	 *          are the modifiers attached to this static way to attach globally
64  	 *          card in the looked for zone.
65  	 * @param filterZone
66  	 *          is the looked for zone where this modifier can be added. Only
67  	 *          components in this zone are affected by this modifier.
68  	 * @param sourceZone
69  	 * 			is the zone where the static-modifier gets to apply.  Default is 
70  	 * 			zone "play".         
71  	 * @param filterTest
72  	 *          is the test applied on components coming into the
73  	 *          <code>filterZone</code>. This modifier is applied only on these
74  	 *          components if they make this test true.
75  	 */
76  	StaticModifier(String name, MCard to, Ability ability, Test whileCondition,
77  			List<MEventListener> linkedEvents, List<MEventListener> until,
78  			boolean linked, ModifierModel[] modifiers, int filterZone, int sourceZone) {
79  		super(name, to, ability, whileCondition, linkedEvents, until, linked, -1);
80  
81  		// we add the trigger looking for new cards coming into play
82  		if (filterZone != IdZones.ANYWHERE) {
83  			final TriggeredStaticModifierAbility refreshAbility = new TriggeredStaticModifierAbility(
84  					new MovedCard(sourceZone, True.getInstance(), new InZone(
85  							filterZone, TestOn.TESTED), ability.getCard()),
86  					new AddModifierFromStaticModifier(modifiers), ability.getCard(),
87  					modifiers);
88  			abilities.add(refreshAbility);
89  			refreshAbility.registerToManager();
90  		}
91  	}
92  
93  	@Override
94  	public void refresh() {
95  		// TODO remove refresh ability of this modifier
96  		// Ignored : throw new InternalError("This modifier cannot be refreshed this
97  		// way");
98  	}
99  
100 }