Fix Angel of Jubilation.

The Angel now properly only restricts the sacrifice of creatures.
This commit is contained in:
Nathaniel Brandes 2016-05-09 00:25:36 -07:00
parent e7a2277252
commit 43205b6f46
11 changed files with 246 additions and 38 deletions

View file

@ -31,11 +31,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostImpl;
import mage.constants.AbilityType;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.common.TargetControlledPermanent;
/**
*
@ -71,6 +74,22 @@ public class SacrificeAllCost extends CostImpl {
@Override
public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) {
UUID activator = controllerId;
if (ability.getAbilityType().equals(AbilityType.ACTIVATED) || ability.getAbilityType().equals(AbilityType.SPECIAL_ACTION)) {
if (((ActivatedAbilityImpl) ability).getActivatorId() != null) {
activator = ((ActivatedAbilityImpl) ability).getActivatorId();
} else {
// Aktivator not filled?
activator = controllerId;
}
}
for (Permanent permanent :game.getBattlefield().getAllActivePermanents(filter, controllerId, game)) {
if(!game.getPlayer(activator).canPaySacrificeCost(permanent, sourceId, controllerId, game)) {
return false;
}
}
return true;
}

View file

@ -59,11 +59,9 @@ public class SacrificeSourceCost extends CostImpl {
@Override
public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) {
if (!game.getPlayer(controllerId).canPaySacrificeCost()) {
return false;
}
Permanent permanent = game.getPermanent(sourceId);
return permanent != null;
return permanent != null && game.getPlayer(controllerId).canPaySacrificeCost(permanent, sourceId, controllerId, game);
}
@Override

View file

@ -30,6 +30,7 @@ package mage.abilities.costs.common;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.costs.Cost;
@ -51,7 +52,7 @@ public class SacrificeTargetCost extends CostImpl {
public SacrificeTargetCost(TargetControlledPermanent target) {
this.addTarget(target);
target.setNotTarget(true); // sacrifice is never targeted
this.text = "sacrifice " + target.getTargetName();
this.text = "sacrifice a " + target.getTargetName();
target.setTargetName(target.getTargetName() + " (to sacrifice)");
}
@ -99,10 +100,15 @@ public class SacrificeTargetCost extends CostImpl {
activator = controllerId;
}
}
if (!game.getPlayer(activator).canPaySacrificeCost()) {
return false;
int validTargets = 0;
for (Permanent permanent :game.getBattlefield().getAllActivePermanents(((TargetControlledPermanent)targets.get(0)).getFilter(), controllerId, game)) {
if(game.getPlayer(activator).canPaySacrificeCost(permanent, sourceId, controllerId, game)) {
validTargets++;
}
}
return targets.canChoose(activator, game);
return validTargets > 0;
}
@Override

View file

@ -62,6 +62,7 @@ import mage.constants.RangeOfInfluence;
import mage.constants.Zone;
import mage.counters.Counter;
import mage.counters.Counters;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.Graveyard;
import mage.game.Table;
@ -132,9 +133,11 @@ public interface Player extends MageItem, Copyable<Player> {
boolean canPayLifeCost();
void setCanPaySacrificeCost(boolean canPaySacrificeCost);
void setCanPaySacrificeCostFilter(FilterPermanent filter);
FilterPermanent getSacrificeCostFilter();
boolean canPaySacrificeCost();
boolean canPaySacrificeCost(Permanent permanent, UUID sourceId, UUID controllerId, Game game);
void setLifeTotalCanChange(boolean lifeTotalCanChange);

View file

@ -99,6 +99,7 @@ import mage.counters.Counter;
import mage.counters.CounterType;
import mage.counters.Counters;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.common.FilterCreatureForCombat;
import mage.filter.common.FilterCreatureForCombatBlock;
@ -200,9 +201,10 @@ public abstract class PlayerImpl implements Player, Serializable {
protected boolean canGainLife = true;
protected boolean canLoseLife = true;
protected boolean canPayLifeCost = true;
protected boolean canPaySacrificeCost = true;
protected boolean loseByZeroOrLessLife = true;
protected boolean canPlayCardsFromGraveyard = true;
protected FilterPermanent sacrificeCostFilter;
protected final List<AlternativeSourceCosts> alternativeSourceCosts = new ArrayList<>();
@ -299,7 +301,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.inRange.addAll(player.inRange);
this.userData = player.userData;
this.canPayLifeCost = player.canPayLifeCost;
this.canPaySacrificeCost = player.canPaySacrificeCost;
this.sacrificeCostFilter = player.sacrificeCostFilter;
this.alternativeSourceCosts.addAll(player.alternativeSourceCosts);
this.storedBookmark = player.storedBookmark;
@ -378,7 +380,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.inRange.clear();
this.inRange.addAll(player.getInRange());
this.canPayLifeCost = player.canPayLifeCost();
this.canPaySacrificeCost = player.canPaySacrificeCost();
this.sacrificeCostFilter = player.getSacrificeCostFilter() != null ? player.getSacrificeCostFilter().copy() : null;
this.loseByZeroOrLessLife = player.canLoseByZeroOrLessLife();
this.canPlayCardsFromGraveyard = player.canPlayCardsFromGraveyard();
this.alternativeSourceCosts.addAll(player.getAlternativeSourceCosts());
@ -476,7 +478,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.canGainLife = true;
this.canLoseLife = true;
this.canPayLifeCost = true;
this.canPaySacrificeCost = true;
this.sacrificeCostFilter = null;
this.loseByZeroOrLessLife = true;
this.canPlayCardsFromGraveyard = false;
this.topCardRevealed = false;
@ -2937,13 +2939,18 @@ public abstract class PlayerImpl implements Player, Serializable {
}
@Override
public boolean canPaySacrificeCost() {
return canPaySacrificeCost;
public boolean canPaySacrificeCost(Permanent permanent, UUID sourceId, UUID controllerId, Game game) {
return sacrificeCostFilter == null || !sacrificeCostFilter.match(permanent, sourceId, controllerId, game);
}
@Override
public void setCanPaySacrificeCost(boolean canPaySacrificeCost) {
this.canPaySacrificeCost = canPaySacrificeCost;
public void setCanPaySacrificeCostFilter(FilterPermanent filter) {
this.sacrificeCostFilter = filter;
}
@Override
public FilterPermanent getSacrificeCostFilter() {
return sacrificeCostFilter;
}
@Override