mirror of
https://github.com/correl/mage.git
synced 2024-12-26 11:09:27 +00:00
[ATQ] fixed implementation of Goblin Artisans (fixes #7629)
This commit is contained in:
parent
50071b59a0
commit
d4311916a4
1 changed files with 62 additions and 72 deletions
|
@ -1,37 +1,33 @@
|
||||||
|
|
||||||
package mage.cards.g;
|
package mage.cards.g;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
|
import mage.MageObjectReference;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.Mode;
|
|
||||||
import mage.abilities.common.SimpleActivatedAbility;
|
import mage.abilities.common.SimpleActivatedAbility;
|
||||||
import mage.abilities.costs.common.TapSourceCost;
|
import mage.abilities.costs.common.TapSourceCost;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.common.CounterTargetEffect;
|
||||||
|
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
|
||||||
|
import mage.abilities.effects.common.FlipCoinEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.cards.Cards;
|
|
||||||
import mage.cards.CardsImpl;
|
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.constants.SubType;
|
import mage.constants.SubType;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.TargetController;
|
||||||
import mage.constants.Zone;
|
import mage.filter.FilterSpell;
|
||||||
import mage.filter.FilterCard;
|
import mage.filter.common.FilterArtifactSpell;
|
||||||
import mage.filter.FilterPermanent;
|
|
||||||
import mage.filter.common.FilterControlledArtifactPermanent;
|
|
||||||
import mage.filter.predicate.Predicates;
|
|
||||||
import mage.filter.predicate.mageobject.NamePredicate;
|
|
||||||
import mage.filter.predicate.permanent.PermanentIdPredicate;
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.players.Player;
|
import mage.game.stack.Spell;
|
||||||
|
import mage.game.stack.StackAbility;
|
||||||
|
import mage.game.stack.StackObject;
|
||||||
import mage.target.Target;
|
import mage.target.Target;
|
||||||
import mage.target.TargetCard;
|
import mage.target.TargetSpell;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @author TheElk801
|
||||||
* @author MarcoMarin
|
|
||||||
*/
|
*/
|
||||||
public final class GoblinArtisans extends CardImpl {
|
public final class GoblinArtisans extends CardImpl {
|
||||||
|
|
||||||
|
@ -43,8 +39,11 @@ public final class GoblinArtisans extends CardImpl {
|
||||||
this.toughness = new MageInt(1);
|
this.toughness = new MageInt(1);
|
||||||
|
|
||||||
// {tap}: Flip a coin. If you win the flip, draw a card. If you lose the flip, counter target artifact spell you control that isn't the target of an ability from another creature named Goblin Artisans.
|
// {tap}: Flip a coin. If you win the flip, draw a card. If you lose the flip, counter target artifact spell you control that isn't the target of an ability from another creature named Goblin Artisans.
|
||||||
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new GoblinArtisansEffect(), new TapSourceCost()));
|
Ability ability = new SimpleActivatedAbility(new FlipCoinEffect(
|
||||||
|
new DrawCardSourceControllerEffect(1), new CounterTargetEffect()
|
||||||
|
), new TapSourceCost());
|
||||||
|
ability.addTarget(new GoblinArtisansTarget());
|
||||||
|
this.addAbility(ability);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GoblinArtisans(final GoblinArtisans card) {
|
private GoblinArtisans(final GoblinArtisans card) {
|
||||||
|
@ -57,68 +56,59 @@ public final class GoblinArtisans extends CardImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GoblinArtisansEffect extends OneShotEffect {
|
class GoblinArtisansTarget extends TargetSpell {
|
||||||
|
|
||||||
private static final FilterPermanent filter = new FilterPermanent("permanent named Goblin Artisans");
|
private static final FilterSpell filter = new FilterArtifactSpell(
|
||||||
|
"artifact spell you control that isn't the target " +
|
||||||
|
"of an ability from another creature named Goblin Artisans"
|
||||||
|
);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
filter.add(new NamePredicate("Goblin Artisans"));
|
filter.add(TargetController.YOU.getOwnerPredicate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public GoblinArtisansEffect() {
|
GoblinArtisansTarget() {
|
||||||
super(Outcome.Damage);
|
super(filter);
|
||||||
staticText = "Flip a coin. If you win the flip, draw a card. If you lose the flip, counter target artifact spell you control that isn't the target of an ability from another creature named Goblin Artisans.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GoblinArtisansEffect(GoblinArtisansEffect effect) {
|
private GoblinArtisansTarget(final GoblinArtisansTarget target) {
|
||||||
super(effect);
|
super(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public GoblinArtisansTarget copy() {
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
return new GoblinArtisansTarget(this);
|
||||||
if (controller != null) {
|
|
||||||
if (controller.flipCoin(source, game, true)) {
|
|
||||||
controller.drawCards(1, source, game);
|
|
||||||
} else {
|
|
||||||
List<Permanent> artifacts = game.getBattlefield().getActivePermanents(new FilterControlledArtifactPermanent(), source.getControllerId(), game);
|
|
||||||
if (artifacts.isEmpty()) {//Don't even bother if there is no artifact to 'counter'/sacrifice
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
filter.add(Predicates.not(new PermanentIdPredicate(source.getSourceId())));
|
|
||||||
//removed the activating instance of Artisans, btw, wasn't that filter declared as static final? How come I can do this here? :)
|
|
||||||
List<Permanent> list = game.getBattlefield().getAllActivePermanents(filter, game);
|
|
||||||
for (Permanent perm : list) { // should I limit below for a particular kind of ability? Going for the most general, it's unlikely there'll be any other artisans anyway, so not concerned about efficiency :p
|
|
||||||
for (Ability abil : perm.getAbilities(game)) {//below is copied from TargetsPermanentPredicate, but why only "selectedModes"? Shouldnt be more general as well?
|
|
||||||
for (UUID modeId : abil.getModes().getSelectedModes()) {
|
|
||||||
Mode mode = abil.getModes().get(modeId);
|
|
||||||
for (Target target : mode.getTargets()) {
|
|
||||||
for (UUID targetId : target.getTargets()) {
|
|
||||||
artifacts.remove(game.getPermanentOrLKIBattlefield(targetId));
|
|
||||||
}// we could
|
|
||||||
}// remove this
|
|
||||||
}//closing bracers
|
|
||||||
}// pyramid, if it's bothering anyone
|
|
||||||
} //they are all one-liners after all :)
|
|
||||||
if (!artifacts.isEmpty()) {
|
|
||||||
Cards cards = new CardsImpl();
|
|
||||||
for (Permanent perm : artifacts) {
|
|
||||||
cards.add(perm.getId());
|
|
||||||
}
|
|
||||||
TargetCard target = new TargetCard(Zone.BATTLEFIELD, new FilterCard());
|
|
||||||
controller.choose(Outcome.Sacrifice, cards, target, game);
|
|
||||||
game.getPermanent(target.getFirstTarget()).sacrifice(source, game);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
|
||||||
|
if (!super.canTarget(controllerId, id, source, game)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
MageObjectReference sourceRef = new MageObjectReference(source.getSourceObject(game), game);
|
||||||
@Override
|
Spell spell = game.getSpell(id);
|
||||||
public GoblinArtisansEffect copy() {
|
if (spell == null) {
|
||||||
return new GoblinArtisansEffect(this);
|
return false;
|
||||||
|
}
|
||||||
|
for (StackObject stackObject : game.getStack()) {
|
||||||
|
if (!(stackObject instanceof StackAbility)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Permanent permanent = ((StackAbility) stackObject).getSourcePermanentOrLKI(game);
|
||||||
|
if (permanent != null
|
||||||
|
&& !sourceRef.refersTo(permanent, game)
|
||||||
|
&& permanent.isCreature()
|
||||||
|
&& "Goblin Artisans".equals(permanent.getName())
|
||||||
|
&& stackObject
|
||||||
|
.getStackAbility()
|
||||||
|
.getTargets()
|
||||||
|
.stream()
|
||||||
|
.map(Target::getTargets)
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.anyMatch(id::equals)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue