use of mage.players.Player in project mage by magefree.
the class FrightfulDelusionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
Cost cost = ManaUtil.createManaCost(1, false);
if (spell != null) {
Player player = game.getPlayer(spell.getControllerId());
if (player != null) {
cost.clearPaid();
game.getPlayer(spell.getControllerId()).discard(1, false, false, source, game);
if (!cost.pay(source, game, source, spell.getControllerId(), false, null)) {
return game.getStack().counter(source.getFirstTarget(), source, game);
}
}
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class FroghemothEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Set<Card> cardsToExile = new HashSet<>();
int numCounters = 0;
int lifeGain = 0;
for (UUID cardId : getTargetPointer().getTargets(game, source)) {
Card card = game.getCard(cardId);
if (card != null && game.getState().getZone(cardId) == Zone.GRAVEYARD && cardsToExile.add(card)) {
if (card.isCreature(game)) {
numCounters++;
} else {
lifeGain++;
}
}
}
if (!cardsToExile.isEmpty()) {
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
if (numCounters > 0) {
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent != null) {
permanent.addCounters(CounterType.P1P1.createInstance(numCounters), source.getControllerId(), source, game);
}
}
if (lifeGain > 0) {
controller.gainLife(lifeGain, game, source);
}
}
return true;
}
use of mage.players.Player in project mage by magefree.
the class FrayingSanityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// In the case that the enchantment is blinked
Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (enchantment == null) {
// It was not blinked, use the standard method
enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
}
if (enchantment == null) {
return false;
}
Player enchantedPlayer = game.getPlayer(enchantment.getAttachedTo());
if (enchantedPlayer != null) {
CardsPutIntoGraveyardWatcher watcher = game.getState().getWatcher(CardsPutIntoGraveyardWatcher.class);
if (watcher != null) {
xAmount = watcher.getAmountCardsPutToGraveyard(enchantedPlayer.getId());
}
enchantedPlayer.millCards(xAmount, source, game);
return true;
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class FreneticEfreetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
boolean flip = controller.flipCoin(source, game, true);
if (permanent == null) {
return false;
}
if (flip) {
return permanent.phaseOut(game);
} else {
permanent.sacrifice(source, game);
return true;
}
}
use of mage.players.Player in project mage by magefree.
the class FreeRangeChickenWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<Integer> results = controller.rollDice(outcome, source, game, 6, 2, 0);
int firstRoll = results.get(0);
int secondRoll = results.get(1);
if (firstRoll == secondRoll) {
game.addEffect(new BoostSourceEffect(firstRoll, firstRoll, Duration.EndOfTurn), source);
}
FreeRangeChickenWatcher watcher = game.getState().getWatcher(FreeRangeChickenWatcher.class);
if (watcher != null) {
int totalRoll = firstRoll + secondRoll;
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
if (watcher.rolledThisTurn(sourcePermanent.getId(), totalRoll)) {
sourcePermanent.sacrifice(source, game);
} else {
watcher.addRoll(sourcePermanent.getId(), totalRoll);
}
}
}
return true;
}
return false;
}
Aggregations