mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
refactored PlayerPredicate
This commit is contained in:
parent
8e29454916
commit
13d76bfc06
11 changed files with 23 additions and 96 deletions
|
|
@ -14,7 +14,6 @@ import mage.constants.Outcome;
|
|||
import mage.constants.TargetController;
|
||||
import mage.filter.FilterPlayer;
|
||||
import mage.filter.predicate.other.PlayerCanGainLifePredicate;
|
||||
import mage.filter.predicate.other.PlayerPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetPlayer;
|
||||
|
|
@ -28,7 +27,7 @@ public class GainLifeOpponentCost extends CostImpl {
|
|||
private static final FilterPlayer filter = new FilterPlayer("opponent that can gain life");
|
||||
|
||||
static {
|
||||
filter.add(new PlayerPredicate(TargetController.OPPONENT));
|
||||
filter.add(TargetController.OPPONENT.getPlayerPredicate());
|
||||
filter.add(new PlayerCanGainLifePredicate()); // you can't pay the costs by letting a player gain life that can't get life by rule changing effect
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import mage.abilities.costs.mana.ManaCost;
|
|||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.*;
|
||||
import mage.filter.FilterPlayer;
|
||||
import mage.filter.predicate.other.PlayerPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.players.ManaPool;
|
||||
import mage.players.Player;
|
||||
|
|
@ -26,7 +25,7 @@ public class AssistAbility extends SimpleStaticAbility implements AlternateManaP
|
|||
private static final FilterPlayer filter = new FilterPlayer("another player");
|
||||
|
||||
static {
|
||||
filter.add(new PlayerPredicate(TargetController.NOT_YOU));
|
||||
filter.add(TargetController.NOT_YOU.getPlayerPredicate());
|
||||
}
|
||||
|
||||
public AssistAbility() {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
package mage.filter;
|
||||
|
||||
import mage.constants.TargetController;
|
||||
import mage.filter.predicate.other.PlayerPredicate;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -16,7 +15,7 @@ public class FilterOpponent extends FilterPlayer {
|
|||
|
||||
public FilterOpponent(String text) {
|
||||
super(text);
|
||||
add(new PlayerPredicate(TargetController.OPPONENT));
|
||||
add(TargetController.OPPONENT.getPlayerPredicate());
|
||||
}
|
||||
|
||||
public FilterOpponent(final FilterOpponent filter) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import mage.constants.TargetController;
|
|||
import mage.filter.common.*;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.MulticoloredPredicate;
|
||||
import mage.filter.predicate.other.PlayerPredicate;
|
||||
import mage.filter.predicate.permanent.AnotherPredicate;
|
||||
import mage.filter.predicate.permanent.AttackingPredicate;
|
||||
import mage.filter.predicate.permanent.ControllerPredicate;
|
||||
|
|
@ -633,7 +632,7 @@ public final class StaticFilters {
|
|||
public static final FilterPlayer FILTER_PLAYER_CONTROLLER = new FilterPlayer("you");
|
||||
|
||||
static {
|
||||
FILTER_PLAYER_CONTROLLER.add(new PlayerPredicate(TargetController.YOU));
|
||||
FILTER_PLAYER_CONTROLLER.add(TargetController.YOU.getPlayerPredicate());
|
||||
FILTER_PLAYER_CONTROLLER.setLockedFilter(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
|
||||
package mage.filter.predicate.other;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.constants.TargetController;
|
||||
import mage.filter.predicate.ObjectSourcePlayer;
|
||||
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public class PlayerPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Player>> {
|
||||
|
||||
private final TargetController targetPlayer;
|
||||
|
||||
public PlayerPredicate(TargetController player) {
|
||||
this.targetPlayer = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ObjectSourcePlayer<Player> input, Game game) {
|
||||
Player player = input.getObject();
|
||||
UUID playerId = input.getPlayerId();
|
||||
if (player == null || playerId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (targetPlayer) {
|
||||
case YOU:
|
||||
if (player.getId().equals(playerId)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case OPPONENT:
|
||||
if (!player.getId().equals(playerId) &&
|
||||
game.getPlayer(playerId).hasOpponent(player.getId(), game)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case NOT_YOU:
|
||||
if (!player.getId().equals(playerId)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Player(" + targetPlayer + ')';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue