Refactor - replaced redundant crews abilities with shared CrewsVehicleSourceTriggeredAbility

This commit is contained in:
JOAC69 2016-09-24 17:48:54 -05:00
parent adf9c1bfe0
commit 71c8adbe5f
4 changed files with 50 additions and 120 deletions

View file

@ -31,6 +31,7 @@ import java.util.UUID;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.CrewsVehicleSourceTriggeredAbility;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.keyword.FirstStrikeAbility;
import mage.cards.CardImpl;
@ -72,41 +73,3 @@ public class GearshiftAce extends CardImpl {
return new GearshiftAce(this);
}
}
class GearshiftAceTriggeredAbility extends TriggeredAbilityImpl {
public GearshiftAceTriggeredAbility(Effect effect) {
super(Zone.BATTLEFIELD, effect, false);
}
public GearshiftAceTriggeredAbility(final GearshiftAceTriggeredAbility ability) {
super(ability);
}
@Override
public GearshiftAceTriggeredAbility copy() {
return new GearshiftAceTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CREWED_VEHICLE;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(getSourceId())) {
for (Effect effect : getEffects()) {
// set the vehicle id as target
effect.setTargetPointer(new FixedTarget(event.getSourceId()));
}
return true;
}
return false;
}
@Override
public String getRule() {
return "When {this} crews a Vehicle, " + super.getRule();
}
}

View file

@ -29,18 +29,13 @@ package mage.sets.kaladesh;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.CrewsVehicleSourceTriggeredAbility;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.keyword.HasteAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.target.targetpointer.FixedTarget;
/**
*
@ -74,40 +69,3 @@ public class SpeedwayFanatic extends CardImpl {
}
}
class CrewsVehicleSourceTriggeredAbility extends TriggeredAbilityImpl {
public CrewsVehicleSourceTriggeredAbility(Effect effect) {
super(Zone.BATTLEFIELD, effect, false);
}
public CrewsVehicleSourceTriggeredAbility(final CrewsVehicleSourceTriggeredAbility ability) {
super(ability);
}
@Override
public CrewsVehicleSourceTriggeredAbility copy() {
return new CrewsVehicleSourceTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CREWED_VEHICLE;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(getSourceId())) {
for (Effect effect : getEffects()) {
// set the vehicle id as target
effect.setTargetPointer(new FixedTarget(event.getSourceId()));
}
return true;
}
return false;
}
@Override
public String getRule() {
return "When {this} crews a Vehicle, " + super.getRule();
}
}

View file

@ -32,6 +32,7 @@ import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.CrewsVehicleSourceTriggeredAbility;
import mage.abilities.effects.common.continuous.BoostTargetEffect;
import mage.abilities.effects.keyword.ScryEffect;
import mage.cards.CardImpl;
@ -63,7 +64,7 @@ public class VeteranMotorist extends CardImpl {
// Whenever Veteran Motorist crews a Vehicle, that Vehicle gets +1/+1 until end of turn.
Effect effect = new BoostTargetEffect(1, 1, Duration.EndOfTurn);
effect.setText("that Vehicle gets +1/+1 until end of turn");
this.addAbility(new VeteranMotoristCrewsTriggeredAbility(effect));
this.addAbility(new CrewsVehicleSourceTriggeredAbility(effect));
}
public VeteranMotorist(final VeteranMotorist card) {
@ -75,41 +76,3 @@ public class VeteranMotorist extends CardImpl {
return new VeteranMotorist(this);
}
}
class VeteranMotoristCrewsTriggeredAbility extends TriggeredAbilityImpl {
public VeteranMotoristCrewsTriggeredAbility(Effect effect) {
super(Zone.BATTLEFIELD, effect, false);
}
public VeteranMotoristCrewsTriggeredAbility(final VeteranMotoristCrewsTriggeredAbility ability) {
super(ability);
}
@Override
public VeteranMotoristCrewsTriggeredAbility copy() {
return new VeteranMotoristCrewsTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CREWED_VEHICLE;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(getSourceId())) {
for (Effect effect : getEffects()) {
// set the vehicle id as target
effect.setTargetPointer(new FixedTarget(event.getSourceId()));
}
return true;
}
return false;
}
@Override
public String getRule() {
return "When {this} crews a Vehicle, " + super.getRule();
}
}

View file

@ -0,0 +1,46 @@
package mage.abilities.effects.common;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.target.targetpointer.FixedTarget;
public class CrewsVehicleSourceTriggeredAbility extends TriggeredAbilityImpl {
public CrewsVehicleSourceTriggeredAbility(Effect effect) {
super(Zone.BATTLEFIELD, effect, false);
}
public CrewsVehicleSourceTriggeredAbility(final CrewsVehicleSourceTriggeredAbility ability) {
super(ability);
}
@Override
public CrewsVehicleSourceTriggeredAbility copy() {
return new CrewsVehicleSourceTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CREWED_VEHICLE;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(getSourceId())) {
for (Effect effect : getEffects()) {
// set the vehicle id as target
effect.setTargetPointer(new FixedTarget(event.getSourceId()));
}
return true;
}
return false;
}
@Override
public String getRule() {
return "When {this} crews a Vehicle, " + super.getRule();
}
}