mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00: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
|
@ -29,6 +29,7 @@ package mage.sets.magic2013;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.condition.CompoundCondition;
|
||||
|
@ -36,6 +37,7 @@ import mage.abilities.condition.Condition;
|
|||
import mage.abilities.condition.common.SourceIsSpellCondition;
|
||||
import mage.abilities.costs.AlternativeCostSourceAbility;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
|
@ -96,7 +98,7 @@ class OmniscienceCastingEffect extends ContinuousEffectImpl {
|
|||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
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 false;
|
||||
|
@ -113,12 +115,21 @@ class OmniscienceCastingEffect extends ContinuousEffectImpl {
|
|||
}
|
||||
}
|
||||
|
||||
class SpellIsBeingCastFromHandCondition implements Condition {
|
||||
class IsBeingCastFromHandCondition implements Condition {
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Spell spell = (Spell) game.getObject(source.getSourceId());
|
||||
return spell != null && spell.getFromZone() == Zone.HAND;
|
||||
MageObject object = game.getObject(source.getSourceId());
|
||||
if(object instanceof Spell) {
|
||||
Spell spell = (Spell) object;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -2238,36 +2238,64 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
}
|
||||
|
||||
protected boolean canPlayCardByAlternateCost(Card sourceObject, ManaOptions available, Ability ability, Game game) {
|
||||
if (sourceObject != null && !(sourceObject instanceof Permanent)) {
|
||||
for (Ability alternateSourceCostsAbility : sourceObject.getAbilities()) {
|
||||
// if cast for noMana no Alternative costs are allowed
|
||||
if (alternateSourceCostsAbility instanceof AlternativeSourceCosts) {
|
||||
if (((AlternativeSourceCosts) alternateSourceCostsAbility).isAvailable(ability, game)) {
|
||||
if (alternateSourceCostsAbility.getCosts().canPay(ability, playerId, playerId, game)) {
|
||||
ManaCostsImpl manaCosts = new ManaCostsImpl();
|
||||
for (Cost cost : alternateSourceCostsAbility.getCosts()) {
|
||||
if (cost instanceof ManaCost) {
|
||||
manaCosts.add((ManaCost) cost);
|
||||
}
|
||||
}
|
||||
if (sourceObject != null && !(sourceObject instanceof Permanent)) {
|
||||
for (Ability alternateSourceCostsAbility : sourceObject.getAbilities()) {
|
||||
// if cast for noMana no Alternative costs are allowed
|
||||
if (alternateSourceCostsAbility instanceof AlternativeSourceCosts) {
|
||||
if (((AlternativeSourceCosts) alternateSourceCostsAbility).isAvailable(ability, game)) {
|
||||
if (alternateSourceCostsAbility.getCosts().canPay(ability, playerId, playerId, game)) {
|
||||
ManaCostsImpl manaCosts = new ManaCostsImpl();
|
||||
for (Cost cost : alternateSourceCostsAbility.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;
|
||||
if (manaCosts.size() == 0) {
|
||||
return true;
|
||||
} else {
|
||||
for (Mana mana : manaCosts.getOptions()) {
|
||||
for (Mana avail : available) {
|
||||
if (mana.enough(avail)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
protected boolean canLandPlayAlternateSourceCostsAbility(Card sourceObject, ManaOptions available, Ability ability, Game game) {
|
||||
|
|
Loading…
Reference in a new issue