mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
(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:
parent
53877424a0
commit
80e11b2052
1719 changed files with 3384 additions and 3325 deletions
|
|
@ -0,0 +1,86 @@
|
|||
package org.mage.test.cards.single.tmp;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class KnightOfDuskTest extends CardTestPlayerBase {
|
||||
private static final String knight = "Knight of Dusk";
|
||||
private static final String lion = "Silvercoat Lion";
|
||||
private static final String murder = "Murder";
|
||||
private static final String blink = "Momentary Blink";
|
||||
|
||||
@Test
|
||||
public void testRegular() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
|
||||
addCard(Zone.BATTLEFIELD, playerA, knight);
|
||||
addCard(Zone.BATTLEFIELD, playerB, lion);
|
||||
|
||||
attack(1, playerA, knight);
|
||||
block(1, playerB, lion, knight);
|
||||
|
||||
activateAbility(1, PhaseStep.DECLARE_BLOCKERS, playerA, "{B}{B}", lion);
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
assertAllCommandsUsed();
|
||||
|
||||
assertPermanentCount(playerA, knight, 1);
|
||||
assertPermanentCount(playerB, lion, 0);
|
||||
assertGraveyardCount(playerA, knight, 0);
|
||||
assertGraveyardCount(playerB, lion, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLeavesBattlefield() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 5);
|
||||
addCard(Zone.BATTLEFIELD, playerA, knight);
|
||||
addCard(Zone.BATTLEFIELD, playerB, lion);
|
||||
addCard(Zone.HAND, playerA, murder);
|
||||
|
||||
attack(1, playerA, knight);
|
||||
block(1, playerB, lion, knight);
|
||||
|
||||
activateAbility(1, PhaseStep.DECLARE_BLOCKERS, playerA, "{B}{B}", lion);
|
||||
castSpell(1, PhaseStep.DECLARE_BLOCKERS, playerA, murder, knight);
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
assertAllCommandsUsed();
|
||||
|
||||
assertPermanentCount(playerA, knight, 0);
|
||||
assertPermanentCount(playerB, lion, 0);
|
||||
assertGraveyardCount(playerA, knight, 1);
|
||||
assertGraveyardCount(playerB, lion, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLeavesBattlefieldReturns() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Scrubland", 4);
|
||||
addCard(Zone.BATTLEFIELD, playerA, knight);
|
||||
addCard(Zone.BATTLEFIELD, playerB, lion);
|
||||
addCard(Zone.HAND, playerA, blink);
|
||||
|
||||
attack(1, playerA, knight);
|
||||
block(1, playerB, lion, knight);
|
||||
|
||||
activateAbility(1, PhaseStep.DECLARE_BLOCKERS, playerA, "{B}{B}", lion);
|
||||
castSpell(1, PhaseStep.DECLARE_BLOCKERS, playerA, blink, knight);
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
assertAllCommandsUsed();
|
||||
|
||||
assertPermanentCount(playerA, knight, 1);
|
||||
assertPermanentCount(playerB, lion, 0);
|
||||
assertGraveyardCount(playerA, knight, 0);
|
||||
assertGraveyardCount(playerB, lion, 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -222,7 +222,7 @@ public class RandomPlayer extends ComputerPlayer {
|
|||
}
|
||||
|
||||
protected boolean chooseRandomTarget(Target target, Ability source, Game game) {
|
||||
Set<UUID> possibleTargets = target.possibleTargets(source == null ? null : source.getSourceId(), playerId, game);
|
||||
Set<UUID> possibleTargets = target.possibleTargets(playerId, source, game);
|
||||
if (possibleTargets.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -246,12 +246,12 @@ public class RandomPlayer extends ComputerPlayer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game) {
|
||||
public boolean choose(Outcome outcome, Target target, Ability source, Game game) {
|
||||
return chooseRandom(target, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game, Map<String, Serializable> options) {
|
||||
public boolean choose(Outcome outcome, Target target, Ability source, Game game, Map<String, Serializable> options) {
|
||||
return chooseRandom(target, game);
|
||||
}
|
||||
|
||||
|
|
@ -294,7 +294,7 @@ public class RandomPlayer extends ComputerPlayer {
|
|||
|
||||
@Override
|
||||
public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) {
|
||||
Set<UUID> possibleTargets = target.possibleTargets(source == null ? null : source.getSourceId(), playerId, game);
|
||||
Set<UUID> possibleTargets = target.possibleTargets(playerId, source, game);
|
||||
if (possibleTargets.isEmpty()) {
|
||||
return !target.isRequired(source);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.mage.test.player;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.choices.Choice;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.RangeOfInfluence;
|
||||
|
|
@ -7,8 +8,6 @@ import mage.game.Game;
|
|||
import mage.player.ai.ComputerPlayer;
|
||||
import mage.target.Target;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
|
|
@ -43,11 +42,11 @@ public class TestComputerPlayer extends ComputerPlayer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game) {
|
||||
public boolean choose(Outcome outcome, Target target, Ability source, Game game) {
|
||||
if (testPlayerLink.canChooseByComputer()) {
|
||||
return super.choose(outcome, target, sourceId, game);
|
||||
return super.choose(outcome, target, source, game);
|
||||
} else {
|
||||
return testPlayerLink.choose(outcome, target, sourceId, game);
|
||||
return testPlayerLink.choose(outcome, target, source, game);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.mage.test.player;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.choices.Choice;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.RangeOfInfluence;
|
||||
|
|
@ -7,8 +8,6 @@ import mage.game.Game;
|
|||
import mage.player.ai.ComputerPlayer7;
|
||||
import mage.target.Target;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Copied-pasted methods from TestComputerPlayer, see docs in there
|
||||
*
|
||||
|
|
@ -28,11 +27,11 @@ public class TestComputerPlayer7 extends ComputerPlayer7 {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game) {
|
||||
public boolean choose(Outcome outcome, Target target, Ability source, Game game) {
|
||||
if (testPlayerLink.canChooseByComputer()) {
|
||||
return super.choose(outcome, target, sourceId, game);
|
||||
return super.choose(outcome, target, source, game);
|
||||
} else {
|
||||
return testPlayerLink.choose(outcome, target, sourceId, game);
|
||||
return testPlayerLink.choose(outcome, target, source, game);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.mage.test.player;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.choices.Choice;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.RangeOfInfluence;
|
||||
|
|
@ -7,8 +8,6 @@ import mage.game.Game;
|
|||
import mage.player.ai.ComputerPlayerMCTS;
|
||||
import mage.target.Target;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Copied-pasted methods from TestComputerPlayer, see docs in there
|
||||
*
|
||||
|
|
@ -28,11 +27,11 @@ public class TestComputerPlayerMonteCarlo extends ComputerPlayerMCTS {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game) {
|
||||
public boolean choose(Outcome outcome, Target target, Ability source, Game game) {
|
||||
if (testPlayerLink.canChooseByComputer()) {
|
||||
return super.choose(outcome, target, sourceId, game);
|
||||
return super.choose(outcome, target, source, game);
|
||||
} else {
|
||||
return testPlayerLink.choose(outcome, target, sourceId, game);
|
||||
return testPlayerLink.choose(outcome, target, source, game);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -499,7 +499,7 @@ public class TestPlayer implements Player {
|
|||
targetName = targetName.substring(0, targetName.length() - 11);
|
||||
}
|
||||
}
|
||||
for (UUID id : currentTarget.possibleTargets(ability.getSourceId(), ability.getControllerId(), game)) {
|
||||
for (UUID id : currentTarget.possibleTargets(ability.getControllerId(), ability, game)) {
|
||||
if (!currentTarget.getTargets().contains(id)) {
|
||||
MageObject object = game.getObject(id);
|
||||
|
||||
|
|
@ -2056,7 +2056,7 @@ public class TestPlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game, Map<String, Serializable> options) {
|
||||
public boolean choose(Outcome outcome, Target target, Ability source, Game game, Map<String, Serializable> options) {
|
||||
UUID abilityControllerId = computerPlayer.getId();
|
||||
if (target.getTargetController() != null && target.getAbilityController() != null) {
|
||||
abilityControllerId = target.getAbilityController();
|
||||
|
|
@ -2064,7 +2064,7 @@ public class TestPlayer implements Player {
|
|||
|
||||
// ignore player select
|
||||
if (target.getMessage().equals("Select a starting player")) {
|
||||
return computerPlayer.choose(outcome, target, sourceId, game, options);
|
||||
return computerPlayer.choose(outcome, target, source, game, options);
|
||||
}
|
||||
|
||||
assertAliasSupportInChoices(true);
|
||||
|
|
@ -2082,11 +2082,6 @@ public class TestPlayer implements Player {
|
|||
List<Integer> usedChoices = new ArrayList<>();
|
||||
List<UUID> usedTargets = new ArrayList<>();
|
||||
|
||||
Ability source = null;
|
||||
StackObject stackObject = game.getStack().getStackObject(sourceId);
|
||||
if (stackObject != null) {
|
||||
source = stackObject.getStackAbility();
|
||||
}
|
||||
|
||||
if ((target.getOriginalTarget() instanceof TargetPermanent)
|
||||
|| (target.getOriginalTarget() instanceof TargetPermanentOrPlayer)) { // player target not implemted yet
|
||||
|
|
@ -2112,7 +2107,7 @@ public class TestPlayer implements Player {
|
|||
targetName = targetName.substring(0, targetName.length() - 11);
|
||||
}
|
||||
}
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filterPermanent, abilityControllerId, sourceId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filterPermanent, abilityControllerId, source, game)) {
|
||||
if (target.getTargets().contains(permanent.getId())) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -2178,7 +2173,7 @@ public class TestPlayer implements Player {
|
|||
|
||||
CheckOneChoice:
|
||||
for (String possibleChoice : possibleChoices) {
|
||||
Set<UUID> possibleCards = target.possibleTargets(sourceId, abilityControllerId, game);
|
||||
Set<UUID> possibleCards = target.possibleTargets(abilityControllerId, source, game);
|
||||
CheckTargetsList:
|
||||
for (UUID targetId : possibleCards) {
|
||||
MageObject targetObject = game.getCard(targetId);
|
||||
|
|
@ -2232,7 +2227,7 @@ public class TestPlayer implements Player {
|
|||
if (target.getOriginalTarget() instanceof TargetSource) {
|
||||
Set<UUID> possibleTargets;
|
||||
TargetSource t = ((TargetSource) target.getOriginalTarget());
|
||||
possibleTargets = t.possibleTargets(sourceId, abilityControllerId, game);
|
||||
possibleTargets = t.possibleTargets(abilityControllerId, source, game);
|
||||
for (String choiceRecord : choices) {
|
||||
String[] targetList = choiceRecord.split("\\^");
|
||||
boolean targetFound = false;
|
||||
|
|
@ -2268,8 +2263,8 @@ public class TestPlayer implements Player {
|
|||
*/
|
||||
}
|
||||
|
||||
this.chooseStrictModeFailed("choice", game, getInfo(game.getObject(sourceId)) + ";\n" + getInfo(target));
|
||||
return computerPlayer.choose(outcome, target, sourceId, game, options);
|
||||
this.chooseStrictModeFailed("choice", game, getInfo(game.getObject(source)) + ";\n" + getInfo(target));
|
||||
return computerPlayer.choose(outcome, target, source, game, options);
|
||||
}
|
||||
|
||||
private void checkTargetDefinitionMarksSupport(Target needTarget, String targetDefinition, String canSupportChars) {
|
||||
|
|
@ -2380,7 +2375,7 @@ public class TestPlayer implements Player {
|
|||
if (filter instanceof FilterPermanentOrSuspendedCard) {
|
||||
filter = ((FilterPermanentOrSuspendedCard) filter).getPermanentFilter();
|
||||
}
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents((FilterPermanent) filter, abilityControllerId, sourceId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents((FilterPermanent) filter, abilityControllerId, source, game)) {
|
||||
if (hasObjectTargetNameOrAlias(permanent, targetName) || (permanent.getName() + '-' + permanent.getExpansionSetCode()).equals(targetName)) { // TODO: remove exp code search?
|
||||
if (target.canTarget(abilityControllerId, permanent.getId(), source, game) && !target.getTargets().contains(permanent.getId())) {
|
||||
if ((permanent.isCopy() && !originOnly) || (!permanent.isCopy() && !copyOnly)) {
|
||||
|
|
@ -3966,10 +3961,10 @@ public class TestPlayer implements Player {
|
|||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Target target,
|
||||
UUID sourceId, Game game
|
||||
Ability source, Game game
|
||||
) {
|
||||
// needed to call here the TestPlayer because it's overwitten
|
||||
return choose(outcome, target, sourceId, game, null);
|
||||
return choose(outcome, target, source, game, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -4066,7 +4061,7 @@ public class TestPlayer implements Player {
|
|||
Assert.assertTrue("target amount must be <= remaining = " + target.getAmountRemaining() + " " + targetInfo, targetAmount <= target.getAmountRemaining());
|
||||
|
||||
if (target.getAmountRemaining() > 0) {
|
||||
for (UUID possibleTarget : target.possibleTargets(source.getSourceId(), source.getControllerId(), game)) {
|
||||
for (UUID possibleTarget : target.possibleTargets(source.getControllerId(), source, game)) {
|
||||
boolean foundTarget = false;
|
||||
|
||||
// permanent
|
||||
|
|
|
|||
|
|
@ -841,12 +841,12 @@ public class PlayerStub implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game) {
|
||||
public boolean choose(Outcome outcome, Target target, Ability source, Game game) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game, Map<String, Serializable> options) {
|
||||
public boolean choose(Outcome outcome, Target target, Ability source, Game game, Map<String, Serializable> options) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue