use of mage.players.Player in project mage by magefree.
the class BeaconOfDestinyEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
// check source
MageObject object = game.getObject(event.getSourceId());
if (object == null) {
game.informPlayers("Couldn't find source of damage");
return false;
}
if (!object.getId().equals(damageSource.getFirstTarget()) && (!(object instanceof Spell) || !((Spell) object).getSourceId().equals(damageSource.getFirstTarget()))) {
return false;
}
TargetPermanent target = new TargetPermanent();
target.add(source.getSourceId(), game);
this.redirectTarget = target;
// check player
Player player = game.getPlayer(event.getTargetId());
if (player != null) {
if (player.getId().equals(source.getControllerId())) {
return true;
}
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class BazaarTraderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
Permanent permanent = targetPermanentReference.getPermanent(game);
if (player != null && permanent != null) {
return permanent.changeControllerId(player.getId(), game, source);
} else {
discard();
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class ProtectionChosenColorTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source));
if (target != null) {
ChoiceColor colorChoice = new ChoiceColor();
if (!controller.choose(Outcome.Benefit, colorChoice, game)) {
return false;
}
game.informPlayers(target.getName() + ": " + controller.getLogName() + " has chosen " + colorChoice.getChoice());
game.getState().setValue(target.getId() + "_color", colorChoice.getColor());
ObjectColor protectColor = (ObjectColor) game.getState().getValue(target.getId() + "_color");
if (protectColor != null) {
ContinuousEffect effect = new ProtectionChosenColorTargetEffect();
game.addEffect(effect, source);
ObjectColor color = target.getColor(game);
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
if (!permanent.getId().equals(target.getId()) && permanent.getColor(game).shares(color)) {
game.getState().setValue(permanent.getId() + "_color", colorChoice.getColor());
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
}
return true;
}
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class BorderlandExplorerEffect 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) {
// Store for each player the cards to discard, that's important because all discard shall happen at the same time
Map<UUID, Cards> cardsToDiscard = new HashMap<>();
// Store for each player the lands to reveal, that's important because all reveals shall happen at the same time
Map<UUID, Cards> cardsToReveal = new HashMap<>();
// choose cards to discard
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
Target target = new TargetDiscard(0, 1, new FilterCard(), playerId);
player.chooseTarget(outcome, target, source, game);
Cards cards = new CardsImpl(target.getTargets());
cardsToDiscard.put(playerId, cards);
}
}
// discard all chosen cards
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
Cards cardsPlayer = cardsToDiscard.get(playerId);
if (cardsPlayer != null) {
for (UUID cardId : cardsPlayer) {
Card card = game.getCard(cardId);
player.discard(card, false, source, game);
}
}
}
}
// search for a land for each player that discarded
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
Cards cardsPlayer = cardsToDiscard.get(playerId);
if (cardsPlayer != null && !cardsPlayer.isEmpty()) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_BASIC_LAND);
if (player.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards cards = new CardsImpl(target.getTargets());
cards.addAll(target.getTargets());
cardsToReveal.put(playerId, cards);
}
}
}
}
}
// reveal the searched lands, put in hands, and shuffle
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
Cards cardsPlayer = cardsToReveal.get(playerId);
if (cardsPlayer != null) {
for (UUID cardId : cardsPlayer) {
Card card = game.getCard(cardId);
Cards cards = new CardsImpl(game.getCard(cardId));
if (card != null && !cards.isEmpty()) {
player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ')', cards, game);
player.moveCards(card, Zone.HAND, source, game);
player.shuffleLibrary(source, game);
}
}
}
}
}
return true;
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class BondOfPassionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
permanent.untap(game);
effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
Permanent permanent2 = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (permanent2 != null) {
permanent2.damage(2, source.getSourceId(), source, game);
} else {
Player player = game.getPlayer(source.getTargets().get(1).getFirstTarget());
if (player != null) {
player.damage(2, source.getSourceId(), source, game);
}
}
return true;
}
Aggregations