Skip to content
Snippets Groups Projects
Commit 9a313e50 authored by ImmuState's avatar ImmuState Committed by Melledy
Browse files

Send periodic notifications to the client for ongoing forges.

parent 4b77e84e
Branches
Tags
No related merge requests found
......@@ -11,11 +11,9 @@ public class ActiveForgeData {
private int startTime;
private int forgeTime;
// private int finishedCount;
// private int unfinishedCount;
// private int nextFinishTimestamp;
// private int totalFinishTimestamp;
private int lastUnfinishedCount;
private boolean changed;
public int getFinishedCount(int currentTime) {
int timeDelta = currentTime - this.startTime;
......@@ -73,4 +71,22 @@ public class ActiveForgeData {
public void setForgeTime(int value) {
this.forgeTime = value;
}
public boolean isChanged() {
return this.changed;
}
public void setChanged(boolean value) {
this.changed = value;
}
public boolean updateChanged(int currentTime) {
int currentUnfinished = this.getUnfinishedCount(currentTime);
if (currentUnfinished != this.lastUnfinishedCount) {
this.changed = true;
this.lastUnfinishedCount = currentUnfinished;
}
return this.changed;
}
}
......@@ -5,6 +5,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.mongodb.QueryBuilder;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData;
......@@ -289,4 +291,34 @@ public class ForgingManager {
break; //Should never happen.
}
}
/**********
Periodic forging updates.
**********/
public void sendPlayerForgingUpdate() {
int currentTime = Utils.getCurrentSeconds();
// Determine if sending an update is necessary.
// We only send an update if there are forges in the forge queue
// that have changed since the last notification.
if (this.player.getActiveForges().size() <= 0) {
return;
}
boolean hasChanges = this.player.getActiveForges().stream()
.filter(forge -> forge.updateChanged(currentTime))
.findAny()
.isPresent();
if (!hasChanges) {
return;
}
// Send notification.
this.sendForgeQueueDataNotify();
// Reset changed flags.
this.player.getActiveForges().stream()
.forEach(forge -> forge.setChanged(false));
}
}
......@@ -1194,6 +1194,9 @@ public class Player {
this.save();
this.sendPacket(new PacketAvatarExpeditionDataNotify(this));
}
// Send updated forge queue data, if necessary.
this.getForgingManager().sendPlayerForgingUpdate();
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment