mirror of
https://github.com/correl/mage.git
synced 2025-03-16 17:00:13 -09: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;
|
package mage.sets.magic2011;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.Constants.CardType;
|
import mage.Constants.CardType;
|
||||||
import mage.Constants.Rarity;
|
import mage.Constants.Rarity;
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.abilities.costs.AlternativeCost;
|
import mage.abilities.costs.AlternativeCostImpl;
|
||||||
import mage.abilities.costs.common.PayLifeCost;
|
import mage.abilities.costs.common.PayLifeCost;
|
||||||
import mage.abilities.costs.common.SacrificeTargetCost;
|
import mage.abilities.costs.common.SacrificeTargetCost;
|
||||||
import mage.abilities.keyword.FlyingAbility;
|
import mage.abilities.keyword.FlyingAbility;
|
||||||
|
@ -41,6 +40,8 @@ import mage.cards.CardImpl;
|
||||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||||
import mage.target.common.TargetControlledPermanent;
|
import mage.target.common.TargetControlledPermanent;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @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");
|
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("black creature");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
|
@ -28,11 +28,10 @@
|
||||||
|
|
||||||
package mage.sets.zendikar;
|
package mage.sets.zendikar;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.Constants.CardType;
|
import mage.Constants.CardType;
|
||||||
import mage.Constants.Rarity;
|
import mage.Constants.Rarity;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.costs.AlternativeCost;
|
import mage.abilities.costs.AlternativeCostImpl;
|
||||||
import mage.abilities.costs.mana.GenericManaCost;
|
import mage.abilities.costs.mana.GenericManaCost;
|
||||||
import mage.abilities.effects.common.PutLibraryIntoGraveTargetEffect;
|
import mage.abilities.effects.common.PutLibraryIntoGraveTargetEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
|
@ -43,8 +42,9 @@ import mage.target.common.TargetOpponent;
|
||||||
import mage.watchers.Watcher;
|
import mage.watchers.Watcher;
|
||||||
import mage.watchers.WatcherImpl;
|
import mage.watchers.WatcherImpl;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class ArchiveTrap extends CardImpl<ArchiveTrap> {
|
public class ArchiveTrap extends CardImpl<ArchiveTrap> {
|
||||||
|
@ -95,7 +95,7 @@ class ArchiveTrapWatcher extends WatcherImpl<ArchiveTrapWatcher> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ArchiveTrapAlternativeCost extends AlternativeCost<ArchiveTrapAlternativeCost> {
|
class ArchiveTrapAlternativeCost extends AlternativeCostImpl<ArchiveTrapAlternativeCost> {
|
||||||
|
|
||||||
public ArchiveTrapAlternativeCost() {
|
public ArchiveTrapAlternativeCost() {
|
||||||
super("you may pay {0} rather than pay Archive Trap's mana cost");
|
super("you may pay {0} rather than pay Archive Trap's mana cost");
|
||||||
|
|
|
@ -32,27 +32,10 @@ import mage.abilities.Ability;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @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 String getName();
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,34 @@
|
||||||
package mage.abilities.costs;
|
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) {
|
public AlternativeCostImpl(String name, Cost cost) {
|
||||||
super(name);
|
this.name = name;
|
||||||
this.add(cost);
|
this.add(cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AlternativeCostImpl(final AlternativeCostImpl cost) {
|
public AlternativeCostImpl(final AlternativeCostImpl cost) {
|
||||||
super(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
|
@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.*;
|
||||||
import mage.abilities.common.PassAbility;
|
import mage.abilities.common.PassAbility;
|
||||||
import mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility;
|
import mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility;
|
||||||
|
import mage.abilities.costs.AlternativeCost;
|
||||||
import mage.abilities.effects.RestrictionEffect;
|
import mage.abilities.effects.RestrictionEffect;
|
||||||
import mage.abilities.effects.common.LoseControlOnOtherPlayersControllerEffect;
|
import mage.abilities.effects.common.LoseControlOnOtherPlayersControllerEffect;
|
||||||
import mage.abilities.keyword.*;
|
import mage.abilities.keyword.*;
|
||||||
|
@ -629,10 +630,21 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
||||||
if (ability.canActivate(playerId, game))
|
if (ability.canActivate(playerId, game))
|
||||||
useable.put(ability.getId(), ability);
|
useable.put(ability.getId(), ability);
|
||||||
}
|
}
|
||||||
if (zone != Zone.HAND && game.getContinuousEffects().asThough(object.getId(), AsThoughEffectType.CAST, game)) {
|
if (zone != Zone.HAND) {
|
||||||
|
if (game.getContinuousEffects().asThough(object.getId(), AsThoughEffectType.CAST, game)) {
|
||||||
for (ActivatedAbility ability: object.getAbilities().getActivatedAbilities(Zone.HAND)) {
|
for (ActivatedAbility ability: object.getAbilities().getActivatedAbilities(Zone.HAND)) {
|
||||||
useable.put(ability.getId(), ability);
|
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;
|
return useable;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue