Skip to content

Commit

Permalink
Implement food heal function
Browse files Browse the repository at this point in the history
Co-authored-by: pris <lilch1022@hotmail.com>
  • Loading branch information
2 people authored and Melledy committed May 3, 2022
1 parent 765f569 commit b253e77
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -937,10 +937,20 @@ public GameItem useItem(Player player, long targetGuid, long itemGuid, int count
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;
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/emu/grasscutter/game/player/TeamManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,31 @@ public boolean reviveAvatar(Avatar avatar) {

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()) {
Expand Down

0 comments on commit b253e77

Please sign in to comment.