use of mage.game.stack.StackObject in project mage by magefree.
the class PsychicPurgeTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (getSourceId().equals(event.getTargetId())) {
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (stackObject != null) {
if (game.getOpponents(this.getControllerId()).contains(stackObject.getControllerId())) {
Effect effect = this.getEffects().get(0);
effect.setTargetPointer(new FixedTarget(stackObject.getControllerId()));
return true;
}
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class PsychicStrikeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean countered = false;
StackObject stackObject = game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (game.getStack().counter(source.getFirstTarget(), source, game)) {
countered = true;
}
if (stackObject != null) {
Player controller = game.getPlayer(stackObject.getControllerId());
if (controller != null) {
controller.millCards(2, source, game);
}
}
return countered;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class RemKarolusStalwartSlayerReplacementEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
UUID targetId = event.getTargetId();
if (targetId.equals(source.getSourceId())) {
return false;
}
UUID controllerId = source.getControllerId();
if (!targetId.equals(controllerId)) {
Permanent permanent = game.getPermanent(targetId);
if (permanent == null || !permanent.isControlledBy(controllerId)) {
return false;
}
}
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (stackObject == null) {
stackObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
}
if (stackObject instanceof Spell) {
return super.applies(event, source, game);
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class ReparationsTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
// spell cast
UUID stackObjectId = event.getTargetId();
// spell caster
UUID casterId = event.getPlayerId();
StackObject stackObject = game.getStack().getStackObject(stackObjectId);
if (stackObject != null && game.getOpponents(controllerId).contains(casterId)) {
Player targetPlayer = game.getPlayer(stackObject.getStackAbility().getFirstTarget());
Permanent targetPermanent = game.getPermanent(stackObject.getStackAbility().getFirstTarget());
if (targetPlayer != null && targetPlayer.getId().equals(controllerId)) {
return true;
}
if (targetPermanent != null && targetPermanent.isCreature(game) && targetPermanent.isControlledBy(controllerId)) {
return true;
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class TestOfTalentsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
if (stackObject == null) {
return false;
}
MageObject targetObject = game.getObject(stackObject.getSourceId());
String cardName;
if (targetObject instanceof Card) {
cardName = targetObject.getName();
} else {
cardName = "";
}
UUID searchPlayerId = stackObject.getControllerId();
Player player = game.getPlayer(searchPlayerId);
if (player == null) {
return false;
}
int previousCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
game.getStack().counter(source.getFirstTarget(), source, game);
this.applySearchAndExile(game, source, cardName, searchPlayerId);
int newCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
if (previousCount > newCount) {
player.drawCards(previousCount - newCount, source, game);
}
return true;
}
Aggregations