use of mage.players.Player in project mage by magefree.
the class ChecksAndBalancesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
for (UUID uuid : game.getOpponents(spell.getControllerId())) {
Player player = game.getPlayer(uuid);
if (player != null) {
if (player.getHand().isEmpty()) {
game.informPlayers(player.getLogName() + " doesn't have a card in hand to discard to counter " + spell.getLogName() + ", effect aborted.");
return true;
}
}
}
for (UUID uuid : game.getOpponents(spell.getControllerId())) {
Player player = game.getPlayer(uuid);
if (player != null) {
if (!player.chooseUse(outcome, "Discard a card to counter " + spell.getLogName() + '?', source, game)) {
game.informPlayers(player.getLogName() + " refuses to discard a card to counter " + spell.getLogName());
return true;
} else {
game.informPlayers(player.getLogName() + " agrees to discard a card to counter " + spell.getLogName());
}
}
}
for (UUID uuid : game.getOpponents(spell.getControllerId())) {
Player player = game.getPlayer(uuid);
if (player != null && !player.getHand().isEmpty()) {
TargetCardInHand target = new TargetCardInHand();
if (player.choose(Outcome.Discard, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
player.discard(card, false, source, game);
}
}
}
game.getStack().counter(spell.getId(), source, game);
return true;
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class ChaosLordEffect method checkInterveningIfClause.
@Override
public boolean checkInterveningIfClause(Game game) {
Condition condition = new ControlsPermanentsComparedToOpponentsCondition(ComparisonType.EQUAL_TO, new FilterPermanent());
Player controller = game.getPlayer(controllerId);
if (controller != null && condition.apply(game, this)) {
return super.checkInterveningIfClause(game);
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class ChaosMoonEvenReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int permanentsInPlay = game.getBattlefield().count(StaticFilters.FILTER_PERMANENT, source.getSourceId(), source.getControllerId(), game);
// Odd
if (permanentsInPlay % 2 == 1) {
game.addEffect(new BoostAllEffect(1, 1, Duration.EndOfTurn, filter, false), source);
new CreateDelayedTriggeredAbilityEffect(new ChaosMoonOddTriggeredAbility()).apply(game, source);
} else // Even
{
game.addEffect(new BoostAllEffect(-1, -1, Duration.EndOfTurn, filter, false), source);
game.addEffect(new ChaosMoonEvenReplacementEffect(), source);
}
return true;
}
use of mage.players.Player in project mage by magefree.
the class ChanneledForceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int xValue = GetXValue.instance.calculate(game, source, this);
if (xValue == 0) {
return false;
}
Player player = game.getPlayer(source.getTargets().get(0).getFirstTarget());
if (player != null) {
player.drawCards(xValue, source, game);
}
game.damagePlayerOrPlaneswalker(source.getTargets().get(1).getFirstTarget(), xValue, source.getSourceId(), source, game, false, true);
return true;
}
use of mage.players.Player in project mage by magefree.
the class ChaosWandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (controller == null || opponent == null) {
return false;
}
Cards cardsToShuffle = new CardsImpl();
while (opponent.canRespond() && opponent.getLibrary().hasCards()) {
Card card = opponent.getLibrary().getFromTop(game);
if (card == null) {
break;
}
opponent.moveCards(card, Zone.EXILED, source, game);
controller.revealCards(source, new CardsImpl(card), game);
if (card.isInstantOrSorcery(game)) {
boolean cardWasCast = false;
if (controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() + " without paying its mana cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
if (!cardWasCast) {
cardsToShuffle.add(card);
}
break;
} else {
cardsToShuffle.add(card);
}
}
return opponent.putCardsOnBottomOfLibrary(cardsToShuffle, game, source, false);
}
Aggregations