mirror of
https://github.com/correl/mage.git
synced 2024-11-28 11:09:54 +00:00
Fixed Dual Nature
This commit is contained in:
parent
f6e4da4040
commit
9a57480f4b
4 changed files with 259 additions and 3 deletions
234
Mage.Sets/src/mage/cards/d/DualNature.java
Normal file
234
Mage.Sets/src/mage/cards/d/DualNature.java
Normal file
|
@ -0,0 +1,234 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.cards.d;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.EntersBattlefieldAllTriggeredAbility;
|
||||
import mage.abilities.common.LeavesBattlefieldAllTriggeredAbility;
|
||||
import mage.abilities.common.ZoneChangeTriggeredAbility;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.CreateTokenCopyTargetEffect;
|
||||
import mage.abilities.effects.common.ExileAllEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SetTargetPointer;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.filter.predicate.permanent.TokenPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class DualNature extends CardImpl {
|
||||
|
||||
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("nontoken creature");
|
||||
|
||||
static {
|
||||
filter.add(Predicates.not(new TokenPredicate()));
|
||||
}
|
||||
|
||||
public DualNature(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{4}{G}{G}");
|
||||
|
||||
// Whenever a nontoken creature enters the battlefield, its controller creates a token that's a copy of that creature.
|
||||
this.addAbility(new EntersBattlefieldAllTriggeredAbility(
|
||||
Zone.BATTLEFIELD, new DualNatureCreateTokenEffect(), filter, false, SetTargetPointer.PERMANENT,
|
||||
"Whenever a nontoken creature enters the battlefield, its controller creates a token that's a copy of that creature."
|
||||
));
|
||||
|
||||
// Whenever a nontoken creature leaves the battlefield, exile all tokens with the same name as that creature.
|
||||
this.addAbility(new LeavesBattlefieldAllTriggeredAbility(
|
||||
Zone.BATTLEFIELD, new DualNatureCreatureLeavesEffect(), filter, false, SetTargetPointer.PERMANENT
|
||||
));
|
||||
|
||||
// When Dual Nature leaves the battlefield, exile all tokens created with Dual Nature.
|
||||
this.addAbility(new DualNatureLeavesBattlefieldTriggeredAbility());
|
||||
}
|
||||
|
||||
public DualNature(final DualNature card) {
|
||||
super(card);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualNature copy() {
|
||||
return new DualNature(this);
|
||||
}
|
||||
}
|
||||
|
||||
class DualNatureCreateTokenEffect extends OneShotEffect {
|
||||
|
||||
DualNatureCreateTokenEffect() {
|
||||
super(Outcome.PutCardInPlay);
|
||||
this.staticText = "its controller creates a token that's a copy of that creature";
|
||||
}
|
||||
|
||||
DualNatureCreateTokenEffect(final DualNatureCreateTokenEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualNatureCreateTokenEffect copy() {
|
||||
return new DualNatureCreateTokenEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(permanent.getControllerId());
|
||||
effect.setTargetPointer(targetPointer);
|
||||
effect.apply(game, source);
|
||||
Object object = game.getState().getValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game));
|
||||
Set<UUID> tokensCreated;
|
||||
if (object != null) {
|
||||
tokensCreated = (Set<UUID>) object;
|
||||
} else {
|
||||
tokensCreated = new HashSet<>();
|
||||
}
|
||||
for (Permanent perm : effect.getAddedPermanent()) {
|
||||
if (perm != null) {
|
||||
tokensCreated.add(perm.getId());
|
||||
}
|
||||
}
|
||||
game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class DualNatureCreatureLeavesEffect extends OneShotEffect {
|
||||
|
||||
DualNatureCreatureLeavesEffect() {
|
||||
super(Outcome.DestroyPermanent);
|
||||
this.staticText = "exile all tokens with the same name as that creature";
|
||||
}
|
||||
|
||||
DualNatureCreatureLeavesEffect(final DualNatureCreatureLeavesEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualNatureCreatureLeavesEffect copy() {
|
||||
return new DualNatureCreatureLeavesEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent creature = game.getPermanentOrLKIBattlefield(this.getTargetPointer().getFirst(game, source));
|
||||
if (creature != null) {
|
||||
FilterPermanent filter = new FilterPermanent();
|
||||
filter.add(new TokenPredicate());
|
||||
filter.add(new NamePredicate(creature.getName()));
|
||||
new ExileAllEffect(filter).apply(game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class DualNatureLeavesBattlefieldTriggeredAbility extends ZoneChangeTriggeredAbility {
|
||||
|
||||
DualNatureLeavesBattlefieldTriggeredAbility() {
|
||||
super(Zone.BATTLEFIELD, null, new DualNatureExileEffect(), "When {this} leaves the battlefield, ", false);
|
||||
}
|
||||
|
||||
DualNatureLeavesBattlefieldTriggeredAbility(DualNatureLeavesBattlefieldTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (super.checkTrigger(event, game)) {
|
||||
for (Effect effect : this.getEffects()) {
|
||||
if (effect instanceof DualNatureExileEffect) {
|
||||
((DualNatureExileEffect) effect).setCardZoneString(CardUtil.getCardZoneString("_tokensCreated", this.getSourceId(), game, true));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualNatureLeavesBattlefieldTriggeredAbility copy() {
|
||||
return new DualNatureLeavesBattlefieldTriggeredAbility(this);
|
||||
}
|
||||
}
|
||||
|
||||
class DualNatureExileEffect extends OneShotEffect {
|
||||
|
||||
private String cardZoneString;
|
||||
|
||||
DualNatureExileEffect() {
|
||||
super(Outcome.Benefit);
|
||||
this.staticText = "exile all tokens created with {this}.";
|
||||
}
|
||||
|
||||
DualNatureExileEffect(final DualNatureExileEffect effect) {
|
||||
super(effect);
|
||||
this.cardZoneString = effect.cardZoneString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualNatureExileEffect copy() {
|
||||
return new DualNatureExileEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Object object = game.getState().getValue(cardZoneString);
|
||||
if (object != null) {
|
||||
Set<UUID> tokensCreated = (Set<UUID>) object;
|
||||
for (UUID tokenId : tokensCreated) {
|
||||
Permanent token = game.getPermanent(tokenId);
|
||||
if (token != null) {
|
||||
token.destroy(source.getSourceId(), game, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setCardZoneString(String cardZoneString) {
|
||||
this.cardZoneString = cardZoneString;
|
||||
}
|
||||
}
|
|
@ -81,6 +81,7 @@ public class Prophecy extends ExpansionSet {
|
|||
cards.add(new SetCardInfo("Despoil", 62, Rarity.COMMON, mage.cards.d.Despoil.class));
|
||||
cards.add(new SetCardInfo("Devastate", 87, Rarity.COMMON, mage.cards.d.Devastate.class));
|
||||
cards.add(new SetCardInfo("Diving Griffin", 6, Rarity.COMMON, mage.cards.d.DivingGriffin.class));
|
||||
cards.add(new SetCardInfo("Dual Nature", 112, Rarity.RARE, mage.cards.d.DualNature.class));
|
||||
cards.add(new SetCardInfo("Entangler", 7, Rarity.UNCOMMON, mage.cards.e.Entangler.class));
|
||||
cards.add(new SetCardInfo("Excavation", 33, Rarity.UNCOMMON, mage.cards.e.Excavation.class));
|
||||
cards.add(new SetCardInfo("Fault Riders", 88, Rarity.COMMON, mage.cards.f.FaultRiders.class));
|
||||
|
|
|
@ -30,12 +30,14 @@ package mage.abilities.common;
|
|||
import java.util.UUID;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.SetTargetPointer;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -44,6 +46,7 @@ import mage.game.permanent.Permanent;
|
|||
public class LeavesBattlefieldAllTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
protected FilterPermanent filter;
|
||||
protected SetTargetPointer setTargetPointer;
|
||||
|
||||
public LeavesBattlefieldAllTriggeredAbility(Effect effect, FilterPermanent filter) {
|
||||
this(effect, filter, false);
|
||||
|
@ -54,13 +57,19 @@ public class LeavesBattlefieldAllTriggeredAbility extends TriggeredAbilityImpl {
|
|||
}
|
||||
|
||||
public LeavesBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional) {
|
||||
this(zone, effect, filter, optional, SetTargetPointer.NONE);
|
||||
}
|
||||
|
||||
public LeavesBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, SetTargetPointer setTargetPointer) {
|
||||
super(zone, effect, optional);
|
||||
this.filter = filter;
|
||||
this.setTargetPointer = setTargetPointer;
|
||||
}
|
||||
|
||||
public LeavesBattlefieldAllTriggeredAbility(final LeavesBattlefieldAllTriggeredAbility ability) {
|
||||
super(ability);
|
||||
filter = ability.filter;
|
||||
setTargetPointer = ability.setTargetPointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,8 +88,20 @@ public class LeavesBattlefieldAllTriggeredAbility extends TriggeredAbilityImpl {
|
|||
if (zEvent.getFromZone() == Zone.BATTLEFIELD) {
|
||||
UUID targetId = event.getTargetId();
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(targetId);
|
||||
if (permanent != null) {
|
||||
return filter.match(permanent, getSourceId(), getControllerId(), game);
|
||||
if (permanent != null && filter.match(permanent, getSourceId(), getControllerId(), game)) {
|
||||
if (setTargetPointer != SetTargetPointer.NONE) {
|
||||
for (Effect effect : this.getEffects()) {
|
||||
switch (setTargetPointer) {
|
||||
case PERMANENT:
|
||||
effect.setTargetPointer(new FixedTarget(permanent.getId()));
|
||||
break;
|
||||
case PLAYER:
|
||||
effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -54,7 +54,7 @@ Lifelink|instance|
|
|||
Living weapon|new|
|
||||
Madness|card, cost|
|
||||
Melee|new|
|
||||
Menace|instance|
|
||||
Menace|new|
|
||||
Miracle|cost|
|
||||
Mountaincycling|cost|
|
||||
Mountainwalk|new|
|
||||
|
|
Loading…
Reference in a new issue