use of mage.MageObject in project mage by magefree.
the class RevealHandSourceControllerCost method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Player controller = game.getPlayer(controllerId);
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
controller.revealCards(sourceObject.getName(), controller.getHand(), game);
paid = true;
}
return paid;
}
use of mage.MageObject in project mage by magefree.
the class ReturnToHandSourceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
MageObject mageObject;
if (returnFromNextZone && game.getState().getZoneChangeCounter(source.getSourceId()) == source.getSourceObjectZoneChangeCounter() + 1) {
mageObject = game.getObject(source.getSourceId());
} else {
mageObject = source.getSourceObjectIfItStillExists(game);
}
if (mageObject == null) {
return true;
}
switch(game.getState().getZone(mageObject.getId())) {
case BATTLEFIELD:
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.isPhasedIn()) {
return controller.moveCards(permanent, Zone.HAND, source, game);
}
break;
case GRAVEYARD:
Card card = (Card) mageObject;
return !fromBattlefieldOnly && controller.moveCards(card, Zone.HAND, source, game);
case STACK:
Spell spell = game.getSpell(source.getSourceId());
return !fromBattlefieldOnly && spell != null && controller.moveCards(spell.getMainCard(), Zone.HAND, source, game);
}
return true;
}
use of mage.MageObject in project mage by magefree.
the class ReturnToHandTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
List<UUID> copyIds = new ArrayList<>();
Set<Card> cards = new LinkedHashSet<>();
if (multitargetHandling) {
for (Target target : source.getTargets()) {
for (UUID targetId : target.getTargets()) {
MageObject mageObject = game.getObject(targetId);
if (mageObject instanceof Spell && mageObject.isCopy()) {
copyIds.add(targetId);
} else if (mageObject instanceof Card) {
cards.add((Card) mageObject);
}
}
}
} else {
for (UUID targetId : targetPointer.getTargets(game, source)) {
MageObject mageObject = game.getObject(targetId);
if (mageObject != null) {
if (mageObject instanceof Spell && mageObject.isCopy()) {
copyIds.add(targetId);
} else if (mageObject instanceof Card) {
cards.add((Card) mageObject);
}
}
}
}
for (UUID copyId : copyIds) {
game.getStack().remove(game.getSpell(copyId), game);
}
return controller.moveCards(cards, Zone.HAND, source, game);
}
use of mage.MageObject in project mage by magefree.
the class PreventAllDamageByAllObjectsEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!super.applies(event, source, game) || !(event instanceof DamageEvent) || event.getAmount() <= 0) {
return false;
}
DamageEvent damageEvent = (DamageEvent) event;
if (!damageEvent.isCombatDamage() && onlyCombat) {
return false;
}
if (filter == null) {
return true;
}
MageObject damageSource = game.getObject(damageEvent.getSourceId());
if (damageSource == null) {
return false;
}
if (filter instanceof FilterInPlay) {
return ((FilterInPlay) filter).match(damageSource, source.getSourceId(), source.getControllerId(), game);
}
return filter.match(damageSource, game);
}
use of mage.MageObject in project mage by magefree.
the class OpponentsCantCastChosenUntilNextTurnEffect method getInfoMessage.
@Override
public String getInfoMessage(Ability source, GameEvent event, Game game) {
MageObject mageObject = game.getObject(source.getSourceId());
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (mageObject != null && cardName != null) {
return "You can't cast a card named " + cardName + " (" + mageObject.getIdName() + ").";
}
return null;
}
Aggregations