mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
Refactoring
See github line by line comments in 'File changed'
This commit is contained in:
parent
c0cf22bbf7
commit
f04ba151f7
52 changed files with 87 additions and 220 deletions
|
|
@ -206,26 +206,20 @@ public class ConditionalMana extends Mana implements Serializable {
|
|||
break;
|
||||
case BLUE:
|
||||
blue += amount;
|
||||
;
|
||||
break;
|
||||
case GREEN:
|
||||
green += amount;
|
||||
;
|
||||
break;
|
||||
case RED:
|
||||
red += amount;
|
||||
;
|
||||
break;
|
||||
case WHITE:
|
||||
white += amount;
|
||||
;
|
||||
break;
|
||||
case COLORLESS:
|
||||
colorless += amount;
|
||||
;
|
||||
case GENERIC:
|
||||
generic += amount;
|
||||
;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import mage.util.Copyable;
|
|||
|
||||
public class MageInt implements Serializable, Copyable<MageInt> {
|
||||
|
||||
public static MageInt EmptyMageInt = new MageInt(Integer.MIN_VALUE, "") {
|
||||
public static final MageInt EmptyMageInt = new MageInt(Integer.MIN_VALUE, "") {
|
||||
|
||||
private static final String exceptionMessage = "MageInt.EmptyMageInt can't be modified.";
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public class Library implements Serializable {
|
|||
public void shuffle() {
|
||||
UUID[] shuffled = library.toArray(new UUID[0]);
|
||||
for (int n = shuffled.length - 1; n > 0; n--) {
|
||||
int r = RandomUtil.nextInt(n);;
|
||||
int r = RandomUtil.nextInt(n);
|
||||
UUID temp = shuffled[n];
|
||||
shuffled[n] = shuffled[r];
|
||||
shuffled[r] = temp;
|
||||
|
|
|
|||
|
|
@ -303,23 +303,18 @@ public class ManaPoolItem implements Serializable {
|
|||
break;
|
||||
case BLUE:
|
||||
blue += amount;
|
||||
;
|
||||
break;
|
||||
case GREEN:
|
||||
green += amount;
|
||||
;
|
||||
break;
|
||||
case RED:
|
||||
red += amount;
|
||||
;
|
||||
break;
|
||||
case WHITE:
|
||||
white += amount;
|
||||
;
|
||||
break;
|
||||
case COLORLESS:
|
||||
colorless += amount;
|
||||
;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
private static final Logger logger = Logger.getLogger(PlayerImpl.class);
|
||||
|
||||
private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
|
||||
private static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
|
||||
|
||||
/**
|
||||
* Used to cancel waiting requests send to the player
|
||||
|
|
@ -987,7 +987,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
} else {
|
||||
result = cast(card.getSpellAbility(), game, noMana);
|
||||
}
|
||||
if (result == false) {
|
||||
if (!result) {
|
||||
game.informPlayer(this, "You can't play " + card.getIdName() + ".");
|
||||
}
|
||||
return result;
|
||||
|
|
@ -2026,7 +2026,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
quit = true;
|
||||
idleTimeout = true;
|
||||
this.concede(game);
|
||||
game.informPlayers(new StringBuilder(getLogName()).append(" was idle for too long, losing the Match.").toString());
|
||||
game.informPlayers(getLogName() + " was idle for too long, losing the Match.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -2241,11 +2241,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
@Override
|
||||
public boolean hasWon() {
|
||||
if (!this.loses) {
|
||||
return this.wins;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return !this.loses && this.wins;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -2364,20 +2360,14 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
public List<Permanent> getAvailableAttackers(UUID defenderId, Game game) {
|
||||
FilterCreatureForCombat filter = new FilterCreatureForCombat();
|
||||
List<Permanent> attackers = game.getBattlefield().getAllActivePermanents(filter, playerId, game);
|
||||
for (Iterator<Permanent> i = attackers.iterator(); i.hasNext();) {
|
||||
Permanent entry = i.next();
|
||||
if (!entry.canAttack(defenderId, game)) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
attackers.removeIf(entry -> !entry.canAttack(defenderId, game));
|
||||
return attackers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Permanent> getAvailableBlockers(Game game) {
|
||||
FilterCreatureForCombatBlock blockFilter = new FilterCreatureForCombatBlock();
|
||||
List<Permanent> blockers = game.getBattlefield().getAllActivePermanents(blockFilter, playerId, game);
|
||||
return blockers;
|
||||
return game.getBattlefield().getAllActivePermanents(blockFilter, playerId, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -2766,8 +2756,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
// activated abilities from stack objects
|
||||
for (StackObject stackObject : game.getState().getStack()) {
|
||||
for (ActivatedAbility ability : stackObject.getAbilities().getActivatedAbilities(Zone.STACK)) {
|
||||
if (ability instanceof ActivatedAbility
|
||||
&& canPlay(ability, availableMana, game.getObject(ability.getSourceId()), game)) {
|
||||
if (ability != null && canPlay(ability, availableMana, game.getObject(ability.getSourceId()), game)) {
|
||||
playableActivated.put(ability.toString(), ability);
|
||||
}
|
||||
|
||||
|
|
@ -2776,9 +2765,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
// activated abilities from objects in the command zone (emblems or commanders)
|
||||
for (CommandObject commandObject : game.getState().getCommand()) {
|
||||
for (ActivatedAbility ability : commandObject.getAbilities().getActivatedAbilities(Zone.COMMAND)) {
|
||||
if (ability.getControllerId().equals(getId())
|
||||
&& ability instanceof ActivatedAbility
|
||||
&& canPlay(ability, availableMana, game.getObject(ability.getSourceId()), game)) {
|
||||
if (ability.getControllerId().equals(getId()) && canPlay(ability, availableMana, game.getObject(ability.getSourceId()), game)) {
|
||||
playableActivated.put(ability.toString(), ability);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ public class UserData implements Serializable {
|
|||
}
|
||||
|
||||
public String getHistory() {
|
||||
if (UserGroup.COMPUTER.equals(this.groupId)) {
|
||||
if (UserGroup.COMPUTER.equals(this.groupId)) { // Why we are checking UserGroup and integer equality??
|
||||
return "";
|
||||
}
|
||||
// todo: add preference to hide rating?
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ import java.io.Serializable;
|
|||
*/
|
||||
|
||||
public class UserSkipPrioritySteps implements Serializable {
|
||||
SkipPrioritySteps yourTurn;
|
||||
SkipPrioritySteps opponentTurn;
|
||||
final SkipPrioritySteps yourTurn;
|
||||
final SkipPrioritySteps opponentTurn;
|
||||
|
||||
boolean stopOnDeclareAttackersDuringSkipAction;
|
||||
boolean stopOnDeclareBlockerIfNoneAvailable;
|
||||
|
|
|
|||
|
|
@ -76,10 +76,7 @@ public abstract class TargetAmount extends TargetImpl {
|
|||
|
||||
@Override
|
||||
public boolean doneChosing() {
|
||||
if (amountWasSet == false) {
|
||||
return false;
|
||||
}
|
||||
return remainingAmount == 0;
|
||||
return amountWasSet && remainingAmount == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ import mage.players.Player;
|
|||
*/
|
||||
public class TargetCard extends TargetObject {
|
||||
|
||||
protected FilterCard filter;
|
||||
protected final FilterCard filter;
|
||||
|
||||
protected TargetCard(Zone zone) {
|
||||
this(1, 1, zone, new FilterCard());
|
||||
|
|
@ -214,10 +214,7 @@ public class TargetCard extends TargetObject {
|
|||
|
||||
public boolean canTarget(UUID id, Cards cards, Game game) {
|
||||
Card card = cards.get(id, game);
|
||||
if (card != null) {
|
||||
return filter.match(card, game);
|
||||
}
|
||||
return false;
|
||||
return card != null && filter.match(card, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import java.util.Iterator;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
|
|
@ -55,8 +54,8 @@ import mage.util.RandomUtil;
|
|||
*/
|
||||
public abstract class TargetImpl implements Target {
|
||||
|
||||
protected Map<UUID, Integer> targets = new LinkedHashMap<>();
|
||||
protected Map<UUID, Integer> zoneChangeCounters = new HashMap<>();
|
||||
protected final Map<UUID, Integer> targets = new LinkedHashMap<>();
|
||||
protected final Map<UUID, Integer> zoneChangeCounters = new HashMap<>();
|
||||
|
||||
protected String targetName;
|
||||
protected Zone zone;
|
||||
|
|
@ -199,18 +198,12 @@ public abstract class TargetImpl implements Target {
|
|||
if (getMaxNumberOfTargets() == 0 && getNumberOfTargets() == 0) {
|
||||
return true;
|
||||
}
|
||||
if (getMaxNumberOfTargets() != 0 && targets.size() == getMaxNumberOfTargets()) {
|
||||
return true;
|
||||
}
|
||||
return chosen;
|
||||
return getMaxNumberOfTargets() != 0 && targets.size() == getMaxNumberOfTargets() || chosen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doneChosing() {
|
||||
if (getMaxNumberOfTargets() == 0) {
|
||||
return false;
|
||||
}
|
||||
return targets.size() == getMaxNumberOfTargets();
|
||||
return getMaxNumberOfTargets() != 0 && targets.size() == getMaxNumberOfTargets();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -78,10 +78,7 @@ public abstract class TargetObject extends TargetImpl {
|
|||
@Override
|
||||
public boolean canTarget(UUID id, Game game) {
|
||||
MageObject object = game.getObject(id);
|
||||
if (object != null && game.getState().getZone(id).match(zone)) {
|
||||
return getFilter().match(object, game);
|
||||
}
|
||||
return false;
|
||||
return object != null && game.getState().getZone(id).match(zone) && getFilter().match(object, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -101,10 +101,7 @@ public class TargetPermanent extends TargetObject {
|
|||
|
||||
public boolean canTarget(UUID controllerId, UUID id, UUID sourceId, Game game, boolean flag) {
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
if (permanent != null) {
|
||||
return filter.match(permanent, sourceId, controllerId, game);
|
||||
}
|
||||
return false;
|
||||
return permanent != null && filter.match(permanent, sourceId, controllerId, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ import mage.players.Player;
|
|||
*/
|
||||
public class TargetPlayer extends TargetImpl {
|
||||
|
||||
protected FilterPlayer filter;
|
||||
protected final FilterPlayer filter;
|
||||
|
||||
public TargetPlayer() {
|
||||
this(1, 1, false);
|
||||
|
|
@ -169,10 +169,7 @@ public class TargetPlayer extends TargetImpl {
|
|||
@Override
|
||||
public boolean canTarget(UUID id, Game game) {
|
||||
Player player = game.getPlayer(id);
|
||||
if (player != null) {
|
||||
return filter.match(player, game);
|
||||
}
|
||||
return false;
|
||||
return player != null && filter.match(player, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ import mage.players.Player;
|
|||
*/
|
||||
public class TargetSource extends TargetObject {
|
||||
|
||||
protected FilterObject filter;
|
||||
protected final FilterObject filter;
|
||||
|
||||
public TargetSource() {
|
||||
this(1, 1, new FilterObject("source of your choice"));
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ import mage.game.stack.StackObject;
|
|||
*/
|
||||
public class TargetSpell extends TargetObject {
|
||||
|
||||
protected FilterSpell filter;
|
||||
protected final FilterSpell filter;
|
||||
|
||||
public TargetSpell() {
|
||||
this(1, 1, new FilterSpell());
|
||||
|
|
@ -82,10 +82,7 @@ public class TargetSpell extends TargetObject {
|
|||
return false;
|
||||
}
|
||||
Spell spell = game.getStack().getSpell(id);
|
||||
if (spell != null) {
|
||||
return filter.match(spell, source.getSourceId(), source.getControllerId(), game);
|
||||
}
|
||||
return false;
|
||||
return spell != null && filter.match(spell, source.getSourceId(), source.getControllerId(), game);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ import java.util.UUID;
|
|||
*/
|
||||
public class TargetStackObject extends TargetObject {
|
||||
|
||||
protected FilterStackObject filter;
|
||||
protected final FilterStackObject filter;
|
||||
|
||||
public TargetStackObject() {
|
||||
this(1, 1, new FilterStackObject());
|
||||
|
|
@ -79,10 +79,7 @@ public class TargetStackObject extends TargetObject {
|
|||
@Override
|
||||
public boolean canTarget(UUID id, Ability source, Game game) {
|
||||
StackObject stackObject = game.getStack().getStackObject(id);
|
||||
if (stackObject != null) {
|
||||
return filter.match(stackObject, source.getSourceId(), source.getControllerId(), game);
|
||||
}
|
||||
return false;
|
||||
return stackObject != null && filter.match(stackObject, source.getSourceId(), source.getControllerId(), game);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import mage.game.Game;
|
|||
|
||||
public class SecondTargetPointer implements TargetPointer {
|
||||
|
||||
private Map<UUID, Integer> zoneChangeCounter = new HashMap<UUID, Integer>();
|
||||
private Map<UUID, Integer> zoneChangeCounter = new HashMap<>();
|
||||
|
||||
public static SecondTargetPointer getInstance() {
|
||||
return new SecondTargetPointer();
|
||||
|
|
@ -41,7 +41,7 @@ public class SecondTargetPointer implements TargetPointer {
|
|||
|
||||
@Override
|
||||
public List<UUID> getTargets(Game game, Ability source) {
|
||||
ArrayList<UUID> target = new ArrayList<UUID>();
|
||||
ArrayList<UUID> target = new ArrayList<>();
|
||||
if (source.getTargets().size() > 1) {
|
||||
for (UUID targetId : source.getTargets().get(1).getTargets()) {
|
||||
Card card = game.getCard(targetId);
|
||||
|
|
|
|||
|
|
@ -64,12 +64,9 @@ public class Copier<T> {
|
|||
ObjectInputStream in = new CopierObjectInputStream(loader, fbos.getInputStream());
|
||||
copy = (T) in.readObject();
|
||||
}
|
||||
catch(IOException e) {
|
||||
catch(IOException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(ClassNotFoundException cnfe) {
|
||||
cnfe.printStackTrace();
|
||||
}
|
||||
return copy;
|
||||
|
||||
}
|
||||
|
|
@ -99,12 +96,9 @@ public class Copier<T> {
|
|||
try (ObjectInputStream in = new CopierObjectInputStream(loader, new GZIPInputStream(new ByteArrayInputStream(buffer)))) {
|
||||
copy = (T) in.readObject();
|
||||
}
|
||||
catch(IOException e) {
|
||||
catch(IOException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(ClassNotFoundException cnfe) {
|
||||
cnfe.printStackTrace();
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import java.io.StreamCorruptedException;
|
|||
public class CopierObjectInputStream extends ObjectInputStream {
|
||||
ClassLoader myLoader = null;
|
||||
|
||||
public CopierObjectInputStream(ClassLoader newLoader, InputStream theStream) throws IOException, StreamCorruptedException {
|
||||
public CopierObjectInputStream(ClassLoader newLoader, InputStream theStream) throws IOException {
|
||||
super(theStream);
|
||||
myLoader = newLoader;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import mage.cards.Card;
|
||||
|
|
|
|||
|
|
@ -83,9 +83,7 @@ public class CopyTokenFunction implements Function<Token, Card> {
|
|||
} else {
|
||||
target.setOriginalExpansionSetCode(source.getExpansionSetCode());
|
||||
target.setOriginalCardNumber(source.getCardNumber());
|
||||
if (source instanceof Card) {
|
||||
target.setCopySourceCard(source);
|
||||
}
|
||||
target.setCopySourceCard(source);
|
||||
}
|
||||
|
||||
target.setName(sourceObj.getName());
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public abstract class Watcher implements Serializable {
|
|||
protected UUID controllerId;
|
||||
protected UUID sourceId;
|
||||
protected boolean condition;
|
||||
protected WatcherScope scope;
|
||||
protected final WatcherScope scope;
|
||||
|
||||
public Watcher(String basicKey, WatcherScope scope) {
|
||||
this.basicKey = basicKey;
|
||||
|
|
|
|||
|
|
@ -43,9 +43,7 @@ public class Watchers extends HashMap<String, Watcher> {
|
|||
}
|
||||
|
||||
public Watchers(final Watchers watchers) {
|
||||
watchers.entrySet().stream().forEach((entry) -> {
|
||||
this.put(entry.getKey(), entry.getValue().copy());
|
||||
});
|
||||
watchers.entrySet().stream().forEach((entry) -> this.put(entry.getKey(), entry.getValue().copy()));
|
||||
}
|
||||
|
||||
public Watchers copy() {
|
||||
|
|
@ -59,16 +57,13 @@ public class Watchers extends HashMap<String, Watcher> {
|
|||
}
|
||||
|
||||
public void watch(GameEvent event, Game game) {
|
||||
for (Iterator<Watcher> it = this.values().iterator(); it.hasNext();) {
|
||||
Watcher watcher = it.next();
|
||||
for (Watcher watcher : this.values()) {
|
||||
watcher.watch(event, game);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.values().stream().forEach((watcher) -> {
|
||||
watcher.reset();
|
||||
});
|
||||
this.values().stream().forEach(Watcher::reset);
|
||||
}
|
||||
|
||||
public Watcher get(String key, UUID id) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import mage.watchers.Watcher;
|
|||
|
||||
public class AttackedThisCombatWatcher extends Watcher {
|
||||
|
||||
public Set<MageObjectReference> attackedThisTurnCreatures = new HashSet<>();
|
||||
public final Set<MageObjectReference> attackedThisTurnCreatures = new HashSet<>();
|
||||
|
||||
public AttackedThisCombatWatcher() {
|
||||
super("AttackedThisCombat", WatcherScope.GAME);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import mage.watchers.Watcher;
|
|||
public class AttackedThisTurnWatcher extends Watcher {
|
||||
|
||||
// TODO: use MageObjectReference instead of UUID
|
||||
public Set<UUID> attackedThisTurnCreatures = new HashSet<>();
|
||||
public final Set<UUID> attackedThisTurnCreatures = new HashSet<>();
|
||||
|
||||
public AttackedThisTurnWatcher() {
|
||||
super("AttackedThisTurn", WatcherScope.GAME);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ import mage.watchers.Watcher;
|
|||
*/
|
||||
public class BlockedAttackerWatcher extends Watcher {
|
||||
|
||||
public HashMap<MageObjectReference, Set<MageObjectReference>> blockData = new HashMap<>();
|
||||
public final HashMap<MageObjectReference, Set<MageObjectReference>> blockData = new HashMap<>();
|
||||
|
||||
public BlockedAttackerWatcher() {
|
||||
super("BlockedAttackerWatcher", WatcherScope.GAME);
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class BloodthirstWatcher extends Watcher {
|
|||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (condition == true) { //no need to check - condition has already occured
|
||||
if (condition) { //no need to check - condition has already occured
|
||||
return;
|
||||
}
|
||||
if (event.getType() == GameEvent.EventType.DAMAGED_PLAYER) {
|
||||
|
|
|
|||
|
|
@ -79,10 +79,7 @@ public class CastFromGraveyardWatcher extends Watcher {
|
|||
|
||||
public boolean spellWasCastFromGraveyard(UUID sourceId, int zcc) {
|
||||
Set zccSet = spellsCastFromGraveyard.get(sourceId);
|
||||
if (zccSet != null) {
|
||||
return zccSet.contains(zcc);
|
||||
}
|
||||
return false;
|
||||
return zccSet != null && zccSet.contains(zcc);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ import mage.watchers.Watcher;
|
|||
public class CommanderInfoWatcher extends Watcher {
|
||||
|
||||
public final Map<UUID, Integer> damageToPlayer = new HashMap<>();
|
||||
public boolean checkCommanderDamage;
|
||||
public final boolean checkCommanderDamage;
|
||||
|
||||
public CommanderInfoWatcher(UUID commander, boolean checkCommanderDamage) {
|
||||
super("CommanderCombatDamageWatcher", WatcherScope.CARD);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ import mage.watchers.Watcher;
|
|||
*/
|
||||
public class DamagedByWatcher extends Watcher {
|
||||
|
||||
public Set<MageObjectReference> damagedBySource = new HashSet<>();
|
||||
public final Set<MageObjectReference> damagedBySource = new HashSet<>();
|
||||
|
||||
private final boolean watchPlaneswalkers;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import mage.watchers.Watcher;
|
|||
*/
|
||||
public class LandfallWatcher extends Watcher {
|
||||
|
||||
Set<UUID> playerPlayedLand = new HashSet<>();
|
||||
final Set<UUID> playerPlayedLand = new HashSet<>();
|
||||
|
||||
public LandfallWatcher() {
|
||||
super("LandPlayed", WatcherScope.GAME);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class MorbidWatcher extends Watcher {
|
|||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (condition == true) {
|
||||
if (condition) {
|
||||
return;
|
||||
}
|
||||
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).isDiesEvent()) {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ import mage.watchers.Watcher;
|
|||
*/
|
||||
public class PlayerCastCreatureWatcher extends Watcher {
|
||||
|
||||
Set<UUID> playerIds = new HashSet<>();
|
||||
final Set<UUID> playerIds = new HashSet<>();
|
||||
|
||||
public PlayerCastCreatureWatcher() {
|
||||
super("PlayerCastCreature", WatcherScope.GAME);
|
||||
|
|
|
|||
|
|
@ -104,10 +104,7 @@ public class ProwlWatcher extends Watcher {
|
|||
return true;
|
||||
}
|
||||
Set<String> subtypes = damagingSubtypes.get(playerId);
|
||||
if (subtypes != null) {
|
||||
return subtypes.contains(subtype);
|
||||
}
|
||||
return false;
|
||||
return subtypes != null && subtypes.contains(subtype);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ import java.util.UUID;
|
|||
*/
|
||||
public class SourceDidDamageWatcher extends Watcher {
|
||||
|
||||
public List<UUID> damageSources = new ArrayList<>();
|
||||
public final List<UUID> damageSources = new ArrayList<>();
|
||||
|
||||
public SourceDidDamageWatcher() {
|
||||
super("SourceDidDamageWatcher", WatcherScope.GAME);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue