From 2adff270449cc4a0730fd47f20c99cd5f250f988 Mon Sep 17 00:00:00 2001 From: tool4ever Date: Wed, 5 Apr 2023 23:51:40 +0200 Subject: [PATCH] Fix NPE (#2839) * Fix NPE * TapsForMana Fix --- .../game/ability/effects/ManaEffect.java | 2 +- .../ability/effects/ManaReflectedEffect.java | 2 +- .../java/forge/game/card/CardProperty.java | 24 +++++++++---------- .../res/cardsfolder/b/bridge_from_below.txt | 4 ++-- forge-gui/res/cardsfolder/g/genesis.txt | 2 +- .../res/cardsfolder/t/thunderblade_charge.txt | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/forge-game/src/main/java/forge/game/ability/effects/ManaEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ManaEffect.java index 1a56a2150d8..26edbb27b5c 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ManaEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ManaEffect.java @@ -245,7 +245,7 @@ public class ManaEffect extends SpellAbilityEffect { producedMana.append(abMana.produceMana(mana, p, sa)); } - abMana.tapsForMana(sa, producedMana.toString()); + abMana.tapsForMana(sa.getRootAbility(), producedMana.toString()); // Only clear express choice after mana has been produced abMana.clearExpressChoice(); diff --git a/forge-game/src/main/java/forge/game/ability/effects/ManaReflectedEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ManaReflectedEffect.java index 32911571321..349a94a8d7a 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ManaReflectedEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ManaReflectedEffect.java @@ -33,7 +33,7 @@ public class ManaReflectedEffect extends SpellAbilityEffect { producedMana.append(ma.produceMana(generated, player, sa)); } - ma.tapsForMana(sa, producedMana.toString()); + ma.tapsForMana(sa.getRootAbility(), producedMana.toString()); } // *************** Utility Functions ********************** diff --git a/forge-game/src/main/java/forge/game/card/CardProperty.java b/forge-game/src/main/java/forge/game/card/CardProperty.java index 90073eb56a3..976e6df868b 100644 --- a/forge-game/src/main/java/forge/game/card/CardProperty.java +++ b/forge-game/src/main/java/forge/game/card/CardProperty.java @@ -989,6 +989,18 @@ public class CardProperty { if (card.getTurnInZone() <= sourceController.getLastTurnNr()) { return false; } + } else if (property.startsWith("ThisTurnEnteredFrom")) { + final String restrictions = property.split("ThisTurnEnteredFrom_")[1]; + final String[] res = restrictions.split("_"); + final ZoneType origin = ZoneType.smartValueOf(res[0]); + + if (card.getTurnInZone() != game.getPhaseHandler().getTurn()) { + return false; + } + + if (!card.getZone().isCardAddedThisTurn(card, origin)) { + return false; + } } else if (property.startsWith("ThisTurnEntered")) { // only check if it entered the Zone this turn if (card.getTurnInZone() != game.getPhaseHandler().getTurn()) { @@ -1012,18 +1024,6 @@ public class CardProperty { if (card.getTurnInZone() == game.getPhaseHandler().getTurn()) { return false; } - } else if (property.startsWith("ThisTurnEnteredFrom")) { - final String restrictions = property.split("ThisTurnEnteredFrom_")[1]; - final String[] res = restrictions.split("_"); - final ZoneType origin = ZoneType.smartValueOf(res[0]); - - if (card.getTurnInZone() != game.getPhaseHandler().getTurn()) { - return false; - } - - if (!card.getZone().isCardAddedThisTurn(card, origin)) { - return false; - } } else if (property.equals("DiscardedThisTurn")) { if (card.getTurnInZone() != game.getPhaseHandler().getTurn()) { return false; diff --git a/forge-gui/res/cardsfolder/b/bridge_from_below.txt b/forge-gui/res/cardsfolder/b/bridge_from_below.txt index d4a19932634..e93545c1907 100644 --- a/forge-gui/res/cardsfolder/b/bridge_from_below.txt +++ b/forge-gui/res/cardsfolder/b/bridge_from_below.txt @@ -2,9 +2,9 @@ Name:Bridge from Below ManaCost:B B B Types:Enchantment A:SP$ PermanentNoncreature | Cost$ B B B | AILogic$ DontCast -T:Mode$ ChangesZone | Origin$ Battlefield | Destination$ Graveyard | ValidCard$ Creature.nonToken+YouOwn | Execute$ TrigToken | TriggerZones$ Graveyard | TriggerDescription$ Whenever a nontoken creature is put into your graveyard from the battlefield, if CARDNAME is in your graveyard, create a 2/2 black Zombie creature token. +T:Mode$ ChangesZone | Origin$ Battlefield | Destination$ Graveyard | ValidCard$ Creature.nonToken+YouOwn | Execute$ TrigToken | IsPresent$ Card.StrictlySelf | PresentZone$ Graveyard | TriggerZones$ Graveyard | TriggerDescription$ Whenever a nontoken creature is put into your graveyard from the battlefield, if CARDNAME is in your graveyard, create a 2/2 black Zombie creature token. SVar:TrigToken:DB$ Token | TokenAmount$ 1 | TokenScript$ b_2_2_zombie | TokenOwner$ You -T:Mode$ ChangesZone | Origin$ Battlefield | Destination$ Graveyard | TriggerZones$ Graveyard | ValidCard$ Creature.OppOwn | Execute$ TrigChange | TriggerDescription$ When a creature is put into an opponent's graveyard from the battlefield, if CARDNAME is in your graveyard, exile CARDNAME. +T:Mode$ ChangesZone | Origin$ Battlefield | Destination$ Graveyard | ValidCard$ Creature.OppOwn | Execute$ TrigChange | IsPresent$ Card.StrictlySelf | PresentZone$ Graveyard | TriggerZones$ Graveyard | TriggerDescription$ When a creature is put into an opponent's graveyard from the battlefield, if CARDNAME is in your graveyard, exile CARDNAME. SVar:TrigChange:DB$ ChangeZone | Origin$ Graveyard | Destination$ Exile AI:RemoveDeck:Random SVar:DiscardMe:5 diff --git a/forge-gui/res/cardsfolder/g/genesis.txt b/forge-gui/res/cardsfolder/g/genesis.txt index 39de00dce06..4c014a75e4f 100644 --- a/forge-gui/res/cardsfolder/g/genesis.txt +++ b/forge-gui/res/cardsfolder/g/genesis.txt @@ -2,7 +2,7 @@ Name:Genesis ManaCost:4 G Types:Creature Incarnation PT:4/4 -T:Mode$ Phase | Phase$ Upkeep | ValidPlayer$ You | TriggerZones$ Graveyard | Execute$ TrigChange | TriggerDescription$ At the beginning of your upkeep, if CARDNAME is in your graveyard, you may pay {2}{G}. If you do, return target creature card from your graveyard to your hand. +T:Mode$ Phase | Phase$ Upkeep | ValidPlayer$ You | TriggerZones$ Graveyard | PresentZone$ Graveyard | IsPresent$ Card.StrictlySelf | Execute$ TrigChange | TriggerDescription$ At the beginning of your upkeep, if CARDNAME is in your graveyard, you may pay {2}{G}. If you do, return target creature card from your graveyard to your hand. SVar:TrigChange:AB$ ChangeZone | Cost$ 2 G | Origin$ Graveyard | Destination$ Hand | ValidTgts$ Creature.YouCtrl SVar:DiscardMe:2 Oracle:At the beginning of your upkeep, if Genesis is in your graveyard, you may pay {2}{G}. If you do, return target creature card from your graveyard to your hand. diff --git a/forge-gui/res/cardsfolder/t/thunderblade_charge.txt b/forge-gui/res/cardsfolder/t/thunderblade_charge.txt index 58f23394464..f308036f6de 100644 --- a/forge-gui/res/cardsfolder/t/thunderblade_charge.txt +++ b/forge-gui/res/cardsfolder/t/thunderblade_charge.txt @@ -2,6 +2,6 @@ Name:Thunderblade Charge ManaCost:1 R R Types:Sorcery A:SP$ DealDamage | Cost$ 1 R R | ValidTgts$ Creature,Player,Planeswalker | TgtPrompt$ Select any target | NumDmg$ 3 | SpellDescription$ CARDNAME deals 3 damage to any target. -T:Mode$ DamageDoneOnce | CombatDamage$ True | ValidSource$ Creature.YouCtrl | TriggerZones$ Graveyard | ValidTarget$ Player | Execute$ TrigPlay | TriggerDescription$ Whenever one or more creatures you control deal combat damage to a player, if CARDNAME is in your graveyard, you may pay {2}{R}{R}{R}. If you do, you may cast it without paying its mana cost. -SVar:TrigPlay:AB$ Play | Cost$ 2 R R R | ActivationZone$ Graveyard | WithoutManaCost$ True | Optional$ True +T:Mode$ DamageDoneOnce | CombatDamage$ True | ValidSource$ Creature.YouCtrl | ValidTarget$ Player | TriggerZones$ Graveyard | PresentZone$ Graveyard | IsPresent$ Card.StrictlySelf| Execute$ TrigPlay | TriggerDescription$ Whenever one or more creatures you control deal combat damage to a player, if CARDNAME is in your graveyard, you may pay {2}{R}{R}{R}. If you do, you may cast it without paying its mana cost. +SVar:TrigPlay:AB$ Play | Cost$ 2 R R R | WithoutManaCost$ True | Optional$ True Oracle:Thunderblade Charge deals 3 damage to any target.\nWhenever one or more creatures you control deal combat damage to a player, if Thunderblade Charge is in your graveyard, you may pay {2}{R}{R}{R}. If you do, you may cast it without paying its mana cost.