From 635e342a3dc6edbf38cbff805bf7ff7d619d4ba2 Mon Sep 17 00:00:00 2001 From: ImmuState Date: Sun, 29 May 2022 16:37:39 -0700 Subject: [PATCH] Make sure the hit target is actually a monster. --- .../managers/EnergyManager/EnergyManager.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/managers/EnergyManager/EnergyManager.java b/src/main/java/emu/grasscutter/game/managers/EnergyManager/EnergyManager.java index 1f18252e3..e6b0c94d3 100644 --- a/src/main/java/emu/grasscutter/game/managers/EnergyManager/EnergyManager.java +++ b/src/main/java/emu/grasscutter/game/managers/EnergyManager/EnergyManager.java @@ -45,6 +45,8 @@ import com.google.protobuf.InvalidProtocolBufferException; public class EnergyManager { private final Player player; + private final Map avatarNormalProbabilities; + private final static Int2ObjectMap> energyDropData = new Int2ObjectOpenHashMap<>(); private final static Int2ObjectMap> skillParticleGenerationData = new Int2ObjectOpenHashMap<>(); @@ -257,8 +259,6 @@ public class EnergyManager { entry("WEAPON_CATALYST", 10) ); - private final Map avatarNormalProbabilities; - private void generateEnergyForNormalAndCharged(EntityAvatar avatar) { // This logic is based on the descriptions given in // https://genshin-impact.fandom.com/wiki/Energy#Energy_Generated_by_Normal_Attacks @@ -304,6 +304,18 @@ public class EnergyManager { if (attackerEntity.isEmpty() || this.player.getTeamManager().getCurrentAvatarEntity().getId() != attackerEntity.get().getId()) { return; } + + // Make sure the target is an actual enemy. + GameEntity targetEntity = this.player.getScene().getEntityById(attackRes.getDefenseId()); + if (!(targetEntity instanceof EntityMonster)) { + return; + } + + EntityMonster targetMonster = (EntityMonster)targetEntity; + String targetType = targetMonster.getMonsterData().getType(); + if (!targetType.equals("MONSTER_ORDINARY") && !targetType.equals("MONSTER_BOSS")) { + return; + } // Get the ability that caused this hit. AbilityIdentifier ability = attackRes.getAbilityIdentifier();