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.action;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import javax.swing.JTabbedPane;
28
29 import net.sf.magicproject.action.listener.WaitingAbility;
30 import net.sf.magicproject.action.listener.WaitingAction;
31 import net.sf.magicproject.clickable.ability.Ability;
32 import net.sf.magicproject.clickable.action.JChoosenAction;
33 import net.sf.magicproject.clickable.targetable.card.MCard;
34 import net.sf.magicproject.clickable.targetable.player.Player;
35 import net.sf.magicproject.event.CanICast;
36 import net.sf.magicproject.stack.ActivatedChoiceList;
37 import net.sf.magicproject.stack.StackManager;
38 import net.sf.magicproject.ui.MagicUIComponents;
39 import net.sf.magicproject.zone.MZone;
40
41 /***
42 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
43 * @since 0.86
44 */
45 public final class WaitChoosenActionChoice extends MAction implements
46 WaitingAction, WaitingAbility {
47
48 /***
49 * Create a new instance of WaitTriggeredBufferChoice
50 */
51 private WaitChoosenActionChoice() {
52 super();
53 }
54
55 /***
56 * This action activate the panel containing the ChoosenAction, highlights the
57 * playable mana-source abilities, and the the spell's controller as the
58 * handed player.
59 *
60 * @param controller
61 * is the player waiting the action choice.
62 * @TODO enable advaned abilities to be played
63 */
64 protected void play(Player controller) {
65 final List<Ability> res = new ArrayList<Ability>();
66 final List<Ability> advRes = new ArrayList<Ability>();
67 CanICast.dispatchManaAbilityEvent(controller.idPlayer, res);
68 finished();
69 if (!res.isEmpty()) {
70 activChoiceList = new ActivatedChoiceList(res, advRes);
71 res.clear();
72 advRes.clear();
73 zoneList = activChoiceList.highLight();
74
75
76 ((JTabbedPane) MagicUIComponents.choosenCostPanel.getParent())
77 .setSelectedComponent(MagicUIComponents.choosenCostPanel);
78 }
79 StackManager.enableAbort();
80 controller.setActivePlayer();
81 }
82
83 public boolean clickOn(JChoosenAction action) {
84
85
86 return false;
87 }
88
89 public boolean clickOn(Ability ability) {
90 return StackManager.idHandedPlayer == 0;
91 }
92
93 public boolean succeedClickOn(JChoosenAction action) {
94 finished();
95 return action.setSelected();
96 }
97
98 public boolean succeedClickOn(Ability ability) {
99 finished();
100 StackManager.newSpell(ability, ability.isMatching());
101 return true;
102 }
103
104 @Override
105 public Actiontype getIdAction() {
106 return Actiontype.WAIT_ACTIVATED_CHOICE;
107 }
108
109 public boolean manualSkip() {
110 finished();
111
112 return MagicUIComponents.choosenCostPanel.playFirstUncompleted();
113 }
114
115 public void finished() {
116 if (activChoiceList != null) {
117 activChoiceList.disHighLight();
118 activChoiceList.clear();
119 activChoiceList = null;
120 }
121 if (zoneList != null) {
122 for (MZone zone : zoneList) {
123 zone.disHighLight();
124 }
125 zoneList.clear();
126 zoneList = null;
127 StackManager.PLAYERS[0].disHighLight();
128 StackManager.PLAYERS[1].disHighLight();
129 }
130 StackManager.disableAbort();
131 }
132
133 public List<Ability> abilitiesOf(MCard card) {
134 return activChoiceList == null ? null : activChoiceList.abilitiesOf(card);
135 }
136
137 public List<Ability> advancedAbilitiesOf(MCard card) {
138 return activChoiceList == null ? null : activChoiceList
139 .advancedAbilitiesOf(card);
140 }
141
142 @Override
143 public String toString(Ability ability) {
144 return "Wait mana source choice";
145 }
146
147 /***
148 * Return the unique instance of this class.
149 *
150 * @return the unique instance of this class.
151 */
152 public static WaitChoosenActionChoice getInstance() {
153 if (instance == null)
154 instance = new WaitChoosenActionChoice();
155 return instance;
156 }
157
158 /***
159 * This is the list of zone concerned by highlighted cards
160 */
161 private List<MZone> zoneList;
162
163 /***
164 * the current list of choices of active player
165 */
166 private ActivatedChoiceList activChoiceList;
167
168 /***
169 * The unique instance of this class
170 */
171 private static WaitChoosenActionChoice instance;
172
173 }