mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
Added constructor with optional parameter.
This commit is contained in:
parent
89b3675552
commit
acb87e81e1
1 changed files with 56 additions and 51 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue