Skip to content

Commit

Permalink
add null check for game.getPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
jimga150 committed Sep 17, 2024
1 parent 47829a3 commit 475d030
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -44,8 +45,12 @@ public boolean pay(Ability ability, Game game, Ability source, UUID controllerId

@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
Player controller = game.getPlayer(controllerId);
if (controller == null){
return false;
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controllerId, game)) {
if (!game.getPlayer(controllerId).canPaySacrificeCost(permanent, source, controllerId, game)) {
if (!controller.canPaySacrificeCost(permanent, source, controllerId, game)) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -82,10 +83,14 @@ protected void addSacrificeTarget(Game game, Permanent permanent) {

@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
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(controllerId).canPaySacrificeCost(permanent, source, controllerId, game)) {
if (controller.canPaySacrificeCost(permanent, source, controllerId, game)) {
validTargets++;
if (validTargets >= neededTargets) {
return true;
Expand Down

0 comments on commit 475d030

Please sign in to comment.