use of mage.MageObjectReference in project mage by magefree.
the class CantAttackIfAttackedLastTurnEffect method canAttack.
@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
AttackedLastTurnWatcher watcher = game.getState().getWatcher(AttackedLastTurnWatcher.class);
if (watcher != null) {
Set<MageObjectReference> attackingCreatures = watcher.getAttackedLastTurnCreatures(attacker.getControllerId());
MageObjectReference mor = new MageObjectReference(attacker, game);
return !attackingCreatures.contains(mor);
}
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class IdolOfEnduranceWatcher method addPlayable.
static void addPlayable(Ability source, Game game) {
MageObjectReference mor = new MageObjectReference(source);
game.getState().getWatcher(IdolOfEnduranceWatcher.class).morMap.computeIfAbsent(mor, m -> new HashMap<>()).compute(source.getControllerId(), CardUtil::setOrIncrementValue);
}
use of mage.MageObjectReference in project mage by magefree.
the class LightmineFieldEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<UUID> attackers = game.getCombat().getAttackers();
int damage = attackers.size();
Set<MageObjectReference> attackSet = (Set<MageObjectReference>) getValue("Lightmine Field");
if (!attackers.isEmpty()) {
for (Iterator<MageObjectReference> it = attackSet.iterator(); it.hasNext(); ) {
MageObjectReference attacker = it.next();
Permanent creature = attacker.getPermanent(game);
if (creature != null) {
creature.damage(damage, source.getSourceId(), source, game, false, true);
}
}
return true;
}
return false;
}
use of mage.MageObjectReference in project mage by magefree.
the class MagmaticChannelerCastFromExileEffect 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(player.getLibrary().getTopCards(game, 2));
player.moveCards(cards, Zone.EXILED, source, game);
cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
Card card = null;
if (cards.isEmpty()) {
return false;
} else if (cards.size() == 1) {
card = cards.getRandom(game);
} else {
TargetCard targetCard = new TargetCardInExile(StaticFilters.FILTER_CARD, null);
player.choose(outcome, cards, targetCard, game);
card = game.getCard(targetCard.getFirstTarget());
}
if (card == null) {
return false;
}
game.addEffect(new MagmaticChannelerCastFromExileEffect(new MageObjectReference(card, game)), source);
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class MythRealizedSetPTEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && new MageObjectReference(source.getSourceObject(game), game).refersTo(permanent, game)) {
int amount = permanent.getCounters(game).getCount(CounterType.LORE);
permanent.getPower().setValue(amount);
permanent.getToughness().setValue(amount);
return true;
} else {
discard();
}
}
return false;
}
Aggregations