mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
added TransformIntoSourceTriggeredAbility to simplify copied code
This commit is contained in:
parent
76a7e4fe2c
commit
3801325a04
9 changed files with 160 additions and 460 deletions
|
|
@ -0,0 +1,58 @@
|
|||
package mage.abilities.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.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class TransformIntoSourceTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
private final boolean whenever;
|
||||
|
||||
public TransformIntoSourceTriggeredAbility(Effect effect) {
|
||||
this(effect, false);
|
||||
}
|
||||
|
||||
public TransformIntoSourceTriggeredAbility(Effect effect, boolean optional) {
|
||||
this(effect, optional, false);
|
||||
}
|
||||
|
||||
public TransformIntoSourceTriggeredAbility(Effect effect, boolean optional, boolean whenever) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
this.whenever = whenever;
|
||||
}
|
||||
|
||||
private TransformIntoSourceTriggeredAbility(final TransformIntoSourceTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.whenever = ability.whenever;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformIntoSourceTriggeredAbility copy() {
|
||||
return new TransformIntoSourceTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.TRANSFORMED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (!event.getTargetId().equals(this.getSourceId())) {
|
||||
return false;
|
||||
}
|
||||
Permanent permanent = getSourcePermanentIfItStillExists(game);
|
||||
return permanent != null && permanent.isTransformed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTriggerPhrase() {
|
||||
return "When" + (whenever ? "ever" : "") + " this creature transforms into this {this}, ";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue