(WIP) Replacing blocking/blocked by predicates (#8729)

* replaced blocking/blocked by predicates

* added test for knight of dusk (currently fails)

* added source parameter to filters and everything else that needs it

* some changes to various predicates

* test fix

* small changes to filter code

* merge fix

* fixed a test failure

* small change to Karn, Scion of Urza

* removed sourceId from filter methods and other similar places

* added new getobject method to fix some test failures

* a few more fixes

* fixed merge conflicts

* merge fix
This commit is contained in:
Evan Kranzler 2022-03-23 18:45:02 -04:00 committed by GitHub
parent 53877424a0
commit 80e11b2052
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1719 changed files with 3384 additions and 3325 deletions

View file

@ -65,21 +65,21 @@ public class TargetPermanent extends TargetObject {
// second for protection from sources (e.g. protection from artifacts + equip ability)
if (!isNotTarget()) {
if (!permanent.canBeTargetedBy(game.getObject(source.getId()), controllerId, game)
|| !permanent.canBeTargetedBy(game.getObject(source.getSourceId()), controllerId, game)) {
|| !permanent.canBeTargetedBy(game.getObject(source), controllerId, game)) {
return false;
}
}
return filter.match(permanent, source.getSourceId(), controllerId, game);
return filter.match(permanent, controllerId, source, game);
} else {
return filter.match(permanent, null, controllerId, game);
return filter.match(permanent, controllerId, source, game);
}
}
return false;
}
public boolean canTarget(UUID controllerId, UUID id, UUID sourceId, Game game, boolean flag) {
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game, boolean flag) {
Permanent permanent = game.getPermanent(id);
return filter.match(permanent, sourceId, controllerId, game);
return filter.match(permanent, controllerId, source, game);
}
@Override
@ -93,20 +93,20 @@ public class TargetPermanent extends TargetObject {
* Takes into account notTarget parameter, in case it's true doesn't check
* for protection, shroud etc.
*
* @param sourceId the target event source
* @param sourceControllerId controller of the target event source
* @param source
* @param game
* @return true if enough valid {@link Permanent} exist
*/
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
public boolean canChoose(UUID sourceControllerId, Ability source, Game game) {
int remainingTargets = this.minNumberOfTargets - targets.size();
if (remainingTargets <= 0) {
return true;
}
int count = 0;
MageObject targetSource = game.getObject(sourceId);
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
MageObject targetSource = game.getObject(source);
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, source, game)) {
if (!targets.containsKey(permanent.getId())) {
if (notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
count++;
@ -149,11 +149,11 @@ public class TargetPermanent extends TargetObject {
}
@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
public Set<UUID> possibleTargets(UUID sourceControllerId, Ability source, Game game) {
// TODO: check if possible targets works with setTargetController from some cards like Nicol Bolas, Dragon-God
Set<UUID> possibleTargets = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
MageObject targetSource = game.getObject(source);
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, source, game)) {
if (!targets.containsKey(permanent.getId())) {
if (notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());