mirror of
https://github.com/magefree/mage.git
synced 2026-01-09 12:22:10 -08:00
Fix SacrificeTargetCost and SacrificeAllCost activator checks (#12809)
* Fix Tergrid's Lantern and add test * Remove custom effect, fix SacrificeTargetCost to avoid checking for activated abilities and sidestepping the controllerID * Add test to verify change to SacrificeTargetCost * Add special action test * Fix canPay check for SacrificeTargetCost * Remove activated ability check in SacrificeAllCost * Remove cost-specific activator checks for special actions, as they are redundant * add null check for game.getPlayer
This commit is contained in:
parent
7c179bad5e
commit
e1f76c2b6c
5 changed files with 254 additions and 30 deletions
|
|
@ -1,14 +1,13 @@
|
|||
package mage.abilities.costs.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbilityImpl;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.CostImpl;
|
||||
import mage.abilities.costs.SacrificeCost;
|
||||
import mage.constants.AbilityType;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -46,19 +45,15 @@ public class SacrificeAllCost extends CostImpl implements SacrificeCost {
|
|||
|
||||
@Override
|
||||
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
|
||||
UUID activator = controllerId;
|
||||
if (ability.getAbilityType().isActivatedAbility() || ability.getAbilityType() == AbilityType.SPECIAL_ACTION) {
|
||||
if (((ActivatedAbilityImpl) ability).getActivatorId() != null) {
|
||||
activator = ((ActivatedAbilityImpl) ability).getActivatorId();
|
||||
} // else, Activator not filled?
|
||||
Player controller = game.getPlayer(controllerId);
|
||||
if (controller == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controllerId, game)) {
|
||||
if (!game.getPlayer(activator).canPaySacrificeCost(permanent, source, controllerId, game)) {
|
||||
if (!controller.canPaySacrificeCost(permanent, source, controllerId, game)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
package mage.abilities.costs.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbilityImpl;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.CostImpl;
|
||||
import mage.abilities.costs.SacrificeCost;
|
||||
import mage.constants.AbilityType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.target.common.TargetSacrifice;
|
||||
import mage.util.CardUtil;
|
||||
|
|
@ -58,12 +57,8 @@ public class SacrificeTargetCost extends CostImpl implements SacrificeCost {
|
|||
|
||||
@Override
|
||||
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
UUID activator = controllerId;
|
||||
if (ability.getAbilityType().isActivatedAbility() || ability.getAbilityType() == AbilityType.SPECIAL_ACTION) {
|
||||
activator = ((ActivatedAbilityImpl) ability).getActivatorId();
|
||||
}
|
||||
// can be cancel by user
|
||||
if (this.getTargets().choose(Outcome.Sacrifice, activator, source.getSourceId(), source, game)) {
|
||||
// can be cancelled by user
|
||||
if (this.getTargets().choose(Outcome.Sacrifice, controllerId, source.getSourceId(), source, game)) {
|
||||
for (UUID targetId : this.getTargets().get(0).getTargets()) {
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
if (permanent == null) {
|
||||
|
|
@ -88,17 +83,14 @@ public class SacrificeTargetCost extends CostImpl implements SacrificeCost {
|
|||
|
||||
@Override
|
||||
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
|
||||
UUID activator = controllerId;
|
||||
if (ability.getAbilityType().isActivatedAbility() || ability.getAbilityType() == AbilityType.SPECIAL_ACTION) {
|
||||
if (((ActivatedAbilityImpl) ability).getActivatorId() != null) {
|
||||
activator = ((ActivatedAbilityImpl) ability).getActivatorId();
|
||||
} // else, Activator not filled?
|
||||
Player controller = game.getPlayer(controllerId);
|
||||
if (controller == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
int validTargets = 0;
|
||||
int neededTargets = this.getTargets().get(0).getNumberOfTargets();
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(((TargetPermanent) this.getTargets().get(0)).getFilter(), controllerId, source, game)) {
|
||||
if (game.getPlayer(activator).canPaySacrificeCost(permanent, source, controllerId, game)) {
|
||||
if (controller.canPaySacrificeCost(permanent, source, controllerId, game)) {
|
||||
validTargets++;
|
||||
if (validTargets >= neededTargets) {
|
||||
return true;
|
||||
|
|
@ -106,10 +98,7 @@ public class SacrificeTargetCost extends CostImpl implements SacrificeCost {
|
|||
}
|
||||
}
|
||||
// solves issue #8097, if a sacrifice cost is optional and you don't have valid targets, then the cost can be paid
|
||||
if (validTargets == 0 && this.getTargets().get(0).getMinNumberOfTargets() == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return validTargets == 0 && this.getTargets().get(0).getMinNumberOfTargets() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue