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.expression.Expression;
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 ObjectPropertyModifier extends PropertyModifier {
38
39 /***
40 * Creates a new instance of ObjectPropertyModifier <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 propertyId
62 * the propety to add/remove
63 * @param addPropperty
64 * Indicates if this modifier remove occurence of the given property.
65 * If true, it adds one instance.
66 * @param main
67 * is this object modifier is the main modifier.
68 */
69 ObjectPropertyModifier(String name, MCard to, Ability ability,
70 Test whileCondition, List<MEventListener> linkedEvents,
71 List<MEventListener> until, boolean linked, int layer,
72 Expression propertyId, boolean addPropperty, boolean main) {
73 super(name, to, ability, whileCondition, linkedEvents, until, linked,
74 layer, propertyId, addPropperty);
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.postRefreshProperties(to, propertyId.getValue(ability, to,
83 null));
84 return next;
85 }
86 return super.removeObject(objectName, objectTest);
87 }
88
89 @Override
90 public int paintObject(Graphics g, int startX, int startY) {
91 if (main) {
92 if (startX + 13 > CardFactory.cardWidth) {
93 return paintObject(g, 3, startY - 16);
94 }
95 g.drawImage(objectPicture, startX, startY, 13, 15, null);
96 return super.paintObject(g, startX + 3, startY);
97 }
98 return super.paintObject(g, startX, startY);
99 }
100
101 @Override
102 public int getNbObjects(String objectName, Test objectTest) {
103 if (main && objectName.equals(name) && objectTest.test(ability, to)) {
104 if (next == null) {
105 return 1;
106 }
107 return 1 + next.getNbObjects(objectName, objectTest);
108 }
109 return super.getNbObjects(objectName, objectTest);
110 }
111
112 /***
113 * Picture representing this object
114 */
115 private Image objectPicture;
116
117 /***
118 * is this object modifier is the main modifier
119 */
120 private boolean main;
121 }