mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-23 10:44:36 +01:00
Implement reserve stamina
This commit is contained in:
@@ -72,6 +72,7 @@ public class Player {
|
||||
private int talentPoints; // Rogue talent points
|
||||
|
||||
private int stamina;
|
||||
private double staminaReserve;
|
||||
private long nextStaminaRecover;
|
||||
|
||||
private transient Battle battle;
|
||||
@@ -130,6 +131,7 @@ public class Player {
|
||||
this.headIcon = 200001;
|
||||
this.level = 1;
|
||||
this.stamina = GameConstants.MAX_STAMINA;
|
||||
this.nextStaminaRecover = System.currentTimeMillis();
|
||||
|
||||
this.unlockedHeadIcons = new IntOpenHashSet();
|
||||
this.lineupManager = new LineupManager(this);
|
||||
@@ -367,6 +369,20 @@ public class Player {
|
||||
this.sendPacket(new PacketStaminaInfoScNotify(this));
|
||||
}
|
||||
|
||||
public int exchangeReserveStamina(int amount) {
|
||||
// Sanity checks
|
||||
if (amount <= 0 || this.staminaReserve < amount) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
this.staminaReserve -= amount;
|
||||
this.stamina += amount;
|
||||
|
||||
// Update to client
|
||||
this.sendPacket(new PacketStaminaInfoScNotify(this));
|
||||
return amount;
|
||||
}
|
||||
|
||||
private void updateStamina() {
|
||||
// Get current timestamp
|
||||
long time = System.currentTimeMillis();
|
||||
@@ -378,12 +394,17 @@ public class Player {
|
||||
if (this.stamina < GameConstants.MAX_STAMINA) {
|
||||
this.stamina += 1;
|
||||
hasChanged = true;
|
||||
} else if (this.stamina < GameConstants.MAX_STAMINA_RESERVE) {
|
||||
double amount = (time - this.nextStaminaRecover) / (18D * 60D * 1000D);
|
||||
this.staminaReserve = Math.min(this.staminaReserve + amount, GameConstants.MAX_STAMINA_RESERVE);
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
// Calculate next stamina recover time
|
||||
if (this.stamina >= GameConstants.MAX_STAMINA) {
|
||||
this.nextStaminaRecover = time;
|
||||
}
|
||||
|
||||
this.nextStaminaRecover += 5 * 60 * 1000;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import emu.lunarcore.proto.ReserveStaminaExchangeCsReqOuterClass.ReserveStaminaExchangeCsReq;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
import emu.lunarcore.server.packet.send.PacketReserveStaminaExchangeScRsp;
|
||||
|
||||
@Opcodes(CmdId.ReserveStaminaExchangeCsReq)
|
||||
public class HandlerReserveStaminaExchangeCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
||||
var req = ReserveStaminaExchangeCsReq.parseFrom(data);
|
||||
|
||||
int exchangedAmount = session.getPlayer().exchangeReserveStamina(req.getNum());
|
||||
session.send(new PacketReserveStaminaExchangeScRsp(exchangedAmount));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.proto.ReserveStaminaExchangeScRspOuterClass.ReserveStaminaExchangeScRsp;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketReserveStaminaExchangeScRsp extends BasePacket {
|
||||
|
||||
public PacketReserveStaminaExchangeScRsp(int amount) {
|
||||
super(CmdId.ReserveStaminaExchangeScRsp);
|
||||
|
||||
var data = ReserveStaminaExchangeScRsp.newInstance();
|
||||
|
||||
if (amount > 0) {
|
||||
data.setNum(amount);
|
||||
} else {
|
||||
data.setRetcode(1);
|
||||
}
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,8 @@ public class PacketStaminaInfoScNotify extends BasePacket {
|
||||
|
||||
var data = StaminaInfoScNotify.newInstance()
|
||||
.setNextRecoverTime(player.getNextStaminaRecover() / 1000)
|
||||
.setStamina(player.getStamina());
|
||||
.setStamina(player.getStamina())
|
||||
.setReserveStamina((int) Math.floor(player.getStaminaReserve()));
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user