use of mage.choices.ChoiceImpl in project mage by magefree.
the class JodahsAvengerEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose one");
choice.setChoices(choices);
if (controller.choose(outcome, choice, game)) {
switch(choice.getChoice()) {
case "Double strike":
gainedAbility = DoubleStrikeAbility.getInstance();
break;
case "Vigilance":
gainedAbility = VigilanceAbility.getInstance();
break;
case "Shadow":
gainedAbility = ShadowAbility.getInstance();
break;
default:
gainedAbility = ProtectionAbility.from(ObjectColor.RED);
break;
}
} else {
discard();
}
}
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class MaintenanceDroidEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose mode");
choice.setChoices(choices);
if (!controller.choose(outcome, choice, game)) {
return false;
}
String chosen = choice.getChoice();
switch(chosen) {
case "Remove a repair counter":
new RemoveCounterTargetEffect(CounterType.REPAIR.createInstance()).apply(game, source);
break;
default:
// "Add another repair counter"
new AddCountersTargetEffect(CounterType.REPAIR.createInstance()).apply(game, source);
break;
}
return true;
}
return false;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class TurnaboutEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || game.getPlayer(source.getFirstTarget()) == null) {
return true;
}
Choice choiceImpl = new ChoiceImpl(true);
choiceImpl.setMessage("Choose card type to tap or untap");
choiceImpl.setChoices(choice);
if (!controller.choose(Outcome.Neutral, choiceImpl, game)) {
return false;
}
FilterPermanent filter;
switch(choiceImpl.getChoice()) {
case "Artifact":
filter = StaticFilters.FILTER_CONTROLLED_PERMANENT_ARTIFACT;
break;
case "Land":
filter = StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND;
break;
case "Creature":
filter = StaticFilters.FILTER_CONTROLLED_CREATURE;
break;
default:
throw new IllegalArgumentException("Choice is required");
}
boolean tap = controller.chooseUse(Outcome.Neutral, "Tap or untap?", null, "Tap", "Untap", source, game);
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getFirstTarget(), source.getSourceId(), game)) {
if (tap) {
permanent.tap(source, game);
} else {
permanent.untap(game);
}
}
return true;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class TundraKavuEffect method init.
@Override
public void init(Ability source, Game game) {
landTypes.clear();
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<String> choiceSet = new LinkedHashSet<>();
choiceSet.add("Island");
choiceSet.add("Plains");
ChoiceImpl choice = new ChoiceImpl(true, ChoiceHintType.CARD);
choice.setChoices(choiceSet);
choice.setMessage("Choose a basic land type");
if (!controller.choose(outcome, choice, game)) {
discard();
return;
}
landTypes.add(SubType.byDescription(choice.getChoice()));
} else {
this.discard();
}
super.init(source, game);
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class RemoveCounterCost method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
paid = false;
int countersRemoved = 0;
Player controller = game.getPlayer(controllerId);
if (controller != null) {
if (countersToRemove == 0) {
// Can happen when used for X costs where X = 0;
return paid = true;
}
target.clearChosen();
if (target.choose(Outcome.UnboostCreature, controllerId, source.getSourceId(), game)) {
for (UUID targetId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
if (!permanent.getCounters(game).isEmpty() && (counterTypeToRemove == null || permanent.getCounters(game).containsKey(counterTypeToRemove))) {
String counterName = null;
if (counterTypeToRemove != null) {
counterName = counterTypeToRemove.getName();
} else if (permanent.getCounters(game).size() > 1 && counterTypeToRemove == null) {
Choice choice = new ChoiceImpl(true);
Set<String> choices = new HashSet<>();
for (Counter counter : permanent.getCounters(game).values()) {
if (permanent.getCounters(game).getCount(counter.getName()) > 0) {
choices.add(counter.getName());
}
}
choice.setChoices(choices);
choice.setMessage("Choose a counter to remove from " + permanent.getLogName());
if (!controller.choose(Outcome.UnboostCreature, choice, game)) {
return false;
}
counterName = choice.getChoice();
} else {
for (Counter counter : permanent.getCounters(game).values()) {
if (counter.getCount() > 0) {
counterName = counter.getName();
}
}
}
if (counterName != null && !counterName.isEmpty()) {
int countersLeft = countersToRemove - countersRemoved;
int countersOnPermanent = permanent.getCounters(game).getCount(counterName);
int numberOfCountersSelected = 1;
if (countersLeft > 1 && countersOnPermanent > 1) {
numberOfCountersSelected = controller.getAmount(1, Math.min(countersLeft, countersOnPermanent), new StringBuilder("Remove how many counters from ").append(permanent.getIdName()).toString(), game);
}
permanent.removeCounters(counterName, numberOfCountersSelected, source, game);
countersRemoved += numberOfCountersSelected;
if (!game.isSimulation()) {
game.informPlayers(new StringBuilder(controller.getLogName()).append(" removes ").append(numberOfCountersSelected == 1 ? "a" : numberOfCountersSelected).append(' ').append(counterName).append(numberOfCountersSelected == 1 ? " counter from " : " counters from ").append(permanent.getName()).toString());
}
if (countersRemoved == countersToRemove) {
this.paid = true;
break;
}
}
}
}
}
}
}
return paid;
}
Aggregations