mirror of
https://github.com/correl/mage.git
synced 2025-04-14 01:01:08 -09:00
Added global alternate costs to canPlay test. Added Omniscienece test
case.
This commit is contained in:
parent
9ab812f1ac
commit
4b6993f398
3 changed files with 117 additions and 33 deletions
Mage.Sets/src/mage/sets/magic2013
Mage.Tests/src/test/java/org/mage/test/cards/cost/alternate
Mage/src/mage/players
|
@ -29,6 +29,7 @@ package mage.sets.magic2013;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.condition.CompoundCondition;
|
import mage.abilities.condition.CompoundCondition;
|
||||||
|
@ -36,6 +37,7 @@ import mage.abilities.condition.Condition;
|
||||||
import mage.abilities.condition.common.SourceIsSpellCondition;
|
import mage.abilities.condition.common.SourceIsSpellCondition;
|
||||||
import mage.abilities.costs.AlternativeCostSourceAbility;
|
import mage.abilities.costs.AlternativeCostSourceAbility;
|
||||||
import mage.abilities.effects.ContinuousEffectImpl;
|
import mage.abilities.effects.ContinuousEffectImpl;
|
||||||
|
import mage.cards.Card;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.constants.Duration;
|
import mage.constants.Duration;
|
||||||
|
@ -96,7 +98,7 @@ class OmniscienceCastingEffect extends ContinuousEffectImpl {
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
controller.getAlternativeSourceCosts().add(new AlternativeCostSourceAbility(
|
controller.getAlternativeSourceCosts().add(new AlternativeCostSourceAbility(
|
||||||
null, new CompoundCondition(SourceIsSpellCondition.getInstance(), new SpellIsBeingCastFromHandCondition()), null, new FilterNonlandCard(), true));
|
null, new CompoundCondition(SourceIsSpellCondition.getInstance(), new IsBeingCastFromHandCondition()), null, new FilterNonlandCard(), true));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -113,12 +115,21 @@ class OmniscienceCastingEffect extends ContinuousEffectImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SpellIsBeingCastFromHandCondition implements Condition {
|
class IsBeingCastFromHandCondition implements Condition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Spell spell = (Spell) game.getObject(source.getSourceId());
|
MageObject object = game.getObject(source.getSourceId());
|
||||||
|
if(object instanceof Spell) {
|
||||||
|
Spell spell = (Spell) object;
|
||||||
return spell != null && spell.getFromZone() == Zone.HAND;
|
return spell != null && spell.getFromZone() == Zone.HAND;
|
||||||
}
|
}
|
||||||
|
if(object instanceof Card) {
|
||||||
|
Card card = (Card)object;
|
||||||
|
return game.getPlayer(card.getOwnerId()).getHand().get(card.getId(), game) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.mage.test.cards.cost.alternate;
|
||||||
|
|
||||||
|
import mage.constants.PhaseStep;
|
||||||
|
import mage.constants.Zone;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||||
|
|
||||||
|
public class OmniscienceTest extends CardTestPlayerBase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSpellNoCost() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Omniscience", 1);
|
||||||
|
|
||||||
|
addCard(Zone.HAND, playerA, "Gray Ogre", 1);
|
||||||
|
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Gray Ogre");
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
//Gray Ogre is cast because it is free
|
||||||
|
assertPermanentCount(playerA, "Gray Ogre", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSpellHasCostIfCastFromGraveyard() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Omniscience", 1);
|
||||||
|
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Haakon, Stromgald Scourge", 1);
|
||||||
|
|
||||||
|
addCard(Zone.GRAVEYARD, playerA, "Knight of the White Orchid", 1);
|
||||||
|
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Knight of the White Orchid");
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
//Knight of the White Orchid was not cast due to lack of mana
|
||||||
|
assertPermanentCount(playerA, "Knight of the White Orchid", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -2266,6 +2266,34 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// controller specific alternate spell costs
|
||||||
|
for (AlternativeSourceCosts alternativeSourceCosts: getAlternativeSourceCosts()) {
|
||||||
|
if (alternativeSourceCosts instanceof Ability) {
|
||||||
|
if (((AlternativeSourceCosts) alternativeSourceCosts).isAvailable(ability, game)) {
|
||||||
|
if (((Ability) alternativeSourceCosts).getCosts().canPay(ability, playerId, playerId, game)) {
|
||||||
|
ManaCostsImpl manaCosts = new ManaCostsImpl();
|
||||||
|
for (Cost cost : ((Ability) alternativeSourceCosts).getCosts()) {
|
||||||
|
if (cost instanceof ManaCost) {
|
||||||
|
manaCosts.add((ManaCost) cost);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (manaCosts.size() == 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
for (Mana mana : manaCosts.getOptions()) {
|
||||||
|
for (Mana avail : available) {
|
||||||
|
if (mana.enough(avail)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue