fixed implementation of Hunter's Insight

This commit is contained in:
Evan Kranzler 2020-04-25 20:12:38 -04:00
parent 8bbdae4af6
commit a07acc895e

View file

@ -1,23 +1,25 @@
package mage.cards.h;
import java.util.UUID;
import mage.abilities.TriggeredAbilityImpl;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Zone;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.DamagedEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.target.common.TargetControlledCreaturePermanent;
import java.util.UUID;
/**
*
* @author North
*/
public final class HuntersInsight extends CardImpl {
@ -25,13 +27,12 @@ public final class HuntersInsight extends CardImpl {
public HuntersInsight(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{G}");
// Choose target creature you control. Whenever that creature deals combat damage to a player or planeswalker this turn, draw that many cards.
this.getSpellAbility().addEffect(new GainAbilityTargetEffect(new HuntersInsightTriggeredAbility(), Duration.EndOfTurn));
this.getSpellAbility().addEffect(new HuntersInsightEffect());
this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent());
}
public HuntersInsight(final HuntersInsight card) {
private HuntersInsight(final HuntersInsight card) {
super(card);
}
@ -41,14 +42,46 @@ public final class HuntersInsight extends CardImpl {
}
}
class HuntersInsightTriggeredAbility extends TriggeredAbilityImpl {
class HuntersInsightEffect extends OneShotEffect {
public HuntersInsightTriggeredAbility() {
super(Zone.BATTLEFIELD, null, false);
HuntersInsightEffect() {
super(Outcome.Benefit);
staticText = "Choose target creature you control. Whenever that creature deals combat damage " +
"to a player or planeswalker this turn, draw that many cards.";
}
public HuntersInsightTriggeredAbility(final HuntersInsightTriggeredAbility ability) {
private HuntersInsightEffect(final HuntersInsightEffect effect) {
super(effect);
}
@Override
public HuntersInsightEffect copy() {
return new HuntersInsightEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent == null) {
return false;
}
game.addDelayedTriggeredAbility(new HuntersInsightTriggeredAbility(new MageObjectReference(permanent, game)), source);
return true;
}
}
class HuntersInsightTriggeredAbility extends DelayedTriggeredAbility {
private final MageObjectReference mor;
HuntersInsightTriggeredAbility(MageObjectReference mor) {
super(null, Duration.EndOfTurn, false, false);
this.mor = mor;
}
private HuntersInsightTriggeredAbility(final HuntersInsightTriggeredAbility ability) {
super(ability);
this.mor = ability.mor;
}
@Override
@ -58,18 +91,20 @@ class HuntersInsightTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.DAMAGED_PLAYER || event.getType() == EventType.DAMAGED_PLANESWALKER;
return event.getType() == EventType.DAMAGED_PLAYER
|| event.getType() == EventType.DAMAGED_PLANESWALKER;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.sourceId) && ((DamagedEvent) event).isCombatDamage()) {
if (!mor.refersTo(event.getSourceId(), game)
|| !((DamagedEvent) event).isCombatDamage()) {
return false;
}
this.getEffects().clear();
this.addEffect(new DrawCardSourceControllerEffect(event.getAmount()));
return true;
}
return false;
}
@Override
public String getRule() {