use of mage.target.TargetPlayer in project mage by magefree.
the class SingeMindOgreEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer != null && !targetPlayer.getHand().isEmpty()) {
Cards revealed = new CardsImpl();
Card card = targetPlayer.getHand().getRandom(game);
if (card != null) {
revealed.add(card);
targetPlayer.revealCards("Singe-Mind Ogre", revealed, game);
targetPlayer.loseLife(card.getManaValue(), game, source, false);
return true;
}
}
return false;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class SinsOfTheFatherEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (you != null && targetPlayer != null) {
int exiledCards = 0;
for (Card card : targetPlayer.getGraveyard().getCards(game)) {
if (filter.match(card, game)) {
if (card.moveToExile(null, "", source, game)) {
exiledCards++;
}
}
}
targetPlayer.loseLife(exiledCards, game, source, false);
return true;
}
return false;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class ThrullSurgeonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Player you = game.getPlayer(source.getControllerId());
if (targetPlayer != null && you != null) {
you.lookAtCards("Discard", targetPlayer.getHand(), game);
TargetCard target = new TargetCard(Zone.HAND, new FilterCard());
target.setNotTarget(true);
if (you.choose(Outcome.Benefit, targetPlayer.getHand(), target, game)) {
Card card = targetPlayer.getHand().get(target.getFirstTarget(), game);
return targetPlayer.discard(card, false, source, game);
}
}
return false;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class TunnelVisionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (targetPlayer == null || cardName == null || cardName.isEmpty()) {
return false;
}
Cards cardsToReveal = new CardsImpl();
Card namedCard = null;
for (Card card : targetPlayer.getLibrary().getCards(game)) {
cardsToReveal.add(card);
if (CardUtil.haveSameNames(card, cardName, game)) {
namedCard = card;
break;
}
}
targetPlayer.revealCards(source, cardsToReveal, game);
if (namedCard != null) {
cardsToReveal.remove(namedCard);
targetPlayer.moveCards(cardsToReveal, Zone.GRAVEYARD, source, game);
targetPlayer.putCardsOnTopOfLibrary(new CardsImpl(namedCard), game, source, true);
} else {
targetPlayer.shuffleLibrary(source, game);
}
return true;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class GameImpl method preventDamage.
@Override
public PreventionEffectData preventDamage(GameEvent event, Ability source, Game game, int amountToPrevent) {
PreventionEffectData result = new PreventionEffectData(amountToPrevent);
if (!event.getFlag()) {
// damage is not preventable
return result;
}
if (!(event instanceof DamageEvent)) {
result.setError(true);
return result;
}
DamageEvent damageEvent = (DamageEvent) event;
GameEvent preventEvent = new PreventDamageEvent(damageEvent.getTargetId(), damageEvent.getSourceId(), source, source.getControllerId(), damageEvent.getAmount(), damageEvent.isCombatDamage());
if (game.replaceEvent(preventEvent)) {
result.setReplaced(true);
return result;
}
if (event.getAmount() > amountToPrevent) {
result.setPreventedDamage(amountToPrevent);
damageEvent.setAmount(event.getAmount() - amountToPrevent);
} else {
result.setPreventedDamage(event.getAmount());
damageEvent.setAmount(0);
}
if (amountToPrevent != Integer.MAX_VALUE) {
// set remaining amount
result.setRemainingAmount(amountToPrevent - result.getPreventedDamage());
}
MageObject damageSource = game.getObject(damageEvent.getSourceId());
MageObject preventionSource = game.getObject(source.getSourceId());
if (damageSource != null && preventionSource != null) {
MageObject targetObject = game.getObject(event.getTargetId());
String targetName = "";
if (targetObject == null) {
Player targetPlayer = game.getPlayer(event.getTargetId());
if (targetPlayer != null) {
targetName = targetPlayer.getLogName();
}
} else {
targetName = targetObject.getLogName();
}
if (!game.isSimulation()) {
StringBuilder message = new StringBuilder(preventionSource.getLogName()).append(": Prevented ");
message.append(result.getPreventedDamage()).append(" damage from ").append(damageSource.getLogName());
if (!targetName.isEmpty()) {
message.append(" to ").append(targetName);
}
game.informPlayers(message.toString());
}
}
game.fireEvent(new PreventedDamageEvent(damageEvent.getTargetId(), source.getSourceId(), source, source.getControllerId(), result.getPreventedDamage()));
return result;
}
Aggregations