Fix avatars having 0 hp after retreating from a battle

This commit is contained in:
Melledy
2023-10-02 05:51:53 -07:00
parent 30e6aec86c
commit d4d6fc9311

View File

@@ -186,6 +186,8 @@ public class BattleService extends BaseGameService {
// Get battle object and setup variables // Get battle object and setup variables
Battle battle = player.getBattle(); Battle battle = player.getBattle();
int minimumHp = 0; int minimumHp = 0;
boolean updateStatus = true;
boolean teleportToAnchor = false; boolean teleportToAnchor = false;
// Handle result // Handle result
@@ -203,28 +205,32 @@ public class BattleService extends BaseGameService {
} }
case BATTLE_END_QUIT -> { case BATTLE_END_QUIT -> {
teleportToAnchor = true; teleportToAnchor = true;
updateStatus = false;
} }
default -> { default -> {
updateStatus = false;
} }
} }
// Set health/energy for player avatars // Check if avatar hp/sp should be updated after a battle
for (var battleAvatar : battleAvatars) { if (updateStatus) {
GameAvatar avatar = player.getAvatarById(battleAvatar.getId()); // Set health/energy for player avatars
if (avatar == null) continue; for (var battleAvatar : battleAvatars) {
GameAvatar avatar = player.getAvatarById(battleAvatar.getId());
if (avatar == null) continue;
AvatarProperty prop = battleAvatar.getAvatarStatus(); AvatarProperty prop = battleAvatar.getAvatarStatus();
int currentHp = (int) Math.round((prop.getLeftHp() / prop.getMaxHp()) * 100); int currentHp = (int) Math.round((prop.getLeftHp() / prop.getMaxHp()) * 100);
int currentSp = (int) prop.getLeftSp() * 100; int currentSp = (int) prop.getLeftSp() * 100;
avatar.setCurrentHp(Math.max(currentHp, minimumHp)); avatar.setCurrentHp(Math.max(currentHp, minimumHp));
avatar.setCurrentSp(Math.max(currentSp, 0)); avatar.setCurrentSp(Math.max(currentSp, 0));
avatar.save(); avatar.save();
}
// Sync with player
player.sendPacket(new PacketSyncLineupNotify(battle.getLineup()));
} }
// Sync with player
player.sendPacket(new PacketSyncLineupNotify(battle.getLineup()));
// Teleport to anchor if player has lost/retreated. On official servers, the player party is teleported to the nearest anchor. // Teleport to anchor if player has lost/retreated. On official servers, the player party is teleported to the nearest anchor.
if (teleportToAnchor) { if (teleportToAnchor) {