use of mage.game.Game in project mage by magefree.
the class KotoseTheSilentSpiderWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.CLEANUP_STEP_POST) {
morMap.entrySet().removeIf(e -> !e.getKey().zoneCounterIsCurrent(game));
morMap.values().stream().flatMap(Collection::stream).map(set -> set.removeIf(mor -> !mor.zoneCounterIsCurrent(game)));
morMap.values().removeIf(Set::isEmpty);
return;
}
if (event.getType() != GameEvent.EventType.SPELL_CAST || event.getAdditionalReference() == null) {
return;
}
Spell spell = game.getSpell(event.getTargetId());
if (spell == null) {
return;
}
morMap.getOrDefault(event.getAdditionalReference().getApprovingMageObjectReference(), Collections.emptySet()).removeIf(set -> set.stream().anyMatch(mor -> mor.getSourceId().equals(spell.getMainCard().getId()) && mor.getZoneChangeCounter() + 1 == spell.getZoneChangeCounter(game)));
}
use of mage.game.Game in project mage by magefree.
the class PsychicTheftWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.SPELL_CAST) {
return;
}
Spell spell = game.getSpell(event.getTargetId());
if (spell == null || spell.getCard() == null || spell.getCard().getMainCard() == null) {
return;
}
map.computeIfAbsent(event.getPlayerId(), x -> new HashSet<>()).add(new MageObjectReference(spell.getCard().getMainCard(), game));
}
use of mage.game.Game 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;
}
use of mage.game.Game in project mage by magefree.
the class NassariDeanOfExpressionTriggeredAbility method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl();
game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).map(Player::getLibrary).map(p -> p.getFromTop(game)).forEach(cards::add);
player.moveCards(cards, Zone.EXILED, source, game);
cards.retainZone(Zone.EXILED, game);
if (cards.isEmpty()) {
return false;
}
for (Card card : cards.getCards(game)) {
CardUtil.makeCardPlayable(game, source, card, Duration.EndOfTurn, true);
}
return true;
}
use of mage.game.Game in project mage by magefree.
the class WallOfStolenIdentityCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
permanent = game.getPermanentEntering(source.getSourceId());
}
final Permanent sourcePermanent = permanent;
if (controller == null || sourcePermanent == null) {
return false;
}
Target target = new TargetPermanent(new FilterCreaturePermanent("target creature (you copy from)"));
target.setRequired(true);
if (source instanceof SimpleStaticAbility) {
target = new TargetPermanent(new FilterCreaturePermanent("creature (you copy from)"));
target.setRequired(false);
target.setNotTarget(true);
}
if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
return false;
}
controller.choose(Outcome.Copy, target, source.getSourceId(), game);
Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
if (copyFromPermanent == null) {
return false;
}
game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new CopyApplier() {
@Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
blueprint.addSubType(SubType.WALL);
blueprint.getAbilities().add(DefenderAbility.getInstance());
return true;
}
});
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new TapTargetEffect(), false, "tap the copied creature " + "and it doesn't untap during its controller's untap step for as long as you control {this}");
ability.addEffect(new DontUntapInControllersUntapStepTargetEffect(Duration.WhileControlled));
ability.getEffects().setTargetPointer(new FixedTarget(copyFromPermanent, game));
game.fireReflexiveTriggeredAbility(ability, source);
return true;
}
Aggregations