use of mage.MageObjectReference in project mage by magefree.
the class HeatStrokeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
BlockedThisTurnWatcher blockedWatcher = game.getState().getWatcher(BlockedThisTurnWatcher.class);
WasBlockedThisTurnWatcher wasBlockedThisTurnWatcher = game.getState().getWatcher(WasBlockedThisTurnWatcher.class);
Set<Permanent> inROI = new HashSet<>(game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game));
boolean toRet = false;
Set<MageObjectReference> toDestroy = new HashSet<>();
if (blockedWatcher != null) {
toDestroy.addAll(blockedWatcher.getBlockedThisTurnCreatures());
}
if (wasBlockedThisTurnWatcher != null) {
toDestroy.addAll(wasBlockedThisTurnWatcher.getWasBlockedThisTurnCreatures());
}
for (MageObjectReference mor : toDestroy) {
Permanent permanent = mor.getPermanent(game);
if (permanent != null && permanent.isCreature(game) && inROI.contains(permanent)) {
permanent.destroy(source, game, false);
toRet = true;
}
}
return toRet;
}
use of mage.MageObjectReference in project mage by magefree.
the class KytheonHeroOfAkrosCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourceObject = game.getPermanent(source.getSourceId());
if (sourceObject != null) {
AttackedOrBlockedThisCombatWatcher watcher = game.getState().getWatcher(AttackedOrBlockedThisCombatWatcher.class);
if (watcher != null) {
boolean sourceFound = false;
int number = 0;
for (MageObjectReference mor : watcher.getAttackedThisTurnCreatures()) {
if (mor.refersTo(sourceObject, game)) {
sourceFound = true;
} else {
number++;
}
}
return sourceFound && number >= 2;
}
}
return false;
}
use of mage.MageObjectReference in project mage by magefree.
the class LurrusOfTheDreamDenWatcher method applies.
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
if (source.isControlledBy(affectedControllerId) && Zone.GRAVEYARD.equals(game.getState().getZone(objectId)) && game.isActivePlayer(source.getControllerId())) {
// only during your turn
Card objectCard = game.getCard(objectId);
Permanent sourceObject = game.getPermanent(source.getSourceId());
if (sourceObject != null && objectCard != null && objectCard.isPermanent(game) && objectCard.isOwnedBy(source.getControllerId()) && objectCard.getManaValue() < 3 && objectCard.getSpellAbility() != null && objectCard.getSpellAbility().spellCanBeActivatedRegularlyNow(affectedControllerId, game)) {
LurrusOfTheDreamDenWatcher watcher = game.getState().getWatcher(LurrusOfTheDreamDenWatcher.class);
return watcher != null && !watcher.isAbilityUsed(new MageObjectReference(sourceObject, game));
}
}
if (!objectId.equals(getTargetPointer().getFirst(game, source))) {
return false;
}
if (!affectedControllerId.equals(source.getControllerId())) {
return false;
}
LurrusOfTheDreamDenWatcher watcher = game.getState().getWatcher(LurrusOfTheDreamDenWatcher.class);
return watcher != null && !watcher.isAbilityUsed(new MageObjectReference(source.getSourceId(), game));
}
use of mage.MageObjectReference in project mage by magefree.
the class MetzaliTowerOfTriumphEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Watcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
if (watcher instanceof AttackedThisTurnWatcher) {
Set<MageObjectReference> attackedThisTurn = ((AttackedThisTurnWatcher) watcher).getAttackedThisTurnCreatures();
List<Permanent> available = new ArrayList<>();
for (MageObjectReference mor : attackedThisTurn) {
Permanent permanent = mor.getPermanent(game);
if (permanent != null && permanent.isCreature(game)) {
available.add(permanent);
}
}
if (!available.isEmpty()) {
Permanent permanent = available.get(RandomUtil.nextInt(available.size()));
if (permanent != null) {
permanent.destroy(source, game, false);
}
}
return true;
}
return false;
}
use of mage.MageObjectReference in project mage by magefree.
the class PastInFlamesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
player.getGraveyard().stream().filter((cardId) -> (affectedObjectList.contains(new MageObjectReference(cardId, game)))).forEachOrdered((cardId) -> {
Card card = game.getCard(cardId);
if (card != null) {
FlashbackAbility ability = new FlashbackAbility(card, card.getManaCost());
ability.setSourceId(cardId);
ability.setControllerId(card.getOwnerId());
game.getState().addOtherAbility(card, ability);
}
});
return true;
}
Aggregations