Merge branch 'master' into move_magepermanent_method

This commit is contained in:
ingmargoudt 2017-04-28 19:29:20 +02:00 committed by GitHub
commit 12eb4c2fb7
9 changed files with 238 additions and 61 deletions

View file

@ -1,7 +1,6 @@
package mage.cards.a;
import java.util.*;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
@ -115,7 +114,7 @@ class ApproachOfTheSecondSunWatcher extends Watcher {
public ApproachOfTheSecondSunWatcher(final ApproachOfTheSecondSunWatcher watcher) {
super(watcher);
approachesCast = new HashMap<>(approachesCast);
approachesCast = new HashMap<>(watcher.approachesCast);
}
@Override
@ -123,19 +122,13 @@ class ApproachOfTheSecondSunWatcher extends Watcher {
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
Spell spell = game.getStack().getSpell(event.getSourceId());
if (spell != null && spell.getName().equals("Approach of the Second Sun")) {
int cast = getApproachesCast(event.getPlayerId());
approachesCast.put(event.getPlayerId(), cast + 1);
approachesCast.put(event.getPlayerId(), getApproachesCast(event.getPlayerId()) + 1);
}
}
}
public int getApproachesCast(UUID player) {
Integer cast = approachesCast.get(player);
if (cast == null) {
return 0;
} else {
return cast;
}
return approachesCast.getOrDefault(player, 0);
}
@Override

View file

@ -27,14 +27,9 @@
*/
package mage.cards.b;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.common.SacrificeTargetCost;
@ -46,11 +41,16 @@ import mage.abilities.effects.common.LoseLifeOpponentsEffect;
import mage.abilities.effects.keyword.ScryEffect;
import mage.abilities.keyword.IndestructibleAbility;
import mage.abilities.keyword.MenaceAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SuperType;
import mage.constants.Zone;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetControlledPermanent;
import mage.watchers.common.CreaturesDiedWatcher;
@ -61,7 +61,7 @@ import mage.watchers.common.CreaturesDiedWatcher;
*/
public class BontuTheGlorified extends CardImpl {
private static final FilterControlledPermanent filter = new FilterControlledPermanent("another creature");
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("another creature");
static {
filter.add(new AnotherPredicate());

View file

@ -0,0 +1,137 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.cards.n;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.common.FilterBasicLandCard;
import mage.filter.common.FilterControlledLandPermanent;
import mage.filter.common.FilterLandPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.players.PlayerList;
import mage.target.common.TargetCardInLibrary;
import mage.target.common.TargetControlledPermanent;
/**
*
* @author Rene - bugisemail at gmail dot com
*/
public class NaturalBalance extends CardImpl {
public NaturalBalance(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{2}{G}{G}");
// Each player who controls six or more lands chooses five lands he or she controls and sacrifices the rest. Each player who controls four or fewer lands may search his or her library for up to X basic land cards and put them onto the battlefield, where X is five minus the number of lands he or she controls. Then each player who searched his or her library this way shuffles it.
this.getSpellAbility().addEffect(new NaturalBalanceEffect());
}
public NaturalBalance(final NaturalBalance card) {
super(card);
}
@Override
public NaturalBalance copy() {
return new NaturalBalance(this);
}
class NaturalBalanceEffect extends OneShotEffect {
public NaturalBalanceEffect() {
super(Outcome.PutCardInPlay);
this.staticText = "Each player who controls six or more lands chooses five lands he or she controls and sacrifices the rest. Each player who controls four or fewer lands may search his or her library for up to X basic land cards and put them onto the battlefield, where X is five minus the number of lands he or she controls. Then each player who searched his or her library this way shuffles it.";
}
public NaturalBalanceEffect(final NaturalBalanceEffect effect) {
super(effect);
}
@Override
public NaturalBalanceEffect copy() {
return new NaturalBalanceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
PlayerList players = game.getState().getPlayersInRange(controller.getId(), game);
for (UUID playerId : players) {
Player player = game.getPlayer(playerId);
if (player != null) {
int landCount = game.getBattlefield().countAll(new FilterControlledLandPermanent(), player.getId(), game);
if (landCount > 5) {
// chooses five lands he or she controls and sacrifices the rest
TargetControlledPermanent target = new TargetControlledPermanent(5, 5, new FilterControlledLandPermanent("lands to keep"), true);
if (target.choose(Outcome.Sacrifice, player.getId(), source.getSourceId(), game)) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterLandPermanent(), player.getId(), game)) {
if (!target.getTargets().contains(permanent.getId())) {
permanent.sacrifice(source.getId(), game);
}
}
}
}
}
}
List<Player> toShuffle = new ArrayList<>();
for (UUID playerId : players) {
Player player = game.getPlayer(playerId);
if (player != null) {
int landCount = game.getBattlefield().countAll(new FilterControlledLandPermanent(), player.getId(), game);
int amount = 5 - landCount;
if (landCount < 5 && player.chooseUse(outcome, "Search your library for up to " + amount + " basic land cards and put them onto the battlefield?", source, game)) {
// Select lands and put them onto battlefield
TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterBasicLandCard());
if (player.searchLibrary(target, game)) {
player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game);
}
toShuffle.add(player);
}
}
}
for (Player player : toShuffle) {
if (player.isInGame()) {
player.shuffleLibrary(source, game);
}
}
return true;
}
return false;
}
}
}

