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.io.IOException;
22 import java.io.InputStream;
23
24 import net.sf.magicproject.clickable.ability.Ability;
25 import net.sf.magicproject.clickable.targetable.card.MCard;
26 import net.sf.magicproject.expression.IntValue;
27 import net.sf.magicproject.test.Test;
28
29 /***
30 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
31 * @since 0.85
32 */
33 class ObjectIdCardModifierModel extends IdCardModifierModel implements
34 ObjectModifierModel {
35
36 /***
37 * Is this object can be paint.
38 */
39 private final boolean paint;
40
41 /***
42 * Creates a new instance of ObjectRegisterModifierModel <br>
43 * <ul>
44 * Structure of InputStream : Data[size]
45 * <li>[super]</li>
46 * <li>is this object can be paint [boolean]</li>
47 * </ul>
48 *
49 * @param inputFile
50 * is the file containing this event
51 * @throws IOException
52 * if error occurred during the reading process from the specified
53 * input stream
54 * @see net.sf.magicproject.token.IdTokens
55 */
56 ObjectIdCardModifierModel(InputStream inputStream) throws IOException {
57 super(inputStream);
58 paint = inputStream.read() == 1;
59
60
61 linked = false;
62 }
63
64 /***
65 * Create a new instance from the given model.
66 *
67 * @param other
68 * the instance to copy
69 */
70 private ObjectIdCardModifierModel(ObjectModifierModel other) {
71 super((IdCardModifierModel) other);
72 this.paint = ((ObjectIdCardModifierModel) other).paint;
73 }
74
75 @Override
76 public void addModifierFromModel(Ability ability, MCard target) {
77 final IdCardModifier newModifier = new ObjectIdCardModifier(name, target,
78 ability, whileCondition, linkedEvents, until, linked, layer,
79 recalculate ? new IntValue(idCard.getValue(ability, target, null))
80 : idCard, op, paint);
81 target.addModifier(newModifier);
82 newModifier.refresh();
83 if (next != null) {
84 next.addModifierFromModel(ability, target);
85 }
86 }
87
88 @Override
89 public ObjectIdCardModifierModel clone() {
90 return new ObjectIdCardModifierModel(this);
91 }
92
93 /***
94 * Return the object name
95 *
96 * @return the object name
97 */
98 public String getObjectName() {
99 return name;
100 }
101
102 @Override
103 public void removeObject(MCard fromCard, Test objectTest) {
104 if (fromCard.idCardModifier != null) {
105 fromCard.idCardModifier = (IdCardModifier) fromCard.idCardModifier
106 .removeObject(name, objectTest);
107 }
108 super.removeObject(fromCard, objectTest);
109 }
110
111 public int getNbObject(MCard card, Test objectTest) {
112 return card.idCardModifier == null ? 0 : card.idCardModifier.getNbObjects(
113 name, objectTest);
114 }
115 }