mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 05:52:06 -08:00
Fixed that some AlternativeCostSourceAbilities had no sourceId set.
This commit is contained in:
parent
0a66f1fca0
commit
4050631807
9 changed files with 113 additions and 37 deletions
|
|
@ -16,6 +16,7 @@ import mage.players.Player;
|
|||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Iterator;
|
||||
import mage.MageObject;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
|
|
@ -135,7 +136,6 @@ public class AlternativeCostSourceAbility extends StaticAbility implements Alter
|
|||
} else {
|
||||
costChoiceText = alternativeCostsToCheck.isEmpty() ? "Cast without paying its mana cost?" : "Pay alternative costs? (" + alternativeCostsToCheck.getText() + ')';
|
||||
}
|
||||
|
||||
if (alternativeCostsToCheck.canPay(ability, ability.getSourceId(), ability.getControllerId(), game)
|
||||
&& player.chooseUse(Outcome.Benefit, costChoiceText, this, game)) {
|
||||
if (ability instanceof SpellAbility) {
|
||||
|
|
|
|||
|
|
@ -20,9 +20,8 @@ import java.util.UUID;
|
|||
|
||||
public class CastFromHandWithoutPayingManaCostEffect extends ContinuousEffectImpl {
|
||||
|
||||
private final FilterCard filter;
|
||||
private final boolean fromHand;
|
||||
|
||||
private final AlternativeCostSourceAbility alternativeCastingCostAbility;
|
||||
|
||||
public CastFromHandWithoutPayingManaCostEffect() {
|
||||
this(StaticFilters.FILTER_CARDS_NON_LAND, true);
|
||||
}
|
||||
|
|
@ -33,8 +32,13 @@ public class CastFromHandWithoutPayingManaCostEffect extends ContinuousEffectImp
|
|||
|
||||
public CastFromHandWithoutPayingManaCostEffect(FilterCard filter, boolean fromHand, Duration duration) {
|
||||
super(duration, Outcome.Detriment);
|
||||
this.filter = filter;
|
||||
this.fromHand = fromHand;
|
||||
Condition condition;
|
||||
if (fromHand) {
|
||||
condition = new CompoundCondition(SourceIsSpellCondition.instance, IsBeingCastFromHandCondition.instance);
|
||||
} else {
|
||||
condition = SourceIsSpellCondition.instance;
|
||||
}
|
||||
this.alternativeCastingCostAbility = new AlternativeCostSourceAbility(null, condition, null, filter, true);
|
||||
this.staticText = "You may cast " + filter.getMessage()
|
||||
+ (fromHand ? " from your hand" : "")
|
||||
+ " without paying their mana costs";
|
||||
|
|
@ -42,8 +46,7 @@ public class CastFromHandWithoutPayingManaCostEffect extends ContinuousEffectImp
|
|||
|
||||
private CastFromHandWithoutPayingManaCostEffect(final CastFromHandWithoutPayingManaCostEffect effect) {
|
||||
super(effect);
|
||||
this.filter = effect.filter;
|
||||
this.fromHand = effect.fromHand;
|
||||
this.alternativeCastingCostAbility = effect.alternativeCastingCostAbility;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -51,21 +54,19 @@ public class CastFromHandWithoutPayingManaCostEffect extends ContinuousEffectImp
|
|||
return new CastFromHandWithoutPayingManaCostEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Ability source, Game game, UUID activePlayerId) {
|
||||
super.init(source, game, activePlayerId);
|
||||
alternativeCastingCostAbility.setSourceId(source.getSourceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
Condition condition;
|
||||
if (fromHand) {
|
||||
condition = new CompoundCondition(SourceIsSpellCondition.instance, IsBeingCastFromHandCondition.instance);
|
||||
} else {
|
||||
condition = SourceIsSpellCondition.instance;
|
||||
}
|
||||
controller.getAlternativeSourceCosts().add(new AlternativeCostSourceAbility(
|
||||
null, condition, null, filter, true
|
||||
));
|
||||
controller.getAlternativeSourceCosts().add(alternativeCastingCostAbility);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +93,7 @@ enum IsBeingCastFromHandCondition implements Condition {
|
|||
}
|
||||
if (object instanceof Spell) { // needed to check if it can be cast by alternate cost
|
||||
Spell spell = (Spell) object;
|
||||
return spell.getFromZone() == Zone.HAND;
|
||||
return Zone.HAND.equals(spell.getFromZone());
|
||||
}
|
||||
if (object instanceof Card) { // needed for the check what's playable
|
||||
Card card = (Card) object;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
package mage.abilities.effects.common.continuous;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.common.SourceIsSpellCondition;
|
||||
import mage.abilities.costs.AlternativeCostSourceAbility;
|
||||
|
|
@ -19,7 +20,7 @@ import mage.players.Player;
|
|||
*/
|
||||
public class WUBRGInsteadEffect extends ContinuousEffectImpl {
|
||||
|
||||
static AlternativeCostSourceAbility alternativeCastingCostAbility = new AlternativeCostSourceAbility(new ManaCostsImpl("{W}{U}{B}{R}{G}"), SourceIsSpellCondition.instance);
|
||||
private final AlternativeCostSourceAbility alternativeCastingCostAbility = new AlternativeCostSourceAbility(new ManaCostsImpl("{W}{U}{B}{R}{G}"), SourceIsSpellCondition.instance);
|
||||
|
||||
public WUBRGInsteadEffect() {
|
||||
super(Duration.WhileOnBattlefield, Outcome.Detriment);
|
||||
|
|
@ -35,6 +36,12 @@ public class WUBRGInsteadEffect extends ContinuousEffectImpl {
|
|||
return new WUBRGInsteadEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Ability source, Game game, UUID activePlayerId) {
|
||||
super.init(source, game, activePlayerId);
|
||||
alternativeCastingCostAbility.setSourceId(source.getSourceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue