refactor: use standard code style

This commit is contained in:
Oleg Agafonov 2024-10-24 13:59:43 +04:00
parent b51fdae550
commit 86fc0028c1
9 changed files with 37 additions and 33 deletions

View file

@ -91,7 +91,8 @@ class CaseOfTheTrampledGardenHint extends CaseSolvedHint {
.stream()
.map(Permanent::getPower)
.map(MageInt::getValue)
.reduce(0, Integer::sum);
.mapToInt(x -> x)
.sum();
return "Total power: " + power + " (need 8).";
}
}

View file

@ -68,7 +68,7 @@ class DismantleEffect extends OneShotEffect {
if (controller != null) {
if (permanent != null) {
int counterCount = 0;
counterCount = permanent.getCounters(game).values().stream().map((counter) -> counter.getCount()).reduce(counterCount, Integer::sum);
counterCount = permanent.getCounters(game).values().stream().mapToInt(Counter::getCount).sum();
permanent.destroy(source, game, false);
if (counterCount > 0) {
Target target = new TargetControlledPermanent(1, 1, new FilterControlledArtifactPermanent("an artifact you control"), true);

View file

@ -96,10 +96,12 @@ class EtrataTheSilencerEffect extends OneShotEffect {
if (card != null) {
card.addCounters(CounterType.HIT.createInstance(), source.getControllerId(), source, game);
}
int cardsFound = 0;
cardsFound = game.getExile().getAllCards(game).stream().filter((exiledCard) -> (exiledCard.getCounters(game).getCount(CounterType.HIT) >= 1
&& exiledCard.getOwnerId().equals(player.getId()))).map((_item) -> 1).reduce(cardsFound, Integer::sum);
if (cardsFound > 2) {
int cardsFound = game.getExile().getAllCards(game).stream()
.filter(c -> c.getOwnerId().equals(player.getId()))
.filter(c -> c.getCounters(game).getCount(CounterType.HIT) > 0)
.mapToInt(x -> 1)
.sum();
if (cardsFound >= 3) {
player.lost(game);
}
Permanent etrataTheSilencer = game.getPermanent(source.getSourceId());

View file

@ -137,21 +137,22 @@ class GoldberryRiverDaughterToEffect extends OneShotEffect {
}
List<Counter> counters = new ArrayList<>(fromPermanent.getCounters(game).values());
counters.sort((c1, c2) -> c1.getName().compareTo(c2.getName()));
counters.sort(Comparator.comparing(Counter::getName));
List<MultiAmountMessage> messages = counters.stream()
.map(c -> new MultiAmountMessage(c.getName() + " (" + c.getCount() + ")", 0, c.getCount()))
.collect(Collectors.toList());
int max = messages.stream().map(m -> m.max).reduce(0, Integer::sum);
int totalMin = 1;
int totalMax = messages.stream().mapToInt(m -> m.max).sum();
int total;
List<Integer> choices;
do {
choices = controller.getMultiAmountWithIndividualConstraints(Outcome.Neutral, messages, 1,
max, MultiAmountType.COUNTERS, game);
choices = controller.getMultiAmountWithIndividualConstraints(Outcome.Neutral, messages, totalMin,
totalMax, MultiAmountType.COUNTERS, game);
total = choices.stream().reduce(0, Integer::sum);
} while (total < 1 && controller.canRespond());
total = choices.stream().mapToInt(x -> x).sum();
} while (total < totalMin && controller.canRespond());
// Move the counters. Make sure some counters were actually moved.
boolean movedCounters = false;

View file

@ -27,6 +27,7 @@ import mage.target.common.TargetControlledPermanent;
import mage.util.MultiAmountMessage;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@ -95,21 +96,21 @@ class ResourcefulDefenseMoveCounterEffect extends OneShotEffect {
}
List<Counter> counters = new ArrayList<>(fromPermanent.getCounters(game).values());
counters.sort((c1, c2) -> c1.getName().compareTo(c2.getName()));
counters.sort(Comparator.comparing(Counter::getName));
List<MultiAmountMessage> messages = counters.stream()
.map(c -> new MultiAmountMessage(c.getName() + " (" + c.getCount() + ")", 0, c.getCount()))
.collect(Collectors.toList());
int max = messages.stream().map(m -> m.max).reduce(0, Integer::sum);
int totalMin = 0;
int totalMax = messages.stream().mapToInt(m -> m.max).sum();
int total;
List<Integer> choices;
do {
choices = controller.getMultiAmountWithIndividualConstraints(Outcome.Neutral, messages, 0,
max, MultiAmountType.COUNTERS, game);
total = choices.stream().reduce(0, Integer::sum);
} while (total < 0 && controller.canRespond());
choices = controller.getMultiAmountWithIndividualConstraints(Outcome.Neutral, messages, totalMin,
totalMax, MultiAmountType.COUNTERS, game);
total = choices.stream().mapToInt(x -> x).sum();
} while (total < totalMin && controller.canRespond());
// Move the counters. Make sure some counters were actually moved.
for (int i = 0; i < choices.size(); i++) {

View file

@ -110,7 +110,7 @@ enum SunbirdEffigyValue implements DynamicValue {
.getCards(game)
.stream()
.map(card -> card.getColor(game))
.reduce(new ObjectColor(), (c1, c2) -> c1.union(c2));
.reduce(new ObjectColor(), ObjectColor::union);
}
}
@ -171,7 +171,7 @@ class SunbirdEffigyEffect extends ManaEffect {
.getCards(game)
.stream()
.map(card -> card.getColor(game))
.reduce(new ObjectColor(), (c1, c2) -> c1.union(c2));
.reduce(new ObjectColor(), ObjectColor::union);
if (color.isWhite()) {
mana.increaseWhite();
}

View file

@ -1,25 +1,25 @@
package mage.cards.w;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.constants.SubType;
import mage.abilities.keyword.ReachAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.counters.CounterType;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.AbilityPredicate;
import mage.game.Game;
import java.util.UUID;
/**
*
* @author TheElk801
*/
public final class WhiptongueHydra extends CardImpl {
@ -74,12 +74,11 @@ class WhiptongueHydraEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
int destroyedPermanents = 0;
destroyedPermanents = game.getBattlefield().getActivePermanents(
filter, source.getControllerId(), source, game
).stream().filter(
(permanent) -> (permanent.destroy(source, game, false))
).map((_item) -> 1).reduce(destroyedPermanents, Integer::sum);
int destroyedPermanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)
.stream()
.filter(permanent -> permanent.destroy(source, game, false))
.mapToInt(x -> 1)
.sum();
if (destroyedPermanents > 0) {
game.processAction();
new AddCountersSourceEffect(

View file

@ -50,7 +50,7 @@ public enum MultiAmountType {
return res;
}
int total = res.stream().reduce(0, Integer::sum);
int total = res.stream().mapToInt(x -> x).sum();;
// Fill values until we reach the overall minimum. Do this by filling values up until either their max or however much is leftover, starting with the first option.
if (min > 0 && total < min) {
@ -85,7 +85,7 @@ public enum MultiAmountType {
// Total should fall between the sum of all of the minimum values and max (in the case that everything was filled with default_value).
// So, we'll never start with too much.
int total = res.stream().reduce(0, Integer::sum);
int total = res.stream().mapToInt(x -> x).sum();
// So add some values evenly until we hit max
while (total < max) {

View file

@ -61,7 +61,7 @@ public class CastSpellLastTurnWatcher extends Watcher {
}
public int getAmountOfSpellsAllPlayersCastOnCurrentTurn() {
return amountOfSpellsCastOnCurrentTurn.values().stream().reduce(0, Integer::sum);
return amountOfSpellsCastOnCurrentTurn.values().stream().mapToInt(x -> x).sum();
}
public int getAmountOfSpellsPlayerCastOnCurrentTurn(UUID playerId) {