1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.magicproject.modifier;
22
23 import java.io.IOException;
24 import java.io.InputStream;
25
26 import net.sf.magicproject.clickable.ability.Ability;
27 import net.sf.magicproject.clickable.targetable.card.MCard;
28 import net.sf.magicproject.test.Test;
29
30 /***
31 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
32 * @since 0.82
33 */
34 public class ObjectAbilityModifierModel extends AbilityModifierModel implements
35 ObjectModifierModel {
36
37 /***
38 * Is this object can be paint.
39 */
40 private final boolean paint;
41
42 /***
43 * Creates a new instance of ObjectAbilityModifierModel <br>
44 * <ul>
45 * Structure of InputStream : Data[size]
46 * <li>[super]</li>
47 * <li>is this object can be paint [boolean]</li>
48 * </ul>
49 *
50 * @param inputStream
51 * the input stream where action will be read
52 * @throws IOException
53 * if error occurred during the reading process from the specified
54 * input stream
55 */
56 ObjectAbilityModifierModel(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 ObjectAbilityModifierModel(ObjectModifierModel other) {
71 super((AbilityModifierModel) other);
72 this.paint = ((ObjectAbilityModifierModel) other).paint;
73 }
74
75 @Override
76 public void addModifierFromModel(Ability ability, MCard target) {
77 final Ability[] copyAbilities = new Ability[abilitiesToAdd.length];
78 for (int i = copyAbilities.length; i-- > 0;) {
79 copyAbilities[i] = abilitiesToAdd[i].clone(target);
80 }
81 final ObjectAbilityModifier newModifier = new ObjectAbilityModifier(name,
82 target, ability, whileCondition, linkedEvents, until, linked, layer,
83 op, copyAbilities, paint);
84 target.addModifier(newModifier);
85 newModifier.refresh();
86 if (next != null) {
87 next.addModifierFromModel(ability, target);
88 }
89 }
90
91 @Override
92 public ObjectAbilityModifierModel clone() {
93 return new ObjectAbilityModifierModel(this);
94 }
95
96 public String getObjectName() {
97 return name;
98 }
99
100 @Override
101 public void removeObject(MCard fromCard, Test objectTest) {
102 if (fromCard.abilityModifier != null) {
103 fromCard.abilityModifier = (AbilityModifier) fromCard.abilityModifier
104 .removeObject(name, objectTest);
105 }
106 super.removeObject(fromCard, objectTest);
107 }
108
109 public int getNbObject(MCard card, Test objectTest) {
110 return card.abilityModifier == null ? 0 : card.abilityModifier
111 .getNbObjects(name, objectTest);
112 }
113
114 }