removed ObjectPlayer and ObjectPlayerPredicate

This commit is contained in:
Evan Kranzler 2021-09-20 23:38:31 -04:00
parent c6feab68da
commit 658ae06e6f
41 changed files with 172 additions and 237 deletions

View file

@ -2,7 +2,10 @@ package mage.filter;
import mage.cards.Card;
import mage.constants.TargetController;
import mage.filter.predicate.*;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.filter.predicate.Predicate;
import mage.filter.predicate.Predicates;
import mage.game.Game;
import java.util.ArrayList;
@ -20,7 +23,7 @@ import java.util.stream.Collectors;
public class FilterCard extends FilterObject<Card> {
private static final long serialVersionUID = 1L;
protected List<ObjectPlayerPredicate<ObjectPlayer<Card>>> extraPredicates = new ArrayList<>();
protected List<ObjectSourcePlayerPredicate<ObjectSourcePlayer<Card>>> extraPredicates = new ArrayList<>();
public FilterCard() {
super("card");
@ -53,21 +56,17 @@ public class FilterCard extends FilterObject<Card> {
}
public boolean match(Card card, UUID playerId, Game game) {
if (!this.match(card, game)) {
return false;
}
return Predicates.and(extraPredicates).apply(new ObjectPlayer(card, playerId), game);
return match(card, null, playerId, game);
}
public boolean match(Card card, UUID sourceId, UUID playerId, Game game) {
if (!this.match(card, game)) {
return false;
}
return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer(card, sourceId, playerId), game);
return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer<Card>(card, sourceId, playerId), game);
}
public final void add(ObjectPlayerPredicate predicate) {
public final void add(ObjectSourcePlayerPredicate predicate) {
if (isLockedFilter()) {
throw new UnsupportedOperationException("You may not modify a locked filter");
}

View file

@ -1,8 +1,8 @@
package mage.filter;
import mage.constants.SubType;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.Predicates;
import mage.game.Game;
@ -18,7 +18,7 @@ import java.util.UUID;
*/
public class FilterPermanent extends FilterObject<Permanent> implements FilterInPlay<Permanent> {
protected List<ObjectPlayerPredicate<ObjectPlayer<Permanent>>> extraPredicates = new ArrayList<>();
protected List<ObjectSourcePlayerPredicate<ObjectSourcePlayer<Permanent>>> extraPredicates = new ArrayList<>();
public FilterPermanent() {
super("permanent");
@ -56,10 +56,10 @@ public class FilterPermanent extends FilterObject<Permanent> implements FilterIn
return false;
}
return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer(permanent, sourceId, playerId), game);
return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer<Permanent>(permanent, sourceId, playerId), game);
}
public final void add(ObjectPlayerPredicate predicate) {
public final void add(ObjectSourcePlayerPredicate predicate) {
if (isLockedFilter()) {
throw new UnsupportedOperationException("You may not modify a locked filter");
}

View file

@ -1,8 +1,7 @@
package mage.filter;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.filter.predicate.Predicates;
import mage.game.Game;
import mage.players.Player;
@ -17,7 +16,7 @@ import java.util.UUID;
*/
public class FilterPlayer extends FilterImpl<Player> {
protected List<ObjectPlayerPredicate<ObjectPlayer<Player>>> extraPredicates = new ArrayList<>();
protected List<ObjectSourcePlayerPredicate<ObjectSourcePlayer<Player>>> extraPredicates = new ArrayList<>();
public FilterPlayer() {
this("player");
@ -32,7 +31,7 @@ public class FilterPlayer extends FilterImpl<Player> {
this.extraPredicates = new ArrayList<>(filter.extraPredicates);
}
public void add(ObjectPlayerPredicate predicate) {
public void add(ObjectSourcePlayerPredicate predicate) {
if (isLockedFilter()) {
throw new UnsupportedOperationException("You may not modify a locked filter");
}
@ -49,7 +48,7 @@ public class FilterPlayer extends FilterImpl<Player> {
return false;
}
return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer(checkPlayer, sourceId, sourceControllerId), game);
return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer<Player>(checkPlayer, sourceId, sourceControllerId), game);
}
@Override

View file

@ -1,7 +1,7 @@
package mage.filter;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.Predicates;
import mage.game.Game;
@ -17,7 +17,7 @@ import java.util.UUID;
*/
public class FilterStackObject extends FilterObject<StackObject> {
protected List<ObjectPlayerPredicate<ObjectPlayer<Permanent>>> extraPredicates = new ArrayList<>();
protected List<ObjectSourcePlayerPredicate<ObjectSourcePlayer<StackObject>>> extraPredicates = new ArrayList<>();
public FilterStackObject() {
this("spell or ability");
@ -37,10 +37,10 @@ public class FilterStackObject extends FilterObject<StackObject> {
return false;
}
return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer(stackObject, sourceId, playerId), game);
return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer<StackObject>(stackObject, sourceId, playerId), game);
}
public final void add(ObjectPlayerPredicate predicate) {
public final void add(ObjectSourcePlayerPredicate predicate) {
if (isLockedFilter()) {
throw new UnsupportedOperationException("You may not modify a locked filter");
}

View file

@ -5,7 +5,8 @@ import mage.filter.FilterImpl;
import mage.filter.FilterInPlay;
import mage.filter.FilterPermanent;
import mage.filter.FilterPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -46,7 +47,7 @@ public class FilterPermanentOrPlayer extends FilterImpl<MageItem> implements Fil
return true;
}
public void add(ObjectPlayerPredicate predicate) {
public void add(ObjectSourcePlayerPredicate predicate) {
playerFilter.add((Predicate<? super Player>) predicate);
permanentFilter.add((Predicate<? super Permanent>) predicate);
}

View file

@ -1,49 +1,17 @@
/*
*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*
*/
package mage.filter.common;
import java.util.UUID;
import mage.MageObject;
import mage.filter.FilterImpl;
import mage.filter.FilterInPlay;
import mage.filter.FilterPermanent;
import mage.filter.FilterSpell;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import java.util.UUID;
/**
*
* @author LevelX
*/
public class FilterSpellOrPermanent extends FilterImpl<MageObject> implements FilterInPlay<MageObject> {
@ -92,12 +60,11 @@ public class FilterSpellOrPermanent extends FilterImpl<MageObject> implements Fi
return false;
}
public final void add(ObjectPlayerPredicate<? extends ObjectPlayer> predicate) {
if (isLockedFilter()) {
throw new UnsupportedOperationException("You may not modify a locked filter");
}
spellFilter.add(predicate);
permanentFilter.add(predicate);
@Override
public void setLockedFilter(boolean lockedFilter) {
super.setLockedFilter(lockedFilter);
spellFilter.setLockedFilter(lockedFilter);
permanentFilter.setLockedFilter(lockedFilter);
}
public FilterPermanent getPermanentFilter() {

View file

@ -1,28 +0,0 @@
package mage.filter.predicate;
import java.util.UUID;
/**
*
* @author North
* @param <T>
*/
public class ObjectPlayer<T> {
protected final T object;
protected final UUID playerId;
public ObjectPlayer(T object, UUID playerId) {
this.object = object;
this.playerId = playerId;
}
public T getObject() {
return object;
}
public UUID getPlayerId() {
return playerId;
}
}

View file

@ -1,11 +0,0 @@
package mage.filter.predicate;
/**
*
* @author North
* @param <T>
*/
@FunctionalInterface
public interface ObjectPlayerPredicate<T extends ObjectPlayer> extends Predicate<T> {
}

View file

@ -1,22 +1,31 @@
package mage.filter.predicate;
import java.util.UUID;
/**
*
* @author North
* @param <T>
* @author North
*/
public class ObjectSourcePlayer<T> extends ObjectPlayer<T> {
public class ObjectSourcePlayer<T> {
protected final T object;
protected final UUID playerId;
protected final UUID sourceId;
public ObjectSourcePlayer(T object, UUID sourceId, UUID sourceControllerId) {
super(object, sourceControllerId);
this.object = object;
this.playerId = sourceControllerId;
this.sourceId = sourceId;
}
public T getObject() {
return object;
}
public UUID getPlayerId() {
return playerId;
}
public UUID getSourceId() {
return sourceId;
}

View file

@ -1,11 +1,9 @@
package mage.filter.predicate;
/**
*
* @author North
* @param <T>
* @author North
*/
@FunctionalInterface
public interface ObjectSourcePlayerPredicate<T extends ObjectSourcePlayer> extends ObjectPlayerPredicate<T> {
public interface ObjectSourcePlayerPredicate<T extends ObjectSourcePlayer<?>> extends Predicate<T> {
}

View file

@ -1,8 +1,8 @@
package mage.filter.predicate.card;
import mage.cards.Card;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.players.Player;
@ -10,12 +10,12 @@ import mage.players.Player;
* @author JayDi85
*/
public enum CardOnTopOfLibraryPredicate implements ObjectPlayerPredicate<ObjectPlayer<Card>> {
public enum CardOnTopOfLibraryPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Card>> {
YOUR,
ANY;
@Override
public boolean apply(ObjectPlayer<Card> input, Game game) {
public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
Player player;
switch (this) {

View file

@ -1,18 +1,18 @@
package mage.filter.predicate.card;
import mage.cards.Card;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
/**
* @author TheElk801
*/
public enum DefendingPlayerOwnsCardPredicate implements ObjectPlayerPredicate<ObjectPlayer<Card>> {
public enum DefendingPlayerOwnsCardPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Card>> {
instance;
@Override
public boolean apply(ObjectPlayer<Card> input, Game game) {
public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
return game.getCombat().getPlayerDefenders(game, false).contains(input.getObject().getOwnerId());
}

View file

@ -1,8 +1,8 @@
package mage.filter.predicate.other;
import mage.constants.TargetController;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Controllable;
import mage.game.Game;
import mage.watchers.common.PlayerDamagedBySourceWatcher;
@ -12,7 +12,7 @@ import java.util.UUID;
/**
* @author LevelX2
*/
public class DamagedPlayerThisTurnPredicate implements ObjectPlayerPredicate<ObjectPlayer<Controllable>> {
public class DamagedPlayerThisTurnPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Controllable>> {
private final TargetController controller;
@ -21,7 +21,7 @@ public class DamagedPlayerThisTurnPredicate implements ObjectPlayerPredicate<Obj
}
@Override
public boolean apply(ObjectPlayer<Controllable> input, Game game) {
public boolean apply(ObjectSourcePlayer<Controllable> input, Game game) {
Controllable object = input.getObject();
UUID playerId = input.getPlayerId();

View file

@ -1,8 +1,8 @@
package mage.filter.predicate.permanent;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -10,10 +10,10 @@ import mage.game.permanent.Permanent;
*
* @author North & L_J
*/
public class AttachedToControlledPermanentPredicate implements ObjectPlayerPredicate<ObjectPlayer<Permanent>> {
public class AttachedToControlledPermanentPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Permanent>> {
@Override
public boolean apply(ObjectPlayer<Permanent> input, Game game) {
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
Permanent attachement = input.getObject();
if (attachement != null) {
Permanent permanent = game.getPermanent(attachement.getAttachedTo());