mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
[SNC] Implemented Dusk Mangler
This commit is contained in:
parent
dcb893dbf7
commit
342eabbfa7
36 changed files with 177 additions and 108 deletions
|
|
@ -1,32 +1,32 @@
|
|||
|
||||
package mage.abilities.costs;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.choices.Choice;
|
||||
import mage.choices.ChoiceImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.Targets;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class OrCost implements Cost {
|
||||
|
||||
private final Cost firstCost;
|
||||
private final Cost secondCost;
|
||||
private final List<Cost> costs = new ArrayList<>();
|
||||
private String description;
|
||||
// which cost was slected to pay
|
||||
private Cost selectedCost;
|
||||
|
||||
public OrCost(Cost firstCost, Cost secondCost, String description) {
|
||||
this.firstCost = firstCost;
|
||||
this.secondCost = secondCost;
|
||||
public OrCost(String description, Cost... costs) {
|
||||
Collections.addAll(this.costs, costs);
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public OrCost(final OrCost cost) {
|
||||
this.firstCost = cost.firstCost.copy();
|
||||
this.secondCost = cost.secondCost.copy();
|
||||
cost.costs.stream().map(Cost::copy).forEach(this.costs::add);
|
||||
this.description = cost.description;
|
||||
this.selectedCost = cost.selectedCost;
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ public class OrCost implements Cost {
|
|||
|
||||
@Override
|
||||
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
|
||||
return firstCost.canPay(ability, source, controllerId, game) || secondCost.canPay(ability, source, controllerId, game);
|
||||
return costs.stream().anyMatch(cost -> cost.canPay(ability, source, controllerId, game));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -60,28 +60,47 @@ public class OrCost implements Cost {
|
|||
@Override
|
||||
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
selectedCost = null;
|
||||
// if only one can be paid select it
|
||||
if (!firstCost.canPay(ability, source, controllerId, game)) {
|
||||
selectedCost = secondCost;
|
||||
List<Cost> usable = costs
|
||||
.stream()
|
||||
.filter(cost -> cost.canPay(ability, source, controllerId, game))
|
||||
.collect(Collectors.toList());
|
||||
Player controller = game.getPlayer(controllerId);
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
if (!secondCost.canPay(ability, source, controllerId, game)) {
|
||||
selectedCost = firstCost;
|
||||
}
|
||||
// if both can be paid player has to select
|
||||
if (selectedCost == null) {
|
||||
Player controller = game.getPlayer(controllerId);
|
||||
if (controller != null) {
|
||||
switch (usable.size()) {
|
||||
case 0:
|
||||
return false;
|
||||
case 1:
|
||||
selectedCost = usable.get(0);
|
||||
break;
|
||||
case 2:
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (firstCost instanceof ManaCost) {
|
||||
if (usable.get(0) instanceof ManaCost) {
|
||||
sb.append("Pay ");
|
||||
}
|
||||
sb.append(firstCost.getText()).append('?');
|
||||
if (controller.chooseUse(Outcome.Detriment, sb.toString(), ability, game)) {
|
||||
selectedCost = firstCost;
|
||||
sb.append(usable.get(0).getText());
|
||||
sb.append(" or ");
|
||||
sb.append(usable.get(1));
|
||||
sb.append('?');
|
||||
if (controller.chooseUse(
|
||||
Outcome.Detriment, sb.toString(), null,
|
||||
usable.get(0).getText(), usable.get(1).getText(), ability, game
|
||||
)) {
|
||||
selectedCost = usable.get(0);
|
||||
} else {
|
||||
selectedCost = secondCost;
|
||||
selectedCost = usable.get(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Map<String, Cost> costMap = usable
|
||||
.stream()
|
||||
.collect(Collectors.toMap(Cost::getText, Function.identity()));
|
||||
Choice choice = new ChoiceImpl(true);
|
||||
choice.setMessage("Choose a cost to pay");
|
||||
choice.setChoices(costMap.keySet());
|
||||
controller.choose(Outcome.Neutral, choice, game);
|
||||
selectedCost = costMap.getOrDefault(choice.getChoice(), null);
|
||||
}
|
||||
if (selectedCost == null) {
|
||||
return false;
|
||||
|
|
@ -92,17 +111,13 @@ public class OrCost implements Cost {
|
|||
|
||||
@Override
|
||||
public boolean isPaid() {
|
||||
if (selectedCost != null) {
|
||||
return selectedCost.isPaid();
|
||||
}
|
||||
return false;
|
||||
return selectedCost != null ? selectedCost.isPaid() : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearPaid() {
|
||||
selectedCost = null;
|
||||
firstCost.clearPaid();
|
||||
secondCost.clearPaid();
|
||||
costs.stream().forEach(Cost::clearPaid);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
|
|
@ -40,7 +41,6 @@ public class SacrificeOpponentsEffect extends OneShotEffect {
|
|||
this.amount = amount;
|
||||
this.filter = filter.copy();
|
||||
this.filter.add(TargetController.YOU.getControllerPredicate());
|
||||
setText();
|
||||
}
|
||||
|
||||
public SacrificeOpponentsEffect(final SacrificeOpponentsEffect effect) {
|
||||
|
|
@ -79,7 +79,11 @@ public class SacrificeOpponentsEffect extends OneShotEffect {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void setText() {
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("each opponent sacrifices ");
|
||||
switch (amount.toString()) {
|
||||
|
|
@ -92,6 +96,6 @@ public class SacrificeOpponentsEffect extends OneShotEffect {
|
|||
default:
|
||||
sb.append(CardUtil.numberToText(amount.toString())).append(' ').append(filter.getMessage());
|
||||
}
|
||||
staticText = sb.toString();
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue