1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.modifier;
20
21 import java.awt.Graphics;
22 import java.awt.Image;
23 import java.util.List;
24
25 import net.sf.magicproject.clickable.ability.Ability;
26 import net.sf.magicproject.clickable.targetable.card.CardFactory;
27 import net.sf.magicproject.clickable.targetable.card.MCard;
28 import net.sf.magicproject.event.MEventListener;
29 import net.sf.magicproject.operation.Operation;
30 import net.sf.magicproject.stack.StackManager;
31 import net.sf.magicproject.test.Test;
32
33 /***
34 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
35 * @since 0.86
36 */
37 public class ObjectAbilityModifier extends AbilityModifier {
38
39 /***
40 * Creates a new instance of ObjectColorModifier <br>
41 *
42 * @param name
43 * the modifier name
44 * @param to
45 * the component to be attached to
46 * @param ability
47 * is the ability owning this test. The card component of this
48 * ability should correspond to the card owning this test too.
49 * @param whileCondition
50 * the test conditionning the activation of this modifier.
51 * @param linkedEvents
52 * the events to be registered. This events would cause this modifier
53 * to be updated.
54 * @param until
55 * this modifier exists while this test is true.
56 * @param linked
57 * is the creator is linked to this modifier.
58 * @param layer
59 * is the strategy used to add this modifier within the existing
60 * chain.
61 * @param idColor
62 * the color to add/remove/...
63 * @param op
64 * the operation applied to previous value with the value of this
65 * modifier.
66 * @param main
67 * is this object modifier is the main modifier ?.
68 */
69 ObjectAbilityModifier(String name, MCard to, Ability ability,
70 Test whileCondition, List<MEventListener> linkedEvents,
71 List<MEventListener> until, boolean linked, int layer, Operation op,
72 Ability[] abilitiesToAdd, boolean main) {
73 super(name, to, ability, whileCondition, linkedEvents, until, linked,
74 layer, op, abilitiesToAdd);
75 objectPicture = ObjectFactory.getObjectPicture(name);
76 this.main = main;
77 }
78
79 @Override
80 public Modifier removeObject(String objectName, Test objectTest) {
81 if (name.equals(objectName) && objectTest.test(ability, to)) {
82 StackManager.postRefreshAbilities(to);
83 return next;
84 }
85 return super.removeObject(objectName, objectTest);
86 }
87
88 @Override
89 public int paintObject(Graphics g, int startX, int startY) {
90 if (main) {
91 if (startX + 13 > CardFactory.cardWidth) {
92 return paintObject(g, 3, startY - 16);
93 }
94 g.drawImage(objectPicture, startX, startY, 13, 15, null);
95 return super.paintObject(g, startX + 3, startY);
96 }
97 return super.paintObject(g, startX, startY);
98 }
99
100 @Override
101 public int getNbObjects(String objectName, Test objectTest) {
102 if (main && objectName.equals(name) && objectTest.test(ability, to)) {
103 if (next == null) {
104 return 1;
105 }
106 return 1 + next.getNbObjects(objectName, objectTest);
107 }
108 return super.getNbObjects(objectName, objectTest);
109 }
110
111 /***
112 * Picture representing this object
113 */
114 private Image objectPicture;
115
116 /***
117 * is this object modifier is the main modifier
118 */
119 private boolean main;
120 }