Added constructor with optional parameter.

This commit is contained in:
LevelX2 2012-09-19 21:15:11 +02:00
parent 89b3675552
commit acb87e81e1

View file

@ -1,51 +1,56 @@
package mage.abilities.common;
import mage.Constants;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
/**
* "When enchanted/equipped creature dies" triggered ability
* @author Loki
*/
public class DiesAttachedTriggeredAbility extends TriggeredAbilityImpl<DiesAttachedTriggeredAbility> {
private String attachedDescription;
public DiesAttachedTriggeredAbility(Effect effect, String attachedDescription) {
super(Constants.Zone.BATTLEFIELD, effect);
this.attachedDescription = attachedDescription;
}
public DiesAttachedTriggeredAbility(final DiesAttachedTriggeredAbility ability) {
super(ability);
this.attachedDescription = ability.attachedDescription;
}
@Override
public DiesAttachedTriggeredAbility copy() {
return new DiesAttachedTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).isDiesEvent()) {
Permanent p = (Permanent) game.getLastKnownInformation(event.getTargetId(), Constants.Zone.BATTLEFIELD);
if (p.getAttachments().contains(this.getSourceId())) {
for (Effect effect : getEffects()) {
effect.setValue("attachedTo", p);
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return "When " + attachedDescription + " dies, " + super.getRule();
}
}
package mage.abilities.common;
import mage.Constants;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
/**
* "When enchanted/equipped creature dies" triggered ability
* @author Loki
*/
public class DiesAttachedTriggeredAbility extends TriggeredAbilityImpl<DiesAttachedTriggeredAbility> {
private String attachedDescription;
public DiesAttachedTriggeredAbility(Effect effect, String attachedDescription) {
this(effect, attachedDescription, false);
}
public DiesAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional) {
super(Constants.Zone.BATTLEFIELD, effect, optional);
this.attachedDescription = attachedDescription;
}
public DiesAttachedTriggeredAbility(final DiesAttachedTriggeredAbility ability) {
super(ability);
this.attachedDescription = ability.attachedDescription;
}
@Override
public DiesAttachedTriggeredAbility copy() {
return new DiesAttachedTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).isDiesEvent()) {
Permanent p = (Permanent) game.getLastKnownInformation(event.getTargetId(), Constants.Zone.BATTLEFIELD);
if (p.getAttachments().contains(this.getSourceId())) {
for (Effect effect : getEffects()) {
effect.setValue("attachedTo", p);
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return "When " + attachedDescription + " dies, " + super.getRule();
}
}