1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.magicproject.action;
24
25 import net.sf.magicproject.action.handler.StandardAction;
26 import net.sf.magicproject.action.listener.WaitingTriggeredCard;
27 import net.sf.magicproject.clickable.ability.Ability;
28 import net.sf.magicproject.clickable.targetable.card.TriggeredCard;
29 import net.sf.magicproject.event.context.ContextEventListener;
30 import net.sf.magicproject.stack.EventManager;
31 import net.sf.magicproject.stack.StackManager;
32 import net.sf.magicproject.tools.Log;
33 import net.sf.magicproject.zone.TriggeredBuffer;
34
35 /***
36 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
37 * @since 0.60
38 */
39 public final class WaitTriggeredBufferChoice extends MAction implements
40 StandardAction, WaitingTriggeredCard {
41
42 /***
43 * Create a new instance of WaitTriggeredBufferChoice
44 */
45 private WaitTriggeredBufferChoice() {
46 super();
47 }
48
49 public void finished() {
50 StackManager.activePlayer().zoneManager.triggeredBuffer.disHighLightAll();
51 if (EventManager.parsinfBeforeEnd() || EventManager.parsingEndPhaseEvent) {
52
53
54
55
56
57 if (StackManager.isEmpty()) {
58
59 EventManager.gotoNextPhase();
60 } else {
61
62 StackManager.resolveStack();
63 }
64
65 } else {
66
67 StackManager.actionManager.currentAction = WaitActivatedChoice
68 .getInstance();
69
70 if (WaitActivatedChoice.getInstance().play(null, null)) {
71 StackManager.resolveStack();
72 }
73 }
74 }
75
76 public boolean play(ContextEventListener context, Ability ability) {
77 throw new InternalError("should not be called");
78 }
79
80 public boolean clickOn(TriggeredCard triggeredCard) {
81 if (StackManager.idHandedPlayer == 0) {
82 TriggeredBuffer cont = StackManager.PLAYERS[0].zoneManager.triggeredBuffer;
83 for (int i = cont.getCardCount(); i-- > 0;) {
84
85 if (cont.getTriggeredAbility(i) == triggeredCard) {
86
87 return true;
88 }
89 }
90
91
92
93
94
95
96 if (!triggeredCard.triggeredAbility.isHidden()) {
97
98 throw new InternalError("Mysterious unhidden triggered ability "
99 + triggeredCard.getCardName()
100 + ", card="
101 + triggeredCard.triggeredAbility.getCard()
102 + (triggeredCard.triggeredAbility.getCard() != null ? "@"
103 + Integer.toHexString(triggeredCard.triggeredAbility.getCard()
104 .hashCode()) : ""));
105 }
106 throw new InternalError("clicked on abstract triggered ability");
107 }
108 return false;
109 }
110
111 public boolean succeedClickOn(TriggeredCard triggeredCard) {
112 try {
113 StackManager.PLAYERS[triggeredCard.triggeredAbility.getCard()
114 .getController().idPlayer].zoneManager.triggeredBuffer
115 .disHighLightAll();
116 } catch (Exception e) {
117 Log.debug("error : " + e);
118 }
119 return triggeredCard.newSpell();
120 }
121
122 public boolean manualSkip() {
123
124
125
126
127
128
129
130 StackManager.actionManager
131 .succeedClickOn((TriggeredCard) StackManager.PLAYERS[StackManager.oldIdHandedPlayer].zoneManager.triggeredBuffer
132 .getComponent(0));
133 return false;
134 }
135
136 @Override
137 public Actiontype getIdAction() {
138 return Actiontype.WAIT_TRIGGERED_BUFFER_CHOICE;
139 }
140
141 @Override
142 public String toString(Ability ability) {
143 return "wait triggered ability buffer choice";
144 }
145
146 /***
147 * Return the unique instance of this class.
148 *
149 * @return the unique instance of this class.
150 */
151 public static WaitTriggeredBufferChoice getInstance() {
152 if (instance == null)
153 instance = new WaitTriggeredBufferChoice();
154 return instance;
155 }
156
157 /***
158 * The unique instance of this class
159 */
160 private static WaitTriggeredBufferChoice instance;
161
162 }