1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.firemox.modifier;
20
21 import java.awt.Graphics;
22 import java.awt.Image;
23
24 import net.sf.firemox.clickable.target.card.CardFactory;
25 import net.sf.firemox.expression.Expression;
26 import net.sf.firemox.modifier.model.ObjectFactory;
27 import net.sf.firemox.operation.Operation;
28 import net.sf.firemox.stack.StackManager;
29 import net.sf.firemox.test.Test;
30
31 /***
32 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
33 * @since 0.85
34 */
35 public class ObjectRegisterModifier extends RegisterModifier {
36
37 /***
38 * Creates a new instance of IdCardModifiers <br>
39 *
40 * @param context
41 * the modifier context.
42 * @param index
43 * the modified index
44 * @param rightExpression
45 * the expression used to modify the register
46 * @param op
47 * the operation applied to previous value with the value of this
48 * modifier.
49 * @param main
50 * is this object modifier is the main modifier.
51 */
52 public ObjectRegisterModifier(ModifierContext context, int index,
53 Expression rightExpression, Operation op, boolean main) {
54 super(context, index, rightExpression, op);
55 objectPicture = ObjectFactory.getObjectPicture(name);
56 this.main = main;
57 }
58
59 @Override
60 public Modifier removeObject(String objectName, Test objectTest) {
61 if (name.equals(objectName) && objectTest.test(ability, to)) {
62 StackManager.postRefreshRegisters(to, index);
63 return next;
64 }
65 return super.removeObject(objectName, objectTest);
66 }
67
68 @Override
69 public int paintObject(Graphics g, int startX, int startY) {
70 if (main) {
71 if (startX + 13 > CardFactory.cardWidth) {
72 return paintObject(g, 3, startY - 16);
73 }
74 g.drawImage(objectPicture, startX, startY, 13, 15, null);
75 return super.paintObject(g, startX + 3, startY);
76 }
77 return super.paintObject(g, startX, startY);
78 }
79
80 @Override
81 public int getNbObjects(String objectName, Test objectTest) {
82 if (main && objectName.equals(name) && objectTest.test(ability, to)) {
83 if (next == null) {
84 return 1;
85 }
86 return 1 + next.getNbObjects(objectName, objectTest);
87 }
88 return super.getNbObjects(objectName, objectTest);
89 }
90
91 /***
92 * Picture representing this object
93 */
94 private Image objectPicture;
95
96 /***
97 * is this object modifier is the main modifier
98 */
99 private boolean main;
100 }