From 17f0d8e33e45ce02e712459ceec65974597180cc Mon Sep 17 00:00:00 2001 From: Dan Bjorge Date: Sat, 18 Apr 2020 12:16:16 -0700 Subject: [PATCH] Avoid NPE in isInCombat checks --- src/main/java/stsjorbsmod/audio/VoiceoverMaster.java | 3 ++- .../stsjorbsmod/patches/CardUpgradeGlowCheckPatch.java | 6 ++---- src/main/java/stsjorbsmod/patches/OnModifyGoldPatch.java | 5 ++--- src/main/java/stsjorbsmod/util/CombatUtils.java | 7 +++++++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/stsjorbsmod/audio/VoiceoverMaster.java b/src/main/java/stsjorbsmod/audio/VoiceoverMaster.java index bfb35b87d..a9a150ab3 100644 --- a/src/main/java/stsjorbsmod/audio/VoiceoverMaster.java +++ b/src/main/java/stsjorbsmod/audio/VoiceoverMaster.java @@ -16,6 +16,7 @@ import com.megacrit.cardcrawl.rooms.MonsterRoom; import stsjorbsmod.JorbsMod; import stsjorbsmod.patches.VoiceoverMasterPatch; +import stsjorbsmod.util.CombatUtils; import java.util.ArrayList; import java.util.HashMap; @@ -128,7 +129,7 @@ private static VoiceoverInfo getSfxByKey(String key) { } private static VoiceoverInfo getSfxByCurrentBattle() { - if (AbstractDungeon.getCurrRoom() == null || AbstractDungeon.getCurrRoom().monsters == null) { + if (!CombatUtils.isInCombat() || AbstractDungeon.getCurrRoom().monsters == null) { return null; } String encounterKey = VoiceoverMasterPatch.MonsterGroup_class.encounterKeyField.get(AbstractDungeon.getCurrRoom().monsters); diff --git a/src/main/java/stsjorbsmod/patches/CardUpgradeGlowCheckPatch.java b/src/main/java/stsjorbsmod/patches/CardUpgradeGlowCheckPatch.java index 3e7147746..8e1e1ae39 100644 --- a/src/main/java/stsjorbsmod/patches/CardUpgradeGlowCheckPatch.java +++ b/src/main/java/stsjorbsmod/patches/CardUpgradeGlowCheckPatch.java @@ -5,6 +5,7 @@ import com.megacrit.cardcrawl.cards.AbstractCard; import com.megacrit.cardcrawl.dungeons.AbstractDungeon; import com.megacrit.cardcrawl.rooms.AbstractRoom; +import stsjorbsmod.util.CombatUtils; // This is for the benefit of the interaction between Warped Tongs and Mania's glow check public class CardUpgradeGlowCheckPatch { @@ -17,10 +18,7 @@ public static class AbstractCard_upgradeName @SpirePostfixPatch public static void patch(AbstractCard __this) { - if (AbstractDungeon.player != null && - AbstractDungeon.player.hand != null && - AbstractDungeon.getCurrRoom() != null && - AbstractDungeon.getCurrRoom().phase == AbstractRoom.RoomPhase.COMBAT) + if (AbstractDungeon.player != null && AbstractDungeon.player.hand != null && CombatUtils.isInCombat()) { AbstractDungeon.player.hand.glowCheck(); } diff --git a/src/main/java/stsjorbsmod/patches/OnModifyGoldPatch.java b/src/main/java/stsjorbsmod/patches/OnModifyGoldPatch.java index 978e8b14a..36568f399 100644 --- a/src/main/java/stsjorbsmod/patches/OnModifyGoldPatch.java +++ b/src/main/java/stsjorbsmod/patches/OnModifyGoldPatch.java @@ -9,12 +9,11 @@ import stsjorbsmod.memories.AbstractMemory; import stsjorbsmod.memories.MemoryManager; import stsjorbsmod.powers.OnModifyGoldSubscriber; +import stsjorbsmod.util.CombatUtils; public class OnModifyGoldPatch { private static void notifyModifyGold(AbstractPlayer player) { - if (AbstractDungeon.currMapNode != null && - AbstractDungeon.getCurrRoom() != null && - AbstractDungeon.getCurrRoom().phase == AbstractRoom.RoomPhase.COMBAT) + if (CombatUtils.isInCombat()) { for (AbstractPower p : player.powers) { if (p instanceof OnModifyGoldSubscriber) { diff --git a/src/main/java/stsjorbsmod/util/CombatUtils.java b/src/main/java/stsjorbsmod/util/CombatUtils.java index 92978999a..02531469d 100644 --- a/src/main/java/stsjorbsmod/util/CombatUtils.java +++ b/src/main/java/stsjorbsmod/util/CombatUtils.java @@ -5,6 +5,7 @@ import com.megacrit.cardcrawl.monsters.MonsterGroup; import com.megacrit.cardcrawl.powers.MinionPower; import com.megacrit.cardcrawl.random.Random; +import com.megacrit.cardcrawl.rooms.AbstractRoom; import java.util.ArrayList; import java.util.List; @@ -36,4 +37,10 @@ public static AbstractMonster getRandomMonster(MonsterGroup group, Predicate