View file

@ -75,7 +75,8 @@ class RichesEffect extends OneShotEffect {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
if (opponent.chooseTarget(Outcome.Detriment, target, source, game)) {
target.setNotTarget(true);
if (opponent.choose(Outcome.Detriment, target, source.getSourceId(), game)) {
creaturesToSteal.add(target.getTargets().get(0));
}
}
@ -85,7 +86,7 @@ class RichesEffect extends OneShotEffect {
// Has to be done as a separate loop in case there's a situation where one creature's
// controller depends on another creatures controller.
for (UUID target : creaturesToSteal) {
GainControlTargetEffect eff = new GainControlTargetEffect(Duration.EndOfGame, true);
GainControlTargetEffect eff = new GainControlTargetEffect(Duration.Custom, true);
eff.setTargetPointer(new FixedTarget(target));
game.addEffect(eff, source);
}

View file

@ -84,14 +84,13 @@ class ShadowOfTheGraveEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
CardsCycledOrDiscardedThisTurnWatcher watcher = (CardsCycledOrDiscardedThisTurnWatcher) game.getState().getWatchers().get("CardsCycledOrDiscardedThisTurnWatcher");
CardsCycledOrDiscardedThisTurnWatcher watcher = (CardsCycledOrDiscardedThisTurnWatcher) game.getState()
.getWatchers().get(CardsCycledOrDiscardedThisTurnWatcher.class.getName());
if (controller != null
&& watcher != null
&& watcher.getCardsCycledOrDiscardedThisTurn(controller.getId()) != null) {
&& watcher != null) {
for (Card card : watcher.getCardsCycledOrDiscardedThisTurn(controller.getId()).getCards(game)) {
if (card != null
&& game.getState().getZone(card.getId()) == Zone.GRAVEYARD //must come from their graveyard
&& card.getOwnerId() == controller.getId()) { //confirm ownership
if (game.getState().getZone(card.getId()) == Zone.GRAVEYARD //must come from their graveyard
&& card.getOwnerId().equals(controller.getId())) { //confirm ownership, but it should not be possible to get not ownwd cards here
controller.moveCardToHandWithInfo(card, source.getId(), game, true);
}
}

View file

@ -30,7 +30,6 @@ package mage.cards.s;
import mage.Mana;
import mage.abilities.Abilities;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.effects.common.ManaEffect;
@ -54,6 +53,7 @@ import mage.target.common.TargetControlledPermanent;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.abilities.mana.SimpleManaAbility;
/**
*
@ -67,7 +67,7 @@ public class SquanderedResources extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{B}{G}");
// Sacrifice a land: Add to your mana pool one mana of any type the sacrificed land could produce.
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new SquanderedResourcesEffect(), new SacrificeTargetCost(new TargetControlledPermanent(filter))));
this.addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, new SquanderedResourcesEffect(), new SacrificeTargetCost(new TargetControlledPermanent(filter))));
}
public SquanderedResources(final SquanderedResources card) {