Refactoring

See github line by line comments in 'File changed'
This commit is contained in:
vraskulin 2016-12-29 16:49:12 +03:00
parent c0cf22bbf7
commit f04ba151f7
52 changed files with 87 additions and 220 deletions

View file

@ -45,8 +45,8 @@ import mage.target.TargetCard;
*/
public class TargetCardInExile extends TargetCard {
private UUID zoneId;
private boolean allExileZones;
private final UUID zoneId;
private final boolean allExileZones;
public TargetCardInExile(FilterCard filter) {
this(1, 1, filter, null);
@ -68,11 +68,7 @@ public class TargetCardInExile extends TargetCard {
public TargetCardInExile(int minNumTargets, int maxNumTargets, FilterCard filter, UUID zoneId, boolean allExileZones) {
super(minNumTargets, maxNumTargets, Zone.EXILED, filter);
this.zoneId = zoneId;
if (zoneId == null) {
this.allExileZones = true;
} else {
this.allExileZones = allExileZones;
}
this.allExileZones = zoneId == null || allExileZones;
}
public TargetCardInExile(final TargetCardInExile target) {

View file

@ -65,10 +65,7 @@ public class TargetCardInGraveyard extends TargetCard {
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
Card card = game.getCard(id);
if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
return filter.match(card, game);
}
return false;
return card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD && filter.match(card, game);
}
@Override

View file

@ -89,10 +89,7 @@ public class TargetCardInGraveyardOrBattlefield extends TargetCard {
return filter.match(permanent, game);
}
Card card = game.getCard(id);
if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
return filter.match(card, game);
}
return false;
return card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD && filter.match(card, game);
}
@Override

View file

@ -69,10 +69,7 @@ public class TargetCardInHand extends TargetCard {
@Override
public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
Card card = game.getPlayer(playerId).getHand().get(id, game);
if (card != null) {
return filter.match(card, source.getSourceId(), playerId, game);
}
return false;
return card != null && filter.match(card, source.getSourceId(), playerId, game);
}
@Override

View file

@ -92,7 +92,7 @@ public class TargetCardInLibrary extends TargetCard {
} else {
cards = new ArrayList<>(targetPlayer.getLibrary().getTopCards(game, librarySearchLimit));
}
Collections.sort(cards, new CardNameComparator());
cards.sort(new CardNameComparator());
Cards cardsId = new CardsImpl();
for (Card card : cards) {
cardsId.add(card);
@ -111,10 +111,7 @@ public class TargetCardInLibrary extends TargetCard {
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
Card card = game.getPlayer(source.getControllerId()).getLibrary().getCard(id, game);
if (card != null) {
return filter.match(card, game);
}
return false;
return card != null && filter.match(card, game);
}
@Override

View file

@ -14,7 +14,7 @@ import mage.players.Player;
public class TargetCardInOpponentsGraveyard extends TargetCard {
protected boolean allFromOneOpponent;
protected final boolean allFromOneOpponent;
public TargetCardInOpponentsGraveyard(FilterCard filter) {
this(1, 1, filter, false);

View file

@ -47,7 +47,7 @@
*/
public class TargetCreatureOrPlaneswalkerAmount extends TargetAmount {
protected FilterCreatureOrPlaneswalkerPermanent filter;
protected final FilterCreatureOrPlaneswalkerPermanent filter;
public TargetCreatureOrPlaneswalkerAmount(int amount) {
// 107.1c If a rule or ability instructs a player to choose any number, that player may choose
@ -85,10 +85,7 @@
@Override
public boolean canTarget(UUID objectId, Game game) {
Permanent permanent = game.getPermanent(objectId);
if (permanent != null) {
return filter.match(permanent, game);
}
return false;
return permanent != null && filter.match(permanent, game);
}
@Override

View file

@ -90,10 +90,7 @@ public class TargetCreatureOrPlayer extends TargetImpl {
return filter.match(permanent, game);
}
Player player = game.getPlayer(id);
if (player != null) {
return filter.match(player, game);
}
return false;
return player != null && filter.match(player, game);
}
@Override
@ -119,10 +116,7 @@ public class TargetCreatureOrPlayer extends TargetImpl {
if (permanent != null) {
return filter.match(permanent, game);
}
if (player != null) {
return filter.match(player, game);
}
return false;
return player != null && filter.match(player, game);
}
/**

View file

@ -49,7 +49,7 @@ import mage.target.TargetAmount;
*/
public class TargetCreatureOrPlayerAmount extends TargetAmount {
protected FilterCreatureOrPlayer filter;
protected final FilterCreatureOrPlayer filter;
public TargetCreatureOrPlayerAmount(int amount) {
// 107.1c If a rule or ability instructs a player to choose any number, that player may choose
@ -84,10 +84,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount {
return filter.match(permanent, game);
}
Player player = game.getPlayer(objectId);
if (player != null) {
return filter.match(player, game);
}
return false;
return player != null && filter.match(player, game);
}
@Override
@ -108,10 +105,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount {
if (permanent != null) {
return filter.match(permanent, game);
}
if (player != null) {
return filter.match(player, game);
}
return false;
return player != null && filter.match(player, game);
}
@Override

View file

@ -49,7 +49,7 @@ import java.util.UUID;
*/
public class TargetCreaturePermanentAmount extends TargetAmount {
protected FilterCreaturePermanent filter;
protected final FilterCreaturePermanent filter;
public TargetCreaturePermanentAmount(int amount) {
this(amount, new FilterCreaturePermanent());
@ -83,10 +83,7 @@ public class TargetCreaturePermanentAmount extends TargetAmount {
@Override
public boolean canTarget(UUID id, Game game) {
Permanent permanent = game.getPermanent(id);
if (permanent != null) {
return filter.match(permanent, game);
}
return false;
return permanent != null && filter.match(permanent, game);
}
@Override
@ -139,7 +136,7 @@ public class TargetCreaturePermanentAmount extends TargetAmount {
@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = new HashSet<UUID>();
Set<UUID> possibleTargets = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
@ -151,7 +148,7 @@ public class TargetCreaturePermanentAmount extends TargetAmount {
@Override
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = new HashSet<UUID>();
Set<UUID> possibleTargets = new HashSet<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());

View file

@ -49,8 +49,8 @@ import java.util.UUID;
*/
public class TargetDefender extends TargetImpl {
protected FilterPlaneswalkerOrPlayer filter;
protected UUID attackerId;
protected final FilterPlaneswalkerOrPlayer filter;
protected final UUID attackerId;
public TargetDefender(Set<UUID> defenders, UUID attackerId) {
this(1, 1, defenders, attackerId);
@ -187,10 +187,7 @@ public class TargetDefender extends TargetImpl {
return filter.match(player, game);
}
Permanent permanent = game.getPermanent(id);
if (permanent != null) {
return filter.match(permanent, game);
}
return false;
return permanent != null && filter.match(permanent, game);
}
@Override

View file

@ -44,7 +44,7 @@ import mage.filter.predicate.other.OwnerIdPredicate;
*/
public class TargetDiscard extends TargetCard {
private UUID playerId;
private final UUID playerId;
public TargetDiscard(UUID playerId) {
this(1, 1, new FilterCard(), playerId);
@ -73,10 +73,7 @@ public class TargetDiscard extends TargetCard {
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
Card card = game.getPlayer(playerId).getHand().get(id, game);
if (card != null) {
return filter.match(card, source.getControllerId(), game);
}
return false;
return card != null && filter.match(card, source.getControllerId(), game);
}
@Override

View file

@ -40,10 +40,7 @@ public class TargetOpponentsChoicePermanent extends TargetPermanent {
@Override
public boolean canTarget(UUID controllerId, UUID id, UUID sourceId, Game game, boolean flag) {
if (opponentId != null) {
return super.canTarget(opponentId, id, sourceId, game, flag);
}
return false;
return opponentId != null && super.canTarget(opponentId, id, sourceId, game, flag);
}
@Override

View file

@ -97,10 +97,7 @@ public class TargetPermanentOrPlayer extends TargetImpl {
return filter.match(permanent, game);
}
Player player = game.getPlayer(id);
if (player != null) {
return filter.match(player, game);
}
return false;
return player != null && filter.match(player, game);
}
@Override
@ -118,7 +115,7 @@ public class TargetPermanentOrPlayer extends TargetImpl {
if (permanent != null) {
if (!isNotTarget()) {
if (!permanent.canBeTargetedBy(game.getObject(source.getId()), source.getControllerId(), game) ||
!permanent.canBeTargetedBy(game.getObject(source.getSourceId()), source.getControllerId(), game)) {
!permanent.canBeTargetedBy(game.getObject(source.getSourceId()), source.getControllerId(), game)) {
return false;
}
}
@ -137,10 +134,7 @@ public class TargetPermanentOrPlayer extends TargetImpl {
if (permanent != null) {
return filter.match(permanent, game);
}
if (player != null) {
return filter.match(player, game);
}
return false;
return player != null && filter.match(player, game);
}
/**

View file

@ -43,7 +43,7 @@ import mage.filter.predicate.permanent.CounterPredicate;
*/
public class TargetPermanentOrPlayerWithCounter extends TargetPermanentOrPlayer {
protected FilterPermanentOrPlayerWithCounter filter;
protected final FilterPermanentOrPlayerWithCounter filter;
public TargetPermanentOrPlayerWithCounter() {
this(1, 1);

View file

@ -48,7 +48,7 @@ import mage.target.TargetImpl;
*/
public class TargetPermanentOrSuspendedCard extends TargetImpl {
protected FilterPermanentOrSuspendedCard filter;
protected final FilterPermanentOrSuspendedCard filter;
public TargetPermanentOrSuspendedCard() {
this(new FilterPermanentOrSuspendedCard(), false);
@ -118,10 +118,7 @@ public class TargetPermanentOrSuspendedCard extends TargetImpl {
return filter.match(permanent, game);
}
Card card = game.getExile().getCard(id, game);
if (card != null) {
return filter.match(card, game);
}
return false;
return card != null && filter.match(card, game);
}
@Override
@ -137,10 +134,7 @@ public class TargetPermanentOrSuspendedCard extends TargetImpl {
}
}
Card card = game.getExile().getCard(id, game);
if (card != null) {
return filter.match(card, game);
}
return false;
return card != null && filter.match(card, game);
}
@Override

View file

@ -105,10 +105,7 @@ public class TargetSpellOrPermanent extends TargetImpl {
return filter.match(permanent, game);
}
Spell spell = game.getStack().getSpell(id);
if (spell != null) {
return filter.match(spell, game);
}
return false;
return spell != null && filter.match(spell, game);
}
@Override
@ -124,11 +121,8 @@ public class TargetSpellOrPermanent extends TargetImpl {
}
}
Spell spell = game.getStack().getSpell(id);
if (spell != null
&& !source.getSourceId().equals(id)) { // 114.4. A spell or ability on the stack is an illegal target for itself.
return filter.match(spell, game);
}
return false;
// 114.4. A spell or ability on the stack is an illegal target for itself.
return spell != null && !source.getSourceId().equals(id) && filter.match(spell, game);
}
@Override