mirror of
https://github.com/magefree/mage.git
synced 2025-12-28 06:22:01 -08:00
refactor DefendingPlayerControlsCondition (#10749)
This commit is contained in:
parent
f75b1c9f0a
commit
4ebfd79005
9 changed files with 84 additions and 56 deletions
|
|
@ -1,27 +0,0 @@
|
|||
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public class DefendingPlayerControlsCondition implements Condition {
|
||||
|
||||
private final FilterPermanent filter;
|
||||
|
||||
public DefendingPlayerControlsCondition(FilterPermanent filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
UUID defendingPlayer = game.getCombat().getDefenderId(source.getSourceId());
|
||||
return defendingPlayer != null && game.getBattlefield().countAll(filter, defendingPlayer, game) > 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.predicate.permanent.DefendingPlayerControlsNoSourcePredicate;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* This condition always returns false outside of the combat phase.
|
||||
*
|
||||
* @author Susucr
|
||||
*/
|
||||
public class DefendingPlayerControlsNoSourceCondition implements Condition {
|
||||
|
||||
private final FilterPermanent filter;
|
||||
|
||||
public DefendingPlayerControlsNoSourceCondition(FilterPermanent filter) {
|
||||
this.filter = filter.copy();
|
||||
this.filter.add(DefendingPlayerControlsNoSourcePredicate.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return game.getBattlefield().count(filter, source.getControllerId(), source, game) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.predicate.permanent.DefendingPlayerControlsSourceAttackingPredicate;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* @author Susucr
|
||||
*/
|
||||
public class DefendingPlayerControlsSourceAttackingCondition implements Condition {
|
||||
|
||||
private final FilterPermanent filter;
|
||||
|
||||
public DefendingPlayerControlsSourceAttackingCondition(FilterPermanent filter) {
|
||||
this.filter = filter.copy();
|
||||
this.filter.add(DefendingPlayerControlsSourceAttackingPredicate.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return game.getBattlefield().count(filter, source.getControllerId(), source, game) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue