add isOwned and isControlled methods. remove some null-checks, remove some unnecessary casts

This commit is contained in:
igoudt 2018-07-04 14:24:11 +02:00
parent e46ad02918
commit 9f06046f22
464 changed files with 567 additions and 562 deletions

View file

@ -645,7 +645,7 @@ public abstract class PlayerImpl implements Player, Serializable {
*/
@Override
public boolean putInHand(Card card, Game game) {
if (card.getOwnerId().equals(playerId)) {
if (card.isOwnedBy(playerId)) {
card.setZone(Zone.HAND, game);
this.hand.add(card);
} else {
@ -834,7 +834,7 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override
public boolean putInGraveyard(Card card, Game game) {
if (card.getOwnerId().equals(playerId)) {
if (card.isOwnedBy(playerId)) {
this.graveyard.add(card);
} else {
return game.getPlayer(card.getOwnerId()).putInGraveyard(card, game);
@ -885,7 +885,7 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override
public boolean putCardOnTopXOfLibrary(Card card, Game game, Ability source, int xFromTheTop) {
if (card.getOwnerId().equals(getId())) {
if (card.isOwnedBy(getId())) {
if (library.size() + 1 < xFromTheTop) {
putCardsOnBottomOfLibrary(new CardsImpl(card), game, source, true);
} else {
@ -1556,7 +1556,7 @@ public abstract class PlayerImpl implements Player, Serializable {
// that phased out indirectly won't phase in by itself, but instead phases in
// along with the card it's attached to.
Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
if (!(attachedTo != null && attachedTo.getControllerId().equals(this.getId()))) {
if (!(attachedTo != null && attachedTo.isControlledBy(this.getId()))) {
permanent.phaseOut(game, false);
}
}
@ -2325,7 +2325,7 @@ public abstract class PlayerImpl implements Player, Serializable {
setStoredBookmark(game.bookmarkState()); // makes it possible to UNDO a declared attacker with costs from e.g. Propaganda
}
Permanent attacker = game.getPermanent(attackerId);
if (attacker != null && attacker.canAttack(defenderId, game) && attacker.getControllerId().equals(playerId)) {
if (attacker != null && attacker.canAttack(defenderId, game) && attacker.isControlledBy(playerId)) {
if (!game.getCombat().declareAttacker(attackerId, defenderId, playerId, game)) {
game.undo(playerId);
}
@ -3023,7 +3023,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()) && canPlay(ability, availableMana, game.getObject(ability.getSourceId()), game)) {
if (ability.isControlledBy(getId()) && canPlay(ability, availableMana, game.getObject(ability.getSourceId()), game)) {
playableActivated.put(ability.toString(), ability);
}
@ -3578,7 +3578,7 @@ public abstract class PlayerImpl implements Player, Serializable {
game.informPlayers(getLogName() + " puts "
+ (withName ? card.getLogName() : (card.isFaceDown(game) ? "a face down card" : "a card"))
+ " from " + fromZone.toString().toLowerCase(Locale.ENGLISH) + ' '
+ (card.getOwnerId().equals(this.getId()) ? "into their hand" : "into its owner's hand")
+ (card.isOwnedBy(this.getId()) ? "into their hand" : "into its owner's hand")
);
}
result = true;
@ -3601,7 +3601,7 @@ public abstract class PlayerImpl implements Player, Serializable {
if (cards.isEmpty()) {
ownerId = card.getOwnerId();
}
if (card.getOwnerId().equals(ownerId)) {
if (card.isOwnedBy(ownerId)) {
it.remove();
cards.add(card);
}
@ -3672,7 +3672,7 @@ public abstract class PlayerImpl implements Player, Serializable {
StringBuilder sb = new StringBuilder(this.getLogName())
.append(" puts ").append(card.getLogName()).append(' ').append(card.isCopy() ? "(Copy) " : "")
.append(fromZone != null ? "from " + fromZone.toString().toLowerCase(Locale.ENGLISH) + ' ' : "");
if (card.getOwnerId().equals(getId())) {
if (card.isOwnedBy(getId())) {
sb.append("into their graveyard");
} else {
sb.append("it into its owner's graveyard");
@ -3704,7 +3704,7 @@ public abstract class PlayerImpl implements Player, Serializable {
sb.append("from ").append(fromZone.toString().toLowerCase(Locale.ENGLISH)).append(' ');
}
sb.append("to the ").append(toTop ? "top" : "bottom");
if (card.getOwnerId().equals(getId())) {
if (card.isOwnedBy(getId())) {
sb.append(" of their library");
} else {
Player player = game.getPlayer(card.getOwnerId());