From fc182e2978847b7c55eea9688497c2b0df3ad0fc Mon Sep 17 00:00:00 2001 From: North Date: Wed, 5 Oct 2011 22:00:46 +0300 Subject: [PATCH] Refactoring --- .../mage/sets/zendikar/FelidarSovereign.java | 57 ++++++++------- .../effects/common/ControllerWinsEffect.java | 70 ------------------- 2 files changed, 30 insertions(+), 97 deletions(-) delete mode 100644 Mage/src/mage/abilities/effects/common/ControllerWinsEffect.java diff --git a/Mage.Sets/src/mage/sets/zendikar/FelidarSovereign.java b/Mage.Sets/src/mage/sets/zendikar/FelidarSovereign.java index da776beb2aa..af90e347d69 100644 --- a/Mage.Sets/src/mage/sets/zendikar/FelidarSovereign.java +++ b/Mage.Sets/src/mage/sets/zendikar/FelidarSovereign.java @@ -28,20 +28,22 @@ package mage.sets.zendikar; import java.util.UUID; -import mage.Constants; import mage.Constants.CardType; +import mage.Constants.Outcome; import mage.Constants.Rarity; +import mage.Constants.TargetController; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.TriggeredAbility; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.condition.Condition; import mage.abilities.decorator.ConditionalTriggeredAbility; -import mage.abilities.effects.common.ControllerWinsEffect; +import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.VigilanceAbility; import mage.abilities.keyword.LifelinkAbility; import mage.cards.CardImpl; import mage.game.Game; +import mage.players.Player; /** * @@ -62,8 +64,8 @@ public class FelidarSovereign extends CardImpl { this.addAbility(VigilanceAbility.getInstance()); this.addAbility(LifelinkAbility.getInstance()); // At the beginning of your upkeep, if you have 40 or more life, you win the game. - TriggeredAbility ability = new BeginningOfUpkeepTriggeredAbility(new ControllerWinsEffect(), Constants.TargetController.YOU, false); - this.addAbility(new ConditionalTriggeredAbility(ability, new FortyOrMoreLifeCondition(FortyOrMoreLifeCondition.CheckType.CONTROLLER), "At the beginning of your upkeep, if you have 40 or more life, you win the game.")); + TriggeredAbility ability = new BeginningOfUpkeepTriggeredAbility(new FelidarSovereignEffect(), TargetController.YOU, false); + this.addAbility(new ConditionalTriggeredAbility(ability, new FortyOrMoreLifeCondition(), "At the beginning of your upkeep, if you have 40 or more life, you win the game.")); } @@ -79,34 +81,35 @@ public class FelidarSovereign extends CardImpl { class FortyOrMoreLifeCondition implements Condition { - public static enum CheckType { + @Override + public boolean apply(Game game, Ability source) { + return game.getPlayer(source.getControllerId()).getLife() >= 40; + } +} - AN_OPPONENT, CONTROLLER, TARGET_OPPONENT - }; - private CheckType type; +class FelidarSovereignEffect extends OneShotEffect { - public FortyOrMoreLifeCondition(CheckType type) { - this.type = type; + public FelidarSovereignEffect() { + super(Outcome.Win); + this.staticText = "you win the game"; + } + + public FelidarSovereignEffect(final FelidarSovereignEffect effect) { + super(effect); + } + + @Override + public FelidarSovereignEffect copy() { + return new FelidarSovereignEffect(this); } @Override public boolean apply(Game game, Ability source) { - boolean conditionApplies = false; - - switch (this.type) { - case AN_OPPONENT: - for (UUID opponentUUID : game.getOpponents(source.getControllerId())) { - conditionApplies |= game.getPlayer(opponentUUID).getLife() >= 40; - } - break; - case CONTROLLER: - conditionApplies |= game.getPlayer(source.getControllerId()).getLife() >= 40; - break; - case TARGET_OPPONENT: - //TODO: Implement this. - break; + Player player = game.getPlayer(source.getControllerId()); + if (player != null) { + player.won(game); + return true; } - - return conditionApplies; + return false; } -} \ No newline at end of file +} diff --git a/Mage/src/mage/abilities/effects/common/ControllerWinsEffect.java b/Mage/src/mage/abilities/effects/common/ControllerWinsEffect.java deleted file mode 100644 index 1d490e6fa2b..00000000000 --- a/Mage/src/mage/abilities/effects/common/ControllerWinsEffect.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.abilities.effects.common; - -import mage.Constants.Outcome; -import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; -import mage.game.Game; -import mage.players.Player; - -/** - * - * @author Rafbill - */ -public class ControllerWinsEffect extends OneShotEffect { - - public ControllerWinsEffect() { - super(Outcome.Win); - } - - public ControllerWinsEffect(final ControllerWinsEffect effect) { - super(effect); - } - - @Override - public ControllerWinsEffect copy() { - return new ControllerWinsEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - player.won(game); - return true; - } - return false; - } - - private void setText() { - staticText = "You win the game."; - } - -}