mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
* Blatant Thievery - Fixed a problem of AI target handling.
This commit is contained in:
parent
1d2132648b
commit
ac7e6e0f86
2 changed files with 111 additions and 113 deletions
|
@ -28,7 +28,6 @@
|
||||||
package mage.cards.b;
|
package mage.cards.b;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import mage.MageObject;
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.SpellAbility;
|
import mage.abilities.SpellAbility;
|
||||||
import mage.abilities.effects.ContinuousEffect;
|
import mage.abilities.effects.ContinuousEffect;
|
||||||
|
@ -40,8 +39,10 @@ import mage.constants.CardType;
|
||||||
import mage.constants.Duration;
|
import mage.constants.Duration;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
|
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.players.Player;
|
||||||
|
import mage.target.Target;
|
||||||
import mage.target.TargetPermanent;
|
import mage.target.TargetPermanent;
|
||||||
import mage.target.targetpointer.FixedTarget;
|
import mage.target.targetpointer.FixedTarget;
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ import mage.target.targetpointer.FixedTarget;
|
||||||
public class BlatantThievery extends CardImpl {
|
public class BlatantThievery extends CardImpl {
|
||||||
|
|
||||||
public BlatantThievery(UUID ownerId, CardSetInfo setInfo) {
|
public BlatantThievery(UUID ownerId, CardSetInfo setInfo) {
|
||||||
super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{4}{U}{U}{U}");
|
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{4}{U}{U}{U}");
|
||||||
|
|
||||||
// For each opponent, gain control of target permanent that player controls.
|
// For each opponent, gain control of target permanent that player controls.
|
||||||
this.getSpellAbility().addEffect(new BlatantThieveryEffect());
|
this.getSpellAbility().addEffect(new BlatantThieveryEffect());
|
||||||
|
@ -66,7 +67,15 @@ public class BlatantThievery extends CardImpl {
|
||||||
public void adjustTargets(Ability ability, Game game) {
|
public void adjustTargets(Ability ability, Game game) {
|
||||||
if (ability instanceof SpellAbility) {
|
if (ability instanceof SpellAbility) {
|
||||||
ability.getTargets().clear();
|
ability.getTargets().clear();
|
||||||
ability.addTarget(new BlatantThieveryTarget(game.getOpponents(ability.getControllerId()).size()));
|
for (UUID opponentId : game.getOpponents(ability.getControllerId())) {
|
||||||
|
Player opponent = game.getPlayer(opponentId);
|
||||||
|
if (opponent != null) {
|
||||||
|
FilterPermanent filter = new FilterPermanent("Permanent of player " + opponent.getName());
|
||||||
|
filter.add(new ControllerIdPredicate(opponentId));
|
||||||
|
TargetPermanent targetPermanent = new TargetPermanent(filter);
|
||||||
|
ability.addTarget(targetPermanent);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,117 +103,13 @@ class BlatantThieveryEffect extends OneShotEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
for (UUID targetId : getTargetPointer().getTargets(game, source)) {
|
for (Target target : source.getTargets()) {
|
||||||
|
if (target.getFirstTarget() != null) {
|
||||||
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame);
|
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame);
|
||||||
effect.setTargetPointer(new FixedTarget(targetId));
|
effect.setTargetPointer(new FixedTarget(target.getFirstTarget()));
|
||||||
game.addEffect(effect, source);
|
game.addEffect(effect, source);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BlatantThieveryTarget extends TargetPermanent {
|
|
||||||
|
|
||||||
Map<UUID, UUID> targetOpponent = new HashMap<>();
|
|
||||||
|
|
||||||
public BlatantThieveryTarget(int opponents) {
|
|
||||||
super(opponents, opponents, new FilterPermanent("a permanent for each opponent"), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlatantThieveryTarget(final BlatantThieveryTarget target) {
|
|
||||||
super(target);
|
|
||||||
this.targetOpponent.putAll(target.targetOpponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canTarget(UUID controllerId, UUID objectId, Ability source, Game game) {
|
|
||||||
Permanent targetObject = game.getPermanent(objectId);
|
|
||||||
if (targetObject == null || !game.getOpponents(source.getControllerId()).contains(targetObject.getControllerId())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// If a permanent changes controller after being targeted but before this spell resolves, you won't gain control of that permanent.
|
|
||||||
if (targetOpponent.containsKey(objectId)) {
|
|
||||||
if (!targetOpponent.get(objectId).equals(targetObject.getControllerId())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// if already a target from this opponent exists, another can't be target
|
|
||||||
if (targetOpponent.values().contains(targetObject.getControllerId())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.canTarget(controllerId, objectId, source, game);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
|
|
||||||
Set<UUID> opponents = new HashSet<>();
|
|
||||||
for (UUID targetId : getTargets()) {
|
|
||||||
Permanent oldTargets = game.getPermanent(targetId);
|
|
||||||
if (oldTargets != null) {
|
|
||||||
opponents.add(oldTargets.getControllerId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Set<UUID> possibleTargets = new HashSet<>();
|
|
||||||
MageObject mageObject = game.getObject(sourceId);
|
|
||||||
if (mageObject == null) {
|
|
||||||
return possibleTargets;
|
|
||||||
}
|
|
||||||
for (UUID opponentId : game.getOpponents(sourceControllerId)) {
|
|
||||||
if (opponents.contains(opponentId)) {
|
|
||||||
// Target for this opponent already selected
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponentId)) {
|
|
||||||
if (permanent.canBeTargetedBy(mageObject, sourceControllerId, game)) {
|
|
||||||
possibleTargets.add(permanent.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return possibleTargets;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
|
|
||||||
for (UUID opponentId : game.getOpponents(sourceControllerId)) {
|
|
||||||
boolean targetAvailable = false;
|
|
||||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponentId)) {
|
|
||||||
if (!targets.containsKey(permanent.getId())) {
|
|
||||||
MageObject mageObject = game.getObject(sourceId);
|
|
||||||
if (mageObject != null && permanent.canBeTargetedBy(mageObject, sourceControllerId, game)) {
|
|
||||||
targetAvailable = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
targetAvailable = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!targetAvailable) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addTarget(UUID objectId, int amount, Ability source, Game game, boolean skipEvent) {
|
|
||||||
Permanent targetObject = game.getPermanent(objectId);
|
|
||||||
if (targetObject != null) {
|
|
||||||
targetOpponent.put(objectId, targetObject.getControllerId());
|
|
||||||
}
|
|
||||||
super.addTarget(objectId, amount, source, game, skipEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(UUID id) {
|
|
||||||
super.remove(id);
|
|
||||||
targetOpponent.remove(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlatantThieveryTarget copy() {
|
|
||||||
return new BlatantThieveryTarget(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package org.mage.test.multiplayer;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import mage.constants.MultiplayerAttackOption;
|
||||||
|
import mage.constants.PhaseStep;
|
||||||
|
import mage.constants.RangeOfInfluence;
|
||||||
|
import mage.constants.Zone;
|
||||||
|
import mage.game.FreeForAll;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.game.GameException;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mage.test.serverside.base.CardTestMultiPlayerBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author LevelX2
|
||||||
|
*/
|
||||||
|
public class BlatantThieveryTest extends CardTestMultiPlayerBase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Game createNewGameAndPlayers() throws GameException, FileNotFoundException {
|
||||||
|
Game game = new FreeForAll(MultiplayerAttackOption.MULTIPLE, RangeOfInfluence.ALL, 0, 20);
|
||||||
|
// Player order: A -> D -> C -> B
|
||||||
|
playerA = createPlayer(game, playerA, "PlayerA");
|
||||||
|
playerB = createPlayer(game, playerB, "PlayerB");
|
||||||
|
playerC = createPlayer(game, playerC, "PlayerC");
|
||||||
|
playerD = createPlayer(game, playerD, "PlayerD");
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void NormalTest() {
|
||||||
|
// For each opponent, gain control of target permanent that player controls.
|
||||||
|
addCard(Zone.HAND, playerA, "Blatant Thievery"); // Sorcery {4}{U}{U}{U}
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Island", 7);
|
||||||
|
|
||||||
|
// Player order: A -> D -> C -> B
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 2);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerC, "Walking Corpse", 2);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerD, "Pillarfield Ox", 2);
|
||||||
|
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Blatant Thievery");
|
||||||
|
addTarget(playerA, "Silvercoat Lion");
|
||||||
|
addTarget(playerA, "Walking Corpse");
|
||||||
|
addTarget(playerA, "Pillarfield Ox");
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertPermanentCount(playerA, "Silvercoat Lion", 1);
|
||||||
|
assertPermanentCount(playerA, "Walking Corpse", 1);
|
||||||
|
assertPermanentCount(playerA, "Pillarfield Ox", 1);
|
||||||
|
assertPermanentCount(playerB, "Silvercoat Lion", 1);
|
||||||
|
assertPermanentCount(playerC, "Walking Corpse", 1);
|
||||||
|
assertPermanentCount(playerD, "Pillarfield Ox", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ControlChangeTest() {
|
||||||
|
// For each opponent, gain control of target permanent that player controls.
|
||||||
|
addCard(Zone.HAND, playerA, "Blatant Thievery"); // Sorcery {4}{U}{U}{U}
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Island", 7);
|
||||||
|
|
||||||
|
addCard(Zone.HAND, playerB, "Act of Aggression"); // Instant {3}{M}{M}
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 5);
|
||||||
|
|
||||||
|
// Player order: A -> D -> C -> B
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerC, "Walking Corpse", 1);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerD, "Pillarfield Ox", 1);
|
||||||
|
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Blatant Thievery");
|
||||||
|
addTarget(playerA, "Silvercoat Lion");
|
||||||
|
addTarget(playerA, "Walking Corpse");
|
||||||
|
addTarget(playerA, "Pillarfield Ox");
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Act of Aggression", "Pillarfield Ox", "Blatant Thievery");
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertGraveyardCount(playerA, "Blatant Thievery", 1);
|
||||||
|
assertGraveyardCount(playerB, "Act of Aggression", 1);
|
||||||
|
|
||||||
|
assertPermanentCount(playerA, "Silvercoat Lion", 1);
|
||||||
|
assertPermanentCount(playerA, "Walking Corpse", 1);
|
||||||
|
assertPermanentCount(playerB, "Pillarfield Ox", 1);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue