From 65eaaa96f27eb40bfa3580437aa1beb455332ef2 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sat, 16 Sep 2023 18:58:36 -0400 Subject: [PATCH] Apply changes from #2310 --- .../grasscutter/game/entity/EntityAvatar.java | 17 +++++++++-------- .../emu/grasscutter/game/entity/GameEntity.java | 13 ++++++++----- .../grasscutter/game/player/TeamManager.java | 12 +++++------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java b/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java index f5c30a9a9..d33149e3b 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityAvatar.java @@ -88,11 +88,6 @@ public class EntityAvatar extends GameEntity { return getPlayer().getRotation(); } - @Override - public boolean isAlive() { - return this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) > 0f; - } - @Override public Int2FloatMap getFightProperties() { return getAvatar().getFightProperties(); @@ -137,13 +132,19 @@ public class EntityAvatar extends GameEntity { @Override public float heal(float amount, boolean mute) { - // Do not heal character if they are dead - if (!this.isAlive()) { + // Do not heal character if they are dead. + var currentHp = this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP); + if (currentHp <= 0) { return 0f; } - float healed = super.heal(amount, mute); + // Check if the character hasn't been marked as dead. + if (currentHp > 0 && this.isDead()) { + this.setDead(false); + mute = false; + } + float healed = super.heal(amount, mute); if (healed > 0f) { getScene() .broadcastPacket( diff --git a/src/main/java/emu/grasscutter/game/entity/GameEntity.java b/src/main/java/emu/grasscutter/game/entity/GameEntity.java index 3574825af..b7320f57c 100644 --- a/src/main/java/emu/grasscutter/game/entity/GameEntity.java +++ b/src/main/java/emu/grasscutter/game/entity/GameEntity.java @@ -15,9 +15,10 @@ import emu.grasscutter.scripts.data.controller.EntityController; import emu.grasscutter.server.event.entity.*; import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; import it.unimi.dsi.fastutil.ints.*; -import java.util.*; import lombok.*; +import java.util.*; + public abstract class GameEntity { @Getter private final Scene scene; @Getter protected int id; @@ -33,6 +34,9 @@ public abstract class GameEntity { @Getter @Setter private boolean lockHP; + @Setter(AccessLevel.PROTECTED) + @Getter private boolean isDead = false; + // Lua controller for specific actions @Getter @Setter private EntityController entityController; @Getter private ElementType lastAttackType = ElementType.None; @@ -63,7 +67,7 @@ public abstract class GameEntity { } public boolean isAlive() { - return true; + return !this.isDead; } public LifeState getLifeState() { @@ -172,10 +176,9 @@ public abstract class GameEntity { this.lastAttackType = attackType; // Check if dead - boolean isDead = false; if (this.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) <= 0f) { this.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 0f); - isDead = true; + this.isDead = true; } this.runLuaCallbacks(event); @@ -186,7 +189,7 @@ public abstract class GameEntity { new PacketEntityFightPropUpdateNotify(this, FightProperty.FIGHT_PROP_CUR_HP)); // Check if dead. - if (isDead) { + if (this.isDead) { this.getScene().killEntity(this, killerId); } } diff --git a/src/main/java/emu/grasscutter/game/player/TeamManager.java b/src/main/java/emu/grasscutter/game/player/TeamManager.java index f6a038e31..be298ba38 100644 --- a/src/main/java/emu/grasscutter/game/player/TeamManager.java +++ b/src/main/java/emu/grasscutter/game/player/TeamManager.java @@ -1,7 +1,5 @@ package emu.grasscutter.game.player; -import static emu.grasscutter.config.Configuration.GAME_OPTIONS; - import dev.morphia.annotations.*; import emu.grasscutter.*; import emu.grasscutter.data.GameData; @@ -23,9 +21,12 @@ import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.Utils; import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import lombok.*; + import java.util.*; import java.util.stream.Stream; -import lombok.*; + +import static emu.grasscutter.config.Configuration.GAME_OPTIONS; @Entity public final class TeamManager extends BasePlayerDataManager { @@ -798,10 +799,7 @@ public final class TeamManager extends BasePlayerDataManager { public void onAvatarDie(long dieGuid) { EntityAvatar deadAvatar = this.getCurrentAvatarEntity(); - - if (deadAvatar.isAlive() || deadAvatar.getId() != dieGuid) { - return; - } + if (deadAvatar == null || deadAvatar.getId() != dieGuid) return; PlayerDieType dieType = deadAvatar.getKilledType(); int killedBy = deadAvatar.getKilledBy();