(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

@ -88,9 +88,9 @@ public class TargetSpellOrPermanent extends TargetImpl {
Permanent permanent = game.getPermanent(id);
if (permanent != null) {
if (source != null) {
MageObject targetSource = game.getObject(source.getSourceId());
MageObject targetSource = game.getObject(source);
return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game)
&& filter.match(permanent, source.getSourceId(), source.getControllerId(), game);
&& filter.match(permanent, source.getControllerId(), source, game);
} else {
return filter.match(permanent, game);
}
@ -110,21 +110,21 @@ public class TargetSpellOrPermanent extends TargetImpl {
* {@link mage.game.stack.Spell} that can be chosen. Should only be used for
* Ability targets since this checks 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 mage.game.permanent.Permanent} or
* {@link mage.game.stack.Spell} exist
*/
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
public boolean canChoose(UUID sourceControllerId, Ability source, Game game) {
int count = 0;
MageObject targetSource = game.getObject(sourceId);
MageObject targetSource = game.getObject(source);
for (StackObject stackObject : game.getStack()) {
Spell spell = game.getStack().getSpell(stackObject.getId());
if (spell != null
&& !sourceId.equals(spell.getSourceId())
&& filter.match(spell, sourceId, sourceControllerId, game)) {
&& !source.getSourceId().equals(spell.getSourceId())
&& filter.match(spell, sourceControllerId, source, game)) {
count++;
if (count >= this.minNumberOfTargets) {
return true;
@ -132,7 +132,7 @@ public class TargetSpellOrPermanent extends TargetImpl {
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceControllerId, source, game)) {
count++;
if (count >= this.minNumberOfTargets) {
return true;
@ -158,7 +158,7 @@ public class TargetSpellOrPermanent extends TargetImpl {
for (StackObject stackObject : game.getStack()) {
Spell spell = game.getStack().getSpell(stackObject.getId());
if (spell != null
&& filter.match(spell, null, sourceControllerId, game) && filter.match(spell, game)) {
&& filter.match(spell, sourceControllerId, null, game) && filter.match(spell, game)) {
count++;
if (count >= this.minNumberOfTargets) {
return true;
@ -166,7 +166,7 @@ public class TargetSpellOrPermanent extends TargetImpl {
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game) && filter.match(permanent, game)) {
if (filter.match(permanent, sourceControllerId, null, game) && filter.match(permanent, game)) {
count++;
if (count >= this.minNumberOfTargets) {
return true;
@ -177,19 +177,19 @@ public class TargetSpellOrPermanent extends TargetImpl {
}
@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
public Set<UUID> possibleTargets(UUID sourceControllerId, Ability source, Game game) {
Set<UUID> possibleTargets = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
MageObject targetSource = game.getObject(source);
for (StackObject stackObject : game.getStack()) {
Spell spell = game.getStack().getSpell(stackObject.getId());
if (spell != null
&& !sourceId.equals(spell.getSourceId())
&& filter.match(spell, sourceId, sourceControllerId, game)) {
&& !source.getSourceId().equals(spell.getSourceId())
&& filter.match(spell, sourceControllerId, source, game)) {
possibleTargets.add(spell.getId());
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceControllerId, source, game)) {
possibleTargets.add(permanent.getId());
}
}
@ -202,12 +202,12 @@ public class TargetSpellOrPermanent extends TargetImpl {
for (StackObject stackObject : game.getStack()) {
Spell spell = game.getStack().getSpell(stackObject.getId());
if (spell != null
&& filter.match(spell, null, sourceControllerId, game)) {
&& filter.match(spell, sourceControllerId, null, game)) {
possibleTargets.add(spell.getId());
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
if (filter.match(permanent, sourceControllerId, null, game)) {
possibleTargets.add(permanent.getId());
}
}