Skip to content

Commit

Permalink
Avoid NPE in isInCombat checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dbjorge committed Apr 18, 2020
1 parent a21f3ec commit 17f0d8e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/main/java/stsjorbsmod/audio/VoiceoverMaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/stsjorbsmod/patches/OnModifyGoldPatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/stsjorbsmod/util/CombatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,4 +37,10 @@ public static AbstractMonster getRandomMonster(MonsterGroup group, Predicate<Abs
}
return candidates.get(rng.random(0, candidates.size() - 1));
}

public static boolean isInCombat() {
return (AbstractDungeon.currMapNode != null &&
AbstractDungeon.getCurrRoom() != null &&
AbstractDungeon.getCurrRoom().phase == AbstractRoom.RoomPhase.COMBAT);
}
}

0 comments on commit 17f0d8e

Please sign in to comment.