use of mage.players.Player in project mage by magefree.
the class CharmingPrinceEffect 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) {
return false;
}
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent == null) {
return false;
}
if (!controller.moveCardToExileWithInfo(permanent, source.getSourceId(), sourceObject.getIdName(), source, game, Zone.BATTLEFIELD, true)) {
return false;
}
// create delayed triggered ability
Effect effect = new ReturnToBattlefieldUnderYourControlTargetEffect();
effect.setText("Return it to the battlefield under your control at the beginning of the next end step");
effect.setTargetPointer(new FixedTarget(permanent.getId(), game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
return true;
}
use of mage.players.Player in project mage by magefree.
the class ChargingCinderhornDamageTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent chargingCinderhoof = game.getPermanent(source.getSourceId());
if (chargingCinderhoof != null) {
chargingCinderhoof.addCounters(CounterType.FURY.createInstance(), source.getControllerId(), source, game);
} else {
chargingCinderhoof = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
if (chargingCinderhoof == null) {
return false;
}
DynamicValue amount = new CountersSourceCount(CounterType.FURY);
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null) {
player.damage(amount.calculate(game, source, this), source.getSourceId(), source, game);
return true;
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class ChaoticBacklashEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer != null) {
int amount = 2 * game.getBattlefield().countAll(filter, targetPlayer.getId(), game);
targetPlayer.damage(amount, source.getSourceId(), source, game);
return true;
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class CracklingDoomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<Permanent> toSacrifice = new ArrayList<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (controller.hasOpponent(playerId, game)) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
int greatestPower = Integer.MIN_VALUE;
int numberOfCreatures = 0;
Permanent permanentToSacrifice = null;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
if (permanent.getPower().getValue() > greatestPower) {
greatestPower = permanent.getPower().getValue();
numberOfCreatures = 1;
permanentToSacrifice = permanent;
} else if (permanent.getPower().getValue() == greatestPower) {
numberOfCreatures++;
}
}
if (numberOfCreatures == 1) {
if (permanentToSacrifice != null) {
toSacrifice.add(permanentToSacrifice);
}
} else if (greatestPower != Integer.MIN_VALUE) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature to sacrifice with power equal to " + greatestPower);
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, greatestPower));
Target target = new TargetControlledCreaturePermanent(filter);
if (opponent.choose(outcome, target, playerId, game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
toSacrifice.add(permanent);
}
}
}
}
}
}
for (Permanent permanent : toSacrifice) {
permanent.sacrifice(source, game);
}
return true;
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class CouncilsJudgmentVote method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
CouncilsJudgmentVote vote = new CouncilsJudgmentVote(player);
vote.doVotes(source, game);
Cards cards = new CardsImpl();
vote.getMostVoted().stream().forEach(cards::add);
return player.moveCards(cards, Zone.EXILED, source, game);
}
Aggregations