mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
- Fixed #6096
This commit is contained in:
parent
4ef9a75fe7
commit
02b75fe668
1 changed files with 99 additions and 118 deletions
|
@ -1,30 +1,30 @@
|
|||
|
||||
package mage.cards.z;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.CopySpellForEachItCouldTargetEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.*;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.FilterInPlay;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.TargetAddress;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class ZadaHedronGrinder extends CardImpl {
|
||||
|
||||
|
||||
public ZadaHedronGrinder(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{R}");
|
||||
addSuperType(SuperType.LEGENDARY);
|
||||
|
@ -32,15 +32,17 @@ public final class ZadaHedronGrinder extends CardImpl {
|
|||
this.power = new MageInt(3);
|
||||
this.toughness = new MageInt(3);
|
||||
|
||||
// Whenever you cast an instant or sorcery spell that targets only Zada, Hedron Grinder, copy that spell for each other creature you control that the spell could target. Each copy targets a different one of those creatures.
|
||||
// Whenever you cast an instant or sorcery spell that targets only Zada, Hedron Grinder,
|
||||
// copy that spell for each other creature you control that the spell could target.
|
||||
// Each copy targets a different one of those creatures.
|
||||
this.addAbility(new ZadaHedronGrinderTriggeredAbility());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ZadaHedronGrinder(final ZadaHedronGrinder card) {
|
||||
super(card);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ZadaHedronGrinder copy() {
|
||||
return new ZadaHedronGrinder(this);
|
||||
|
@ -48,136 +50,115 @@ public final class ZadaHedronGrinder extends CardImpl {
|
|||
}
|
||||
|
||||
class ZadaHedronGrinderTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
|
||||
ZadaHedronGrinderTriggeredAbility() {
|
||||
super(Zone.BATTLEFIELD, new ZadaHedronGrinderEffect(), false);
|
||||
super(Zone.BATTLEFIELD, new ZadaHedronGrinderCopySpellEffect(), false);
|
||||
}
|
||||
|
||||
|
||||
ZadaHedronGrinderTriggeredAbility(final ZadaHedronGrinderTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ZadaHedronGrinderTriggeredAbility copy() {
|
||||
return new ZadaHedronGrinderTriggeredAbility(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.SPELL_CAST;
|
||||
return event.getType() == EventType.SPELL_CAST;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getPlayerId().equals(this.getControllerId())) {
|
||||
Spell spell = game.getStack().getSpell(event.getTargetId());
|
||||
if (isControlledInstantOrSorcery(spell)) {
|
||||
boolean targetsSource = false;
|
||||
for (Ability ability : spell.getSpellAbilities()) {
|
||||
for (UUID modeId : ability.getModes().getSelectedModes()) {
|
||||
Mode mode = ability.getModes().get(modeId);
|
||||
for (Target target : mode.getTargets()) {
|
||||
if (!target.isNotTarget()) {
|
||||
for (UUID targetId : target.getTargets()) {
|
||||
if (targetId.equals(getSourceId())) {
|
||||
targetsSource = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (targetsSource) {
|
||||
this.getEffects().get(0).setTargetPointer(new FixedTarget(spell.getId()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
Spell spell = game.getStack().getSpell(event.getTargetId());
|
||||
return checkSpell(spell, game)
|
||||
&& event.getPlayerId().equals(controllerId);
|
||||
}
|
||||
|
||||
private boolean isControlledInstantOrSorcery(Spell spell) {
|
||||
return spell != null
|
||||
&& (spell.isControlledBy(this.getControllerId()))
|
||||
&& (spell.isInstant() || spell.isSorcery());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever you cast an instant or sorcery spell that targets only {this}, copy that spell for each other creature you control that the spell could target. Each copy targets a different one of those creatures.";
|
||||
}
|
||||
}
|
||||
|
||||
class ZadaHedronGrinderEffect extends OneShotEffect {
|
||||
|
||||
public ZadaHedronGrinderEffect() {
|
||||
super(Outcome.Detriment);
|
||||
this.staticText = "copy that spell for each other creature you control that the spell could target. Each copy targets a different one of those creatures";
|
||||
}
|
||||
|
||||
public ZadaHedronGrinderEffect(final ZadaHedronGrinderEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZadaHedronGrinderEffect copy() {
|
||||
return new ZadaHedronGrinderEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (spell != null && controller != null) {
|
||||
// search the target that targets source
|
||||
Target usedTarget = null;
|
||||
setUsedTarget:
|
||||
for (Ability ability : spell.getSpellAbilities()) {
|
||||
for (UUID modeId : ability.getModes().getSelectedModes()) {
|
||||
Mode mode = ability.getModes().get(modeId);
|
||||
for (Target target : mode.getTargets()) {
|
||||
if (!target.isNotTarget() && target.getFirstTarget().equals(source.getSourceId())) {
|
||||
usedTarget = target.copy();
|
||||
usedTarget.clearChosen();
|
||||
break setUsedTarget;
|
||||
}
|
||||
|
||||
private boolean checkSpell(Spell spell, Game game) {
|
||||
if (spell != null
|
||||
&& (spell.isInstant() || spell.isSorcery())) {
|
||||
boolean noTargets = true;
|
||||
for (TargetAddress addr : TargetAddress.walk(spell)) {
|
||||
noTargets = false;
|
||||
Target targetInstance = addr.getTarget(spell);
|
||||
for (UUID target : targetInstance.getTargets()) {
|
||||
Permanent permanent = game.getPermanent(target);
|
||||
if (permanent == null || !permanent.getId().equals(getSourceId())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (usedTarget == null) {
|
||||
if (noTargets) {
|
||||
return false;
|
||||
}
|
||||
for (Permanent creature : game.getState().getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
|
||||
if (!creature.getId().equals(source.getSourceId()) && usedTarget.canTarget(source.getControllerId(), creature.getId(), source, game)) {
|
||||
Spell copy = spell.copySpell(source.getControllerId());
|
||||
game.getStack().push(copy);
|
||||
setTarget:
|
||||
for (UUID modeId : copy.getSpellAbility().getModes().getSelectedModes()) {
|
||||
Mode mode = copy.getSpellAbility().getModes().get(modeId);
|
||||
for (Target target : mode.getTargets()) {
|
||||
if (target.getClass().equals(usedTarget.getClass())) {
|
||||
target.clearChosen(); // For targets with Max > 1 we need to clear before the text is comapred
|
||||
if (target.getMessage().equals(usedTarget.getMessage())) {
|
||||
target.addTarget(creature.getId(), copy.getSpellAbility(), game, false);
|
||||
break setTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
game.fireEvent(new GameEvent(GameEvent.EventType.COPIED_STACKOBJECT, copy.getId(), spell.getId(), source.getControllerId()));
|
||||
String activateMessage = copy.getActivatedMessage(game);
|
||||
if (activateMessage.startsWith(" casts ")) {
|
||||
activateMessage = activateMessage.substring(6);
|
||||
}
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(controller.getLogName() + activateMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
getEffects().get(0).setValue("triggeringSpell", spell);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever you cast an instant or sorcery spell that targets only {this}, "
|
||||
+ "copy that spell for each other creature you control that the spell could target. "
|
||||
+ "Each copy targets a different one of those creatures.";
|
||||
}
|
||||
}
|
||||
|
||||
class ZadaHedronGrinderCopySpellEffect extends CopySpellForEachItCouldTargetEffect<Permanent> {
|
||||
|
||||
public ZadaHedronGrinderCopySpellEffect() {
|
||||
this(new FilterControlledCreaturePermanent());
|
||||
this.staticText = "copy that spell for each other creature you control that the spell could target. Each copy targets a different one of those creatures.";
|
||||
}
|
||||
|
||||
public ZadaHedronGrinderCopySpellEffect(ZadaHedronGrinderCopySpellEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
private ZadaHedronGrinderCopySpellEffect(FilterInPlay<Permanent> filter) {
|
||||
super(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Player getPlayer(Game game, Ability source) {
|
||||
Spell spell = getSpell(game, source);
|
||||
if (spell != null) {
|
||||
return game.getPlayer(spell.getControllerId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Spell getSpell(Game game, Ability source) {
|
||||
return (Spell) getValue("triggeringSpell");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean changeTarget(Target target, Game game, Ability source) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void modifyCopy(Spell copy, Game game, Ability source) {
|
||||
Spell spell = getSpell(game, source);
|
||||
copy.setControllerId(spell.getControllerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean okUUIDToCopyFor(UUID potentialTarget, Game game, Ability source, Spell spell) {
|
||||
Permanent permanent = game.getPermanent(potentialTarget);
|
||||
if (permanent == null
|
||||
|| !permanent.isControlledBy(spell.getControllerId())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZadaHedronGrinderCopySpellEffect copy() {
|
||||
return new ZadaHedronGrinderCopySpellEffect(this);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue