use of mage.players.Player in project mage by magefree.
the class ElvishSoultillerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && mageObject != null) {
Choice typeChoice = new ChoiceCreatureType(mageObject);
if (controller.choose(outcome, typeChoice, game)) {
if (!game.isSimulation()) {
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
}
Cards cardsToLibrary = new CardsImpl();
FilterCreatureCard filter = new FilterCreatureCard();
filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
cardsToLibrary.addAll(controller.getGraveyard().getCards(filter, source.getSourceId(), source.getControllerId(), game));
controller.putCardsOnTopOfLibrary(cardsToLibrary, game, source, false);
controller.shuffleLibrary(source, game);
return true;
}
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class FightOrFlightEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(game.getCombat().getAttackingPlayerId());
if (player != null && targetPlayer != null) {
int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, targetPlayer.getId(), game);
TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, count, new FilterCreaturePermanent("creatures to put in the first pile"), true);
List<Permanent> pile1 = new ArrayList<>();
creatures.setRequired(false);
if (player.choose(Outcome.Neutral, creatures, source.getSourceId(), game)) {
List<UUID> targets = creatures.getTargets();
for (UUID targetId : targets) {
Permanent p = game.getPermanent(targetId);
if (p != null) {
pile1.add(p);
}
}
}
List<Permanent> pile2 = new ArrayList<>();
for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
if (!pile1.contains(p)) {
pile2.add(p);
}
}
boolean choice = targetPlayer.choosePile(outcome, "Choose which pile can attack this turn.", pile1, pile2, game);
List<Permanent> chosenPile = choice ? pile2 : pile1;
List<Permanent> otherPile = choice ? pile1 : pile2;
for (Permanent permanent : chosenPile) {
if (permanent != null) {
RestrictionEffect effect = new CantAttackTargetEffect(Duration.EndOfTurn);
effect.setText("");
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
game.informPlayers("Creatures that can attack this turn: " + otherPile.stream().map(Permanent::getLogName).collect(Collectors.joining(", ")));
return true;
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class FeudkillersVerdictEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.gainLife(10, game, source);
boolean moreLife = false;
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
Player opponent = game.getPlayer(opponentId);
if (opponent != null) {
if (controller.getLife() > opponent.getLife()) {
moreLife = true;
break;
}
}
}
if (moreLife) {
return new CreateTokenEffect(new GiantWarriorToken(), 1).apply(game, source);
}
return true;
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class FeveredVisionsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
UUID activePlayerId = game.getActivePlayerId();
Player player = game.getPlayer(activePlayerId);
if (controller != null && player != null) {
player.drawCards(1, source, game);
Set<UUID> opponents = game.getOpponents(source.getControllerId());
if (opponents.contains(player.getId()) && player.getHand().size() > 3) {
player.damage(2, source.getSourceId(), source, game);
}
return true;
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class FieldOfRuinEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_BASIC_LAND);
if (player.searchLibrary(target, source, game)) {
player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game);
player.shuffleLibrary(source, game);
}
}
}
return true;
}
return false;
}
Aggregations