1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package net.sf.magicproject.clickable.ability;
23
24 import net.sf.magicproject.action.DetachMe;
25 import net.sf.magicproject.action.MAction;
26 import net.sf.magicproject.action.target.SingletonTarget;
27 import net.sf.magicproject.clickable.targetable.card.MCard;
28 import net.sf.magicproject.event.MEventListener;
29 import net.sf.magicproject.event.context.ContextEventListener;
30 import net.sf.magicproject.test.Test;
31 import net.sf.magicproject.test.TestOn;
32 import net.sf.magicproject.token.TrueFalseAuto;
33
34 /***
35 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
36 */
37 public class DetachmentAbility extends AbstractAbility {
38
39 /***
40 * Creates a new instance of DetachmentAbility <br>
41 *
42 * @param event
43 * the event attached to this ability.
44 * @param from
45 * the card is to going to be attached.
46 * @param to
47 * the card is to going to be attached to.
48 * @param attachmentTest
49 * the attachement condition.
50 */
51 public DetachmentAbility(MEventListener event, MCard from, MCard to,
52 Test attachmentTest) {
53 super("detach myself", event, null, null, TrueFalseAuto.AUTO);
54 actionList = new MAction[] { SingletonTarget
55 .getInstance(TestOn.CURRENT_CARD) };
56 effectList = new MAction[] { DetachMe.getInstance() };
57 this.from = from;
58 this.to = to;
59 this.attachmentTest = attachmentTest;
60
61
62 priority = Priority.hidden_high;
63
64 optimizer = Optimization.follow;
65 }
66
67 @Override
68 public MCard getCard() {
69 return eventComing.card;
70 }
71
72 @Override
73 public Ability clone(MCard container) {
74 return new DetachmentAbility(eventComing.clone(container), container, to,
75 attachmentTest);
76 }
77
78 @Override
79 public boolean triggerIt(ContextEventListener context) {
80 super.triggerIt(context);
81 eventComing.card.controller.zoneManager.triggeredBuffer.addHidden(this,
82 context);
83 return true;
84 }
85
86 @Override
87 public String getLog(ContextEventListener context) {
88 return "detachment of " + eventComing.card;
89 }
90
91 @Override
92 public String getAbilityTitle() {
93 return "DetachedAbility" + (getName() != null ? ": " + getName() : "")
94 + super.getAbilityTitle();
95 }
96
97 /***
98 * Returns the attached card.
99 *
100 * @return the attached card.
101 */
102 public MCard getAttachedCard() {
103 return from;
104 }
105
106 /***
107 * The attached card.
108 */
109 private final MCard from;
110
111 private final MCard to;
112
113 private final Test attachmentTest;
114 }