mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +00:00
loop to streams
This commit is contained in:
parent
6eba170e3c
commit
a167122459
10 changed files with 38 additions and 81 deletions
|
@ -129,9 +129,7 @@ public class ChatSession {
|
|||
clientsToRemove.add(userId);
|
||||
}
|
||||
}
|
||||
for (UUID userIdToRemove : clientsToRemove) {
|
||||
clients.remove(userIdToRemove);
|
||||
}
|
||||
clients.keySet().removeAll(clientsToRemove);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import mage.game.Table;
|
|||
import mage.game.events.Listener;
|
||||
import mage.game.events.PlayerQueryEvent;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.game.match.MatchPlayer;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.interfaces.Action;
|
||||
import mage.players.Player;
|
||||
|
@ -65,7 +66,6 @@ import java.util.*;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import mage.game.match.MatchPlayer;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -108,12 +108,7 @@ public class GameController implements GameCallback {
|
|||
this.tableId = tableId;
|
||||
this.choosingPlayerId = choosingPlayerId;
|
||||
this.gameOptions = gameOptions;
|
||||
for (Player player : game.getPlayers().values()) {
|
||||
if (!player.isHuman()) {
|
||||
useTimeout = false; // no timeout for AI players because of beeing idle
|
||||
break;
|
||||
}
|
||||
}
|
||||
useTimeout = game.getPlayers().values().stream().allMatch(Player::isHuman);
|
||||
init();
|
||||
|
||||
}
|
||||
|
@ -832,13 +827,8 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
final String message = new StringBuilder(game.getStep().getType().toString()).append(" - Waiting for ").append(controller.getName()).toString();
|
||||
for (final Entry<UUID, GameSessionPlayer> entry : gameSessions.entrySet()) {
|
||||
boolean skip = false;
|
||||
for (UUID uuid : players) {
|
||||
if (entry.getKey().equals(uuid)) {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
boolean skip = players.stream().anyMatch(playerId -> entry.getKey().equals(playerId));
|
||||
|
||||
if (!skip) {
|
||||
entry.getValue().inform(message);
|
||||
}
|
||||
|
|
|
@ -45,13 +45,10 @@ public enum DashedCondition implements Condition {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Card card = game.getCard(source.getSourceId());
|
||||
if (card != null) {
|
||||
for (Ability ability : card.getAbilities()) {
|
||||
if (ability instanceof DashAbility) {
|
||||
if (((DashAbility) ability).isActivated(source, game)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return card.getAbilities().stream()
|
||||
.filter(a -> a instanceof DashAbility)
|
||||
.anyMatch(d -> ((DashAbility)d).isActivated(source, game));
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -48,13 +48,9 @@ public enum EvokedCondition implements Condition {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Card card = game.getCard(source.getSourceId());
|
||||
if (card != null) {
|
||||
for (Ability ability: card.getAbilities()) {
|
||||
if (ability instanceof EvokeAbility) {
|
||||
if(((EvokeAbility) ability).isActivated(source, game)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return card.getAbilities().stream()
|
||||
.filter(ab -> ab instanceof EvokeAbility)
|
||||
.anyMatch(evoke -> ((EvokeAbility) evoke).isActivated(source, game));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -27,13 +27,15 @@
|
|||
*/
|
||||
package mage.abilities.costs.mana;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.VariableCost;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -63,14 +65,10 @@ public interface ManaCosts<T extends ManaCost> extends List<T>, ManaCost {
|
|||
|
||||
|
||||
static ManaCosts<ManaCost> removeVariableManaCost(ManaCosts<ManaCost> m) {
|
||||
ManaCosts<ManaCost> manaCosts = new ManaCostsImpl<>();
|
||||
for(ManaCost manaCost : m){
|
||||
if(!(manaCost instanceof VariableManaCost)){
|
||||
manaCosts.add(manaCost);
|
||||
return m.stream()
|
||||
.filter(mc -> !(mc instanceof VariableManaCost))
|
||||
.collect(Collectors.toCollection(ManaCostsImpl<ManaCost>::new));
|
||||
|
||||
}
|
||||
}
|
||||
return manaCosts;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,11 +18,7 @@ public class DiscardCostCardConvertedMana implements DynamicValue {
|
|||
for (Cost cost : sourceAbility.getCosts()) {
|
||||
if (cost instanceof DiscardTargetCost) {
|
||||
DiscardTargetCost discardCost = (DiscardTargetCost) cost;
|
||||
int cmc = 0;
|
||||
for (Card card : discardCost.getCards()) {
|
||||
cmc += card.getConvertedManaCost();
|
||||
}
|
||||
return cmc;
|
||||
return discardCost.getCards().stream().mapToInt(Card::getConvertedManaCost).sum();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -6,7 +6,6 @@ import mage.abilities.costs.common.SacrificeTargetCost;
|
|||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
|
@ -18,11 +17,8 @@ public class SacrificeCostCreaturesPower implements DynamicValue {
|
|||
for (Cost cost : sourceAbility.getCosts()) {
|
||||
if (cost instanceof SacrificeTargetCost) {
|
||||
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
|
||||
int powerSum = 0;
|
||||
for (Permanent permanent : sacrificeCost.getPermanents()) {
|
||||
powerSum += permanent.getPower().getValue();
|
||||
}
|
||||
return powerSum;
|
||||
return sacrificeCost.getPermanents()
|
||||
.stream().mapToInt(p -> p.getPower().getValue()).sum();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -6,7 +6,6 @@ import mage.abilities.costs.common.SacrificeTargetCost;
|
|||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
|
@ -18,11 +17,7 @@ public class SacrificeCostCreaturesToughness implements DynamicValue {
|
|||
for (Cost cost : sourceAbility.getCosts()) {
|
||||
if (cost instanceof SacrificeTargetCost) {
|
||||
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
|
||||
int toughnessSum = 0;
|
||||
for (Permanent permanent : sacrificeCost.getPermanents()) {
|
||||
toughnessSum += permanent.getToughness().getValue();
|
||||
}
|
||||
return toughnessSum;
|
||||
return sacrificeCost.getPermanents().stream().mapToInt(p -> p.getToughness().getValue()).sum();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -27,10 +27,6 @@
|
|||
*/
|
||||
package mage.abilities.keyword;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.StaticAbility;
|
||||
|
@ -56,6 +52,11 @@ import mage.game.stack.StackObject;
|
|||
import mage.players.Player;
|
||||
import mage.target.common.TargetControlledPermanent;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/*
|
||||
* 702.77. Conspire
|
||||
* 702.77a Conspire is a keyword that represents two abilities.
|
||||
|
@ -165,7 +166,7 @@ public class ConspireAbility extends StaticAbility implements OptionalAdditional
|
|||
if (conspireCost.canPay(ability, getSourceId(), getControllerId(), game)
|
||||
&& player.chooseUse(Outcome.Benefit, "Pay " + conspireCost.getText(false) + " ?", ability, game)) {
|
||||
activateConspire(ability, game);
|
||||
for (Iterator it = ((Costs) conspireCost).iterator(); it.hasNext();) {
|
||||
for (Iterator it = conspireCost.iterator(); it.hasNext(); ) {
|
||||
Cost cost = (Cost) it.next();
|
||||
ability.getCosts().add(cost.copy());
|
||||
}
|
||||
|
|
|
@ -28,20 +28,16 @@
|
|||
|
||||
package mage.game.draft;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.game.draft.DraftOptions.TimingOption;
|
||||
import mage.game.events.Listener;
|
||||
import mage.game.events.PlayerQueryEvent;
|
||||
import mage.game.events.PlayerQueryEventSource;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.game.events.*;
|
||||
import mage.game.events.TableEvent.EventType;
|
||||
import mage.game.events.TableEventSource;
|
||||
import mage.players.Player;
|
||||
import mage.players.PlayerList;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -262,22 +258,16 @@ public abstract class DraftImpl implements Draft {
|
|||
if(isAbort()) {
|
||||
return true;
|
||||
}
|
||||
for (DraftPlayer player: players.values()) {
|
||||
if (player.isPicking()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return players.values()
|
||||
.stream()
|
||||
.noneMatch(DraftPlayer::isPicking);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allJoined() {
|
||||
for (DraftPlayer player: this.players.values()) {
|
||||
if (!player.isJoined()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return players.values().stream()
|
||||
.allMatch(DraftPlayer::isJoined);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue