Fix Unlicensed Hearse
@@ -19,18 +19,46 @@ import mage.constants.Duration;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.StaticFilters;
+import mage.game.ExileZone;
import mage.game.Game;
import mage.target.common.TargetCardInASingleGraveyard;
import mage.util.CardUtil;
-import java.util.HashSet;
-import java.util.Objects;
-import java.util.Optional;
import java.util.UUID;
/**
* @author TheElk801
*/
+enum UnlicensedHearseValue implements DynamicValue {
+ instance;
+
+ @Override
+ public int calculate(Game game, Ability sourceAbility, Effect effect) {
+ ExileZone cardsExiledWithUnlicensedHearse =
+ game.getExile()
+ .getExileZone(
+ CardUtil.getExileZoneId(
+ game,
+ sourceAbility.getSourceId(),
+ game.getState().getZoneChangeCounter(sourceAbility.getSourceId())));
+ if (cardsExiledWithUnlicensedHearse == null) {
+ return 0;
+ }
+
+ return cardsExiledWithUnlicensedHearse.size();
+ }
+
+ @Override
+ public UnlicensedHearseValue copy() {
+ return this;
+ }
+
+ @Override
+ public String getMessage() {
+ return "cards exiled with it";
+ }
+}
+
public final class UnlicensedHearse extends CardImpl {
private static final Hint hint = new ValueHint("Cards exiled", UnlicensedHearseValue.instance);
@@ -43,19 +71,17 @@ public final class UnlicensedHearse extends CardImpl {
this.toughness = new MageInt(0);
// {T}: Exile up to two target cards from a single graveyard.
- Ability ability = new SimpleActivatedAbility(new ExileTargetForSourceEffect(), new TapSourceCost());
- ability.addTarget(new TargetCardInASingleGraveyard(
- 0, 2, StaticFilters.FILTER_CARD_CARDS
- ));
+ Ability ability =
+ new SimpleActivatedAbility(new ExileTargetForSourceEffect(), new TapSourceCost());
+ ability.addTarget(new TargetCardInASingleGraveyard(0, 2, StaticFilters.FILTER_CARD_CARDS));
this.addAbility(ability);
// Unlicensed Hearse's power and toughness are each equal to the number of cards exiled with it.
- this.addAbility(new SimpleStaticAbility(
+ this.addAbility(
+ new SimpleStaticAbility(
Zone.ALL,
- new SetPowerToughnessSourceEffect(
- UnlicensedHearseValue.instance, Duration.Custom
- )
- ).addHint(hint));
+ new SetPowerToughnessSourceEffect(UnlicensedHearseValue.instance, Duration.Custom))
+ .addHint(hint));
// Crew 2
this.addAbility(new CrewAbility(2));
@@ -70,30 +96,3 @@ public final class UnlicensedHearse extends CardImpl {
return new UnlicensedHearse(this);
}
}
-
-enum UnlicensedHearseValue implements DynamicValue {
- instance;
-
- @Override
- public int calculate(Game game, Ability sourceAbility, Effect effect) {
- return Optional.of(game
- .getExile()
- .getExileZone(CardUtil.getExileZoneId(
- game, sourceAbility.getSourceId(),
- game.getState().getZoneChangeCounter(sourceAbility.getSourceId())
- )))
- .filter(Objects::nonNull)
- .map(HashSet::size)
- .orElse(0);
- }
-
- @Override
- public UnlicensedHearseValue copy() {
- return this;
- }
-
- @Override
- public String getMessage() {
- return "cards exiled with it";
- }
-}
\ No newline at end of file
