* Tuktuk Scrapper - Fixed that the triggered ability did not work.

This commit is contained in:
LevelX2 2015-02-26 00:43:43 +01:00
parent f96a256c28
commit d45c8b52dd

View file

@ -28,17 +28,17 @@
package mage.sets.worldwake; package mage.sets.worldwake;
import java.util.UUID; import java.util.UUID;
import mage.constants.*;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterPermanent; import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
@ -58,7 +58,6 @@ public class TuktukScrapper extends CardImpl {
this.subtype.add("Artificer"); this.subtype.add("Artificer");
this.subtype.add("Ally"); this.subtype.add("Ally");
this.color.setRed(true);
this.power = new MageInt(2); this.power = new MageInt(2);
this.toughness = new MageInt(2); this.toughness = new MageInt(2);
@ -80,6 +79,7 @@ class TuktukScrapperTriggeredAbility extends TriggeredAbilityImpl {
public TuktukScrapperTriggeredAbility() { public TuktukScrapperTriggeredAbility() {
super(Zone.BATTLEFIELD, new TuktukScrapperEffect(), true); super(Zone.BATTLEFIELD, new TuktukScrapperEffect(), true);
this.addTarget(new TargetArtifactPermanent());
} }
public TuktukScrapperTriggeredAbility(final TuktukScrapperTriggeredAbility ability) { public TuktukScrapperTriggeredAbility(final TuktukScrapperTriggeredAbility ability) {
@ -91,15 +91,19 @@ class TuktukScrapperTriggeredAbility extends TriggeredAbilityImpl {
return new TuktukScrapperTriggeredAbility(this); return new TuktukScrapperTriggeredAbility(this);
} }
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD;
}
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) { Permanent permanent = game.getPermanent(event.getTargetId());
Permanent permanent = game.getPermanent(event.getTargetId()); if (permanent != null) {
if (permanent != null && permanent.getId() == this.getSourceId()) { if (permanent.getId() == this.getSourceId()) {
return true; return true;
} }
if (permanent != null if (permanent.hasSubtype("Ally")
&& permanent.hasSubtype("Ally")
&& permanent.getControllerId().equals(this.getControllerId())) { && permanent.getControllerId().equals(this.getControllerId())) {
return true; return true;
} }
@ -115,11 +119,10 @@ class TuktukScrapperTriggeredAbility extends TriggeredAbilityImpl {
class TuktukScrapperEffect extends OneShotEffect { class TuktukScrapperEffect extends OneShotEffect {
private static final FilterPermanent filter = new FilterPermanent(); private static final FilterControlledPermanent filter = new FilterControlledPermanent();
static { static {
filter.add(new SubtypePredicate("Ally")); filter.add(new SubtypePredicate("Ally"));
filter.add(new ControllerPredicate(TargetController.YOU));
} }
public TuktukScrapperEffect() { public TuktukScrapperEffect() {
@ -137,22 +140,18 @@ class TuktukScrapperEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
TargetArtifactPermanent target = new TargetArtifactPermanent(); Permanent targetArtifact = game.getPermanent(getTargetPointer().getFirst(game, source));
Player you = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (you != null) { if (controller != null && targetArtifact != null) {
if (target.canChoose(source.getControllerId(), game) && target.choose(Outcome.DestroyPermanent, source.getControllerId(), source.getSourceId(), game)) { targetArtifact.destroy(source.getSourceId(), game, false);
Permanent targetedArtifact = game.getPermanent(target.getFirstTarget()); Player targetController = game.getPlayer(targetArtifact.getControllerId());
if (targetedArtifact != null) { if (targetController != null && game.getState().getZone(targetArtifact.getId()).equals(Zone.GRAVEYARD)) {
Card artifact = game.getCard(targetedArtifact.getId()); int alliesControlled = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
Player controller = game.getPlayer(targetedArtifact.getControllerId()); if (alliesControlled > 0) {
targetedArtifact.destroy(id, game, true); targetController.damage(alliesControlled, source.getSourceId(), game, false, true);
if (controller.getGraveyard().contains(artifact.getId())) {
int alliesControlled = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
controller.damage(alliesControlled, id, game, false, true);
return true;
}
} }
} }
return true;
} }
return false; return false;
} }