updated implementation of Hostage Taker

This commit is contained in:
Evan Kranzler 2019-09-16 19:41:57 -04:00
parent 062548584a
commit 7a43bbd5a9
2 changed files with 53 additions and 64 deletions

View file

@ -1,6 +1,5 @@
package mage.cards.h;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
@ -12,17 +11,12 @@ import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.AsThoughEffectType;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.ExileZone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.ManaPoolItem;
@ -31,8 +25,10 @@ import mage.target.TargetPermanent;
import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
import java.util.Objects;
import java.util.UUID;
/**
*
* @author TheElk801
*/
public final class HostageTaker extends CardImpl {
@ -43,7 +39,8 @@ public final class HostageTaker extends CardImpl {
filter.add(AnotherPredicate.instance);
filter.add(Predicates.or(
new CardTypePredicate(CardType.ARTIFACT),
new CardTypePredicate(CardType.CREATURE)));
new CardTypePredicate(CardType.CREATURE)
));
}
public HostageTaker(UUID ownerId, CardSetInfo setInfo) {
@ -55,13 +52,13 @@ public final class HostageTaker extends CardImpl {
this.toughness = new MageInt(3);
// When Hostage Taker enters the battlefield, exile another target artifact or creature until Hostage Taker leaves the battlefield. You may cast that card as long as it remains exiled, and you may spend mana as though it were mana of any type to cast that spell.
Ability ability = new EntersBattlefieldTriggeredAbility(new HostageTakerExileEffect(filter.getMessage()));
Ability ability = new EntersBattlefieldTriggeredAbility(new HostageTakerExileEffect());
ability.addTarget(new TargetPermanent(filter));
ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()));
this.addAbility(ability);
}
public HostageTaker(final HostageTaker card) {
private HostageTaker(final HostageTaker card) {
super(card);
}
@ -73,14 +70,14 @@ public final class HostageTaker extends CardImpl {
class HostageTakerExileEffect extends OneShotEffect {
public HostageTakerExileEffect(String targetName) {
HostageTakerExileEffect() {
super(Outcome.Benefit);
this.staticText = "exile another target artifact or creature until {this} leaves the battlefield. "
+ "You may cast that card as long as it remains exiled, "
+ "and you may spend mana as though it were mana of any type to cast that spell";
}
public HostageTakerExileEffect(final HostageTakerExileEffect effect) {
private HostageTakerExileEffect(final HostageTakerExileEffect effect) {
super(effect);
}
@ -93,35 +90,41 @@ class HostageTakerExileEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Permanent card = game.getPermanent(getTargetPointer().getFirst(game, source));
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && card != null) {
Player controller = game.getPlayer(card.getControllerId());
if (controller != null) {
// move card to exile
UUID exileId = CardUtil.getCardExileZoneId(game, source);
controller.moveCardToExileWithInfo(card, exileId, permanent.getIdName(), source.getSourceId(), game, Zone.BATTLEFIELD, true);
// allow to cast the card
ContinuousEffect effect = new HostageTakerCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source);
// and you may spend mana as though it were mana of any color to cast it
effect = new HostageTakerSpendAnyManaEffect();
effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source);
}
if (permanent == null || card == null) {
return false;
}
Player controller = game.getPlayer(card.getControllerId());
if (controller == null) {
return false;
}
// move card to exile
UUID exileId = CardUtil.getCardExileZoneId(game, source);
controller.moveCardToExileWithInfo(card, exileId, permanent.getIdName(), source.getSourceId(), game, Zone.BATTLEFIELD, true);
// allow to cast the card
game.addEffect(new HostageTakerCastFromExileEffect(card.getId(), exileId), source);
// and you may spend mana as though it were mana of any color to cast it
ContinuousEffect effect = new HostageTakerSpendAnyManaEffect();
effect.setTargetPointer(new FixedTarget(card.getId(), game));
game.addEffect(effect, source);
return false;
}
}
class HostageTakerCastFromExileEffect extends AsThoughEffectImpl {
public HostageTakerCastFromExileEffect() {
private UUID cardId;
private UUID exileId;
HostageTakerCastFromExileEffect(UUID cardId, UUID exileId) {
super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.Custom, Outcome.Benefit);
staticText = "You may cast that card for as long as it remains exiled, and you may spend mana as though it were mana of any color to cast that spell";
this.cardId = cardId;
this.exileId = exileId;
}
public HostageTakerCastFromExileEffect(final HostageTakerCastFromExileEffect effect) {
private HostageTakerCastFromExileEffect(final HostageTakerCastFromExileEffect effect) {
super(effect);
this.cardId = effect.cardId;
this.exileId = effect.exileId;
}
@Override
@ -135,29 +138,26 @@ class HostageTakerCastFromExileEffect extends AsThoughEffectImpl {
}
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
if (objectId.equals(getTargetPointer().getFirst(game, source))) {
if (affectedControllerId.equals(source.getControllerId())) {
return true;
}
} else {
if (((FixedTarget) getTargetPointer()).getTarget().equals(objectId)) {
// object has moved zone so effect can be discarted
this.discard();
}
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
if (!sourceId.equals(cardId) || !source.isControlledBy(affectedControllerId)) {
return false;
}
ExileZone exileZone = game.getState().getExile().getExileZone(exileId);
if (exileZone != null && exileZone.contains(cardId)) {
return true;
}
discard();
return false;
}
}
class HostageTakerSpendAnyManaEffect extends AsThoughEffectImpl implements AsThoughManaEffect {
public HostageTakerSpendAnyManaEffect() {
HostageTakerSpendAnyManaEffect() {
super(AsThoughEffectType.SPEND_OTHER_MANA, Duration.Custom, Outcome.Benefit);
staticText = "you may spend mana as though it were mana of any color to cast it";
}
public HostageTakerSpendAnyManaEffect(final HostageTakerSpendAnyManaEffect effect) {
private HostageTakerSpendAnyManaEffect(final HostageTakerSpendAnyManaEffect effect) {
super(effect);
}
@ -173,22 +173,11 @@ class HostageTakerSpendAnyManaEffect extends AsThoughEffectImpl implements AsTho
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
objectId = game.getCard(objectId).getMainCard().getId(); // for split cards
if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget())
&& game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) {
if (affectedControllerId.equals(source.getControllerId())) {
// if the card moved from exile to spell the zone change counter is increased by 1
if (game.getState().getZoneChangeCounter(objectId) == ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) {
return true;
}
}
} else {
if (((FixedTarget) getTargetPointer()).getTarget().equals(objectId)) {
// object has moved zone so effect can be discarted
this.discard();
}
}
return false;
FixedTarget fixedTarget = ((FixedTarget) getTargetPointer());
return source.isControlledBy(affectedControllerId)
&& Objects.equals(objectId, fixedTarget.getTarget())
&& fixedTarget.getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId)
&& game.getState().getZone(objectId) == Zone.STACK;
}
@Override

View file

@ -194,10 +194,10 @@ class RobberOfTheRichSpendAnyManaEffect extends AsThoughEffectImpl implements As
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
FixedTarget fixedTarget = ((FixedTarget) getTargetPointer());
return source.isControlledBy(affectedControllerId)
&& Objects.equals(objectId, ((FixedTarget) getTargetPointer()).getTarget())
&& ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId)
&& (((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId))
&& Objects.equals(objectId, fixedTarget.getTarget())
&& fixedTarget.getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId)
&& game.getState().getZone(objectId) == Zone.STACK;
}