mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 18:56:15 +00:00
Send periodic notifications to the client for ongoing forges.
This commit is contained in:
parent
4b77e84e81
commit
9a313e50eb
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user