Improved satiation (#2055)

* Natural satiation decreasing
Graphic showing satiation when eating (usually)

* Reworking values to match original

* Little fixes

* Satiation bar matches real values
Revival correctly updates bar

* Greatly simplify handling
Some fixes

* Inline variables
Add TODO for bug

* Satiation works correctly
Finally it all works as intended

* Remove unnecessary packets

* Improve satiation reduction handling
This commit is contained in:
Thoronium
2023-02-15 17:32:59 -07:00
committed by GitHub
parent b4b8f1ec38
commit 1b2210f5a7
10 changed files with 1772 additions and 14 deletions

View File

@@ -1,5 +1,7 @@
package emu.grasscutter.server.packet.send;
import java.util.Map;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.net.packet.BasePacket;
@@ -9,19 +11,19 @@ import emu.grasscutter.net.proto.AvatarPropNotifyOuterClass.AvatarPropNotify;
public class PacketAvatarPropNotify extends BasePacket {
public PacketAvatarPropNotify(Avatar avatar) {
super(PacketOpcodes.AvatarPropNotify);
AvatarPropNotify proto = AvatarPropNotify.newBuilder()
.setAvatarGuid(avatar.getGuid())
.putPropMap(PlayerProperty.PROP_LEVEL.getId(), avatar.getLevel())
.putPropMap(PlayerProperty.PROP_EXP.getId(), avatar.getExp())
.putPropMap(PlayerProperty.PROP_BREAK_LEVEL.getId(), avatar.getPromoteLevel())
.putPropMap(PlayerProperty.PROP_SATIATION_VAL.getId(), 0)
.putPropMap(PlayerProperty.PROP_SATIATION_PENALTY_TIME.getId(), 0)
.putPropMap(PlayerProperty.PROP_SATIATION_VAL.getId(), avatar.getSatiation())
.putPropMap(PlayerProperty.PROP_SATIATION_PENALTY_TIME.getId(), avatar.getSatiationPenalty())
.build();
this.setData(proto);
}
public PacketAvatarPropNotify(Avatar avatar, PlayerProperty prop, int value) {
super(PacketOpcodes.AvatarPropNotify);
@@ -29,7 +31,18 @@ public class PacketAvatarPropNotify extends BasePacket {
.setAvatarGuid(avatar.getGuid())
.putPropMap(prop.getId(), value)
.build();
this.setData(proto);
}
public PacketAvatarPropNotify(Avatar avatar, Map<Integer, Long> propMap) {
super(PacketOpcodes.AvatarPropNotify);
AvatarPropNotify proto = AvatarPropNotify.newBuilder()
.setAvatarGuid(avatar.getGuid())
.putAllPropMap(propMap)
.build();
this.setData(proto);
}
}

View File

@@ -0,0 +1,48 @@
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.net.proto.AvatarSatiationDataNotifyOuterClass.AvatarSatiationDataNotify;
import emu.grasscutter.net.proto.AvatarSatiationDataOuterClass.AvatarSatiationData;
public class PacketAvatarSatiationDataNotify extends BasePacket {
public PacketAvatarSatiationDataNotify(Avatar avatar, float finishTime, long penaltyTime) {
super(PacketOpcodes.AvatarSatiationDataNotify);
AvatarSatiationData.Builder avatarSatiation = AvatarSatiationData.newBuilder()
.setAvatarGuid(avatar.getGuid())
.setFinishTime(finishTime);
// Penalty for overeating
if (penaltyTime > 0) {
avatarSatiation.setPenaltyFinishTime(penaltyTime);
}
avatarSatiation.build();
AvatarSatiationDataNotify notify = AvatarSatiationDataNotify.newBuilder()
.addSatiationDataList(0, avatarSatiation)
.build();
this.setData(notify);
}
public PacketAvatarSatiationDataNotify(float time, Avatar avatar) {
super(PacketOpcodes.AvatarSatiationDataNotify);
var avatarSatiation = AvatarSatiationData.newBuilder()
.setAvatarGuid(avatar.getGuid())
.setFinishTime(time + (avatar.getSatiation() / 30f))
// Penalty time always ends before finish time
.setPenaltyFinishTime(time + (avatar.getSatiationPenalty() / 100f))
.build();
AvatarSatiationDataNotify notify = AvatarSatiationDataNotify.newBuilder()
.addSatiationDataList(0, avatarSatiation)
.build();
this.setData(notify);
}
}