Merge pull request #3472 from ingmargoudt/text

Text
This commit is contained in:
ingmargoudt 2017-06-06 09:34:22 +02:00 committed by GitHub
commit 52460c1224
6 changed files with 84 additions and 94 deletions

View file

@ -38,6 +38,7 @@ import mage.util.ThreadLocalStringBuilder;
import org.apache.log4j.Logger;
import java.util.*;
import java.util.stream.Collectors;
/**
* @param <T>
@ -117,82 +118,72 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
@Override
public Abilities<ActivatedAbility> getActivatedAbilities(Zone zone) {
Abilities<ActivatedAbility> zonedAbilities = new AbilitiesImpl<>();
for (T ability : this) {
if (ability instanceof ActivatedAbility && ability.getZone().match(zone)) {
zonedAbilities.add((ActivatedAbility) ability);
}
}
return zonedAbilities;
return stream()
.filter(ability -> ability instanceof ActivatedAbility)
.filter(ability -> ability.getZone().match(zone))
.map(ability -> (ActivatedAbility) ability)
.collect(Collectors.toCollection(AbilitiesImpl::new));
}
@Override
public Abilities<ActivatedAbility> getPlayableAbilities(Zone zone) {
Abilities<ActivatedAbility> zonedAbilities = new AbilitiesImpl<>();
for (T ability : this) {
if ((ability instanceof ActivatedAbility || (ability instanceof PlayLandAbility))
&& ability.getZone().match(zone)) {
zonedAbilities.add((ActivatedAbility) ability);
}
}
return zonedAbilities;
return stream()
.filter(ability -> (ability instanceof ActivatedAbility))
.filter(ability -> ability.getZone().match(zone))
.map(ability -> (ActivatedAbility) ability)
.collect(Collectors.toCollection(AbilitiesImpl::new));
}
@Override
public Abilities<ActivatedManaAbilityImpl> getActivatedManaAbilities(Zone zone) {
Abilities<ActivatedManaAbilityImpl> abilities = new AbilitiesImpl<>();
for (T ability : this) {
if (ability instanceof ActivatedManaAbilityImpl && ability.getZone().match(zone)) {
abilities.add((ActivatedManaAbilityImpl) ability);
}
}
return abilities;
return stream()
.filter(ability -> ability instanceof ActivatedManaAbilityImpl)
.filter(ability -> ability.getZone().match(zone))
.map(ability -> (ActivatedManaAbilityImpl) ability)
.collect(Collectors.toCollection(AbilitiesImpl::new));
}
@Override
public Abilities<ActivatedManaAbilityImpl> getAvailableActivatedManaAbilities(Zone zone, Game game) {
Abilities<ActivatedManaAbilityImpl> abilities = new AbilitiesImpl<>();
for (T ability : this) {
if (ability instanceof ActivatedManaAbilityImpl && ability.getZone().match(zone)) {
if ((((ActivatedManaAbilityImpl) ability).canActivate(ability.getControllerId(), game))) {
abilities.add((ActivatedManaAbilityImpl) ability);
}
}
}
return abilities;
return stream()
.filter(ability -> ability instanceof ActivatedManaAbilityImpl)
.filter(ability -> ability.getZone().match(zone))
.filter(ability -> (((ActivatedManaAbilityImpl) ability).canActivate(ability.getControllerId(), game)))
.map(ability -> (ActivatedManaAbilityImpl) ability)
.collect(Collectors.toCollection(AbilitiesImpl::new));
}
@Override
public Abilities<Ability> getManaAbilities(Zone zone) {
Abilities<Ability> abilities = new AbilitiesImpl<>();
for (T ability : this) {
if (ability.getAbilityType() == AbilityType.MANA && ability.getZone().match(zone)) {
abilities.add(ability);
}
}
return abilities;
return stream()
.filter(ability -> ability.getAbilityType() == AbilityType.MANA)
.filter(ability -> ability.getZone().match(zone))
.collect(Collectors.toCollection(AbilitiesImpl::new));
}
@Override
public Abilities<EvasionAbility> getEvasionAbilities() {
Abilities<EvasionAbility> abilities = new AbilitiesImpl<>();
for (T ability : this) {
if (ability instanceof EvasionAbility) {
abilities.add((EvasionAbility) ability);
}
}
return abilities;
return stream()
.filter(ability -> ability instanceof EvasionAbility)
.map(ability -> (EvasionAbility) ability)
.collect(Collectors.toCollection(AbilitiesImpl::new));
}
@Override
public Abilities<StaticAbility> getStaticAbilities(Zone zone) {
Abilities<StaticAbility> zonedAbilities = new AbilitiesImpl<>();
for (T ability : this) {
if (ability instanceof StaticAbility && ability.getZone().match(zone)) {
zonedAbilities.add((StaticAbility) ability);
}
}
return zonedAbilities;
return stream()
.filter(ability -> ability instanceof StaticAbility)
.filter(ability -> ability.getZone().match(zone))
.map(ability -> (StaticAbility) ability)
.collect(Collectors.toCollection(AbilitiesImpl::new));
}
@Override
@ -213,13 +204,11 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
@Override
public Abilities<ProtectionAbility> getProtectionAbilities() {
Abilities<ProtectionAbility> abilities = new AbilitiesImpl<>();
for (T ability : this) {
if (ability instanceof ProtectionAbility) {
abilities.add((ProtectionAbility) ability);
}
}
return abilities;
return stream()
.filter(ability -> ability instanceof ProtectionAbility)
.map(ability -> (ProtectionAbility) ability)
.collect(Collectors.toCollection(AbilitiesImpl::new));
}
@Override
@ -305,11 +294,7 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
@Override
public int getOutcomeTotal() {
int total = 0;
for (T ability : this) {
total += ability.getEffects().getOutcomeTotal();
}
return total;
return stream().mapToInt(ability -> ability.getEffects().getOutcomeTotal()).sum();
}
@Override

View file

@ -27,11 +27,12 @@
*/
package mage.abilities.condition;
import java.util.ArrayList;
import java.util.Arrays;
import mage.abilities.Ability;
import mage.game.Game;
import java.util.ArrayList;
import java.util.Arrays;
/**
* Combines conditions to one compound conditon, all single conditons must be
* true to return true for the compound condtion.
@ -55,12 +56,7 @@ public class CompoundCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
for (Condition condition : conditions) {
if (!condition.apply(game, source)) {
return false;
}
}
return true;
return conditions.stream().allMatch(condition -> condition.apply(game, source));
}
@Override

View file

@ -28,7 +28,6 @@
package mage.abilities.costs.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostImpl;
@ -36,16 +35,25 @@ import mage.cards.Card;
import mage.game.Game;
import mage.players.Player;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class DiscardSourceCost extends CostImpl {
private boolean nameCard = true;
public DiscardSourceCost() {}
public DiscardSourceCost(boolean nameCard){
this.nameCard = nameCard;
}
public DiscardSourceCost(DiscardSourceCost cost) {
super(cost);
nameCard = cost.nameCard;
}
@Override
@ -67,8 +75,13 @@ public class DiscardSourceCost extends CostImpl {
@Override
public String getText() {
if(nameCard) {
return "Discard {this}";
}
else{
return "Discard this card";
}
}
@Override
public DiscardSourceCost copy() {

View file

@ -48,14 +48,14 @@ public class CyclingAbility extends ActivatedAbilityImpl {
public CyclingAbility(Cost cost) {
super(Zone.HAND, new DrawCardSourceControllerEffect(1), cost);
this.addCost(new DiscardSourceCost());
this.addCost(new DiscardSourceCost(false));
this.cost = cost;
this.text = "Cycling";
}
public CyclingAbility(Cost cost, FilterCard filter, String text) {
super(Zone.HAND, new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true), cost);
this.addCost(new DiscardSourceCost());
this.addCost(new DiscardSourceCost(false));
this.cost = cost;
this.text = text;
}

View file

@ -27,13 +27,15 @@
*/
package mage.choices;
import java.util.ArrayList;
import java.util.List;
import mage.abilities.Ability;
import mage.constants.Outcome;
import mage.game.Game;
import mage.players.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
*
* @author BetaSteward_at_googlemail.com
@ -57,13 +59,9 @@ public class Choices extends ArrayList<Choice> {
}
public List<Choice> getUnchosen() {
List<Choice> unchosen = new ArrayList<>();
for (Choice choice : this) {
if (!choice.isChosen()) {
unchosen.add(choice);
}
}
return unchosen;
return stream()
.filter(choice -> !choice.isChosen())
.collect(Collectors.toList());
}
public void clearChosen() {

View file

@ -27,27 +27,24 @@
*/
package mage.util;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.Mana;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.SpellAbility;
import mage.abilities.costs.VariableCost;
import mage.abilities.costs.mana.*;
import mage.cards.Card;
import mage.filter.FilterMana;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.Token;
import mage.game.stack.Spell;
import mage.util.functions.CopyTokenFunction;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
* @author nantuko
*/
@ -396,6 +393,7 @@ public final class CardUtil {
}
public static boolean checkNumeric(String s) {
for (int i = 0; i < s.length(); i++) {
if (!Character.isDigit(s.charAt(i))) {
return false;