forked from External/mage
use common methods for WardAbility
This commit is contained in:
parent
0086c5e4a2
commit
ee68726865
1 changed files with 6 additions and 18 deletions
|
|
@ -11,7 +11,6 @@ import mage.constants.Zone;
|
|||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.target.Target;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
|
|
@ -22,7 +21,6 @@ public class WardAbility extends TriggeredAbilityImpl {
|
|||
|
||||
private final Cost cost;
|
||||
private final DynamicValue genericMana;
|
||||
|
||||
private final boolean showAbilityHint;
|
||||
private final String whereXIs;
|
||||
|
||||
|
|
@ -74,29 +72,19 @@ public class WardAbility extends TriggeredAbilityImpl {
|
|||
return event.getType() == GameEvent.EventType.TARGETED;
|
||||
}
|
||||
|
||||
private StackObject getTargetingObject(GameEvent event, Game game) {
|
||||
for (StackObject stackObject : game.getStack()) {
|
||||
if (stackObject.getId().equals(event.getSourceId()) || stackObject.getSourceId().equals(event.getSourceId())) {
|
||||
for (Target target : stackObject.getStackAbility().getTargets()) {
|
||||
if (target.contains(getSourceId())) {
|
||||
return stackObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (!getSourceId().equals(event.getTargetId())) {
|
||||
return false;
|
||||
}
|
||||
StackObject stackObject = getTargetingObject(event, game);
|
||||
if (stackObject == null || !game.getOpponents(getControllerId()).contains(stackObject.getControllerId())) {
|
||||
StackObject targetingObject = CardUtil.getTargetingStackObject(event, game);
|
||||
if (targetingObject == null || !game.getOpponents(getControllerId()).contains(targetingObject.getControllerId())) {
|
||||
return false;
|
||||
}
|
||||
getEffects().setTargetPointer(new FixedTarget(stackObject.getId(), game));
|
||||
if (!CardUtil.checkTargetMap(this.id, targetingObject, event, game)) {
|
||||
return false;
|
||||
}
|
||||
getEffects().setTargetPointer(new FixedTarget(targetingObject.getId()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue