use of mage.MageObject in project mage by magefree.
the class RaidersKarveEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller == null || sourceObject == null) {
return false;
}
Card card = controller.getLibrary().getFromTop(game);
if (card == null) {
return true;
}
controller.lookAtCards(sourceObject.getIdName(), new CardsImpl(card), game);
if (!card.isLand(game)) {
return true;
}
String message = "Put " + card.getLogName() + " onto the battlefield tapped?";
if (controller.chooseUse(Outcome.PutLandInPlay, message, source, game)) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
}
return true;
}
use of mage.MageObject in project mage by magefree.
the class RhysticScryingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
boolean result = true;
boolean doEffect = false;
Cost cost = ManaUtil.createManaCost(2, false);
// check if any player is willing to pay
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && player.canRespond() && cost.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + " for " + sourceObject.getLogName() + "?", source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source, player.getId(), false, null)) {
if (!game.isSimulation()) {
game.informPlayers(player.getLogName() + " pays the cost for " + sourceObject.getLogName());
}
doEffect = true;
break;
}
}
}
// do the effects if anybody paid
if (doEffect) {
controller.discard(3, false, false, source, game);
}
return result;
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class RhysticStudyDrawEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && opponent != null && sourceObject != null) {
if (controller.chooseUse(Outcome.DrawCard, "Draw a card (" + sourceObject.getLogName() + ')', source, game)) {
Cost cost = ManaUtil.createManaCost(1, false);
if (opponent.chooseUse(Outcome.Benefit, "Pay {1}?", source, game) && cost.pay(source, game, source, opponent.getId(), false, null)) {
return true;
}
controller.drawCards(1, source, game);
}
return true;
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class RicochetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
Targets targets = new Targets();
Ability sourceAbility = spell.getSpellAbility();
for (UUID modeId : sourceAbility.getModes().getSelectedModes()) {
Mode mode = sourceAbility.getModes().get(modeId);
targets.addAll(mode.getTargets());
}
if (targets.size() != 1 || targets.get(0).getTargets().size() != 1) {
return false;
}
Map<Player, Integer> playerRolls = new HashMap<>();
for (UUID playerId : game.getPlayerList().copy()) {
Player player = game.getPlayer(playerId);
if (player != null) {
playerRolls.put(player, 7);
}
}
do {
for (Player player : playerRolls.keySet()) {
// bad outcome - ai must choose lowest value
playerRolls.put(player, player.rollDice(Outcome.Detriment, source, game, 6));
}
int minValueInMap = Collections.min(playerRolls.values());
for (Map.Entry<Player, Integer> mapEntry : new HashSet<>(playerRolls.entrySet())) {
if (mapEntry.getValue() > minValueInMap) {
playerRolls.remove(mapEntry.getKey());
}
}
} while (playerRolls.size() > 1);
if (playerRolls.size() == 1) {
Player loser = (Player) playerRolls.keySet().toArray()[0];
UUID loserId = loser.getId();
Target target = targets.get(0);
if (target.getFirstTarget().equals(loserId)) {
return true;
}
String oldTargetName = null;
if (target.canTarget(spell.getControllerId(), loserId, sourceAbility, game)) {
Player oldPlayer = game.getPlayer(targets.getFirstTarget());
if (oldPlayer != null) {
oldTargetName = oldPlayer.getLogName();
}
target.clearChosen();
target.addTarget(loserId, sourceAbility, game);
}
MageObject sourceObject = game.getObject(source.getSourceId());
if (oldTargetName != null && sourceObject != null) {
game.informPlayers(sourceObject.getLogName() + ": Changed target of " + spell.getLogName() + " from " + oldTargetName + " to " + loser.getLogName());
}
}
return true;
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class ReweaveEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
MageObject sourceObject = source.getSourceObject(game);
if (permanent != null && sourceObject != null) {
if (permanent.sacrifice(source, game)) {
Player permanentController = game.getPlayer(permanent.getControllerId());
if (permanentController != null) {
Library library = permanentController.getLibrary();
if (library.hasCards()) {
Cards cards = new CardsImpl();
Card permanentCard = null;
for (Card card : permanentController.getLibrary().getCards(game)) {
cards.add(card);
if (card.isPermanent(game)) {
for (CardType cardType : permanent.getCardType(game)) {
if (card.getCardType(game).contains(cardType)) {
permanentCard = card;
break;
}
}
}
}
permanentController.revealCards(source, cards, game);
if (permanentCard != null) {
permanentController.moveCards(permanentCard, Zone.BATTLEFIELD, source, game);
}
permanentController.shuffleLibrary(source, game);
}
return true;
}
return false;
}
}
return true;
}
Aggregations