mirror of
https://github.com/correl/mage.git
synced 2024-12-25 19:25:41 +00:00
Reimplemented alternative costs a little (converted to interface)
This commit is contained in:
parent
7ddf5e8074
commit
015ea665af
6 changed files with 169 additions and 86 deletions
|
@ -28,11 +28,10 @@
|
|||
|
||||
package mage.sets.magic2011;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Rarity;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.costs.AlternativeCost;
|
||||
import mage.abilities.costs.AlternativeCostImpl;
|
||||
import mage.abilities.costs.common.PayLifeCost;
|
||||
import mage.abilities.costs.common.SacrificeTargetCost;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
|
@ -41,6 +40,8 @@ import mage.cards.CardImpl;
|
|||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.target.common.TargetControlledPermanent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -71,7 +72,7 @@ public class DemonOfDeathsGate extends CardImpl<DemonOfDeathsGate> {
|
|||
|
||||
}
|
||||
|
||||
class DemonOfDeathsGateAlternativeCost extends AlternativeCost<DemonOfDeathsGateAlternativeCost> {
|
||||
class DemonOfDeathsGateAlternativeCost extends AlternativeCostImpl<DemonOfDeathsGateAlternativeCost> {
|
||||
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("black creature");
|
||||
|
||||
static {
|
||||
|
|
|
@ -28,11 +28,10 @@
|
|||
|
||||
package mage.sets.zendikar;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Rarity;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.AlternativeCost;
|
||||
import mage.abilities.costs.AlternativeCostImpl;
|
||||
import mage.abilities.costs.mana.GenericManaCost;
|
||||
import mage.abilities.effects.common.PutLibraryIntoGraveTargetEffect;
|
||||
import mage.cards.CardImpl;
|
||||
|
@ -43,85 +42,86 @@ import mage.target.common.TargetOpponent;
|
|||
import mage.watchers.Watcher;
|
||||
import mage.watchers.WatcherImpl;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ArchiveTrap extends CardImpl<ArchiveTrap> {
|
||||
|
||||
public ArchiveTrap(UUID ownerId) {
|
||||
super(ownerId, 41, "Archive Trap", Rarity.RARE, new CardType[]{CardType.INSTANT}, "{3}{U}{U}");
|
||||
this.expansionSetCode = "ZEN";
|
||||
this.color.setBlue(true);
|
||||
this.getSpellAbility().addTarget(new TargetOpponent());
|
||||
this.getSpellAbility().addEffect(new PutLibraryIntoGraveTargetEffect(13));
|
||||
this.getSpellAbility().addAlternativeCost(new ArchiveTrapAlternativeCost());
|
||||
this.addWatcher(new ArchiveTrapWatcher());
|
||||
}
|
||||
public ArchiveTrap(UUID ownerId) {
|
||||
super(ownerId, 41, "Archive Trap", Rarity.RARE, new CardType[]{CardType.INSTANT}, "{3}{U}{U}");
|
||||
this.expansionSetCode = "ZEN";
|
||||
this.color.setBlue(true);
|
||||
this.getSpellAbility().addTarget(new TargetOpponent());
|
||||
this.getSpellAbility().addEffect(new PutLibraryIntoGraveTargetEffect(13));
|
||||
this.getSpellAbility().addAlternativeCost(new ArchiveTrapAlternativeCost());
|
||||
this.addWatcher(new ArchiveTrapWatcher());
|
||||
}
|
||||
|
||||
public ArchiveTrap(final ArchiveTrap card) {
|
||||
super(card);
|
||||
}
|
||||
public ArchiveTrap(final ArchiveTrap card) {
|
||||
super(card);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArchiveTrap copy() {
|
||||
return new ArchiveTrap(this);
|
||||
}
|
||||
@Override
|
||||
public ArchiveTrap copy() {
|
||||
return new ArchiveTrap(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ArchiveTrapWatcher extends WatcherImpl<ArchiveTrapWatcher> {
|
||||
|
||||
public ArchiveTrapWatcher() {
|
||||
super("LibrarySearched");
|
||||
}
|
||||
public ArchiveTrapWatcher() {
|
||||
super("LibrarySearched");
|
||||
}
|
||||
|
||||
public ArchiveTrapWatcher(final ArchiveTrapWatcher watcher) {
|
||||
super(watcher);
|
||||
}
|
||||
public ArchiveTrapWatcher(final ArchiveTrapWatcher watcher) {
|
||||
super(watcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArchiveTrapWatcher copy() {
|
||||
return new ArchiveTrapWatcher(this);
|
||||
}
|
||||
@Override
|
||||
public ArchiveTrapWatcher copy() {
|
||||
return new ArchiveTrapWatcher(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (condition == true) //no need to check - condition has already occured
|
||||
return;
|
||||
if (event.getType() == EventType.LIBRARY_SEARCHED && game.getOpponents(controllerId).contains(event.getPlayerId()))
|
||||
condition = true;
|
||||
}
|
||||
if (event.getType() == EventType.LIBRARY_SEARCHED && game.getOpponents(controllerId).contains(event.getPlayerId()))
|
||||
condition = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ArchiveTrapAlternativeCost extends AlternativeCost<ArchiveTrapAlternativeCost> {
|
||||
class ArchiveTrapAlternativeCost extends AlternativeCostImpl<ArchiveTrapAlternativeCost> {
|
||||
|
||||
public ArchiveTrapAlternativeCost() {
|
||||
super("you may pay {0} rather than pay Archive Trap's mana cost");
|
||||
this.add(new GenericManaCost(0));
|
||||
}
|
||||
public ArchiveTrapAlternativeCost() {
|
||||
super("you may pay {0} rather than pay Archive Trap's mana cost");
|
||||
this.add(new GenericManaCost(0));
|
||||
}
|
||||
|
||||
public ArchiveTrapAlternativeCost(final ArchiveTrapAlternativeCost cost) {
|
||||
super(cost);
|
||||
}
|
||||
public ArchiveTrapAlternativeCost(final ArchiveTrapAlternativeCost cost) {
|
||||
super(cost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArchiveTrapAlternativeCost copy() {
|
||||
return new ArchiveTrapAlternativeCost(this);
|
||||
}
|
||||
@Override
|
||||
public ArchiveTrapAlternativeCost copy() {
|
||||
return new ArchiveTrapAlternativeCost(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(Game game, Ability source) {
|
||||
Watcher watcher = game.getState().getWatchers().get(source.getControllerId(), "LibrarySearched");
|
||||
if (watcher != null && watcher.conditionMet())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isAvailable(Game game, Ability source) {
|
||||
Watcher watcher = game.getState().getWatchers().get(source.getControllerId(), "LibrarySearched");
|
||||
if (watcher != null && watcher.conditionMet())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return "If an opponent searched his or her library this turn, you may pay {0} rather than pay Archive Trap's mana cost";
|
||||
}
|
||||
@Override
|
||||
public String getText() {
|
||||
return "If an opponent searched his or her library this turn, you may pay {0} rather than pay Archive Trap's mana cost";
|
||||
}
|
||||
|
||||
}
|
|
@ -32,27 +32,10 @@ import mage.abilities.Ability;
|
|||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public abstract class AlternativeCost<T extends AlternativeCost<T>> extends CostsImpl<Cost> {
|
||||
public interface AlternativeCost extends Cost {
|
||||
public boolean isAvailable(Game game, Ability source);
|
||||
|
||||
protected String name;
|
||||
|
||||
public AlternativeCost(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public AlternativeCost(final AlternativeCost<T> cost) {
|
||||
super(cost);
|
||||
this.name = cost.name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isAvailable(Game game, Ability source) {
|
||||
return true;
|
||||
}
|
||||
public String getName();
|
||||
}
|
||||
|
|
|
@ -1,14 +1,34 @@
|
|||
package mage.abilities.costs;
|
||||
|
||||
public class AlternativeCostImpl extends AlternativeCost<AlternativeCostImpl> {
|
||||
import mage.abilities.Ability;
|
||||
import mage.game.Game;
|
||||
|
||||
public class AlternativeCostImpl<T extends AlternativeCostImpl<T>> extends CostsImpl<Cost> implements AlternativeCost {
|
||||
|
||||
protected String name;
|
||||
|
||||
public AlternativeCostImpl(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public AlternativeCostImpl(String name, Cost cost) {
|
||||
super(name);
|
||||
this.name = name;
|
||||
this.add(cost);
|
||||
}
|
||||
|
||||
public AlternativeCostImpl(final AlternativeCostImpl cost) {
|
||||
super(cost);
|
||||
this.name = cost.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(Game game, Ability source) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
67
Mage/src/mage/abilities/costs/common/FlashbackCost.java
Normal file
67
Mage/src/mage/abilities/costs/common/FlashbackCost.java
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright 2011 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.costs.common;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.AlternativeCostImpl;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* DON'T USE. DOESN'T WORK FOR NOW.
|
||||
* FOR FUTURE USE ONLY.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
@Deprecated
|
||||
public class FlashbackCost extends AlternativeCostImpl<FlashbackCost> {
|
||||
|
||||
public FlashbackCost(ManaCost cost) {
|
||||
super("Flashback", cost);
|
||||
}
|
||||
|
||||
protected FlashbackCost(FlashbackCost flashbackCost) {
|
||||
super(flashbackCost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(Game game, Ability source) {
|
||||
Constants.Zone zone = game.getZone(source.getSourceId());
|
||||
if (zone != null) {
|
||||
return zone.equals(Constants.Zone.GRAVEYARD);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlashbackCost copy() {
|
||||
return new FlashbackCost(this);
|
||||
}
|
||||
}
|
|
@ -47,6 +47,7 @@ import mage.Mana;
|
|||
import mage.abilities.*;
|
||||
import mage.abilities.common.PassAbility;
|
||||
import mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility;
|
||||
import mage.abilities.costs.AlternativeCost;
|
||||
import mage.abilities.effects.RestrictionEffect;
|
||||
import mage.abilities.effects.common.LoseControlOnOtherPlayersControllerEffect;
|
||||
import mage.abilities.keyword.*;
|
||||
|
@ -629,10 +630,21 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
if (ability.canActivate(playerId, game))
|
||||
useable.put(ability.getId(), ability);
|
||||
}
|
||||
if (zone != Zone.HAND && game.getContinuousEffects().asThough(object.getId(), AsThoughEffectType.CAST, game)) {
|
||||
for (ActivatedAbility ability: object.getAbilities().getActivatedAbilities(Zone.HAND)) {
|
||||
useable.put(ability.getId(), ability);
|
||||
}
|
||||
if (zone != Zone.HAND) {
|
||||
if (game.getContinuousEffects().asThough(object.getId(), AsThoughEffectType.CAST, game)) {
|
||||
for (ActivatedAbility ability: object.getAbilities().getActivatedAbilities(Zone.HAND)) {
|
||||
useable.put(ability.getId(), ability);
|
||||
}
|
||||
} else {
|
||||
// this allows alternative costs like Flashback work from other than hand zones
|
||||
for (ActivatedAbility ability: object.getAbilities().getActivatedAbilities(Zone.HAND)) {
|
||||
for (AlternativeCost cost: ability.getAlternativeCosts()) {
|
||||
if (cost.isAvailable(game, ability)) {
|
||||
useable.put(ability.getId(), ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return useable;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue