From b253e779a2c49a8e185dbe3c82792b8c1bff40b5 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 3 May 2022 12:07:41 +0800 Subject: [PATCH] Implement food heal function Co-authored-by: pris --- .../game/managers/InventoryManager.java | 12 ++++++++- .../grasscutter/game/player/TeamManager.java | 26 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java index 6fef8afc4..55663b844 100644 --- a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java +++ b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java @@ -937,10 +937,20 @@ public class InventoryManager { if (target == null) { break; } - + used = player.getTeamManager().reviveAvatar(target) ? 1 : 0; } break; + case MATERIAL_NOTICE_ADD_HP: + if (useItem.getItemData().getUseTarget().equals("ITEM_USE_TARGET_SPECIFY_ALIVE_AVATAR")) { + if (target == null) { + break; + } + + int[] SatiationParams = useItem.getItemData().getSatiationParams(); + used = player.getTeamManager().healAvatar(target, SatiationParams[0], SatiationParams[1]) ? 1 : 0; + } + break; case MATERIAL_CHEST: if (useItem.getRewardBoxId() > 0) { used = handleRewardBox(player, useItem) ? 1 : 0; diff --git a/src/main/java/emu/grasscutter/game/player/TeamManager.java b/src/main/java/emu/grasscutter/game/player/TeamManager.java index 84ee38424..b67e9898e 100644 --- a/src/main/java/emu/grasscutter/game/player/TeamManager.java +++ b/src/main/java/emu/grasscutter/game/player/TeamManager.java @@ -457,7 +457,31 @@ public class TeamManager { return false; } - + + public boolean healAvatar(Avatar avatar, int healRate, int healAmount) { + for (EntityAvatar entity : getActiveTeam()) { + if (entity.getAvatar() == avatar) { + if (!entity.isAlive()) { + return false; + } + + entity.setFightProperty( + FightProperty.FIGHT_PROP_CUR_HP, + (float) Math.min( + (entity.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) + + entity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) * (float) healRate / 100.0 + + (float) healAmount / 100.0), + entity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) + ) + ); + getPlayer().sendPacket(new PacketAvatarFightPropUpdateNotify(entity.getAvatar(), FightProperty.FIGHT_PROP_CUR_HP)); + getPlayer().sendPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar())); + return true; + } + } + return false; + } + public void respawnTeam() { // Make sure all team members are dead for (EntityAvatar entity : getActiveTeam()) {