Yeah, I was pretty confident, but not 100% that what Rob was saying was what is going. It is just funky because it automagically runs again in new client, where I think in old client, if you hold shift, it wont run again until you release and press shift again(after depletion and regen). So it was more hidden before.
But the server probably sends out the regen and subtraction at the same time and does not null each other out, so regen probably sends after subtraction, or at the same time and doesn't handle both like that. And if server only sends regen amount to client every second, then you have a full second to use before it fixes that tiny amount.
But also, I dont have the code in front of my face, so this is all speculation : D
Im not sure this is so much a bug, but a fluidity of gameplay annoyance. But well worth noting and pushing a fix for. Maybe IF energy depleted, turn run toggle off.
Maybe something like this?
class Player {
private:
bool isRunning;
int runEnergy;
public:
Player() : isRunning(false), runEnergy(100) {}
void toggleRun() {
isRunning = !isRunning;
std::cout << "Run toggled " << (isRunning ? "on" : "off") << std::endl;
}
void updateRunEnergy() {
if (isRunning) {
runEnergy -= 1;
if (runEnergy <= 0) {
runEnergy = 0;
if (isRunning) {
toggleRun();
std::cout << "Run energy depleted. Run automatically turned off." << std::endl;
}
}
}
}
void displayStatus() {
std::cout << "Running: " << (isRunning ? "Yes" : "No") << std::endl;
std::cout << "Run Energy: " << runEnergy << std::endl;
}
};
int main() {
Player player;
// Simulate running until energy is depleted
player.toggleRun();
for (int i = 0; i < 105; ++i) {
player.updateRunEnergy();
if (i % 10 == 0) {
player.displayStatus();
}
}
return 0;
}