forked from External/mage
New common class CopyTargetStackAbilityEffect (#10525)
- Fix superfluous null check in Lithoform Engine - Remove hardcoding of controlled abilities in TargetTriggeredAbility (used only in Strionic Resonator) - EnchantmentSourcePredicate analogous to ArtifactSourcePredicate
This commit is contained in:
parent
8d55419003
commit
231ab77bcd
8 changed files with 137 additions and 219 deletions
|
|
@ -0,0 +1,52 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.StackAbility;
|
||||
|
||||
public class CopyTargetStackAbilityEffect extends OneShotEffect {
|
||||
|
||||
/**
|
||||
* Copy target (activated/triggered) ability on the stack, choosing new targets for the copy
|
||||
*/
|
||||
public CopyTargetStackAbilityEffect() {
|
||||
super(Outcome.Copy);
|
||||
}
|
||||
|
||||
public CopyTargetStackAbilityEffect(final CopyTargetStackAbilityEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(targetPointer.getFirst(game, source));
|
||||
if (stackAbility == null) {
|
||||
return false;
|
||||
}
|
||||
stackAbility.createCopyOnStack(game, source, source.getControllerId(), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CopyTargetStackAbilityEffect copy() {
|
||||
return new CopyTargetStackAbilityEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("copy ");
|
||||
if (!mode.getTargets().isEmpty()) {
|
||||
sb.append("target ").append(mode.getTargets().get(0).getTargetName());
|
||||
}
|
||||
sb.append(". You may choose new targets for the copy");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue