* Blatant Thievery - Changed handling to custom target.

This commit is contained in:
LevelX2 2015-10-06 00:47:17 +02:00
parent 65e7527b2f
commit 6a78684da8
5 changed files with 158 additions and 63 deletions

View file

@ -27,6 +27,9 @@
*/ */
package mage.sets.magic2015; package mage.sets.magic2015;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -48,10 +51,6 @@ import mage.players.Player;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/** /**
* @author noxx * @author noxx
*/ */
@ -145,7 +144,7 @@ class SoulOfShandalarTarget extends TargetPermanent {
@Override @Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game); Set<UUID> availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
Set<UUID> possibleTargets = new HashSet<UUID>(); Set<UUID> possibleTargets = new HashSet<>();
MageObject object = game.getObject(sourceId); MageObject object = game.getObject(sourceId);
for (StackObject item : game.getState().getStack()) { for (StackObject item : game.getState().getStack()) {

View file

@ -27,7 +27,12 @@
*/ */
package mage.sets.onslaught; package mage.sets.onslaught;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
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;
@ -39,10 +44,8 @@ import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.ControllerIdPredicate;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.game.permanent.Permanent;
import mage.target.Target;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
@ -68,14 +71,7 @@ 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();
for (UUID opponentId : game.getOpponents(ability.getControllerId())) { ability.addTarget(new BlatantThieveryTarget(game.getOpponents(ability.getControllerId()).size()));
Player opponent = game.getPlayer(opponentId);
if (opponent != null) {
FilterPermanent filter = new FilterPermanent("permanent controlled by " + opponent.getName());
filter.add(new ControllerIdPredicate(opponentId));
ability.addTarget(new TargetPermanent(filter));
}
}
} }
} }
@ -103,11 +99,111 @@ class BlatantThieveryEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
for (Target target : source.getTargets()) { for (UUID targetId : getTargetPointer().getTargets(game, source)) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame); ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame);
effect.setTargetPointer(new FixedTarget(target.getFirstTarget())); effect.setTargetPointer(new FixedTarget(targetId));
game.addEffect(effect, source); game.addEffect(effect, source);
} }
return true; 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;
}
@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 BlatantThieveryTarget copy() {
return new BlatantThieveryTarget(this);
}
}

View file

@ -28,11 +28,6 @@
package mage.sets.planechase2012; package mage.sets.planechase2012;
import java.util.UUID; import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
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;
@ -41,6 +36,10 @@ import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.effects.common.continuous.GainControlTargetEffect; import mage.abilities.effects.common.continuous.GainControlTargetEffect;
import mage.abilities.keyword.HasteAbility; import mage.abilities.keyword.HasteAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.ControllerIdPredicate; import mage.filter.predicate.permanent.ControllerIdPredicate;
import mage.game.Game; import mage.game.Game;
@ -60,8 +59,8 @@ public class MassMutiny extends CardImpl {
super(ownerId, 48, "Mass Mutiny", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{3}{R}{R}"); super(ownerId, 48, "Mass Mutiny", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{3}{R}{R}");
this.expansionSetCode = "PC2"; this.expansionSetCode = "PC2";
this.getSpellAbility().addEffect(new MassMutinyEffect());
// For each opponent, gain control of up to one target creature that player controls until end of turn. Untap those creatures. They gain haste until end of turn. // For each opponent, gain control of up to one target creature that player controls until end of turn. Untap those creatures. They gain haste until end of turn.
this.getSpellAbility().addEffect(new MassMutinyEffect());
} }
@Override @Override
@ -90,7 +89,6 @@ public class MassMutiny extends CardImpl {
} }
} }
class MassMutinyEffect extends OneShotEffect { class MassMutinyEffect extends OneShotEffect {
public MassMutinyEffect() { public MassMutinyEffect() {

View file

@ -6,18 +6,19 @@ import mage.abilities.Ability;
import mage.game.Game; import mage.game.Game;
public class BasicManaEffect extends ManaEffect { public class BasicManaEffect extends ManaEffect {
protected Mana mana; protected Mana mana;
public BasicManaEffect(Mana mana) { public BasicManaEffect(Mana mana) {
super(); super();
this.mana = mana; this.mana = mana;
staticText = "Add " + mana.toString() + " to your mana pool"; staticText = "add " + mana.toString() + " to your mana pool";
} }
public BasicManaEffect(ConditionalMana conditionalMana) { public BasicManaEffect(ConditionalMana conditionalMana) {
super(); super();
this.mana = conditionalMana; this.mana = conditionalMana;
staticText = "Add " + mana.toString() + " to your mana pool. " + conditionalMana.getDescription(); staticText = "add " + mana.toString() + " to your mana pool. " + conditionalMana.getDescription();
} }
public BasicManaEffect(final BasicManaEffect effect) { public BasicManaEffect(final BasicManaEffect effect) {

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.filter; package mage.filter;
import java.util.ArrayList; import java.util.ArrayList;
@ -44,6 +43,7 @@ import mage.game.permanent.Permanent;
* @author North * @author North
*/ */
public class FilterPermanent extends FilterObject<Permanent> implements FilterInPlay<Permanent> { public class FilterPermanent extends FilterObject<Permanent> implements FilterInPlay<Permanent> {
protected List<ObjectPlayerPredicate<ObjectPlayer<Permanent>>> extraPredicates = new ArrayList<>(); protected List<ObjectPlayerPredicate<ObjectPlayer<Permanent>>> extraPredicates = new ArrayList<>();
public FilterPermanent() { public FilterPermanent() {
@ -64,6 +64,7 @@ public class FilterPermanent extends FilterObject<Permanent> implements FilterIn
this.add(new SubtypePredicate(subtype)); this.add(new SubtypePredicate(subtype));
} }
@Override
public boolean match(Permanent permanent, UUID sourceId, UUID playerId, Game game) { public boolean match(Permanent permanent, UUID sourceId, UUID playerId, Game game) {
if (!this.match(permanent, game)) { if (!this.match(permanent, game)) {
return false; return false;